Expand description
Delonix Seiva — the HTTP transport.
This crate provides the transport-level pieces a module’s generated
controller builds on. It is demo-free and DORM-free: it links no example
module and no data layer, so it is a publishable building block. A module’s
#[seiva::controller] router and the composition root (seiva-server or a
project’s apps/<name>-api) merge the module routes into router.
problem— RFC 9457application/problem+jsonerrors (Problem).valid— a typed, validated JSON body extractor (Valid,Validate).guard— a descriptor-driven permission guard (permission_guard,Principal,RequiredPermission) plus tenant-ownership checks.bus— the context-bound pipeline behaviors (Authorize,Idempotent) that complete the ADR 0020 chain over theseiva-cqrsValidate/Transactional.security— secure-by-default response headers and configurable CORS.rate_limit— a per-client request rate limiter.health—/health/liveand/health/readyover aStarting -> Ready -> Draininglifecycle (Health).docs— an interactive/docsAPI reference over/openapi.json.request_id— per-request correlation (RequestId).
router assembles the framework surface — health, /openapi.json
(generated from every facade linked into the binary) and /docs — wrapped in
the security headers, optional CORS, the body-size limit, the rate limiter and
the request-id middleware. It mounts no module route itself; the composition
root merges those in.
Re-exports§
pub use audit::audit;pub use authn::authn;pub use authn::AuthConfig;pub use authn::Authn;pub use backpressure::with_route_controls;pub use backpressure::RouteControls;pub use backpressure::RouteLimit;pub use bus::Authorize;pub use bus::Idempotent;pub use bus::DEFAULT_IDEMPOTENCY_TTL;pub use ctx::Ctx;pub use docs::docs_handler;pub use docs::redoc_handler;pub use docs::scalar_handler;pub use docs::DOCS_HTML;pub use guard::permission_guard;pub use guard::require_permission;pub use guard::PrincipalExt;pub use guard::RequiredPermission;pub use guard::Scoped;pub use health::health_router;pub use health::health_router_with_dependency;pub use health::Health;pub use health::HealthState;pub use health::ReadinessCheck;pub use idempotency::fingerprint;pub use idempotency::in_progress_problem;pub use idempotency::mismatch_problem;pub use idempotency::scoped_key;pub use idempotency::IdempotencyKey;pub use idempotency::OptionalIdempotencyKey;pub use idempotency::IDEMPOTENCY_HEADER;pub use idempotency::MAX_KEY_LEN;pub use metrics::track_metrics;pub use metrics::REQUESTS_IN_FLIGHT;pub use metrics::REQUESTS_TOTAL;pub use metrics::REQUEST_DURATION_SECONDS;pub use problem::ProblemResponse;pub use problem::PROBLEM_JSON;pub use rate_limit::rate_limit;pub use rate_limit::rate_limit_with_store;pub use rate_limit::DistributedRateLimit;pub use rate_limit::RateLimit;pub use rate_limit::RateLimiter;pub use request_id::request_id;pub use request_id::RequestId;pub use request_id::REQUEST_ID_HEADER;pub use security::cors_layer;pub use security::security_headers;pub use security::HttpSecurity;pub use valid::Valid;
Modules§
- audit
- Persistent audit of administrative (and other sensitive) mutations (ADR 0013).
- authn
- The deny-by-default authentication middleware (ADR 0006).
- backpressure
- Per-route load control: a request timeout (→
504 Gateway Timeout) and a concurrency limit with immediate shedding (→503 Service Unavailable), applied per route so one slow or heavy endpoint cannot pin every worker while the rest of the service stays responsive. - bus
- The two pipeline behaviors that bind to the request context (ADR 0020).
- ctx
- The framework request context a facade method may receive as
&Ctx. - docs
- The interactive API-reference pages — Seiva’s FastAPI
/docsparity. - guard
- The descriptor-driven permission guard.
- health
- Liveness and readiness endpoints.
- idempotency
- HTTP-facing building blocks for durable idempotency (ADR 0011).
- metrics
- Per-request metrics, recorded against the
metricsfacade (ADR 0027). - problem
- RFC 9457
application/problem+jsonerror responses. - rate_
limit - A fixed-window, per-client request rate limiter (OWASP API4).
- request_
id - Per-request correlation id.
- security
- Secure-by-default response headers and configurable CORS.
- valid
- A typed, validated JSON body extractor.
Structs§
- ApiKey
Authenticator - An opaque API-key →
Principalmap with revocation: theX-API-Keycounterpart toTokenAuthenticator, sitting behind the sameAuthenticatortrait so a transport treats it like any other bearer path. - Audit
Entry - An audit record of a sensitive — typically administrative — mutation
(ADR 0013): who did what, to which object, with what result, and a
correlation id. Field-level
detailsare redacted of secrets before they ever reach a sink (seeAuditEntry::redacted); the full request body with its secrets is never stored. - JwtAuthenticator
- Verifies an OIDC/JWT bearer against an injected JWKS and maps its claims to a
Principal. - Principal
- The authenticated caller: who they are, the tenant their requests are scoped to (if any), and the permissions they hold.
- Problem
- An RFC 9457 problem detail: a machine-readable description of an error.
- Token
Authenticator - A static bearer-token →
Principalmap: the first-cut authenticator. - Validation
Error - Why a body was rejected as invalid. A single message in this first cut; a later phase can carry a per-field map.
Enums§
- Auth
Error - Why authentication failed. Free of any HTTP type so the trait does not drag a transport into the auth contract; each transport maps the variants to its own status codes.
- Rate
Limit Decision - The outcome of a rate-limit check for one client (ADR 0015).
Constants§
- DEFAULT_
BODY_ LIMIT_ BYTES - The default maximum request body size (1 MiB). Oversized bodies are rejected
before a handler runs. Mounted as
DefaultBodyLimitinrouter. - DEFAULT_
REQUEST_ TIMEOUT - The default per-request timeout (30 s). A request whose handler (or whose slow
client streaming the body) outlives this is cut off with
408 Request Timeout, so a slowloris client cannot pin a worker indefinitely (OWASP API4). Mounted as atower_http::timeout::TimeoutLayerin the framework layers.
Traits§
- Audit
Sink - A persistent sink for
AuditEntryrecords (ADR 0013). The base framework codes against this port; an adapter (the DORM gateway) persists the entries. - Authenticator
- Turns a presented bearer token into a
Principal, or rejects it. - Rate
Limit Store - A distributed rate-limit backend (ADR 0015): the authority a cluster shares so a client’s budget is enforced across replicas, not per-process.
- Validate
- A domain-shaped validation check on a deserialized body. Keep it cheap and synchronous: structural and range checks, not I/O. Business rules that need ports belong in the application layer, not here.
Functions§
- openapi_
document - Builds the service’s OpenAPI 3.1 document from every facade linked into the
binary, discovered through
seiva::contract::registered_facades(each#[seiva::facade]registers itself in a link-time inventory). Nothing here is hand-written and no central list is kept: a module mounted into the runtime contributes its operations automatically (OWASP API9). This crate links no facade of its own, so a plainseiva-httpbinary documents nothing; the full runtime (seeseiva-server) documents every mounted module. - route_
collisions - The
(version, resource)route-prefix collisions among every facade linked into the binary — two facades whose generated routers would mount on the same prefix and makeRouter::mergepanic at startup. Empty when the mounted facades are collision-free. A composition root calls this at boot to fail fast with a clear message instead of a bare axum panic (seeseiva::contract::route_collisions). - router
- Builds the framework router with the default security posture
(
HttpSecurity::default: secure response headers on, same-origin only — no CORS). Equivalent torouter_with_securitywith the default configuration; the zero-config entrypoint. - router_
with_ auth - Builds the framework router under
securityand an optional authentication layer, described byauth(anAuthConfig, or anyOption<Arc<dyn Authenticator>>which converts into a bearer-only one). When it carries any authenticator, every request is authenticated (ADR 0006) ahead of any route’spermission_guard— a missing credential becomesPrincipal::anonymous(public routes still serve, guarded routes403), a present-but-invalid one is a401.AuthConfig::nonemounts no authn layer (no caller is ever authenticated, so guarded routes answer403): the composition root supplies anAuthenticatorto actually admit callers. PassAuthConfig::with_api_keyto also admit opaqueX-API-Keycallers. - router_
with_ modules - Builds the full application router: the framework routes plus the caller’s
modules, wrapped in the framework layers — the composition a realapps/<name>-apineeds. - router_
with_ modules_ distributed - Like
router_with_modules, but enforces the per-client rate limit with a distributed store (DistributedRateLimit, ADR 0015) instead of the per-process limiter — the form that holds ONE budget across replicas behind a load balancer. The distributed limiter takes the in-process one’s exact layer position (inside the security headers, so a429still carries them), so a429keeps its correlation id and headers;security.rate_limitis ignored when a distributed limiter is supplied. Setsecurity.trust_forwarded_for(and pass it through on the limiter) only behind a single trusted proxy. - router_
with_ security - Builds the framework router — the health endpoints,
/openapi.jsonand/docs. Request flows through the layers outermost-first:request_id()→security_headers→ the rate limiter → the optional CORS layer → the body-size limit → the route.