← Tous les modèles

Pas de unwrap dans les handlers, erreurs typées, middleware Tower, SQL vérifié à la compilation.

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.

  1. No unwrap in handlers. Handlers and the code they call never use unwrap, expect or indexing that can panic on input. Clippy runs with -D warnings and clippy::unwrap_used denied outside tests and startup.

  2. Typed errors. Each layer has an error enum built with thiserror; the HTTP layer has one AppError that implements IntoResponse and maps each variant to a status and a body. Handlers return Result<T, AppError> and use ?.

  3. Tower middleware. Timeouts, request ids, tracing, compression and body limits are Tower layers from tower-http added once on the router. Handlers do not repeat cross-cutting code.

  4. Compile-checked SQL. Queries use sqlx::query! and query_as!, checked against the schema at build time with the offline .sqlx data committed. Migrations live in migrations/ and run with sqlx migrate.

  5. Extractors for input. Requests are read through extractors (Path, Query, Json, State) into typed structs with serde; validation runs in a custom extractor so invalid input never reaches the handler.

  6. Async without blocking. No blocking calls on the Tokio runtime; CPU-heavy or blocking work goes through spawn_blocking. Shared state is an Arc in State, and a std::sync::Mutex is never held across .await.

  7. Tested through the router. Handlers are tested by calling the real Router with tower::ServiceExt::oneshot, and database code with #[sqlx::test] against a real PostgreSQL.