# piyushdoorwar/domain-driven-design architecture

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

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

## Overview

##### Project type and purpose
- This is a backend Web API built with .NET 8 following **Domain-Driven Design (DDD)** and **Clean Architecture**.
- It exposes REST endpoints (documented via Swagger) for managing books in a library, coordinating business logic (borrowing books) with a PostgreSQL database via Entity Framework Core.

##### File structure
- Top-level “ddd” project folder contains:
- **Controllers** (HTTP entry points)
- **Application** (Use-case handlers, e.g. BorrowBookHandler)
- **Domain** (Core entities, e.g. Book)
- **Infrastructure** (EF Core repository implementations, DbContext, migrations)
- **Program.cs** & **Properties** (application startup & configuration)
- **appsettings.json** (connection strings, environment config)
- **Migrations** (database schema history & seeding)
- This layered structure maps directly to the DDD/Clean-Architecture pattern.

##### README for additional insights
- Confirms technology stack: .NET 8, PostgreSQL, EF Core, Swagger.
- Emphasizes four layers: Domain, Application, Infrastructure, Controllers.
- Describes use cases (CRUD, BorrowBook use case) and configuration steps.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Boundary
    subgraph "External Boundary" 
        direction TB
        Client["Client / Swagger UI"]:::external
    end

    %% Controllers Layer
    subgraph "Controllers Layer"
        direction TB
        BooksController["BooksController"]:::controller
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        BorrowBookHandler["BorrowBookHandler"]:::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        BookEntity["Book Entity"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        IBookRepo["IBookRepository"]:::infrastructure
        EFCoreRepo["EFCoreBookRepository"]:::infrastructure
        LibraryDbContext["LibraryDbContext"]:::infrastructure
        Migrations["Migrations"]:::infrastructure
    end

    %% Startup & Configuration
    subgraph "Startup & Configuration"
        direction TB
        Program["Program.cs / DI & Middleware"]:::infrastructure
        AppSettings["appsettings.json & launchSettings.json"]:::infrastructure
    end

    %% Database
    PostgreSQLDB["PostgreSQL Database"]:::db

    %% Connections
    Client -->|"HTTP Request"| BooksController
    BooksController -->|"invokes"| BorrowBookHandler
    BorrowBookHandler -->|"manipulates & calls"| IBookRepo
    IBookRepo -->|"implemented by"| EFCoreRepo
    EFCoreRepo -->|"uses"| LibraryDbContext
    LibraryDbContext -->|"executes SQL"| PostgreSQLDB
    Program -->|"configures DI & registers DbContext"| BooksController
    Program -->|"configures DI & registers DbContext"| BorrowBookHandler
    Program -->|"applies migrations at startup"| Migrations
    Migrations -->|"defines schema & seed data"| LibraryDbContext

    %% Click Events
    click BooksController "https://github.com/piyushdoorwar/domain-driven-design/blob/main/ddd/Controllers/BooksController.cs"
    click BorrowBookHandler "https://github.com/piyushdoorwar/domain-driven-design/blob/main/ddd/Application/BorrowBookHandler.cs"
    click BookEntity "https://github.com/piyushdoorwar/domain-driven-design/blob/main/ddd/Domain/Book.cs"
    click IBookRepo "https://github.com/piyushdoorwar/domain-driven-design/blob/main/ddd/Infrastructure/IBookRepository.cs"
    click EFCoreRepo "https://github.com/piyushdoorwar/domain-driven-design/blob/main/ddd/Infrastructure/EFCoreBookRepository.cs"
    click LibraryDbContext "https://github.com/piyushdoorwar/domain-driven-design/blob/main/ddd/Infrastructure/LibraryDbContext.cs"
    click Migrations "https://github.com/piyushdoorwar/domain-driven-design/tree/main/ddd/Migrations/"
    click Program "https://github.com/piyushdoorwar/domain-driven-design/blob/main/ddd/Program.cs"
    click AppSettings "https://github.com/piyushdoorwar/domain-driven-design/blob/main/ddd/appsettings.json"

    %% Styles
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef controller fill:#FFB6C1,stroke:#333,stroke-width:1px
    classDef application fill:#90EE90,stroke:#333,stroke-width:1px
    classDef domain fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef infrastructure fill:#FFFF99,stroke:#333,stroke-width:1px
    classDef db fill:#C0C0C0,stroke:#333,stroke-width:1px,shape:cylinder
```
