How liuizn/tech-curse-api works
Purpose and entry points
Tech Curse API is a .NET 8 ASP.NET Core REST backend for course catalog, students, enrollments, authentication, and payment transactions. The composition root is tech-curse-api/src/API/Program.cs; HTTP entry points are the controllers in tech-curse-api/src/API/Controllers/. OpenAPI/Swagger and /health are operational entry points.
Layered architecture and boundaries
The project follows Clean Architecture/DDD separation:
• API owns HTTP, middleware, dependency wiring, auth, logging, Swagger, EF, and cache setup: tech-curse-api/src/API/Program.cs, tech-curse-api/src/API/Configuration/EFCoreSetup.cs, tech-curse-api/src/API/Configuration/IdentityAuthenticationSetup.cs.
• Application owns use cases, DTO contracts, service interfaces, and payment strategy selection: tech-curse-api/src/Application/Services/PaymentService.cs, tech-curse-api/src/Application/Factory/PaymentStrategyFactory.cs.
• Domain holds core entities, state enums, business exceptions, and payment eligibility rules without infrastructure dependencies: tech-curse-api/src/Domain/Entities/Payment.cs, tech-curse-api/src/Domain/Specifications/PaymentProcessableSpecification.cs.
• Infrastructure implements persistence, identity context access, and external gateways: tech-curse-api/src/Infrastructure/Data/TechCurseContext.cs, tech-curse-api/src/Infrastructure/ExternalServices/SimulatedPaymentGatewayAdapter.cs.
HTTP request pipeline
Requests enter ASP.NET Core and pass cross-cutting middleware for correlation IDs, exception translation, and idempotency before controller dispatch. Controllers map HTTP contracts to application services; services return DTO-oriented results or domain failures. Relevant paths: tech-curse-api/src/API/Middleware/CorrelationIdMiddleware.cs, tech-curse-api/src/API/Middleware/ExceptionHandlingMiddleware.cs, tech-curse-api/src/API/Middleware/IdempotencyFilterMiddleware.cs.
Identity and authorization
Authentication uses ASP.NET Core Identity plus JWT Bearer tokens. AuthController delegates registration/login behavior to application services; token creation and current-user retrieval are isolated behind interfaces and infrastructure implementations. Authorization is therefore an API/Application boundary rather than direct controller access to identity storage: tech-curse-api/src/API/Controllers/AuthController.cs, tech-curse-api/src/Application/Services/AuthService.cs, tech-curse-api/src/Infrastructure/Identity/CurrentUserService.cs.
Core learning-domain flow
Courses, students, and enrollments follow Controller → Application Service → Repository Interface → EF Core Repository → SQL Server. Domain entities represent the durable business model, while DTOs isolate API payloads from entities. Primary paths: tech-curse-api/src/API/Controllers/EnrollmentController.cs, tech-curse-api/src/Application/Services/EnrollmentService.cs, tech-curse-api/src/Infrastructure/Repositories/EnrollmentRepository.cs.
Payment processing flow
Payment requests are handled separately from enrollment CRUD. PaymentService applies domain processability rules, uses PaymentStrategyFactory to choose a payment-method strategy, then calls the gateway abstraction and persists transaction state through a repository. The current external provider is simulated, keeping the gateway replaceable: tech-curse-api/src/Application/Services/PaymentService.cs, tech-curse-api/src/Application/Strategies/CreditCardPaymentStrategy.cs, tech-curse-api/src/Infrastructure/ExternalServices/SimulatedPaymentGatewayAdapter.cs.
Data, cache, and operations
EF Core targets SQL Server; migrations define schema evolution and startup initialization applies migrations/seeds data. Redis is a distributed cache accessed through an application abstraction. Serilog emits structured logs to Seq, while Docker Compose provisions API, SQL Server, Redis, and Seq. Key paths: tech-curse-api/src/Infrastructure/Data/DbInitializer.cs, tech-curse-api/src/Application/Services/RedisCacheService.cs, docker-compose.yml.
Main entry points: PaymentService.cs Payment Service · Program.cs ASP.NET Core Host · EnrollmentRepository.cs EF Core Repositories · TechCurseContext.cs TechCurse DbContext
Components 20
API
HTTP host and request boundary.
- ASP.NET Core Host
tech-curse-api/src/API/Program.cs - Request Middleware · Correlation, exception translation, and idempotency.
tech-curse-api/src/API/Middleware/CorrelationIdMiddleware.cs - REST Controllers · Courses, students, enrollments, auth, and payments.
- Auth Controller
tech-curse-api/src/API/Controllers/AuthController.cs - Enrollment Controller
tech-curse-api/src/API/Controllers/EnrollmentController.cs
Application
Use cases and service abstractions.
- Auth Service
tech-curse-api/src/Application/Services/AuthService.cs - Enrollment Service
tech-curse-api/src/Application/Services/EnrollmentService.cs - Payment Service · Coordinates eligibility, strategy, gateway, and transaction persistence.
tech-curse-api/src/Application/Services/PaymentService.cs - Payment Strategy Factory
tech-curse-api/src/Application/Factory/PaymentStrategyFactory.cs - Redis Cache Service
tech-curse-api/src/Application/Services/RedisCacheService.cs - Credit Card Strategy
tech-curse-api/src/Application/Strategies/CreditCardPaymentStrategy.cs
Domain
Business model and payment rules.
- Payment Entity & Rules · Owns payment state and processability eligibility.
tech-curse-api/src/Domain/Specifications/PaymentProcessableSpecification.cs
Infrastructure
Persistence, identity, and external adapters.
- EF Core Repositories · Implements application repository interfaces.
tech-curse-api/src/Infrastructure/Repositories/EnrollmentRepository.cs - TechCurse DbContext
tech-curse-api/src/Infrastructure/Data/TechCurseContext.cs - Current User Service · Isolates current-user access from application services.
tech-curse-api/src/Infrastructure/Identity/CurrentUserService.cs - Simulated Payment Gateway · Replaceable external payment provider implementation.
tech-curse-api/src/Infrastructure/ExternalServices/SimulatedPaymentGatewayAdapter.cs - Database Initializer · Applies migrations and seed data.
tech-curse-api/src/Infrastructure/Data/DbInitializer.cs
Operations
Runtime dependencies and observability.
- SQL Server
docker-compose.yml - Redis
docker-compose.yml - Seq
docker-compose.yml
Connections 20
- ASP.NET Core Host → Request Middleware: configures
- Request Middleware → REST Controllers: dispatches
- REST Controllers → Enrollment Controller: includes
- REST Controllers → Auth Controller: includes
- Enrollment Controller → Enrollment Service: invokes
- Auth Controller → Auth Service: invokes
- REST Controllers → Payment Service: submits payments
- Enrollment Service → EF Core Repositories: uses repository interface
- Payment Service → Payment Entity & Rules: checks eligibility
- Payment Service → Payment Strategy Factory: selects strategy
- Payment Strategy Factory → Credit Card Strategy: creates
- Credit Card Strategy → Simulated Payment Gateway: charges through
- Payment Service → EF Core Repositories: persists transaction
- Auth Service → Current User Service: gets current user
- EF Core Repositories → TechCurse DbContext: uses
- TechCurse DbContext → SQL Server: persists to
- Redis Cache Service → Redis: caches in
- Database Initializer → TechCurse DbContext: migrates and seeds
- ASP.NET Core Host → Database Initializer: runs at startup
- ASP.NET Core Host → Seq: writes structured logs