Skip to main content

Crate seiva_server

Crate seiva_server 

Source
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.json and the /health/{live,ready} endpoints — through seiva_http::router. It is demo-free: it mounts no example module, so it is publishable. A real service’s apps/<name>-api composition root merges its modules’ generated controllers and calls serve_router; the accounts composition is exercised in this crate’s tests. See serve.
  • Runs a background worker host on the framework’s worker runtime (seiva::worker::run_worker). See run_workers.
  • Reads 12-factor configuration from the environment with seiva_config, validated at startup and guarded against dev shortcuts in production. See ServerConfig.
  • 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§

ConfigError
A compact startup-configuration error.
OidcConfig
The inbound-JWT verification configuration read from the environment. Present only when OIDC_JWKS_FILE_VAR, OIDC_ISSUER_VAR and OIDC_AUDIENCE_VAR are all set; a partial set fails the boot.
Server
A Seiva service with opt-in observability (ADR 0027).
ServerConfig
The runtime configuration of a Seiva service, read from the environment.
WorkerReport
What a worker did between start and shutdown.

Enums§

AppEnv
The runtime environment a service runs in, read from the APP_ENV environment variable.
ServeError
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). See HttpSecurity::cors_allowed_origins.
DEFAULT_HTTP_ADDR
The default HTTP bind address when neither HTTP_ADDR_VAR nor PORT_VAR is 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.json and the interactive reference (/docs, /redoc, /scalar). Defaults to true (FastAPI parity); set false to stop publishing the contract to anonymous callers (OWASP API9). See HttpSecurity::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; see ServerConfig.
METRICS_ADDR_VAR
The environment variable holding the Prometheus /metrics bind 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 the metrics feature; see Server::with_metrics.
OIDC_AUDIENCE_VAR
The expected JWT aud (audience). Required when OIDC_JWKS_FILE_VAR is set.
OIDC_ISSUER_VAR
The expected JWT iss (issuer). Required when OIDC_JWKS_FILE_VAR is 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, scope fallback). 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_VAR is unset; see ServerConfig.
RATE_LIMIT_MAX_REQUESTS_VAR
The per-client rate-limit budget per window. Defaults to RateLimit::DEFAULT_MAX_REQUESTS; 0 disables rate limiting entirely.
RATE_LIMIT_WINDOW_SECS_VAR
The rate-limit window length in seconds. Defaults to RateLimit::DEFAULT_WINDOW (60s); a 0 is clamped to 1s.
TRUST_FORWARDED_FOR_VAR
Whether the rate limiter keys on the trusted X-Forwarded-For client IP instead of the raw TCP peer. Set to true only behind a single trusted reverse proxy; defaults to false. See HttpSecurity::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.interval until shutdown resolves. Each pass runs IdempotencyStore::purge_expired inside a UnitOfWork transaction — the DORM store’s purge needs an open session — and reports how many it removed.
run_workers
Runs the background worker host until shutdown resolves, returning one WorkerReport per worker.
serve
Serves the framework HTTP surface until shutdown resolves, then drains.
serve_router
Serves an arbitrary application router on addr with the framework’s lifecycle: bind, flip health Starting -> Ready once the socket is live, and on shutdown flip to Draining before the server stops accepting so /health/ready goes 503 while in-flight requests finish.
shutdown_signal
Resolves once the process is asked to shut down: Ctrl-C (SIGINT) on every platform, or SIGTERM on unix (the signal an orchestrator sends to stop a container). A generated apps/<name>-api feeds this to serve_router so its service drains gracefully on delonix/Kubernetes termination without reimplementing signal handling.