04 - Architecture
Clean Architecture at a glance. For full component diagrams and sequence flows, see Backend Architecture (diagrams).
This page is a quick summary. For component diagrams, request pipeline, provider chain sequence diagrams, and clean architecture circles, open backend-architecture.html.
The 5 Projects
| # | Project | Role | Depends on |
|---|---|---|---|
| 1 | Domain | 75 POCO entities | Nothing |
| 2 | Shared | ApiRoutes, ErrorCodes, ApiResponse, helpers | Nothing |
| 3 | Application | CQRS models, Interfaces (IJourneyTracker, IPaymentService, etc.) | Domain, Shared |
| 4 | Infrastructure | EF Core, services, external providers, Hangfire, Kafka | Application, Domain, Shared |
| 5 | Api | Controllers, Filters, Middleware, Program.cs (composition root) | Application, Infrastructure, Shared |
Dependency Rule
Dependencies flow inward. The outermost layer (Api) depends on everything. The innermost layer (Domain) depends on nothing. Interfaces in Application let Infrastructure swap implementations without rippling back.
Example: IJourneyTracker is defined in MO.Ekyc.Application/Interfaces/. The implementation JourneyTracker lives in MO.Ekyc.Infrastructure/Services/Common/. Services consume the interface, DI wires the implementation in Program.cs.
Request Flow (one sentence)
HTTP request → CorrelationId → Exception handler → Request logging → JWT auth → Session refresh → CORS → StageValidationFilter → Controller action → Service → ProviderChainExecutor (for external calls) → EF Core → ApiResponse<T> JSON back to client.
Where Logic Lives
| What | Where |
|---|---|
| HTTP routing + validation | Controller action (minimal - delegates to service) |
| Stage enforcement | [RequiresStage(N)] attribute + StageValidationFilter |
| Business logic + orchestration | Stage-specific services (RegistrationService, BankVerificationService, etc.) |
| Database reads/writes | EkycDbContext via services |
| External API calls | External providers through ProviderChainExecutor |
| Journey state transitions | IJourneyTracker (Common service) |
| Audit logging | ApiAuditLogger (for external calls), JourneyActivityLogger (for lead events) |
| Mock mode decisions | Service constructors read MockMode:GlobalMockEnabled; ProviderChainExecutor reads provider_configurations.mock_mode |
Full Diagrams
- Backend Architecture HTML - component diagram, clean arch layers, request pipeline, sequence diagrams
- Sync Tables Master List
- DB Actions Checklist