Skip to content

Local Development

Everything in the API repo is driven by mise tasks, which also load the service’s environment. Prefer mise run <task> over bare go commands so the env is present.

  • mise ≥ 2026.10.8 (min_version in mise.toml; task daemons are an experimental feature it enables). It provisions Go 1.27, sqlc, swag, sql-formatter, golangci-lint, gofumpt, psqldef, the Railway CLI, and more. Migrations run through cmd/migrate (goose as a library), so goose is not a standalone provisioned CLI.
  • Railway access — mise run env pulls config from Railway and mise run run tunnels to Railway’s Postgres and Redis, so you need to be logged in with project access.
  • Docker (optional) — only for a throwaway local Postgres/Redis (mise run db:local / redis:local).
  1. Install tools:

    Terminal window
    mise install
  2. Pull environment variables from Railway:

    Terminal window
    mise run env # writes .env.json (gitignored); mise auto-loads it
  3. Run the server:

    Terminal window
    mise run run # go run ./cmd/server, logs piped through logfmt

    Serves on :${PORT} — health at GET /, Swagger UI at GET /docs/*.

The Railway databases have no public URL — Postgres and Redis are reachable only on Railway’s private network. From a laptop you go through Railway’s tunneling instead: mise.toml declares two mise daemons, db-tunnel and redis-tunnel, which run railway connect "API Postgres" / "API Redis" with --tunnel-only for the current ENVIRONMENT (default development) onto localhost:$DB_PORT / localhost:$REDIS_PORT. mise.toml pins DB_HOST and REDIS_HOST to localhost, so every task and the server connect through them.

Terminal window
mise daemons start db-tunnel # open the Postgres tunnel on its own (e.g. for db:* tasks or a SQL client)
mise daemons # list daemons and their status
mise daemons stop # close the tunnels

mise run run declares both daemons, so it starts any that aren’t already running before the server boots, and leaves them up after it exits. A local server therefore talks to that environment’s real database, which Railway has already migrated (see Deployment); there’s no local migrate-and-seed step. The db:* tasks don’t start the tunnel themselves — run mise daemons start db-tunnel first. To reach another environment, set ENVIRONMENT, re-run mise run env, and mise daemons restart the tunnels.

db/<schema>/<table>/schema.sql is the source of truth: you edit it in place to the shape you want, and generate the migration from it. Never hand-write a migration from scratch or edit one that has already shipped.

  1. Edit schema.sql. Change the table’s CREATE TABLE (and its indexes, triggers, functions) directly. For a new table, add a db/<schema>/<table>/ directory with schema.sql + query.sql and a matching entry in sqlc.yaml. db/layout_test.go used to fail if a migrated table and its directory didn’t pair up; #506 removed it and relies on mise run db:check (CI’s Schema job) instead.

  2. Generate the migration (it needs a database — the db-tunnel daemon or a local container, see the caution below):

    Terminal window
    mise daemons start db-tunnel
    mise run db:schema # ./scripts/schema.sh plan

    It concatenates db/_global/*.sql (schema.sql first) and every table’s schema.sql (in migration order, so foreign keys resolve; tables without a migration yet go last), diffs that against the database with psqldef --dry-run, prints the DDL, and writes it as the -- +goose Up half of db/_migrations/000NN_CHANGEME.sql. psqldef can’t parse composite types, so schema.sh strips CREATE TYPE … AS (…) blocks before diffing: a composite type (today only page in db/_global/page.sql, #505) is neither generated nor drift-checked, and its migration is hand-written (00032_page.sql).

  3. Finish the file. Rename it (000NN_<schema>_<table>.sql for a new table — schema.sh orders by that name — or e.g. 00021_bond_bond_bond_number.sql for a change), write the -- +goose Down section, and add anything a diff can’t produce: data backfills, DISABLE/ENABLE TRIGGER around them, and -- +goose StatementBegin/End around plpgsql bodies (00022_bond_attachment.sql does all three).

  4. Regenerate and apply:

    Terminal window
    mise run sql # sqlc reads db/_migrations as its schema
    mise run db:migrate # against a local Postgres, not the shared one
    mise run db:check # should now pass

Two generators must be re-run when their inputs change:

Terminal window
mise run sql # sql-formatter + sqlc generate — after editing any query.sql or adding a migration
mise run docs # swag fmt + swag init + jq post-process — after changing handlers/models

mise run docs runs swag to emit docs/swagger.json (OpenAPI 3.1), then scripts/openapi_query.jq rewrites the QUERY endpoints and bumps the spec to OpenAPI 3.2.

  • Enums live in internal/model (type X string + // @name X); DB columns stay string, converted at the boundary. See Architecture.
  • Service files — each resource X in a domain’s Service interface gets core_X.go, auth_X.go, cache_X.go, and audit_X.go, all with the same X. Methods appear in interface order: Create, Get, List, Update, Delete, then variants, Watch* after the method that triggers it, and Presign* last. Types and constructors live in service.go (#484).
  • FromDB converters — every model type has an XFromDB(...); services return model.*, never raw sqlc rows. utils.Map converts slices.
  • Transactions — services Begin, derive Queries.WithTx(tx), defer tx.Rollback, and commit at the end. Audit writes happen after commit, in the WithAudit decorator — core methods never call the audit logger.
  • Errors — sentinel model.Error values with Wrap/WithMsg; pgx.ErrNoRows maps to ErrNotFound. Each sentinel carries its own HTTP status (model.Error implements Echo’s HTTPStatusCoder), so Echo’s DefaultHTTPErrorHandler renders it directly — there is no error-mapping middleware.
  • IDs — ULIDs everywhere (internal/id.ULID), stored as Postgres uuid; the zero ULID marshals to SQL NULL / JSON null.
  • Config injection — constructors and initializers that need config take the whole *config.Config and reach into the sub-config they need, so callers don’t have to know which slice a package consumes. This is uniform across the service (service.New, db.New, authn.New, storage.New, …). The AuthConfig / BucketConfig / DBConfig sub-structs (AuthConfig holds AUTH_JWT_SECRET, AUTH_JWT_ISSUER, and, since #504, AUTH_OTP_SECRET) group related keys (and back the reflection-based check of required env vars, which now runs only when VALIDATE_CONFIG is set), but they are read inside the package from the passed *config.Config rather than accepted as parameters.
  • Formatting/lint — gofumpt + golangci-lint (with revive). sqlc-generated internal/db/** is excluded from lint.
  • Swagger docstrings — a mandatory godoc first line, tab-indented annotations in a fixed order (@Summary → @Description → @Tags → @Accept → @Produce → @Param → @Success → @Failure → @Router), function-scoped request-struct naming, and no comments inside function bodies.

CI runs on push and mirrors what you can run locally. The unified check:

Terminal window
mise run check # test + fmt + lint + docs
Step Command Purpose
Test mise run test go test ./...
Format mise run fmt gofumpt -l -w .
Lint mise run lint golangci-lint run
Docs mise run docs Regenerate the OpenAPI spec, then fail if the committed docs/ differs — a stale spec can’t merge (#394)
Schema go run ./cmd/migrate up + ./scripts/schema.sh check Applies db/_migrations to a throwaway Postgres service, then fails if db/**/schema.sql disagrees — catches a schema.sql edit without its migration and vice versa, except for composite types (see above)

