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
errorssets an operation’s typed error channel tonever. - Internal storage and transport failures cannot leak across a service boundary. Handlers must map them into declared
Schema.TaggedErrortypes or escalate them viaEffect.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(...)throwsTopologyBoundaryErrorif two units claim the same statefulTable,Collection,Bucket,Queue, orCronunless you place it inshared. - Automatic remote RPC edges. When unit A declares a
Servicewithdependencies: [OrdersService]andOrdersServicelives in unit B,Topologyinfers the remote dependency and wiresKEEL_SERVICE_ORDERS_URL(Docker) or Cloudflare Service Bindings (SERVICE_ORDERS) without leakingOrdersService’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 onlyserdeandserde_json) orkeel codegen --lang go --entry <module> --service <name> --out pdfcontract/keel_contract.go(uses only the Go standard library, with no externalgo.moddependencies). Both generate a self-contained contract with typed structs, closed_tagerrors, a compile-timetraitorinterface,X-Keel-Workload-TokenHMAC verification, and an RPCdispatchornet/http.Handler. Pass--checkin CI to fail on contract drift.