Crates¶
The backend is a Cargo workspace with four crates. Dependencies flow strictly downward.
shared¶
Pure types with no business logic. Depends on nothing.
Contains:
- DTOs (request/response types)
- Error types (
ProblemDetails— RFC 7807) - Validation utilities
- Pagination types
- Common enums shared between layers
Key files:
src/lib.rs— Re-exportssrc/types.rs— Core type definitionssrc/problem_details.rs— Error response format
domain¶
Business logic layer. Defines traits that infra implements.
Contains:
- Entity definitions (
entities.rs) - Repository traits (
repositories.rs) —CaseRepository,ParticipantRepository, etc. - Domain services (
services/) — Business rules, calculations - Document processing — Block types, DOCX export, variable resolution
- Template evaluation engine
Key patterns:
- Repository traits use
async_traitwithSend + Sync - Services accept
Arc<dyn RepositoryTrait>for DI - Entities use
UuidIDs andchrono::DateTime<Utc>timestamps
Key files:
src/entities.rs— All entity structssrc/repositories.rs— All repository trait definitionssrc/services/— Business logic implementations
infra¶
Infrastructure layer. Implements domain traits with concrete technologies.
Contains:
- PostgreSQL repositories (
postgres/) — sqlx-based implementations - Email providers (SMTP, Microsoft Graph)
- LDAP client
- TOTP (2FA)
- Image processing (signatures)
- File storage (encrypted)
- Export (CSV, PDF)
- Seeding (templates, demo data)
- Legacy migration (SQL Server)
Key patterns:
- Each repository in
postgres/implements a domain trait - Queries use
sqlx::query!orsqlx::query_as!with compile-time checking - Connection pooling via
sqlx::PgPool
Key files:
src/postgres/— One file per repositorysrc/seeding/—templates.rs,demo.rssrc/email.rs— SMTP and Graph providerssrc/storage.rs— Encrypted file storage
Binaries:
src/bin/seed_demo.rs— Demo data seeder (cargo run --bin seed-demo)
api¶
HTTP layer. Axum handlers, router, middleware.
Contains:
- Route handlers (
handlers/) — One file per resource - Router configuration (
router.rs) - Application state (
state.rs) — Holds allArc<dyn Trait>services - Middleware (auth, CORS, logging)
- WebSocket support
Key patterns:
- Handlers extract from Axum (
Json<T>,Path<Uuid>,Query<T>) - Auth via JWT middleware (
AuthUserextractor) - Responses use
ProblemDetailsfor errors (RFC 7807) - All request/response types use
#[serde(rename_all = "camelCase")]
Key files:
src/main.rs— Server entry pointsrc/router.rs— Route definitionssrc/state.rs— AppState with 35+ injected servicessrc/handlers/— One handler file per resource