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:
bunvia a thindb.DBwrapper (db/) — Postgres only, no DDL - Declaration: typed Go DSL —
schema.Definein 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:
- Guard
Check(session-level deny, before any DB hit) - Strip unknown / readonly / PK keys (mass-assignment guard)
from:injection (server-overwrites-client), defaults, timestamps- Validation (
422on failure,409on unique conflicts) - Guard
Filterpushdown into a single query — out-of-scope reads are404, not403
Concepts
App setup
Brick[TCtx], Config, Middleware, Handler, Scalar docs
Resources
Schema → Resource() → ResourceConfig and CRUD routes
Access control
Guards, Access slots, Check + Filter pushdown
Hooks
Before/After + Validate inside the write transaction
Schema DSL
Define resources in typed Go, generate db/crud code
Codegen
GenerateDB + GenerateCRUD emitters
DB layer
db.DB, Where, ListOptions, QueryFilter
REST & OpenAPI
Routes, pagination envelope, error shape
Deploy to Vercel
Serverless entrypoints, pooled Postgres, PORT (no framework changes)
Changelog
Release history, generated from main at release time
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)