Appearance
Module anatomy
A module is one business area, such as leave or payroll. It owns one Postgres schema, its handlers, its Cedar policies and a manifest. The doors (GraphQL, MCP, CLI) are generated from what it registers: a module writes no door code.
Start from hello
modules/hello is the smallest complete module and the step-by-step guide for writing one.
Layout
modules/<id>/
├─ Cargo.toml package orbit-<id>, behind a cargo feature named <id>
├─ module.toml the manifest
├─ policies.cedar who may attempt each action, and on which records
├─ migrations/ NNNN_name.up.sql and .down.sql
├─ src/lib.rs ID, module(), subscribe(), schedules
├─ src/domain.rs ID newtypes, domain types, pure rules (no SQL)
├─ src/commands.rs command handlers
├─ src/queries.rs query handlers
├─ src/events.rs event names, payloads, subscribers
└─ tests/ integration, allow/deny and golden-vector testsThe manifest
module.toml declares everything the module does. The registry refuses a handler the manifest doesn't declare, and a declared name with no handler.
toml
[module]
id = "leave"
requires = ["core@^0.1"]
licence = "AGPL-3.0-only"
[provides]
commands = ["leave.apply", "leave.approve", "leave.reject"]
queries = ["leave.balance", "leave.applications"]
events = ["leave.approval.requested", "leave.application.approved"]
[consumes]
events = ["core.employee.joined", "core.employee.left"]
[ui]
routes = ["/me/leave", "/me/leave/new"]
[mcp]
tools = ["leave.balance", "leave.apply", "leave.approve"]
sensitive = ["leave.approve"] # runs only after the person approves the exact call(Shortened from the real modules/leave/module.toml.)
Migrations
- The first migration creates the module's schema.
- Every tenant-owned table has
tenant_idand, right after it is created, row-level security and grants to the module's own role only:sqlSELECT kernel.enable_tenant_rls('leave.applications'); SELECT kernel.grant_module('leave.applications', 'leave', ARRAY['SELECT', 'INSERT', 'UPDATE']); - Migrations run once for the whole database in
orbit migrate, never in a serving process (ADR 0004). Enabling a module for a tenant only flips its flag; disabling never deletes data.
Handlers
A command handler is a domain function plus repository calls:
rust
async fn handle(ctx: &Ctx, cmd: ApplyLeave) -> Result<LeaveApplication, DomainError>Ctxcarries the tenant, the actor (person, API client or agent), the door, the request id and the open transaction.- A handler that acts on a record calls
ctx.authorizeon it; the bus refuses to commit otherwise. - State changes and their events go in the same transaction (the outbox). Subscribers must be idempotent: delivery is at least once.
- Errors are a typed
DomainError, mapped once at the door to GraphQL codes, MCP errors and CLI exit codes.
Policies
Every command and query has a Cedar action in policies.cedar, with tests that allow and deny. Duties such as payroll_admin or finance are grants the module stores and hands to Cedar as module roles (ADR 0008).
What you get for free
| Door | Generated from |
|---|---|
| GraphQL | one mutation per command, one query field per query |
| MCP | one tool per entry in [mcp] tools, with confirm for sensitive ones |
| CLI | one orbit <module> <verb> per command and query, with JSON output |
The committed snapshots (crates/orbit-bin/schema.all-modules.graphql, mcp-tools.all-modules.json, cli-help.all-modules.txt) change with every new action, and tests fail until they are updated.
Personal data and files
- Seal personal fields with
orbit-pii; they are encrypted, redacted in logs and revealed only by a Cedar field check (Security model). - Accept files only through the files door,
POST /files/<module>/<purpose>(ADR 0009).
Checklist for a new module
- Manifest, data model, commands, events and the Cedar allow/deny matrix.
- Failing integration and authz tests, including a cross-tenant leakage test.
- Migrations, domain, handlers and policies.
- Updated GraphQL, MCP and CLI snapshots.
- Web routes and pages, with loading, empty and error states, in light and dark mode.
- A user guide page with a screenshot (Contributing).