# hernaski/domain-driven-design-solution architecture

> Architecture diagram of the GitHub repository hernaski/domain-driven-design-solution, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hernaski/domain-driven-design-solution
- Repository: https://github.com/hernaski/domain-driven-design-solution

## Overview

##### Main Project Components
- Domain Layer (MySolution.Domain): This contains the main business entities (Category.cs, Product.cs) and interfaces (both for repositories and services) without any dependency on concrete implementations.
- Infrastructure Layer (MySolution.Infrastructure): Here you find the EF Core database context (MyDatabaseContext.cs), Fluent API configurations (CategoryFluent.cs, ProductFluent.cs) and repository implementations. This layer contains the actual data access logic and is isolated from the Domain.
- Services Layer (MySolution.Services): This layer holds the application/business logic implementations (e.g. CategoryServices.cs, ProductServices.cs) that consume the Domain interfaces.
- IoC (Dependency Injection) Project (MySolution.Ioc): This project is responsible for configuring and enforcing dependency injection. It makes use of PrivateAssets in its project references to ensure that concrete implementations (from Services and Infrastructure) are hidden from the presentation layer.
- Presentation Layer (MySolution.Web.Api): This is your Web API project with controllers, DTOs, and configuration files (e.g. Startup.cs, Program.cs) that expose endpoints for external users or systems. It references only Domain and IoC, ensuring that the core logic remains decoupled from the presentation.

##### Diagramming the Relationships and Interactions
- Domain (Entities and Interfaces)
- Infrastructure (Data Access: Context, Fluent APIs, Repository Implementations)
- Services (Business/Application Logic)
- IoC/Dependency Injection (Service registration and configuration)
- Web API (Controllers, DTOs, API Configuration)
- The Web API layer depends on Domain for its entity and interface definitions and on IoC for dependency injection configuration.
- The IoC project wires up the Services and Infrastructure components by mapping Domain interfaces to their concrete implementations in these layers.
- Services depend on Domain (for interfaces/data contracts) and are registered via IoC; likewise, Infrastructure’s repositories implement the interfaces declared in Domain.
- Optionally, illustrate data flow from Web API controllers to Services to Infrastructure and back, highlighting that changes in UI (presentation) do not affect the Domain.

##### Highlighting Architectural Patterns and Principles
- Domain Driven Design (DDD): Emphasize that the Domain layer is the core of the solution and contains only the business rules and entities.
- Separation of Concerns: Display that the Domain, Services, Infrastructure, and Presentation layers are independent, reducing coupling.
- Dependency Injection / Inversion of Control: Highlight the IoC project configuration where concrete implementations are injected based on domain interfaces.
- Use of Fluent API for mapping entity behaviors in the Infrastructure layer (instead of Data Annotations), making the domain purely business-oriented.

##### Including Specific Technologies and Frameworks
- That the solution is built with .NET 5 and uses Entity Framework Core 5 for ORM.
- Swagger configuration exists in the Web API project for API documentation.

##### Essential Elements
- “Services”: with the business logic classes.
- “IoC/Dependency Injection”: showing how the services and repositories are wired.
- “Web API”: with controllers, DTOs, and configuration.
- Implementation layers (Infrastructure and Services) in another.
- Annotations for key patterns (DDD, DI), technologies (.NET 5, EF Core 5, Swagger) beside the respective components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Domain Layer (MySolution.Domain)"
        Domain_Entities["Entities (Category.cs, Product.cs)"]:::domainEntity
        Domain_Interfaces["Interfaces (Repository & Services)"]:::domainInterface
    end

    subgraph "Infrastructure Layer (MySolution.Infrastructure)"
        Infra_DB["EF Core DbContext (MyDatabaseContext.cs)"]:::infrastructure
        Infra_Fluent["Fluent API Configurations (CategoryFluent.cs, ProductFluent.cs)"]:::infrastructure
        Infra_Repo["Repository Implementations (CategoryRepository.cs, ProductRepository.cs)"]:::infrastructure
    end

    subgraph "Services Layer (MySolution.Services)"
        Services_Category["CategoryServices.cs"]:::services
        Services_Product["ProductServices.cs"]:::services
    end

    subgraph "IoC/Dependency Injection (MySolution.Ioc)"
        IoC_Config["DI Configuration (DependencyInjection.cs)"]:::ioc
    end

    subgraph "Presentation Layer (MySolution.Web.Api)"
        WebAPI_Controller["Controllers & DTOs (CategoryController.cs, ProductController.cs)"]:::webapi
        WebAPI_Config["API Configuration (Startup.cs, Program.cs)"]:::webapi
    end

    %% Relationships
    WebAPI_Controller -->|"uses"| IoC_Config
    WebAPI_Controller -->|"basedOn"| Domain_Entities
    IoC_Config -->|"registers"| Services_Category
    IoC_Config -->|"registers"| Services_Product
    IoC_Config -->|"registers"| Infra_DB
    IoC_Config -->|"registers"| Infra_Fluent
    IoC_Config -->|"registers"| Infra_Repo
    Services_Category -->|"dependsOn"| Domain_Interfaces
    Services_Category -->|"uses"| Domain_Entities
    Services_Product -->|"dependsOn"| Domain_Interfaces
    Services_Product -->|"uses"| Domain_Entities
    Infra_DB -->|"implements"| Domain_Interfaces
    Infra_Fluent -->|"maps"| Domain_Entities
    Infra_Repo -->|"implements"| Domain_Interfaces

    %% Click Events
    click Domain_Entities "https://github.com/hernaski/domain-driven-design-solution/tree/master/MySolution.Domain/Entities"
    click Domain_Interfaces "https://github.com/hernaski/domain-driven-design-solution/tree/master/MySolution.Domain/Interfaces"
    click Infra_DB "https://github.com/hernaski/domain-driven-design-solution/blob/master/MySolution.Infrastructure/Context/MyDatabaseContext.cs"
    click Infra_Fluent "https://github.com/hernaski/domain-driven-design-solution/tree/master/MySolution.Infrastructure/FluentApi"
    click Infra_Repo "https://github.com/hernaski/domain-driven-design-solution/tree/master/MySolution.Infrastructure/Repository"
    click Services_Category "https://github.com/hernaski/domain-driven-design-solution/blob/master/MySolution.Services/CategoryServices.cs"
    click Services_Product "https://github.com/hernaski/domain-driven-design-solution/blob/master/MySolution.Services/ProductServices.cs"
    click IoC_Config "https://github.com/hernaski/domain-driven-design-solution/blob/master/MySolution.Ioc/ServiceCollectionExtensions/DependencyInjection.cs"
    click WebAPI_Controller "https://github.com/hernaski/domain-driven-design-solution/tree/master/MySolution.Web.Api/Controllers"
    click WebAPI_Config "https://github.com/hernaski/domain-driven-design-solution/blob/master/MySolution.Web.Api/Startup.cs"

    %% Styles
    classDef domainEntity fill:#FFDDC1,stroke:#333,stroke-width:2px;
    classDef domainInterface fill:#FFCC80,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef services fill:#BBDEFB,stroke:#333,stroke-width:2px;
    classDef ioc fill:#D1C4E9,stroke:#333,stroke-width:2px;
    classDef webapi fill:#FFF9C4,stroke:#333,stroke-width:2px;
```
