Clean Architecture Guidelines
When working on the backend of the Smart Travel Management System, you MUST adhere to the following Clean Architecture principles.
Structure
The solution consists of four main layers.
1. Domain Layer (SmartTravel.Domain)
- •Purpose: Inner-most layer. Contains enterprise logic and entities.
- •Contents: Entities, Enums, Value Objects, Domain Exceptions.
- •Dependencies: NONE. This project must not reference any other project.
- •Rules:
- •Do not include data annotations that depend on EF Core.
- •Keep logic pure C#.
2. Application Layer (SmartTravel.Application)
- •Purpose: Orchestrates application logic.
- •Contents: DTOs, Interfaces (Service contracts, Repository contracts), Validators, Mappers.
- •Dependencies: references
SmartTravel.Domain. - •Rules:
- •Define interfaces here (e.g.,
IUserService), implement them in Infrastructure. - •Use DTOs for data transfer, never expose Entities directly to the API.
- •Define interfaces here (e.g.,
3. Infrastructure Layer (SmartTravel.Infrastructure)
- •Purpose: Implements interfaces defined in Application.
- •Contents: Database Context (EF Core), Repositories, Services (e.g., EmailService), External API Integrations.
- •Dependencies: references
SmartTravel.ApplicationandSmartTravel.Domain. - •Rules:
- •All external concerns (SQL, File System, 3rd party APIs) go here.
4. API Layer (SmartTravel.API)
- •Purpose: The entry point.
- •Contents: Controllers, Middleware, Program.cs (DI setup).
- •Dependencies: references
SmartTravel.ApplicationandSmartTravel.Infrastructure. - •Rules:
- •Controllers should be thin. Delegate logic to Services/mediators.
- •Return standard HTTP responses.
Workflow for New Features
- •Domain: Define the Entity (if new).
- •Application: Define the DTOs and the Interface (e.g.,
IProductService). - •Infrastructure: Implement the Interface (e.g.,
ProductService). - •API: Create the Controller and register services in
Program.cs.