# ntxinh/aspnetcore-ddd architecture

> Architecture diagram of the GitHub repository ntxinh/aspnetcore-ddd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ntxinh/aspnetcore-ddd
- Repository: https://github.com/ntxinh/aspnetcore-ddd

## Overview

##### Project type and purpose
- This is a back-end, Domain-Driven Design (DDD) project built with ASP.NET Core Web API.
- It implements layered architecture (Presentation/API, Application, Domain, Infrastructure), CQRS, Event Sourcing, Repository/Unit-of-Work, MediatR, FluentValidation, Identity, External Providers, and migration tooling (DbUp via CLI).

##### File structure
- Top-level “Src/DDD.Services.Api” is the API layer (controllers, StartupExtensions, Program).
- “Src/DDD.Application” contains application services, DTO/ViewModels, MediatR handlers.
- “Src/DDD.Domain” holds core entities, commands/events, specifications, validations, and domain event handlers.
- “Src/DDD.Infra.Data” implements EF Core DbContexts (ApplicationDbContext, EventStoreSQLContext), mappings, repositories, UoW, and event store persistence.
- “Src/DDD.Infra.CrossCutting.Identity” is the identity subsystem with its own DbContext, JWT, email/SMS services.
- “Src/DDD.Infra.CrossCutting.Bus” provides the in-memory MediatR bus.
- “Src/DDD.CLI.Migration” is a console tool that runs SQL scripts (DbUp).
- “Tests” contains unit tests for application services and integration tests for the API.
- Docker, Kubernetes manifests, and CI/CD workflows sit at the repo root.

##### README and embedded docs
- The technical stack and patterns section confirms DDD, CQRS, Event Sourcing, UoW, Repository, Mediator, Specification, Options Pattern, AutoMapper, FluentValidation, MediatR, EF Core, Identity, Quartz, SignalR, Refit, NPOI, Polly, Swagger.

