Expand description
Delonix Seiva — the service runtime (“the main a module installs”).
This crate is the runtime that boots a Seiva service. It is the piece a
module’s binary installs instead of writing its own main; it replaces
DORM’s old dorm-api. It does four things, each delegated to a focused
framework crate so nothing is re-implemented here:
- Mounts the framework HTTP surface —
/openapi.jsonand the/health/{live,ready}endpoints — throughseiva_http::router. It is demo-free: it mounts no example module, so it is publishable. A real service’sapps/<name>-apicomposition root merges its modules’ generated controllers and callsserve_router; theaccountscomposition is exercised in this crate’s tests. Seeserve. - Runs a background worker host on the framework’s worker runtime
(
seiva::worker::run_worker). Seerun_workers. - Reads 12-factor configuration from the environment with
seiva_config, validated at startup and guarded against dev shortcuts in production. SeeServerConfig. - Shuts down gracefully: on a shutdown signal it flips the process to
HealthState::Draining— so a load balancer takes it out of rotation — and drains in-flight requests before exiting.
It is a LIBRARY (so each piece is testable without a live port or a running
clock) plus a thin binary (seiva-server) that wires the pieces together.
§DORM-free
This crate depends on no dorm-* crate and on none of the excluded,
DORM-git-coupled Seiva crates (seiva-data-dorm, seiva-outbox-relay,
seiva-rag-worker, seiva-mcp). It declares no cargo feature that could pull
any of them in. run_workers therefore ships a no-op demonstration pass
today; the real transactional-outbox relay pass is injected here behind the
framework’s dorm feature once the CI token for the private DORM repo exists.
§Example
use seiva_server::{run_workers, serve, ServerConfig};
let config = ServerConfig::from_process_env()?;
// A resolved shutdown future would stop both at once; a real binary feeds a
// Ctrl-C / SIGTERM future to each (see `src/main.rs`).
let (served, _reports) = tokio::join!(serve(config, async {}), run_workers(async {}));
served?;Modules§
- observability
- Structured logging for a Seiva service (12-factor: logs are an event stream written to stdout, for the platform to collect).
Structs§
- Config
Error - A compact startup-configuration error.
- Oidc
Config - The inbound-JWT verification configuration read from the environment. Present
only when
OIDC_JWKS_FILE_VAR,OIDC_ISSUER_VARandOIDC_AUDIENCE_VARare all set; a partial set fails the boot. - Server
- A Seiva service with opt-in observability (ADR 0027).
- Server
Config - The runtime configuration of a Seiva service, read from the environment.
- Worker
Report - What a worker did between start and shutdown.
Enums§
- AppEnv
- The runtime environment a service runs in, read from the
APP_ENVenvironment variable. - Serve
Error - An error raised while binding or serving the HTTP application.
Constants§
- CORS_
ALLOWED_ ORIGINS_ VAR - Comma-separated allowlist of cross-origin (CORS) origins, e.g.
https://app.example.com,https://admin.example.com. Unset or empty means same-origin only (no CORS layer). SeeHttpSecurity::cors_allowed_origins. - DEFAULT_
HTTP_ ADDR - The default HTTP bind address when neither
HTTP_ADDR_VARnorPORT_VARis set: loopback only, so an unconfigured service is not exposed off-box. - DEFAULT_
WORKER_ INTERVAL - The default interval between background worker passes. A pass that drains a backlog could poll faster; the demonstration pass has no backlog, so it idles at this cadence until shutdown.
- EXPOSE_
DOCS_ VAR - Whether to serve
/openapi.jsonand the interactive reference (/docs,/redoc,/scalar). Defaults totrue(FastAPI parity); setfalseto stop publishing the contract to anonymous callers (OWASP API9). SeeHttpSecurity::expose_docs. - EXPOSE_
ERROR_ DETAILS_ VAR - The environment variable for the development-only “expose internal error details to clients” shortcut. Guarded: it must not be enabled in production.
- HTTP_
ADDR_ VAR - The environment variable holding the full HTTP bind address (
host:port). Highest precedence; seeServerConfig. - METRICS_
ADDR_ VAR - The environment variable holding the Prometheus
/metricsbind address (host:port) — the separate admin scrape surface (ADR 0027), kept off the public API port. Unset (or empty) means no metrics exporter. Honoured only when the binary is built with themetricsfeature; seeServer::with_metrics. - OIDC_
AUDIENCE_ VAR - The expected JWT
aud(audience). Required whenOIDC_JWKS_FILE_VARis set. - OIDC_
ISSUER_ VAR - The expected JWT
iss(issuer). Required whenOIDC_JWKS_FILE_VARis set. - OIDC_
JWKS_ FILE_ VAR - Path to a JWKS (JSON Web Key Set) file whose keys verify inbound bearer JWTs. Setting it (with the issuer and audience below) turns on the authentication layer; leaving all three unset means no authn layer (every caller anonymous).
- OIDC_
PERMISSION_ CLAIM_ VAR - The claim carrying the caller’s permissions (default
permissions,scopefallback). Optional. - OIDC_
TENANT_ CLAIM_ VAR - The claim carrying the caller’s tenant (default
tenant). Optional. - PORT_
VAR - The environment variable holding a bare port, the convention many hosting
platforms (Heroku, Cloud Run, …) set. Used only when
HTTP_ADDR_VARis unset; seeServerConfig. - RATE_
LIMIT_ MAX_ REQUESTS_ VAR - The per-client rate-limit budget per window. Defaults to
RateLimit::DEFAULT_MAX_REQUESTS;0disables rate limiting entirely. - RATE_
LIMIT_ WINDOW_ SECS_ VAR - The rate-limit window length in seconds. Defaults to
RateLimit::DEFAULT_WINDOW(60s); a0is clamped to 1s. - TRUST_
FORWARDED_ FOR_ VAR - Whether the rate limiter keys on the trusted
X-Forwarded-Forclient IP instead of the raw TCP peer. Set totrueonly behind a single trusted reverse proxy; defaults tofalse. SeeHttpSecurity::trust_forwarded_for.
Functions§
- demo_
pass - The demonstration worker pass: a no-op that processes nothing and never fails.
- run_
idempotency_ purge - Runs a background worker that purges expired idempotency records (ADR 0011) on
config.intervaluntilshutdownresolves. Each pass runsIdempotencyStore::purge_expiredinside aUnitOfWorktransaction — the DORM store’s purge needs an open session — and reports how many it removed. - run_
workers - Runs the background worker host until
shutdownresolves, returning oneWorkerReportper worker. - serve
- Serves the framework HTTP surface until
shutdownresolves, then drains. - serve_
router - Serves an arbitrary application
routeronaddrwith the framework’s lifecycle: bind, fliphealthStarting -> Readyonce the socket is live, and onshutdownflip toDrainingbefore the server stops accepting so/health/readygoes503while in-flight requests finish. - shutdown_
signal - Resolves once the process is asked to shut down: Ctrl-C (SIGINT) on every
platform, or
SIGTERMon unix (the signal an orchestrator sends to stop a container). A generatedapps/<name>-apifeeds this toserve_routerso its service drains gracefully ondelonix/Kubernetes termination without reimplementing signal handling.