mise run check doesn’t include the schema check (it needs a database at the migrations’ head); run mise run db:check yourself, per Changing the schema. CI pins mise via jdx/mise-action’s version:, which has to stay at or above min_version — an older mise rejects the [daemons] tables and fails every job at setup.

A separate release.yaml workflow runs when a GitHub release is published and fast-forwards production to the release tag (#494); see Deployment › The promotion model.

Railway builds the API from its Dockerfile, which ships a ./migrate binary next to ./server (building it also validates the embedded migration set). Each environment’s pre-deploy command is ./migrate up: it runs once, between build and deploy, and a failure halts the deployment while the old version keeps serving. The server never migrates on startup — goose takes no lock by default, and rolling deploys overlap instances. The pre-deploy command is a per-environment Railway dashboard setting, not committed config.

Because the old version is still serving while the new migration applies, keep migrations backward compatible with the code already deployed (expand, deploy, then contract).

The TypeScript and Python SDKs are generated from this repo’s CI (not from the SDK repos), driven directly by the Speakeasy CLI. The artifact repos (api-client-typescript, api-client-python) are pure build outputs — the authoritative Speakeasy config lives here under .speakeasy/.

graph LR
    A[push to staging<br/>docs/** spec changed] --> B[build-spec<br/>mise run docs]
    B --> C[swagger.json artifact]
    C --> D[generate: typescript]
    C --> E[generate: python]
    D --> F["@huddlesurety/api<br/>→ GitHub Packages"]
    E --> G["huddlesurety-api<br/>→ git-installed"]
  1. Trigger — a push to the staging branch that touches the committed spec or SDK config: docs/**, scripts/**, .swaggo, mise.toml, .speakeasy/**, or the workflow itself (plus manual workflow_dispatch). Runs are serialized.

  2. build-spec — runs mise run docs and uploads docs/swagger.json.

  3. generate (matrix: TypeScript + Python) — each language uses its own Speakeasy workspace/key, clones its artifact repo, drops in the spec + .speakeasy/<lang>/ config, computes a deterministic version 0.1.<commit-count>, runs speakeasy run --set-version, and pushes to the artifact repo’s main if anything changed.

The version is the api commit count, so generate checks out the full history (fetch-depth: 0) and refuses to publish from a shallow clone or one with fewer than 700 commits (#476). A shallow count used to come out as 1, and because 0.1.1 was already published, the publish step skipped and the run went green without shipping an SDK.

  • TypeScript — package @huddlesurety/api, class HuddleAPI, published to GitHub Packages (restricted). Consumers authenticate installs with a GITHUB_TOKEN that has read:packages.
  • Python — package huddlesurety-api, class HuddleAPI, git-installed (no PyPI publish).