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.
Start by defining a service and declaring its resources and dependencies. Compose typed TypeScript primitives—verified in milliseconds and ready for production.
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() })) $ 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 // 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],
},
},
}) $ inferKeelInfra([OrdersService])
✓ Service "orders": 4 resources, 1 dependency
✓ Closed error contract verified (0 undeclared)
done 0 YAML files · Infra derived from code // 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)
} $ pnpm typecheck
✓ OrdersService.placeOrder wired via .live(...)
✓ Table (+ JSONB), bucket, KV & events typechecked
next Wire your backend & deployment target 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
) $ 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 // 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 $ 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 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.
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],
},
},
})
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.
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.
Handlers must handle or map every failure into the declared
errors list. Undeclared database or network leaks fail
tsc --noEmit before code ever ships.
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.
k.bucket Object storage with upload guards, streaming reads, and presigned URLs.
k.cache Read-through caching with singleflight and tag invalidation.
k.cron Distributed schedules with overlap guards and leader locks.
DurableStream Durable append-only streams with live tailing and replay.
@chimp-labs/keel-streams k.external Typed third-party API clients with timeouts, retries, and mocks.
k.flag Typed feature flags evaluated against request context.
k.idempotency Deduplicate repeat requests and reuse successful results.
k.queue Background jobs with delays, retries, and dead-letter queues.
k.kv Typed key-value storage with TTL and atomic operations.
k.lock Distributed leases with automatic renewal and release.
k.modulith Compose services in a modular monolith with a shared database.
k.rateLimit Sliding-window quotas with weighted costs and retry timing.
k.secret Boot-verified, redacted credentials from env vars, files, or cloud bindings.
k.service Define service boundaries, resource ownership, and typed errors.
signal Wake suspended workflows with typed external events.
@chimp-labs/keel-workflow k.table Typed SQL and JSONB tables with transactions, joins, and change streams.
k.topic Typed pub/sub with durable replay, upcasting, and a transactional outbox.
Topology Define isolated deployable services with Rust and Go codegen.
workflow Durable steps with crash replay and saga compensation.
@chimp-labs/keel-workflow async/await on top, Effect v4 ManagedRuntime underneath.
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.
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",
},
}) $ 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 * * *"] 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" },
}) $ 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 @chimp-labs/keel-alchemy provisions R2 buckets, KV
namespaces, Queues, Cron triggers, encrypted secrets, and zero-hop
Service Bindings between split workers.
Run the same services on your own servers with PostgreSQL 17 or SurrealDB 4, alongside Garage S3, per-unit schemas, and deploy-time schema verification.
Install Keel and declare a service with its resources, dependencies, and error boundaries.
pnpm add @chimp-labs/keel effect pgnpm install @chimp-labs/keel effect pgbun add @chimp-labs/keel effect pg 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.
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. 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