# liuizn/tech-curse-api architecture

> Architecture diagram of the GitHub repository liuizn/tech-curse-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/liuizn/tech-curse-api
- Repository: https://github.com/liuizn/tech-curse-api

## Overview

#### 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: [`tech-curse-api/src/Application/Services/PaymentService.cs`](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Application/Services/PaymentService.cs) (Payment Service), [`tech-curse-api/src/API/Program.cs`](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/API/Program.cs) (ASP.NET Core Host), [`tech-curse-api/src/Infrastructure/Repositories/EnrollmentRepository.cs`](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Infrastructure/Repositories/EnrollmentRepository.cs) (EF Core Repositories), [`tech-curse-api/src/Infrastructure/Data/TechCurseContext.cs`](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Infrastructure/Data/TechCurseContext.cs) (TechCurse DbContext)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API"]
  node_program["ASP.NET Core Host<br/>composition root<br/>[Program.cs]"]
  node_middleware["Request Middleware<br/>cross-cutting pipeline"]
  node_controllers["REST Controllers<br/>HTTP endpoints"]
  node_auth_controller["Auth Controller<br/>HTTP endpoint<br/>[AuthController.cs]"]
  node_enrollment_controller["Enrollment Controller<br/>HTTP endpoint"]
end

subgraph group_application["Application"]
  node_auth_service["Auth Service<br/>application service<br/>[AuthService.cs]"]
  node_enrollment_service["Enrollment Service<br/>application service"]
  node_payment_service["Payment Service<br/>application service<br/>[PaymentService.cs]"]
  node_payment_factory["Payment Strategy Factory<br/>strategy selector"]
  node_cache_service["Redis Cache Service<br/>cache abstraction"]
  node_payment_strategy["Credit Card Strategy<br/>payment strategy"]
end

subgraph group_domain["Domain"]
  node_payment_domain{{"Payment Entity &amp; Rules<br/>domain model"}}
end

subgraph group_infrastructure["Infrastructure"]
  node_ef_repository["EF Core Repositories<br/>repository implementation"]
  node_db_context[("TechCurse DbContext<br/>EF Core context")]
  node_identity_adapter["Current User Service<br/>identity adapter"]
  node_payment_gateway["Simulated Payment Gateway<br/>gateway adapter"]
  node_initializer["Database Initializer<br/>startup initialization<br/>[DbInitializer.cs]"]
end

subgraph group_operations["Operations"]
  node_sql_server[("SQL Server<br/>relational database<br/>[docker-compose.yml]")]
  node_redis[("Redis<br/>distributed cache<br/>[docker-compose.yml]")]
  node_seq["Seq<br/>log sink<br/>[docker-compose.yml]"]
end

node_program -->|"configures"| node_middleware
node_middleware -->|"dispatches"| node_controllers
node_controllers -.->|"includes"| node_enrollment_controller
node_controllers -.->|"includes"| node_auth_controller
node_enrollment_controller -->|"invokes"| node_enrollment_service
node_auth_controller -->|"invokes"| node_auth_service
node_controllers -->|"submits payments"| node_payment_service
node_enrollment_service -->|"uses repository interface"| node_ef_repository
node_payment_service -->|"checks eligibility"| node_payment_domain
node_payment_service -->|"selects strategy"| node_payment_factory
node_payment_factory -->|"creates"| node_payment_strategy
node_payment_strategy -->|"charges through"| node_payment_gateway
node_payment_service -->|"persists transaction"| node_ef_repository
node_auth_service -->|"gets current user"| node_identity_adapter
node_ef_repository -->|"uses"| node_db_context
node_db_context -->|"persists to"| node_sql_server
node_cache_service -->|"caches in"| node_redis
node_initializer -->|"migrates and seeds"| node_db_context
node_program -->|"runs at startup"| node_initializer
node_program -->|"writes structured logs"| node_seq

