# Dealspace Coding Guide

## Build & Test

```bash
make build              # Local build
make build-linux        # Linux/amd64 with CGO + fts5
make test               # Run all tests
CGO_ENABLED=1 go test -tags fts5 ./lib -run TestPackUnpack -v  # Single test
```

## Code Style

- **Format**: `gofmt` (standard Go formatting)
- **Imports**: stdlib → third-party → internal (github.com/mish/dealspace)
- **Types**: Use JSON tags with `snake_case`, e.g., `EntryID string `json:"entry_id"``
- **Naming**: PascalCase for exported, camelCase for unexported; constants use prefix like `TypeProject`, `StageDataroom`
- **Errors**: Wrap with `fmt.Errorf("context: %w", err)`; check sentinel errors with `==`

## Architecture Rules

**Database access ONLY through three choke points in `lib/dbcore.go`:**
- `EntryRead(db, cfg, actorID, projectID, filter)` — all reads
- `EntryWrite(db, cfg, actorID, entries...)` — all writes  
- `EntryDelete(db, actorID, projectID, entryIDs...)` — all deletes

**FORBIDDEN:** `db.Exec()`, `db.Query()`, `db.QueryRow()` outside dbcore.go; wrapper functions bypassing choke points; modifications to dbcore.go without explicit approval.

`actorID=""` = system/internal access (always granted). RBAC enforced at DB level, not UI.

## Tech Stack

Go 1.24, SQLite with mattn/go-sqlite3 (CGO required), chi router, uuid, pdfcpu, excelize, golang.org/x/crypto
