Build your backend.
Keep your TypeScript.
Your actions, resources, and rules.
Compiled into a backend ready to run on Bun.
One service file
Write the block once.
Brick serves it everywhere.
Each building block is a few lines of TypeScript. Pick one to see the code and what it serves.
export const getUser = usersService.action({
name: "getUser",
input: t.Object({ id: t.String() }),
execute: ({ input, error }) => {
const user = users.get(input.id);
if (!user) error.NOT_FOUND("User not found");
return user;
},
});servesPOST /api/users/get-userapi.users.getUser()
export const order = orders
.resource({ name: "order", table: ordersTable, id: ordersTable.id })
.use(
crud({
access: "public",
fields: {
id: { read: true, filter: ["eq", "in"] },
status: { read: true, update: true, sort: true },
},
}),
);servesPOST /api/orders/order/queryGET PATCH DELETE /api/orders/order/:id
export default order.command("ship", {
access: "public",
input: t.Object({ trackingId: t.String() }),
errors: { NOT_PAID: { status: 409, message: "Only paid orders can ship" } },
decide: (row, input, { error }) =>
row.status !== "paid"
? error.NOT_PAID()
: {
set: { status: "shipped" },
emit: { shipped: { id: row.id, trackingId: input.trackingId } },
},
});servesPOST /api/orders/order/:id/shipapi.orders.order.ship()
export const orders = defineService("orders", {
database,
events: {
shipped: t.Object({ id: t.String(), trackingId: t.String() }),
},
});
export const sendTracking = defineListener({
name: "send-tracking",
on: orders.events.shipped,
run: ({ payload }) => mailer.tracking(payload.id, payload.trackingId),
});servesorders.shipped → send-tracking
chat.socket({
name: "live",
input: {
say: t.Object({ text: t.String({ minLength: 1, maxLength: 2000 }) }),
},
output: {
message: t.Object({ text: t.String() }),
},
authorize: ({ ctx }) => ctx.user != null,
handlers: {
say: ({ input, socket }) => {
socket.send("message", { text: input.text });
},
},
});servesGET /api/chat/live (upgrade)api.chat.live.connect()
export const searchDocs = docsService.tool({
name: "search_docs",
description: "Search knowledge base documents by query string",
input: t.Object({
query: t.String({ description: "Search terms or keywords" }),
limit: t.Optional(t.Number({ default: 5 })),
}),
output: t.Array(t.Object({ id: t.String(), title: t.String() })),
execute: ({ input }) => search(input.query, input.limit),
});servestools/listtools/call search_docs
Your first app
From empty folder
to running API.
One file, a few minutes. Follow the steps or read the full quickstart.
- 01
Install Brick
Start a Bun project and add the core, CRUD and CLI packages.
terminal
bun init -y bun add @brickkit/core @brickkit/crud @brickkit/cli - 02
Define a table
Plain Drizzle. The columns are the types every later step uses.
src/app.ts
export const pages = sqliteTable("pages", { id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()), title: text("title").notNull(), content: text("content"), }); const database = defineDatabase({ tables: { pages } }); export const pagesService = defineService("pages", { database }); - 03
Turn it into a resource
Say who can read, write, filter and sort each field. Brick writes the routes.
src/app.ts
pagesService.resource({ name: "page", table: pages, id: pages.id }).use( crud({ access: "public", fields: { id: { read: true, filter: ["eq"] }, title: { read: true, create: true, update: true, filter: ["eq", "contains"], sort: true }, content: { read: true, create: true, update: true }, }, }), ); - 04
Compose the app
List your services. That is the whole entry point.
src/app.ts
syncSchema(pagesService); export default brick({ services: [pagesService], title: "Pages API", version: "1.0.0", }); - 05
Run it
brick dev reloads on save and prints every route it mounted.
terminal
bunx brick dev src/app.ts --port 4000 # • pages (8 actions) # -> POST /api/pages/page/query # -> GET /api/pages/page/:id # -> POST /api/pages/page # -> PATCH /api/pages/page/:id # -> DELETE /api/pages/page/:id - 06
Call it
Validated JSON in and out, with OpenAPI docs served at /docs.
terminal
curl -X POST localhost:4000/api/pages/page \ -H "Content-Type: application/json" \ -d '{"title": "First Page", "content": "Hello"}' # {"id":"e379b38c-…","title":"First Page","content":"Hello"}
From table to browser
One type, five places.
Change a column and the types follow it through the resource, the route and the generated client contract to your UI.
Drizzle table
status: text("status")Resource + CRUD
.use(crud({ fields }))HTTP route
PATCH /api/orders/order/:idClient contract
_brick/contract.tsYour UI
api.orders.order.update()
The rest of the backend
Every piece is opt-in.
Each one is typed from the same definitions and documented on its own page.
- Services and actions
Validated, typed units of work you call in process or over HTTP.
- Resources
A Drizzle table becomes CRUD routes with field policies and filters.
- Commands
Business rules that write a row and emit events in one transaction.
- Events
Events recorded with the write, delivered to listeners after commit.
- Realtime
Typed WebSockets with rooms, fan-out, and reconnect.
- Typed client
A generated browser contract, with TanStack Query options.
- MCP tools
Expose tools to AI agents over the Model Context Protocol.
- Access control
Authorization guards on actions and row scoping on resources.
- OpenAPI
An OpenAPI document generated from the same definitions.
- Migrations
Create tables in development and run migrations in production.
- Plugins
Package routes, resources, and dashboard tabs to reuse across apps.
- Dev dashboard
brick dev serves a dashboard of requests, spans, and failures.
Built on tools you know
No new runtime to learn.
Brick is a layer of structure over Bun, Elysia, TypeBox and Drizzle. Drop down to any of them when you need to.
- Bun 1.2+
- Elysia
- TypeBox
- Drizzle ORM
- Workflow SDK
- @brickkit/core
- services, actions, client
- @brickkit/crud
- resources, policies, hooks
- @brickkit/cli
- dev, build, gen, dashboard
- @brickkit/redis-world
- durable workflows on Redis
- @brickkit/bullmq-world
- durable workflows on BullMQ
For your agent
Your agent builds
with Brick too.
Give your coding agent the Brick skill and docs. Your own tools reach other agents over MCP.
Lay the first brick.
Install, define a service, and run it on Bun.