1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//! 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 9457 `application/problem+json` errors ([`Problem`]).
//! - [`valid`] — a typed, validated JSON body extractor ([`Valid`], [`Validate`]).
//! - [`guard`] — a descriptor-driven permission guard ([`permission_guard`],
//! [`Principal`], [`RequiredPermission`]) plus tenant-ownership checks.
//! - [`security`] — secure-by-default response headers and configurable CORS.
//! - [`mod@rate_limit`] — a per-client request rate limiter.
//! - [`health`] — `/health/live` and `/health/ready` over a
//! `Starting -> Ready -> Draining` lifecycle ([`Health`]).
//! - [`docs`] — an interactive `/docs` API reference over `/openapi.json`.
//! - [`mod@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.
use Arc;
use DefaultBodyLimit;
use ;
use get;
use ;
pub use authn;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
// The identity model is owned by `seiva-identity` (transport-free, shared with
// MCP); re-exported here so a `seiva_http::Principal` import keeps working.
pub use ;
/// The default maximum request body size (1 MiB). Oversized bodies are rejected
/// before a handler runs. Mounted as [`DefaultBodyLimit`] in [`router`].
pub const DEFAULT_BODY_LIMIT_BYTES: usize = 1024 * 1024;
/// Builds the service's OpenAPI 3.1 document from **every facade linked into the
/// binary**, discovered through [`delonix_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 plain `seiva-http` binary documents nothing;
/// the full runtime (see `seiva-server`) documents every mounted module.
/// `GET /openapi.json` — serves the generated [`openapi_document`].
async
/// Builds the framework router with the **default** security posture
/// ([`HttpSecurity::default`]: secure response headers on, same-origin only — no
/// CORS). Equivalent to [`router_with_security`] with the default configuration;
/// the zero-config entrypoint.
/// Builds the framework router — the health endpoints, `/openapi.json` and
/// `/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.
///
/// `security_headers` and `request_id` are the **outermost** layers on purpose:
/// every response carries them even when an outer layer short-circuits before the
/// route runs — a rate-limiter `429` or a CORS preflight included. (With the
/// headers mounted inside the rate limiter, a `429` went out naked — no CSP, no
/// `nosniff`, no HSTS — measured end-to-end.)
///
/// It mounts no module route; the composition root merges each module's generated
/// controller router into the result. `security` controls the transport-level
/// API8 defences: the response headers are always applied, and CORS is mounted
/// only when [`HttpSecurity::cors_allowed_origins`] is non-empty (otherwise the
/// browser enforces same-origin).
/// Builds the framework router under `security` and an optional authentication
/// layer: when `authenticator` is `Some`, every request is authenticated (ADR
/// 0006) ahead of any route's [`permission_guard`] — a missing bearer becomes
/// [`Principal::anonymous`] (public routes still serve, guarded routes `403`),
/// a present-but-invalid one is a `401`. `None` mounts no authn layer (no caller
/// is ever authenticated, so guarded routes answer `403`): the composition root
/// supplies an [`Authenticator`] to actually admit callers.
///
/// Layer order, outermost-first: [`request_id()`] → [`security_headers`] →
/// [`authn()`] → the rate limiter → CORS → the body-size limit → the route.
/// `authn` sits inside the header layers (so a `401` still carries them) but
/// outside the routes (so it runs before each route's guard).
/// Builds the full application router: the framework routes **plus the caller's
/// `modules`**, wrapped in the framework layers — the composition a real
/// `apps/<name>-api` needs.
///
/// Why this exists: axum's [`Router::layer`](axum::Router::layer) wraps only the
/// routes already present, so `router_with_auth(..).merge(modules)` would leave
/// the module routes **outside** every middleware — no authn, no security
/// headers, no rate limit. Merging the modules *before* layering (what this does)
/// is the only order that applies the framework's guarantees to module routes.
/// Mount each module's generated controller router into `modules` and pass it here.
/// The framework's own routes, unlayered: health, `/openapi.json` and `/docs`.
///
/// There is deliberately **no** `/admin` here: the admin console is an optional
/// extension (`seiva-console-admin`, ADR 0008), not part of the base. A backend
/// built without that crate answers `404` for `/admin`; a composition root that
/// wants it calls `seiva_console_admin::mount(router)` before serving.
/// Wraps `app` (framework routes, and any merged module routes) in the transport
/// middleware. Layer order, outermost-first: [`request_id()`] →
/// [`security_headers`] → [`authn()`] → the rate limiter → CORS → the body-size
/// limit → the route. `authn` sits inside the header layers (so a `401` still
/// carries them) but outside the routes (so it runs before each route's guard).