How william-le1004/dtp-backend works
Project type and purpose
• This is a RESTful, backend-only API built in ASP.NET Core 8 using Clean (Onion/Hexagonal) Architecture.
• It provides user authentication, role-based authorization, user management, ordering and payment features, caching via Redis, background jobs via Hangfire, and integration events via a message bus.
File structure
• Top-level layers:
– API (Presentation)
– Application (Business Logic & CQRS/MediatR)
– Domain (Entities, Value Objects, Domain Events)
– Infrastructure (EF Core DbContexts, Repositories, External Services)
• Key infra services: RedisCache, Cloudinary, Firebase (FCM), JWT token service, Hangfire job services, EventBus
• Persistence: MySQL via DtpDbContext, EF Core Migrations
• Middleware pipeline: ErrorHandling, JWTBlacklist, Transaction
README for insights
• Confirms Clean Architecture, CQRS (MediatR), EF Core, Redis, Docker Compose orchestrating API + Redis + MySQL
• Mentions Swagger, role-based access control, Docker setup
a. Main components
– API Layer
• HTTP Clients → API Gateway (ASP.NET Core WebHost)
• Middleware chain → Authentication, Authorization, ErrorHandling, Transaction
• Controllers (Authentication, User, Tour, Order, Payment, Wallet, etc.)
– Application Layer
• MediatR pipeline → Commands & Queries → Domain Events → Integration Events
• DTOs, Validation, Mapping
– Domain Layer
• Entities, ValueObjects, DomainEvents
– Infrastructure Layer
• Persistence
· EF Core DbContext → MySQL database
· Repositories implementing I*Repository interfaces
• Caching
· Redis cache service → Redis server
• External Services
· Cloudinary (media uploads)
· Firebase FCM (notifications)
· EventBus (message broker, e.g., RabbitMQ or similar)
· Hangfire (job scheduling & background workers)
– External Data Stores & Services
• MySQL DB container
• Redis container
• Docker Engine hosting all containers
b. Relationships & data flows
1. Client HTTP → API Gateway
2. Middleware validates token, enforces roles, handles errors
3. Controller receives request → delegates to Application via MediatR
4. Command/Query Handler loads/stores Domain Entities through Repository → DbContext → MySQL
5. Handler may raise DomainEvent → Infrastructure’s EventBus publishes IntegrationEvent
6. InfraServices call Redis, Cloudinary, Firebase as needed
7. Hangfire jobs run in background (triggered by EventBus or scheduled)
8. Response travels back up chain → client
c. Architectural patterns & principles
– Clean Architecture / Onion / Hexagonal: Dependency Inversion between layers
– CQRS via MediatR for separation of reads (Queries) and writes (Commands)
– Repository Pattern and Unit of Work via EF Core DbContext
– Domain Events with integration to a messaging bus
– Middleware Pipeline for cross-cutting concerns (error handling, auth, transactions)
– Docker Compose for containerized dependencies
d. Key technologies
– ASP.NET Core Web API, Controllers, Middleware
– MediatR
– Entity Framework Core → MySQL
– Redis (IDistributedCache)
– Hangfire for background processing
– Cloudinary, Firebase FCM
– Docker & Docker Compose
– Swagger (OpenAPI)