Getting Started

Install Chimpbase and build your first backend in minutes.

Install

Bun
Deno
Node.js
bun add @chimpbase/bun

Create a runtime

import { createChimpbase } from "@chimpbase/bun";
import { action, subscription, worker, v } from "@chimpbase/runtime";

const chimpbase = await createChimpbase({
  storage: { engine: "postgres", url: process.env.DATABASE_URL! },
});

Define an action

const createCustomer = action({
  args: v.object({
    email: v.string(),
    name: v.string(),
    plan: v.string(),
  }),
  async handler(ctx, input) {
    const [customer] = await ctx.query<{ id: number }>(
      "insert into customers (email, name, plan) values (?1, ?2, ?3) returning id",
      [input.email, input.name, input.plan],
    );

    ctx.pubsub.publish("customer.created", {
      customerId: customer.id,
      email: input.email,
    });

    return customer;
  },
});

React to events

const onCustomerCreated = subscription(
  "customer.created",
  async (ctx, event) => {
    await ctx.queue.enqueue("customer.sync", event);
  },
  { idempotent: true, name: "enqueueCustomerSync" },
);

const syncCustomer = worker(
  "customer.sync",
  async (ctx, event) => {
    ctx.log.info("syncing customer", { customerId: event.customerId });
    await ctx.query(
      "update customers set synced_at = now() where id = ?1",
      [event.customerId],
    );
  },
);

Register and start

chimpbase.register({ createCustomer, onCustomerCreated, syncCustomer });

await chimpbase.start();

One runtime, one database, explicit primitives, no infrastructure ceremony.

Local development

Use SQLite or in-memory storage when you don't need PostgreSQL:

// SQLite
const chimpbase = await createChimpbase({
  storage: { engine: "sqlite", path: "./dev.db" },
});

// In-memory (tests)
const chimpbase = await createChimpbase({
  storage: { engine: "memory" },
});