Brick

What is Brick?

Opinionated Go framework for CRUD APIs on Huma + Bun + Postgres.

Brick is an opinionated Go framework for building CRUD APIs. You declare a resource once and get typed routes, validation, auth pushdown, and an OpenAPI 3.1 spec — without writing handlers by hand.

Stack

  • HTTP + OpenAPI: Huma v2 on bunrouter (brick.go)
  • Postgres access: bun via a thin db.DB wrapper (db/) — Postgres only, no DDL
  • Declaration: typed Go DSL — schema.Define in a DSL app (schema/, dsl/)
  • Codegen: deterministic gofmt-clean emitters with golden tests (codegen/)

What you get per resource

GET /api/{name} (list) · GET /api/{name}/{id} · POST /api/{name} · PATCH /api/{name}/{id} · DELETE /api/{name}/{id} — each gated by the same exec pipeline:

  1. Guard Check (session-level deny, before any DB hit)
  2. Strip unknown / readonly / PK keys (mass-assignment guard)
  3. from: injection (server-overwrites-client), defaults, timestamps
  4. Validation (422 on failure, 409 on unique conflicts)
  5. Guard Filter pushdown into a single query — out-of-scope reads are 404, not 403

Concepts

Repo layout

go.work         workspace (use ./brick, ./dsl, ./examples/...)
brick/          runtime module (import github.com/brick-org/brick/brick; tagged brick/vX.Y.Z)
  brick.go        app bootstrap (Brick[TCtx], Config, Handler, OpenAPISpec)
  resource.go     Schema → Resource() + exec pipelines
  access.go       Guards / Access
  hooks.go        lifecycle hooks
  validate.go     validation + unique precheck
  autoname.go     PK strategies
  context.go      User / Session / AppCtx identity plumbing
  errors.go       RFC 9457 helpers (404/401/403/400/422/409/500)
  db/             Postgres DML wrapper (no DDL)
dsl/            toolchain module (import github.com/brick-org/brick/dsl,
                zero external deps — the only thing a DSL app requires)
  schema/         Go DSL: Define, Validate, field builders, PK strategies
  codegen/        GenerateDB + GenerateCRUD (golden-pinned)
  runner.go       dsl.Run: validate + emit into the main app's gen/
  emit.go         dsl.EmitGo: defs back to Define source
  cmd/dsl         `dsl init` project scaffolder
examples/shop/  two-app example (dsl/ definitions + app/ runtime + gen/;
              app/ deploys to Vercel: appshop/ shared constructor,
              api/ function, vercel.json server preset)
apps/docs/      docs site (TanStack Start + Fumadocs)

On this page