Keel by ChimpLabs
Jump to page or section Esc
Built by ChimpLabs

Building blocks for your agent. Build complex software without accidental complexity.

Start by defining a service and declaring its resources and dependencies. Compose typed TypeScript primitives—verified in milliseconds and ready for production.

src/primitives.ts KEEL
import { k } from "@chimp-labs/keel/sdk"

export const orders = k.table("orders", {
  id: k.uuid().primaryKey(),
  userId: k.text().index(),
  totalCents: k.integer(),
  meta: k.json(k.object({ tier: k.string(), tags: k.array(k.string()) })).index(),
}, { indexes: [["meta.tier"]] })

export const receipts = k.bucket("receipts", {
  contentTypes: ["application/pdf"] as const,
  maxBytes: 5 * 1024 * 1024,
})

export const sessions = k.kv("sessions", k.object({ lastOrderId: k.string() }), { ttl: "24 hours" })

export const orderPlaced = k.topic("orders.placed", k.object({ orderId: k.string() }))
~/keel-app PRIMITIVES
$ pnpm typecheck

✓ 4 typed primitives declared (zero cloud SDKs)
✓ Table (+ JSONB indexes), bucket, KV, and event topic ready
next Group them into a service contract
src/orders.service.ts KEEL
// Declare what this service owns, calls, and exposes
export const OrdersService = k.service("orders", {
  resources: [
    orders,
    receipts,
    sessions,
    orderPlaced,
  ],
  dependencies: [InventoryService],
  operations: {
    placeOrder: {
      input: k.object({
        userId: k.string(),
        totalCents: k.int(),
      }),
      output: k.object({ orderId: k.string() }),
      errors: [OutOfStockError],
    },
  },
})
~/keel-app SERVICE
$ inferKeelInfra([OrdersService])

✓ Service "orders": 4 resources, 1 dependency
✓ Closed error contract verified (0 undeclared)
done 0 YAML files · Infra derived from code
src/orders.live.ts KEEL
// Wire the handler body directly to OrdersService
export const ordersApi = await keel.ordersService.live({
  placeOrder: async ({ userId, totalCents }) => {
    const order = await keel.orders.insert({
      userId,
      totalCents,
      meta: { tier: "pro", tags: ["web"] },
    }) // relational + JSONB table
    await keel.receipts.put(`${order.id}.pdf`, pdf, { contentType: "application/pdf" }) // bucket
    await keel.sessions.set(userId, { lastOrderId: order.id }) // kv
    await keel.orderPlaced.publish({ orderId: order.id }) // publish event
    return { orderId: order.id }
  },
})

for await (const ev of keel.orderPlaced.subscribe({ signal })) { // listen to event
  console.log("Order placed:", ev.payload.orderId)
}
~/keel-app IMPL
$ pnpm typecheck

✓ OrdersService.placeOrder wired via .live(...)
✓ Table (+ JSONB), bucket, KV & events typechecked
next Wire your backend & deployment target
src/wire.ts KEEL
import { createKeel } from "@chimp-labs/keel/sdk"

// Local: bind all resources to memory or sqlite
export const keel = await createKeel({
  backend: "memory",
  resources: {
    orders,
    receipts,
    sessions,
    orderPlaced,
    ordersService: OrdersService,
  },
  ensureAll: true,
})

// Prod: Cloudflare or Docker (PostgreSQL 17 or SurrealDB 4)
export const stack = keelCloudflareStack(
  { orders: { entrypoint: "./src/wire.ts", services: [OrdersService] } },
  { surreal: { url: process.env.SURREAL_URL! } } // or keelDockerStack
)
~/keel-app WIRE
$ inferKeelInfra([OrdersService])

✓ Local: 4 resources bound to memory backend (2ms)
✓ Prod:  table, R2 bucket, KV & RPC bindings inferred
ready Same service runs locally or in production
src/main.ts KEEL
// Call the wired service—10ms in memory or live in prod
const res = await ordersApi.placeOrder({
  userId: "usr_01",
  totalCents: 4500,
})

console.log(res.orderId)
// → "ord_94f2"
// → receipt saved to receipts/ord_94f2.pdf
// → event orders.placed received by subscribers
~/keel-app LIVE
$ vitest run && alchemy deploy --stage production

✓ ordersApi.placeOrder → { orderId: "ord_94f2" } (6ms)
✓ Table, bucket & KV verified in memory
✓ Deployed unit "orders" with scoped bindings
done Running locally and live in production
DEFINE A SERVICE TABLES COLLECTIONS BUCKETS KV PUBLISH & LISTEN TO EVENTS QUEUES & CRONS DURABLE WORKFLOWS 10MS IN-MEMORY TESTS AUTOMATIC IAC CLOSED ERROR CONTRACTS CLOUDFLARE WORKERS SELF-HOST ON DOCKER POSTGRESQL 17 SURREALDB 4 GARAGE S3 DEFINE A SERVICE TABLES COLLECTIONS BUCKETS KV PUBLISH & LISTEN TO EVENTS QUEUES & CRONS DURABLE WORKFLOWS 10MS IN-MEMORY TESTS AUTOMATIC IAC CLOSED ERROR CONTRACTS CLOUDFLARE WORKERS SELF-HOST ON DOCKER POSTGRESQL 17 SURREALDB 4 GARAGE S3
01 · Start with a service

You start by defining a service and declaring its resources and dependencies

