Skip to content

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-exports
  • src/types.rs — Core type definitions
  • src/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_trait with Send + Sync
  • Services accept Arc<dyn RepositoryTrait> for DI
  • Entities use Uuid IDs and chrono::DateTime<Utc> timestamps

Key files:

  • src/entities.rs — All entity structs
  • src/repositories.rs — All repository trait definitions
  • src/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! or sqlx::query_as! with compile-time checking
  • Connection pooling via sqlx::PgPool

Key files:

  • src/postgres/ — One file per repository
  • src/seeding/templates.rs, demo.rs
  • src/email.rs — SMTP and Graph providers
  • src/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 all Arc<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 (AuthUser extractor)
  • Responses use ProblemDetails for errors (RFC 7807)
  • All request/response types use #[serde(rename_all = "camelCase")]

Key files:

  • src/main.rs — Server entry point
  • src/router.rs — Route definitions
  • src/state.rs — AppState with 35+ injected services
  • src/handlers/ — One handler file per resource