Development Guide
Prerequisites
- Docker + Docker Compose (full-stack development), or
- Go 1.25+, Node 22+ (
enginesinpackage.json), and PostgreSQL 16 for standalone development make(all common tasks are Makefile targets —make helplists them)
Setup — Docker Compose (recommended)
make doctor # node 22+, npm, Docker daemon and image store — fix anything red first
make setup # copies .env.example to .env, npm install, Studio build
make up # API + PostgreSQL + Redis + frontend
make logs # tail all logs
# Frontend: http://localhost:3000
# API: http://localhost:8080
make up rebuilds the images from this checkout, starts the stack, and the
development API container applies every pending migration with the ledger
runner (cmd/migrate, ADR-0167) before it serves. It then waits for the API and
seeds the three development accounts (local only — known public passwords;
the seed is idempotent). Run it again at any time.
The stack's Compose project is cardsite, so its containers, images and
volumes never mix with another folder called platform. To start over from
nothing (destroys local data): make fresh.
Setup — standalone (without Docker)
# 1. PostgreSQL
docker run --name cardsite-pg -e POSTGRES_USER=cardsite -e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=cardsite_db -p 5432:5432 -d postgres:16
# 2. Apply migrations (the binary does NOT auto-run them)
cd apps/api
for f in migrations/*.up.sql; do
psql postgres://cardsite:password@localhost:5432/cardsite_db -f "$f"
done
# 3. Backend
cat > .env <<EOF
DATABASE_URL=postgres://cardsite:password@localhost:5432/cardsite_db
JWT_SECRET=$(openssl rand -hex 32)
PORT=8080
EOF
go run ./cmd/server
# 4. Frontend (separate terminal)
cd apps/web
npm install
npm run dev # → http://localhost:3000
Everyday commands
make help lists every command, grouped (Start, Check, Build, Staging,
Database, Production); the Makefile is the one place they are defined. The
ones used daily:
make up / make down # Docker dev stack on :3000 / :8080
make staging # the staging topology without Docker, smoke-tested
make test # Go, web and toolkit unit tests (no Docker)
make validate # the merge gate
make fresh # DESTROY the dev stack's data and images, then make up
Testing
cd apps/api && go test ./... # Go unit tests (handlers/services/repos with mocks)
cd apps/api && go vet ./... # static analysis
cd apps/web && npx tsc --noEmit # TypeScript check
cd apps/web && npm run build # production build
cd apps/web && npm run storybook # component dev environment on :6006
cd apps/web && npm run test:visual # Playwright visual regression
cd apps/web && npm run test:visual:update # update baseline snapshots
k6 run scripts/load-test.js # load test against /l/{url} and /b/{url}
The merge gate is local:
npm run verify # studio build+lint, 29 parity gates, unit tests, web build
cd apps/api && go vet ./... && go test ./... # when apps/api changed
CI (.github/workflows/ci.yml) runs six jobs on every pull request — Go
vet/test/staticcheck against a migrated PostgreSQL, frontend typecheck, unit
tests and build, Playwright E2E (stub suite and live suite) against a live
stack, migration lint (sequential numbering + matching .down.sql files),
OpenAPI client-route coverage, and the Studio build/lint/dist-staleness check
followed by the whole of npm run verify. The merge gate is local verify
green and every check green; the policy is stated once, in
ROADMAP.md → Standing policy.
Dependabot's minor and patch updates arrive grouped, one pull request per
ecosystem per week, and .github/workflows/dependabot-auto-merge.yml
squash-merges each one after the CI workflow passes on its head. A major
version bump is opened on its own and is never auto-merged.
Database changes
- Add
apps/api/migrations/NNNNNN_description.up.sqland a matching.down.sqlat the next sequential number, no gaps (the number is stated once, in ROADMAP.md; checkapps/api/migrations/). - Apply manually:
psql $DATABASE_URL -f apps/api/migrations/NNNNNN_description.up.sql. - Never renumber or edit the SQL of an already-applied migration.
Building for production
cd apps/web && npm run build # → apps/web/dist/
cd apps/api && go build -o ../../cardsite-api ./cmd/server
Deployment (systemd + Caddy), environment variables, backups, and DR are covered in DEPLOYMENT.md.
Ports
| Context | Frontend | API |
|---|---|---|
| Docker Compose / standalone default | 3000 | 8080 |
Production (operator-one) | served by Caddy | 18810 (PORT in .env.production) |
Troubleshooting
| Symptom | Fix |
|---|---|
| API 500s on fresh DB | Migrations not applied — make up applies them; if that fails, make fresh |
| Widespread 500s (links, domains, languages, PWAs, referrals) and every create fails | Database volume was initialized before v1.0.0 (stale partial schema). The API now refuses to start in this state and logs the fix. Start over: make fresh (destroys local data) |
API container restart-loops with DATABASE SCHEMA OUT OF DATE | Working as intended — the schema guard detected a stale/partial database. Run make fresh (destroys local data) |
| Frontend can't reach API in Docker | Vite dev server proxies /api → http://api:8080; ensure the api container is healthy (make ps) |
JWT_SECRET startup error | Secret must be ≥ 32 characters — openssl rand -hex 32 |
| Redis warnings | Redis is optional; the API falls back gracefully when REDIS_URL is unset |
Repository checks
| Command | Holds |
|---|---|
make validate | The merge gate: npm run verify (Studio build and lint, the parity gates, web unit tests, web build, toolkit), Go vet and tests, dev logins, generated pages, Studio 2.2, Icons, marketing, the Apple static checks |
make check (npm run check:station) | station check at Level 2: root shape, five-section README, manifest, every job's eight headings, the CONTENT rules, generated design tokens (docs/guides/station.md) |
node .github/check.mjs --fix | Regenerates public/design/tokens.{json,css} from .station/modules/studio-system/system.json and creates empty required directories |
make site (npm run public:build, the root page, the toolkit) | Copies Studio's stylesheet, behaviour layer and fonts into public/; npm run public:check fails on drift |
.github/check.mjs finds the checker in this order: $STATION_CLI, a sibling
checkout at ../station/src/cli.js, a global station, then
npx @stationprotocol/station.
When the machine, not the repository, is the problem
| Symptom | Cause | Fix |
|---|---|---|
npm warn install-scripts … esbuild … blocked | npm 12 refuses install scripts it has not been told to trust; without esbuild's postinstall, Vite and npm run verify fail | npm install-scripts approve esbuild fsevents then npm install (make setup does this) |
make up builds then dies at FROM golang:… failed to register layer: … file exists | Docker Desktop's layer database holds a half-written layer from an interrupted pull; every later pull of that image trips on it | Quit and reopen Docker Desktop, then docker pull golang:1.26-alpine. If it repeats: Docker Desktop → Troubleshoot → Clean / Purge data. make doctor detects this state |
Every docker command answers 500 Internal Server Error … check if the server supports the requested API version | The daemon is either still starting or its image store is broken past a restart | Wait for the whale icon to settle and run docker info; if it still errors, Troubleshoot → Clean / Purge data, then Reset to factory defaults, then reinstall Docker Desktop, in that order |
API log says DATABASE SCHEMA MISSING and make db-seed reports relation "users" does not exist | The Postgres init hook (scripts/db-init.sh) did not apply the migrations on the volume's first boot; docker compose logs db says why | Fixed: the hook is executable (it used to be sourced into the entrypoint) and make up now applies pending migrations on every start. On an older checkout: make fresh |
docker compose up -d prints nothing for minutes | First build: two base images, a Go compile and a Vite build | docker compose build in the foreground shows every stage |
Docker is optional: the standalone setup above runs the API and the SPA
against a Homebrew PostgreSQL (brew install go postgresql@16).
Source: docs/DEVELOPMENT.md