Whether your agent is building a single CRUD endpoint or a multi-service platform, every piece of software starts with one explicit TypeScript contract: what the service owns, which services it depends on, and how its operations can fail.

src/orders.service.ts Service contract
import { k } from "@chimp-labs/keel/sdk"

export const OrdersService = k.service("orders", {
  // 1. Declare the primitives this service owns
  resources: [
    OrdersTable,
    ReceiptsBucket,
    OrderPlaced,
    FulfillmentWorkflow,
    StripeKey,
  ],

  // 2. Declare the other services it calls
  dependencies: [InventoryService],

  // 3. Declare typed operations and allowed errors
  operations: {
    placeOrder: {
      input: PlaceOrderInput,
      output: OrderReceipt,
      errors: [OutOfStockError, CardDeclinedError],
    },
  },
})
Hover highlighted symbols to inspect what Keel infers
What Keel derives from this single file
01 / Scoped infrastructure

Zero YAML. Least-privilege bindings by default.

Keel reads resources to build the infrastructure graph—creating tables, R2 or Garage buckets, topics, crons, and secrets scoped strictly to the service that declared them.

02 / Typed dependencies

In-process today, remote RPC whenever you split.

Every service in dependencies gets a typed client and a topological deploy order. Keep everything in one process to start, or split units across workers and containers without changing handlers.

03 / Closed error contracts

The compiler catches what coding agents miss.

Handlers must handle or map every failure into the declared errors list. Undeclared database or network leaks fail tsc --noEmit before code ever ships.

04 / Instant verification

Boot the whole service in memory in under 10ms.

Pass backend: "memory" to run transactions, outbox relays, buckets, workflows, and secret checks in process—giving your agent a real feedback loop without Docker or hand-rolled mocks.

19 backend primitives

Read the docs
Plain async/await on top, Effect v4 ManagedRuntime underneath.
03 · Automatic infrastructure inference

Zero YAML. Alchemy infers your infrastructure straight from code.

Pass your services or Topology directly into @chimp-labs/keel-alchemy. Keel computes the dependency graph, provisions only the databases, buckets, crons, secrets, and RPC bindings each unit declared, and deploys to Cloudflare or self-hosted Docker.

Alchemy IaC guide
alchemy.run.ts ALCHEMY
import {
  keelCloudflareStack,
} from "@chimp-labs/keel-alchemy/cloudflare/stack"
import { App } from "./src/topology"

// Infers stack name, R2 buckets, KV, Queues, Service Bindings,
// Cron triggers & encrypted Redacted secrets from code
export default keelCloudflareStack(App, {
  surreal: {
    url: process.env.SURREAL_URL!,
    namespace: "prod",
  },
})
inferred plan INFERRED · CLOUDFLARE
$ alchemy plan --stage prod

plan  3 to create
      stack: commerce-platform · inventory → orders

+ [BktReceipts] create
  R2 bucket · BUCKET_RECEIPTS on orders only

+ [WorkerInventory] create
  KEEL_EXPOSED_SERVICES + SURREAL_*

+ [WorkerOrders] create
  SERVICE_INVENTORY (zero-hop RPC binding)
  STRIPE_KEY (Redacted secret binding)
  crons: ["0 */6 * * *"]
alchemy.run.ts ALCHEMY
import {
  keelDockerStack,
} from "@chimp-labs/keel-alchemy/docker"
import { App } from "./src/topology"

// Infers stack name, Docker network, PostgreSQL 17,
// per-unit schemas, Garage S3 & least-privilege env maps
export default keelDockerStack(App, {
  database: "postgres",
  postgres: {
    schemaMode: "migrate-and-verify",
  },
  garage: { configPath: "./docker/garage.toml" },
})
inferred plan INFERRED · DOCKER
$ alchemy plan --stage prod

plan  5 to create, 2 adopted, 3 tasks
      stack: commerce-platform · inventory → orders

+ [KeelNet] create
  bridge network commerce-platform-prod

+ [KeelPostgres] create
  postgres:17-alpine (needsDatabase)

+ [KeelGarage] create
  bucket "receipts" · S3_* on orders only

▶ [InitPostgresSchemasAndRoles] run [action]
  per-unit schemas + search_path isolation

▶ [SyncPostgresSchema] run [action]
  migrate-and-verify · stock, orders

▶ [InitGarage] run [action]
  auto-provisions declared S3 buckets
Get started

Describe the outcome and let your agent ship

  1. 1

    Install Keel and declare a service with its resources, dependencies, and error boundaries.

    pnpm add @chimp-labs/keel effect pg
    npm install @chimp-labs/keel effect pg
    bun add @chimp-labs/keel effect pg
  2. 2

    Describe the business and technical outcome to your coding agent—Keel lets it pick the right primitives and verify everything in memory in under 20ms.

    agent-prompt.txt
    Build an order checkout service with Keel:
    1. Store customer orders, save PDF receipts, and check inventory before charging.
    2. Guarantee that an order and its confirmation event either both commit or both roll back.
    3. Show each customer their updated total spend immediately after checkout.
    4. Write fast unit tests covering payment failures, rollbacks, and immediate reads.
  3. 3

    Deploy managed on Cloudflare Workers with SurrealDB Earth, or self-host on Docker with PostgreSQL 17 or SurrealDB 4 alongside Garage S3.

    alchemy deploy --stage production