Clean Architecture
The Games API is built using Clean Architecture principles for maintainability, testability, and flexibility.Core Principles
1. Dependency Rule
Dependencies point inward toward business logic:2. Layers
Domain Layer (Entities)
Pure business rules with no external dependencies. Location:games/wheel/wheel-core/src/entities/
Profile- Validates names, versions, config hashesPrize- Validates prize data and image URLsConfig- Content-addressed configurations with probability validationInstance- Game instance lifecycle managementLink- Slug generation and validation
Application Layer (Use Cases)
Orchestrates business workflows. Location:games/wheel/wheel-core/src/use-cases/
CreateProfileUseCase- Profile creation with hash generationLookupLinkUseCase- Slug → instance resolutionCompleteInstanceUseCase- Prize selection algorithm
Infrastructure Layer
Database adapters implementing domain interfaces. Location:games/wheel/wheel-infrastructure/src/repositories/
NileProfileRepositoryimplementsIProfileRepositoryNilePrizeRepositoryimplementsIPrizeRepository- etc.
Presentation Layer
HTTP handlers (Rust + Axum). Location:api/wheel/src/adapters/
Converts HTTP requests → domain operations → HTTP responses
3. Benefits
Testability
Test business logic without frameworks:Flexibility
Swap infrastructure without changing business logic:Independence
- Framework changes don’t affect business logic
- Database changes don’t affect use cases
- UI changes don’t affect entities
Design Patterns
Repository Pattern
Domain defines interfaces, infrastructure implements:Use Case Pattern
Each use case handles one workflow:Config Deduplication
Configs are content-addressed and deduplicated:- Client POSTs config data
- System generates SHA256 hash
- Check if hash exists in database
- If exists: return existing config ID
- If not: create new config with hash
Folder Structure
Learn More
- Clean Architecture Book by Robert C. Martin
- Repository Architecture Guide
- Migration Guide
- Contributing Guide