click node_program "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/API/Program.cs"
click node_middleware "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/API/Middleware/CorrelationIdMiddleware.cs"
click node_auth_controller "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/API/Controllers/AuthController.cs"
click node_enrollment_controller "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/API/Controllers/EnrollmentController.cs"
click node_auth_service "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Application/Services/AuthService.cs"
click node_enrollment_service "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Application/Services/EnrollmentService.cs"
click node_payment_service "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Application/Services/PaymentService.cs"
click node_payment_factory "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Application/Factory/PaymentStrategyFactory.cs"
click node_cache_service "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Application/Services/RedisCacheService.cs"
click node_payment_domain "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Domain/Specifications/PaymentProcessableSpecification.cs"
click node_ef_repository "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Infrastructure/Repositories/EnrollmentRepository.cs"
click node_db_context "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Infrastructure/Data/TechCurseContext.cs"
click node_identity_adapter "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Infrastructure/Identity/CurrentUserService.cs"
click node_payment_gateway "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Infrastructure/ExternalServices/SimulatedPaymentGatewayAdapter.cs"
click node_payment_strategy "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Application/Strategies/CreditCardPaymentStrategy.cs"
click node_sql_server "https://github.com/liuizn/tech-curse-api/blob/main/docker-compose.yml"
click node_redis "https://github.com/liuizn/tech-curse-api/blob/main/docker-compose.yml"
click node_seq "https://github.com/liuizn/tech-curse-api/blob/main/docker-compose.yml"
click node_initializer "https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Infrastructure/Data/DbInitializer.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_program,node_middleware,node_controllers,node_auth_controller,node_enrollment_controller toneBlue
class node_auth_service,node_enrollment_service,node_payment_service,node_payment_factory,node_cache_service,node_payment_strategy toneAmber
class node_payment_domain toneMint
class node_ef_repository,node_db_context,node_identity_adapter,node_payment_gateway,node_initializer toneRose
class node_sql_server,node_redis,node_seq toneIndigo
```

## Components

### API

HTTP host and request boundary.

- [ASP.NET Core Host](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/API/Program.cs): composition root · `tech-curse-api/src/API/Program.cs`
- [Request Middleware](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/API/Middleware/CorrelationIdMiddleware.cs): cross-cutting pipeline · Correlation, exception translation, and idempotency. · `tech-curse-api/src/API/Middleware/CorrelationIdMiddleware.cs`
- **REST Controllers**: HTTP endpoints · Courses, students, enrollments, auth, and payments.
- [Auth Controller](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/API/Controllers/AuthController.cs): HTTP endpoint · `tech-curse-api/src/API/Controllers/AuthController.cs`
- [Enrollment Controller](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/API/Controllers/EnrollmentController.cs): HTTP endpoint · `tech-curse-api/src/API/Controllers/EnrollmentController.cs`

### Application

Use cases and service abstractions.

- [Auth Service](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Application/Services/AuthService.cs): application service · `tech-curse-api/src/Application/Services/AuthService.cs`
- [Enrollment Service](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Application/Services/EnrollmentService.cs): application service · `tech-curse-api/src/Application/Services/EnrollmentService.cs`
- [Payment Service](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Application/Services/PaymentService.cs): application service · Coordinates eligibility, strategy, gateway, and transaction persistence. · `tech-curse-api/src/Application/Services/PaymentService.cs`
- [Payment Strategy Factory](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Application/Factory/PaymentStrategyFactory.cs): strategy selector · `tech-curse-api/src/Application/Factory/PaymentStrategyFactory.cs`
- [Redis Cache Service](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Application/Services/RedisCacheService.cs): cache abstraction · `tech-curse-api/src/Application/Services/RedisCacheService.cs`
- [Credit Card Strategy](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Application/Strategies/CreditCardPaymentStrategy.cs): payment strategy · `tech-curse-api/src/Application/Strategies/CreditCardPaymentStrategy.cs`

### Domain

Business model and payment rules.

- [Payment Entity & Rules](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Domain/Specifications/PaymentProcessableSpecification.cs): domain model · Owns payment state and processability eligibility. · `tech-curse-api/src/Domain/Specifications/PaymentProcessableSpecification.cs`

### Infrastructure

Persistence, identity, and external adapters.

- [EF Core Repositories](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Infrastructure/Repositories/EnrollmentRepository.cs): repository implementation · Implements application repository interfaces. · `tech-curse-api/src/Infrastructure/Repositories/EnrollmentRepository.cs`
- [TechCurse DbContext](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Infrastructure/Data/TechCurseContext.cs): EF Core context · `tech-curse-api/src/Infrastructure/Data/TechCurseContext.cs`
- [Current User Service](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Infrastructure/Identity/CurrentUserService.cs): identity adapter · Isolates current-user access from application services. · `tech-curse-api/src/Infrastructure/Identity/CurrentUserService.cs`
- [Simulated Payment Gateway](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Infrastructure/ExternalServices/SimulatedPaymentGatewayAdapter.cs): gateway adapter · Replaceable external payment provider implementation. · `tech-curse-api/src/Infrastructure/ExternalServices/SimulatedPaymentGatewayAdapter.cs`
- [Database Initializer](https://github.com/liuizn/tech-curse-api/blob/main/tech-curse-api/src/Infrastructure/Data/DbInitializer.cs): startup initialization · Applies migrations and seed data. · `tech-curse-api/src/Infrastructure/Data/DbInitializer.cs`

### Operations

Runtime dependencies and observability.

- [SQL Server](https://github.com/liuizn/tech-curse-api/blob/main/docker-compose.yml): relational database · `docker-compose.yml`
- [Redis](https://github.com/liuizn/tech-curse-api/blob/main/docker-compose.yml): distributed cache · `docker-compose.yml`
- [Seq](https://github.com/liuizn/tech-curse-api/blob/main/docker-compose.yml): log sink · `docker-compose.yml`

## Connections

- 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
