Keel by ChimpLabs
Jump to page or section Esc
Core Concepts

Bounded-Context Services & Topology

Define bounded-context Services with closed error contracts and extract microservices from a monolith with zero caller changes.

Service (@chimp-labs/keel/service) models a domain bounded context. Each service owns its Keel resources (Table, Topic, Secret, ExternalSystem), declares upstream dependencies, and exposes schema-validated operations with closed error contracts.

Closed error contracts

  • Omitting errors sets an operation’s typed error channel to never.
  • Internal storage and transport failures cannot leak across a service boundary. Handlers must map them into declared Schema.TaggedError types or escalate them via Effect.orDie.
  • At runtime, any undeclared failure escalates to Effect.die(new ServiceUndeclaredError(...)).

Topology inference (inferKeelTopology)

Keel infers remoteness from deployment membership instead of hardcoding it on the Service:

import { inferKeelTopology } from "@chimp-labs/keel"

const topology = inferKeelTopology({
  inventory: [InventoryService],
  billing: [BillingService],
})
// topology.deployOrder -> ["inventory", "billing"]
// topology.units.billing.remoteDependencies -> [{ service: "inventory", targetUnit: "inventory" }]
// topology.units.inventory.exposedServices -> ["inventory"]

When you co-locate both services in one unit ({ api: [InventoryService, BillingService] }), remoteDependencies and exposedServices become [].

Declarative Topology and polyglot services (Rust and Go)

For multi-unit monorepos with shared contracts, wrap your units in Topology:

  • Static single-owner enforcement. Topology(...) throws TopologyBoundaryError if two units claim the same stateful Table, Collection, Bucket, Queue, or Cron unless you place it in shared.
  • Automatic remote RPC edges. When unit A declares a Service with dependencies: [OrdersService] and OrdersService lives in unit B, Topology infers the remote dependency and wires KEEL_SERVICE_ORDERS_URL (Docker) or Cloudflare Service Bindings (SERVICE_ORDERS) without leaking OrdersService’s private tables or secrets into unit A.
  • Rust and Go contract codegen. Run keel codegen --lang rust --entry <module> --service <name> --out src/keel_contract.rs (requires only serde and serde_json) or keel codegen --lang go --entry <module> --service <name> --out pdfcontract/keel_contract.go (uses only the Go standard library, with no external go.mod dependencies). Both generate a self-contained contract with typed structs, closed _tag errors, a compile-time trait or interface, X-Keel-Workload-Token HMAC verification, and an RPC dispatch or net/http.Handler. Pass --check in CI to fail on contract drift.