CL

Clean Architecture

Used in 498 rust projects (avg ★81)

Details

Language / Topic
rustRust
Category
Architecture

Rules

balanced
- Organize into crates or modules: `domain` (structs, traits), `application` (use cases), `infrastructure` (DB, HTTP).
- Domain crate has zero external dependencies beyond `std`. Define repository traits in domain.
- Define domain traits for repositories and services — implement them in the infrastructure layer. Use `Arc<dyn Trait>` for dependency injection.
- Use traits for ports (repository interfaces). Implement with concrete types in infrastructure.
- Use cases are functions or structs that take trait bounds: `fn create_user(repo: &impl UserRepository, ...)`.
- Use `thiserror` for domain error types. Map infrastructure errors to domain errors at boundaries.
- Use `Arc<dyn Trait>` or generics for dependency injection at the application entry point.