##### Diagramming conventions
- Blue: Presentation/API
- Green: Application
- Yellow: Domain
- Orange: Infrastructure/Cross-cutting
- Gray: External Systems/Databases
- Rectangles for services/components
- Clouds for external providers (SMTP, HTTP APIs)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation/API Layer
    subgraph "Presentation/API Layer"
        direction TB
        APIControllers["Controllers (v1/v2)"]:::frontend
        APIProgram["Program.cs"]:::frontend
        APIMiddleware["Middleware & Swagger"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        ICustomerAppService["ICustomerAppService"]:::application
        CustomerAppService["CustomerAppService"]:::application
        EventNormalizers["EventSourcedNormalizers"]:::application
        CustomerViewModel["CustomerViewModel"]:::application
        AutoMapperConfig["AutoMapperConfig"]:::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        CoreKernel["Core Kernel"]:::domain
        CustomerEntity["Customer Entity"]:::domain
        Commands["Commands"]:::domain
        CommandHandler["CustomerCommandHandler"]:::domain
        Events["Domain Events"]:::domain
        EventHandler["CustomerEventHandler"]:::domain
        Specifications["Specifications"]:::domain
        Validations["Validations"]:::domain
        DomainProviders["Domain Providers (Crons, HTTP, Mail, Office, Webhooks, Hubs)"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        subgraph "Data Persistence"
            direction TB
            ApplicationDbContext["ApplicationDbContext"]:::infra
            EventStoreSQLContext["EventStoreSQLContext"]:::infra
            CustomerMap["CustomerMap"]:::infra
            StoredEventMap["StoredEventMap"]:::infra
            EFMigrations["Migrations"]:::infra
        end
        subgraph "Repository & UoW"
            direction TB
            RepoBase["Repository & SpecEvaluator"]:::infra
            CustomerRepository["CustomerRepository"]:::infra
            EventStoreRepo["EventStoreSQLRepository"]:::infra
            UnitOfWork["UnitOfWork"]:::infra
        end
        SqlEventStore["SqlEventStore"]:::infra
    end

    %% Cross-Cutting Services
    subgraph "Cross-Cutting Services"
        direction TB
        subgraph "Identity Subsystem"
            direction TB
            AuthDbContext["AuthDbContext & Migrations"]:::infra
            JwtOptions["JwtIssuerOptions & ClaimRequirement"]:::infra
            EmailSMS["Email/SMS Senders"]:::infra
            IdentityModels["Account/Role ViewModels"]:::infra
        end
        InMemoryBus["InMemoryBus (MediatR)"]:::infra
        Bootstrapper["NativeInjectorBootStrapper"]:::infra
    end

    %% CLI Migration Tool
    CLI["CLI Migration Tool"]:::infra

    %% Databases
    subgraph "Databases"
        direction TB
        MainDB["Main SQL DB"]:::database
        IdentityDB["Identity SQL DB"]:::database
        EventStoreDB["Event Store SQL DB"]:::database
    end

    %% External Systems & Providers
    subgraph "External Systems/Providers"
        direction TB
        SMTP["SMTP"]:::external
        HTTPAPI["HTTP APIs"]:::external
        Webhooks["Webhooks"]:::external
        OfficeExcel["Office/Excel"]:::external
        SignalRHub["SignalR Hub"]:::external
        Quartz["Quartz Scheduler"]:::external
        Clients["External Clients/Consumers"]:::external
    end

    %% Connections
    APIControllers -->|REST calls| ICustomerAppService
    APIProgram -->|bootstraps| Bootstrapper
    APIMiddleware -->|uses| Bootstrapper
    ICustomerAppService -->|invokes| CustomerAppService
    CustomerAppService -->|MediatR| CoreKernel
    CoreKernel -->|handles| CommandHandler
    CommandHandler -->|raises| Events
    Events -.->|persist| SqlEventStore
    SqlEventStore -->|stores| EventStoreDB
    CommandHandler -->|writes| CustomerRepository
    CustomerRepository -->|uses| ApplicationDbContext
    ApplicationDbContext -->|connects| MainDB
    InMemoryBus -->|dispatches| EventHandler
    EventHandler -->|notifies| Clients
    CoreKernel -->|queries| Specifications
    CoreKernel -->|validates| Validations
    CoreKernel -->|calls| DomainProviders
    DomainProviders -->|uses| SMTP
    DomainProviders -->|calls| HTTPAPI
    DomainProviders -->|pushes| Webhooks
    DomainProviders -->|generates| OfficeExcel
    DomainProviders -->|emits| SignalRHub
    DomainProviders -->|schedules| Quartz
    APIControllers -->|auth| AuthDbContext
    AuthDbContext -->|connects| IdentityDB
    JwtOptions -->|configures| APIControllers
    EmailSMS -->|sends| SMTP
    Bootstrapper -->|registers| AllComponents[All Components]
    CLI -->|executes scripts| MainDB

    %% Click Events
    click APIControllers "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.Services.Api/Controllers"
    click APIProgram "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Services.Api/Program.cs"
    click APIMiddleware "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.Services.Api/StartupExtensions"
    click ICustomerAppService "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Application/Interfaces/ICustomerAppService.cs"
    click CustomerAppService "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Application/Services/CustomerAppService.cs"
    click EventNormalizers "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.Application/EventSourcedNormalizers"
    click CustomerViewModel "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Application/ViewModels/CustomerViewModel.cs"
    click AutoMapperConfig "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Application/AutoMapper/AutoMapperConfig.cs"
    click CoreKernel "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Domain.Core"
    click CustomerEntity "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Domain/Models/Customer.cs"
    click Commands "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.Domain/Commands"
    click CommandHandler "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Domain/CommandHandlers/CustomerCommandHandler.cs"
    click Events "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.Domain/Events"
    click EventHandler "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Domain/EventHandlers/CustomerEventHandler.cs"
    click Specifications "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Domain/Specifications/CustomerFilterPaginatedSpecification.cs"
    click Validations "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.Domain/Validations"
    click DomainProviders "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.Domain/Providers"
    click ApplicationDbContext "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Infra.Data/Context/ApplicationDbContext.cs"
    click EventStoreSQLContext "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Infra.Data/Context/EventStoreSQLContext.cs"
    click CustomerMap "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Infra.Data/Mappings/CustomerMap.cs"
    click StoredEventMap "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Infra.Data/Mappings/StoredEventMap.cs"
    click EFMigrations "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.Infra.Data/Migrations"
    click RepoBase "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Infra.Data/Repository/Repository.cs"
    click CustomerRepository "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Infra.Data/Repository/CustomerRepository.cs"
    click EventStoreRepo "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Infra.Data/Repository/EventSourcing/EventStoreSQLRepository.cs"
    click UnitOfWork "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Infra.Data/UoW/UnitOfWork.cs"
    click SqlEventStore "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Infra.Data/EventSourcing/SqlEventStore.cs"
    click AuthDbContext "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Infra.CrossCutting.Identity/Data/AuthDbContext.cs"
    click JwtOptions "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Infra.CrossCutting.Identity/Authorization/JwtIssuerOptions.cs"
    click EmailSMS "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Infra.CrossCutting.Identity/Services/AuthEmailMessageSender.cs"
    click InMemoryBus "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Infra.CrossCutting.Bus/InMemoryBus.cs"
    click Bootstrapper "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Infra.CrossCutting.IoC/NativeInjectorBootStrapper.cs"
    click CLI "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.CLI.Migration/Program.cs"
    click CLI "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.CLI.Migration/Scripts"
    click SMTP "https://github.com/ntxinh/aspnetcore-ddd/blob/main/Src/DDD.Infra.CrossCutting.Identity/Services/AuthEmailMessageSender.cs"
    click HTTPAPI "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.Domain/Providers/Http"
    click Webhooks "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.Domain/Providers/Webhooks"
    click OfficeExcel "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.Domain/Providers/Office"
    click SignalRHub "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.Domain/Providers/Hubs/Notification"
    click Quartz "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.Domain/Providers/Crons"
    click Clients "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.Services.Api/Controllers"
    click AllComponents "https://github.com/ntxinh/aspnetcore-ddd/tree/main/Src/DDD.Services.Api/StartupExtensions"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#006064;
    classDef application fill:#E8F5E9,stroke:#1B5E20,color:#1B5E20;
    classDef domain fill:#FFF8E1,stroke:#F57F17,color:#F57F17;
    classDef infra fill:#FFF3E0,stroke:#E65100,color:#E65100;
    classDef database fill:#ECEFF1,stroke:#263238,color:#263238;
    classDef external fill:#CFD8DC,stroke:#455A64,color:#455A64;
```
