brick.ts
Brick v0.15.0, open source

Build your backend.
Keep your TypeScript.

Your actions, resources, and rules. Compiled into a backend ready to run on Bun.

Building with an AI agent? ↗

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()

Your first app

From empty folder
to running API.

One file, a few minutes. Follow the steps or read the full quickstart.

  1. 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
  2. 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 });
  3. 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 },
        },
      }),
    );
  4. 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",
    });
  5. 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
  6. 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.

  1. Drizzle table

    status: text("status")
  2. Resource + CRUD

    .use(crud({ fields }))
  3. HTTP route

    PATCH /api/orders/order/:id
  4. Client contract

    _brick/contract.ts
  5. Your 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.

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.

Set up your agent with Brick docs and MCP

Lay the first brick.

Install, define a service, and run it on Bun.