How hcmc-metro-swd392/summer2025swd392_net1703_group2_be works
Project Type & Purpose
• This is a monolithic, layered ASP.NET Core Web API backend (“MetroTicketBE”) powering a metro ticketing system for Ho Chi Minh City.
• It implements end-to-end ticketing workflows (route search, purchase, QR check-in/out, over-station payment), staff/training scheduling, real-time notifications, and audit logging.
File Structure Analysis
• Top-level solution (.sln) with four projects:
• Domain – core entities, enums, DTOs
• Application – business services, SignalR hubs, AutoMapper mappings, third-party integrations (Redis, AWS, PayOS)
• Infrastructure – EF Core DbContext, repositories, UnitOf-Work, seeding
• WebAPI – controllers, DI extensions, program startup, SignalR endpoints, swagger/CORS/auth setup
• CI/CD pipeline under .github/workflows.
• External-integration code (Redis extensions, AWS S3/SES, PayOS).
README Insights
• Clean-layered architecture (Domain-Application-Infrastructure-WebAPI).
• Key capabilities: multi-line routing (StationGraph + Dijkstra), QR lifecycle (Redis short-lived + persisted for single rides), over-station price adjustments, SignalR notifications, JWT/Identity auth with Redis refresh tokens.
• Persistence: EF Core → PostgreSQL. Caching: Redis. Real-time: SignalR. Cloud: AWS S3/SES. Payments: PayOS.
Diagramming the Architecture
a. Main Components & Layers
• Clients (Web/Mobile) → HTTP/SignalR
• WebAPI Layer
– Controllers (REST endpoints)
– SignalR Hubs (real-time channels)
– Authentication & Authorization (JWT + Identity)
• Application Layer
– Services (IAuthService, ITicketService, ITrainScheduleService, etc.)
– Hubs (ChatRoomHub, LobbyHub, NotificationHub)
– Mappings (AutoMapper profiles)
– Integrations (Redis service, S3 service, Email service, PayOS service)
– StationGraph module (routing engine)
• Domain Layer
– Entities, Enums, DTOs
• Infrastructure Layer
– ApplicationDBContext (EF Core)
– Repositories & UnitOfWork
– Seeding logic
• External Systems
– PostgreSQL database
– Redis cache/session store
– AWS S3 & SES
– PayOS API
– CI/CD → GitHub Actions → AWS EC2/Kestrel
b. Relationships & Data Flow
1. Client issues REST call or opens SignalR connection against WebAPI.
2. WebAPI Controller dispatches to Application Services via DI.
3. Application Service executes business logic, may:
– Query StationGraph for routing,
– Generate/validate QR (persist or use Redis TTL),
– Trigger notifications via SignalR hub,
– Call Infrastructure Repositories to read/write Domain Entities,
– Upload attachments to S3 or send email via SES,
– Initiate payment link via PayOS SDK.
4. Infrastructure layer interacts with PostgreSQL and Redis.
5. Application returns DTOs to Controller → response to Client.
c. Architectural Patterns & Principles
• Layered/Clean architecture with clear separation of concerns
• Repository + Unit Of Work for data access
• Dependency Injection for service wiring
• Event-style notifications via SignalR
• External adapter pattern for AWS, Redis, PayOS
• Graph abstraction (StationGraph) encapsulates routing algorithm
d. Key Technologies
• ASP.NET Core 8, C#
• EF Core 8 (PostgreSQL via Npgsql)
• Redis (StackExchange.Redis)
• SignalR
• AWS S3 & SES
• PayOS SDK
• AutoMapper, Swagger (Swashbuckle)
• GitHub Actions → AWS EC2