Niente unwrap negli handler, errori tipizzati, middleware Tower, SQL verificato in compilazione.
Constitution — Rust + Axum service
Version 1.0.0 · Ratified 2026-11-10
These principles hold for every spec, plan and task of the project. A spec may add rules; it never weakens these.
-
No unwrap in handlers. Handlers and the code they call never use
unwrap,expector indexing that can panic on input. Clippy runs with-D warningsandclippy::unwrap_useddenied outside tests and startup. -
Typed errors. Each layer has an error enum built with
thiserror; the HTTP layer has oneAppErrorthat implementsIntoResponseand maps each variant to a status and a body. Handlers returnResult<T, AppError>and use?. -
Tower middleware. Timeouts, request ids, tracing, compression and body limits are Tower layers from
tower-httpadded once on the router. Handlers do not repeat cross-cutting code. -
Compile-checked SQL. Queries use
sqlx::query!andquery_as!, checked against the schema at build time with the offline.sqlxdata committed. Migrations live inmigrations/and run withsqlx migrate. -
Extractors for input. Requests are read through extractors (
Path,Query,Json,State) into typed structs withserde; validation runs in a custom extractor so invalid input never reaches the handler. -
Async without blocking. No blocking calls on the Tokio runtime; CPU-heavy or blocking work goes through
spawn_blocking. Shared state is anArcinState, and astd::sync::Mutexis never held across.await. -
Tested through the router. Handlers are tested by calling the real
Routerwithtower::ServiceExt::oneshot, and database code with#[sqlx::test]against a real PostgreSQL.