Appearance
Architecture
Orbit is a modular monolith. One binary, orbit, holds a small kernel and every module compiled into it. Each module's actions are reached through thin adapters called doors. Postgres is the only database. This page describes the code on development today.
mermaid
flowchart LR
subgraph clients[Clients]
browser[Browser]
cli[orbit CLI]
agent[MCP client]
end
subgraph web[orbit --role web]
spa["/ (web app)"]
proxy["/api/auth proxy"]
gql["/graphql"]
mcp["/mcp"]
bus[Command and query bus<br/>Cedar gate, audit]
handlers[Module handlers]
end
subgraph worker[orbit --role worker,scheduler]
relay[Event relay]
jobs[Job worker]
sched[Scheduler]
end
migrate[orbit migrate<br/>one-shot, owner login]
sidecar[Auth sidecar<br/>Better Auth]
pg[(Postgres)]
browser --> spa
browser -- sign-in --> proxy
proxy --> sidecar
browser -- JWT --> gql
cli -- JWT --> gql
agent -- JWT --> mcp
gql -. JWKS .-> sidecar
gql --> bus
mcp --> bus
bus --> handlers
handlers -- state + outbox + audit, one transaction --> pg
pg --> relay
relay --> handlers
sched -- cron --> pg
pg --> jobs
migrate -- migrations --> pgKernel
The kernel (crates/kernel) holds:
- The registry. It loads each module's manifest (
module.toml), handlers, migrations and policies. It refuses a handler that the manifest does not declare, and a declared name that has no handler. - Tenancy. Tenants live in
kernel.tenants. The modules this database has been migrated for live inkernel.modules(id, version, the ids it requires). Which modules a tenant has enabled lives inkernel.tenant_modules, and every change to that is appended tokernel.module_switches. - The command and query bus. Every action runs through it (see below).
Ctx. The context each handler receives: tenant, actor, door, request id, whether the attempt was confirmed, and the open transaction.- ID newtypes. IDs are UUIDv7 values wrapped in a type per entity.
The kernel also has built-in actions that are always available: kernel.module.enable, kernel.module.disable, kernel.session.get, kernel.member.list, kernel.member.remove, kernel.member.restore and kernel.dead_letter.list.
Kernel events, written to the outbox in the same transaction as the change:
| Event | Payload | Emitted by |
|---|---|---|
kernel.module.enabled | { module, sources: [module id] } | kernel.module.enable (disabled to enabled) |
kernel.member.removed | { person } | kernel.member.remove (never a refused removal) |
kernel.member.restored | { person } | kernel.member.restore |
The command and query bus
Every command and query goes through the bus. There is no other way to run a handler. For each attempt the bus:
- Looks the handler up by name. An unknown name is
NOT_FOUND. - Opens a transaction scoped to the request's tenant (read-only for queries).
- Checks that the tenant exists.
- Asks Cedar whether the actor may attempt this action in this tenant (the gate).
- Checks that the action's module is enabled for the tenant. This comes after the gate, so someone outside the tenant learns nothing about which modules it runs.
- Runs the handler. A handler that acts on a record must call
ctx.authorizeon that record (the resource check). If it never does, the bus refuses to commit, unless the handler is declared as acting on the tenant as a whole. - Checks that the handler did not switch the transaction to another tenant.
- For a command, writes the audit entry in the same transaction, then commits.
A denied attempt, and a command that fails after it was allowed, is rolled back and then audited on a separate connection. Allowed queries and failed queries are not audited. A handler that panics is rolled back and audited as a failure.
Every transaction, the built-in kernel commands included, runs on the runtime login. ADR 0001 explains the gate and the resource check.
Modules
A module owns one Postgres schema, its handlers, its policies and its manifest. Modules are compiled in behind a cargo feature named after the module (--all-features builds every one). See Modules for the list on development.
- Migrations run only in
orbit migrate, for the kernel, the platform crates and every module compiled into the binary, whether or not any tenant uses it.orbit migratethen records each module inkernel.modules(ADR 0004). - Enabling a module only flips a flag.
kernel.module.enablechecks the gate, a resource check onkernel.module/<id>and the module's dependencies, then calls the database functionkernel.set_module_enabled. That function accepts only a module inkernel.modules, only for the tenant the transaction is scoped to, checks the dependencies again under a per-tenant lock, and appends the change tokernel.module_switches. A module that is compiled in but not migrated is refused withCONFLICT("runorbit migrate"). A module id the binary does not know isNOT_FOUND. - Disabling is refused while another enabled module requires the module. It hides the module for that tenant and never deletes data or runs a down migration.
Pure rules (leave days and balances, automatic attendance status, expense limits, policy due dates and more) live in each module's domain code and are checked against golden vectors in its tests/vectors/.
Doors
Doors turn an outside request into a bus call. They hold no business logic.
| Door | Where | Built from |
|---|---|---|
| GraphQL | POST /graphql on the web role | One mutation per command and one query field per query in the registry |
| MCP | POST /mcp on the web role (Streamable HTTP, stateless, JSON responses) | One tool per entry in a module's [mcp] tools |
| CLI | the orbit binary (orbit login, orbit <module> ...) | One subcommand per command and query. It calls /graphql with a stored token and never connects to the database |
The web app uses the GraphQL door. Every door authenticates the same way, maps errors to the same codes and applies the same per-actor limits. Each request gets a fresh request id, returned in the x-request-id header. See API.
What the web role serves
One origin serves everything a browser needs:
| Path | What |
|---|---|
/graphql, /mcp | The doors |
/health | The process is up |
/ready | Both of its database connections (runtime and doors) answer |
/api/auth/* | Proxied to the auth sidecar (when ORBIT_AUTH_UPSTREAM is set), so the sidecar's session cookie is first-party |
| everything else | The built web app (when ORBIT_WEB_DIR is set): hashed /assets/* cached for a year, other paths no-cache, unknown paths answered with index.html |
The server speaks plain HTTP/1.1 only. TLS, HTTP/2 and HSTS belong to the reverse proxy in front (deploy/README.md). Every response carries security headers unless it sets its own (see Security model).
Authentication
Sign-in, organisations and single sign-on are handled by the auth sidecar (services/auth, Better Auth). It issues JWTs signed with EdDSA that last 15 minutes. The web role verifies them against the sidecar's JWKS. A token's organisation must be mapped to an Orbit tenant by an operator first (orbit tenant provision, see ADR 0002). The person's tenant role (owner, admin, member) is synced from the token on each request. Open email sign-up and organisation creation are off by default; see deploy/README.md.
Events and the outbox
- A handler emits an event with
orbit_events::emit. The event row goes intoevents.outboxin the handler's transaction, so it commits or rolls back with the change. Only event names that a module declares in its manifest are accepted. - The relay (worker role) reads committed outbox rows tenant by tenant, in order, and hands them to the in-process Postgres event bus. Several relays can run at once: one tenant's stream is drained by one relay at a time.
NOTIFYwakes the relay, and it also polls. - Subscribers run in a transaction scoped to the event's tenant. The delivery is recorded in the same transaction, so a redelivery after success is a no-op. Delivery is at-least-once.
- A failing subscriber is retried with exponential backoff (by default 8 attempts, starting at 1 second and capped at 5 minutes) and then dead-lettered. While it retries, that tenant's later events wait, so order holds.
- The relay refuses to start if a module consumes an event that has no subscriber.
- Events for a module that is disabled in a tenant are held (
events.skipped) and replayed, before anything newer, when the module is enabled again (ADR 0005).
Jobs
Background jobs use apalis with its Postgres backend.
- A job's name starts with its module id. It runs only for tenants where that module is enabled.
- A handler, subscriber or job enqueues a job inside its own transaction, so the job is queued only if that transaction commits.
- The worker role runs jobs, each in a transaction scoped to the job's tenant.
- The scheduler role enqueues jobs on cron schedules (with seconds, in UTC).
Modules register their own schedules, for example attendance's hourly auto attendance, core's leavers and document purge, policies' daily reminders and recruitment's retention purge.
Personal data and files
crates/pii(orbit-pii) encrypts personal fields in the application before they reach Postgres, keeps them out of logs (Pii<T>prints and serialises as[redacted]), and reveals a field only when a Cedar field-level check allows it. Keys come from one master key,ORBIT_DATA_KEY, which never enters the database. See Security model.crates/storage(orbit-storage) stores files for modules: local disk by default, or S3-compatible storage with thes3feature. Each module gets its own area under the tenant. Uploads are limited in size (10 MiB by default) and in type (PDF, PNG, JPEG and WebP, sniffed from the bytes), encrypted with the tenant's data key, and named by a keyed hash of their content. Downloads use signed tokens that last at most 5 minutes.
Modules that hold personal data seal it with orbit-pii (core, leave, attendance, payroll, expenses, recruitment, policies). Files reach a module only through the files door, POST /files/<module>/<purpose> (ADR 0009): employee documents, receipts, CVs and offer letters, policy PDFs and signatures, payslip PDFs.
Process roles
orbit --role <roles> picks what a process runs, as a comma-separated list. The default is all.
| Role | Runs | Needs |
|---|---|---|
web | The HTTP server | Runtime and doors connections, ORBIT_AUDIT_KEY, ORBIT_DATA_KEY, the sidecar's JWKS URL and issuer |
worker | The event relay and the job worker | Runtime and worker connections, ORBIT_AUDIT_KEY, ORBIT_DATA_KEY |
scheduler | The cron scheduler | Runtime and worker connections, ORBIT_AUDIT_KEY |
all | All three | All of the above |
The self-hosted stack runs web and worker,scheduler as two containers, after a one-shot migrate container (deploy/README.md).
At startup, each serving process:
- refuses connections it must not hold. Every role refuses the owner's URL (
ORBIT_MIGRATION_DATABASE_URL). A process that runs neitherworkernorschedulerrefuses the worker URL. A process that does not runwebrefuses the doors URL. - checks each login. No login may be a superuser or have
BYPASSRLS. The runtime, worker and doors logins also must not haveCREATEROLE, must not own schemakernel, and must be a member of exactly their own group (orbit_runtime,orbit_worker,orbit_doors). The operator commands apply the first check to the owner login.
If any part stops or panics, the whole process exits with a non-zero code, so the supervisor (container runtime, systemd) can restart it. The environment variables are listed in deploy/.env.example. The operator commands (orbit migrate, orbit tenant provision, orbit keys ..., orbit health) are described in Operations.
Database roles
Each process connects with a login that has only what it needs.
| Role | Used by | Can do |
|---|---|---|
Owner (orbit_migrator) | orbit migrate, orbit tenant provision, orbit keys ... only. No serving process | Owns every Orbit schema and table |
orbit_runtime (login orbit_app) | The bus and every handler and subscriber, the kernel commands included | Read and write module tables, read memberships, insert audit entries, call kernel.set_module_enabled, read and add personal-data key versions. No DDL. Cannot bypass row-level security |
orbit_worker (login orbit_worker_login) | Relay, job worker, scheduler | Job queue and event delivery state. Not a member of orbit_runtime |
orbit_doors (login orbit_doors_login) | The web role only | Execute the identity, role-sync and MCP confirmation functions. No table privileges |
orbit_auth_migrator, orbit_auth | The auth sidecar | Only the auth schema |
The runtime role reads kernel.tenant_modules and kernel.module_switches but cannot write them directly: only kernel.set_module_enabled (owned by the owner, SECURITY DEFINER) can. It cannot update or delete key rows in pii.tenant_keys: re-wrapping and destroying keys are operator commands.
Row-level security
Every tenant-owned table has a tenant_id column. Migrations turn on row-level security for each such table with kernel.enable_tenant_rls. The policy shows and accepts only rows whose tenant_id equals the tenant set on the transaction. With no tenant set, no rows are visible. The policy is forced, so it applies to the owner role too. Handlers must still filter every statement by tenant_id: row-level security is the second safety net, not the first.
Databases and placements
Every install has the shared database. A tenant's data can live in another one listed in ORBIT_DATABASES (ADR 0011):
kernel.placements(shared) says where each tenant lives and whether it is being moved; no row meansshared. Sign-in mapping (doors.identities), MCP revocations and the files door's counters stay in the shared database.- The bus, the audit sink, the doors and the MCP door resolve the placement for every request and use that database's pools, opened on first use and bounded. Writers (a command, a job, an event delivery, an audit entry, a role sync) hold the tenant's write lock and re-read the placement under it, so a move can freeze them. A lookup that fails refuses; nothing falls back to
shared. - The worker and scheduler run a relay, a job runner and a scheduler per database.
orbit migratemigrates every database;orbit tenant movemoves a tenant between them.ORBIT_TENANT_ALLOWLISTlimits an instance to the tenants it lists.
Audit log
audit.entries holds one row per attempt: executed commands, denied commands and queries, failed commands, and queries that revealed personal fields (one row per request, naming the columns in fields). Operator commands that change a tenant (orbit tenant provision, orbit keys rotate|rewrap|destroy) are recorded too, with the actor and door system. Each row records the tenant, actor, door, request id, action, outcome (allowed, denied, failed, or read for a query that revealed personal fields) and whether the attempt was confirmed. It does not store input values. It stores keyed digests instead (see Security model). A published call (Ctx::query, ADR 0007) writes its own row with via, the calling module; a handler can add flags (e.g. self_approved) to its row. The table is append-only: the runtime role can only insert, cannot set the timestamp, and triggers refuse updates, deletes and truncation.