Skip to content

Server Architecture

The server follows clean architecture with four layers.

Dependency Rule

graph TD
    P[Presentation] --> A[Application]
    A --> D[Domain]
    I[Infrastructure] --> D
    I --> A
    P --> I

Dependencies always point inward. The domain layer has zero external dependencies.

Layer Responsibilities

Domain

  • Entities and value objects
  • Repository traits (interfaces)
  • Domain errors
  • Business rules that are always true regardless of use case

Application

  • Use cases (one struct per use case)
  • DTOs for input/output
  • Service traits
  • Application-level error types
  • Orchestrates domain objects — no direct DB or HTTP knowledge

Infrastructure

  • SQLx repository implementations
  • JWT token service
  • External API clients
  • Anything that talks to the outside world

Presentation

  • Actix-web route handlers
  • Request/response types (serde)
  • Middleware (auth, logging, error handling)
  • Askama template rendering
  • Dependency injection wiring (in main.rs)