# pjneethling/bookmon-api architecture

> Architecture diagram of the GitHub repository pjneethling/bookmon-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pjneethling/bookmon-api
- Repository: https://github.com/pjneethling/bookmon-api

## Overview

##### Main Components
- API Layer (Bookmon.API): This is the entry point for HTTP requests and includes Controllers (BooksController, OrdersController), Middleware (ExceptionMiddleware), and extensions for caching and route handling.
- Domain Layer (Bookmon.Domain): Contains the core business logic. This layer defines your Entities (Book, Order, User), Domain Exceptions, Interfaces (repositories and services), and domain services (BookService, OrderService). It also holds validators and utility components.
- Infrastructure Layer (Bookmon.Infrastructure): Provides data access implementations using EntityFramework contexts (AuthDbContext and CosmosDbContext), repository implementations (BookRepository, OrderRepository), IoC configuration (registering repositories and services), and mapping profiles.
- Testing Components: Separate test projects for API, Domain, and Infrastructure components ensure unit and integration tests are in place.
- Deployment & CI/CD: The Deployment folder (with azure.pipelines.yml and deployment.yml) alongside the Dockerfile indicate containerization and automated build/deployment pipelines.
- External Interfaces: Represent external databases (e.g., Cosmos DB) and potentially other services that the system might interact with.

##### Relationships and Interactions
- External Clients: Users or clients send HTTP requests that hit the API layer.
- API Controllers: Route incoming requests to the appropriate business logic after going through custom middleware (e.g., for exception handling) and extensions (cache, route helpers).
- Domain Services: Once a request is processed by the controllers, it calls into domain services that encapsulate business rules.
- Repository Pattern: Domain services interact with the data access layer through interfaces defined in the Domain and implemented in the Infrastructure layer.
- Dependency Injection: The project uses IoC configurations (RegisterServices, RegisterRepositories) across Domain and Infrastructure to facilitate loose coupling.
- Testing Layers: Unit tests validate the controllers, services, and repositories separately, ensuring each component’s functionality before integration.

##### Architectural Patterns and Design Principles
- Layered Architecture: Separates presentation, business, and data access concerns.
- Dependency Injection/IoC: Bootstraps interfaces with concrete implementations in the Infrastructure layer.
- Repository Pattern: Helps abstract data access logic and promotes a testable design.
- Domain-Driven Design: The Domain project encapsulates business entities, logic, domain exceptions, and validations, enforcing business rules.
- CI/CD and Containerization: The presence of pipeline configurations and a Dockerfile indicates an environment setup for continuous integration and deployment.

##### Relevant Technologies
- ASP.NET Core for building the API.
- Entity Framework Core (evident from the presence of EF-based DB contexts) for data access.
- Azure Cosmos DB (as seen in the CosmosDbContext) for database operations.
- Middleware for global exception handling and caching extensions.
- Testing frameworks for .NET (unit testing in the Tests folder).
- Docker for containerization and Azure Pipelines for CI/CD.

- A “Testing” area showing separate units for API, Domain, and Infrastructure tests.
- A “Deployment & Operations” section to include CI/CD pipelines (Azure Pipelines) and a Docker container representation.
- Relationships and Data Flow:
- Internal calls from Controllers to Domain Services, and from Domain Services to Repositories.
- Visual Distinction:

##### Detail and Clarity
- Avoid over-simplification. Detail every essential component by splitting the project into its natural layers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    E1("External Client"):::external

    subgraph "API Layer"
        A1("API Controllers"):::apiLayer
        A2("Middleware"):::apiLayer
        A3("Cache Extensions"):::apiLayer
        A4("Route Helper"):::apiLayer
    end

    subgraph "Domain Layer"
        D1("Entities & Exceptions"):::domainLayer
        D2("Interfaces & Services"):::domainLayer
        D3("Domain Validators"):::domainLayer
    end

    subgraph "Infrastructure Layer"
        I1("Repository Implementations"):::infraLayer
        I2("EF DB Contexts"):::infraLayer
        I3("IoC Configurations"):::infraLayer
        I4("Mapping Profiles"):::infraLayer
    end

    subgraph "Testing"
        T1("API Tests"):::testing
        T2("Domain Tests"):::testing
        T3("Infrastructure Tests"):::testing
    end

    subgraph "Deployment & Operations"
        Dep1("CI/CD Pipelines"):::deployment
        Dep2("Docker Container"):::deployment
    end

    DB("Cosmos DB"):::external

    %% Connections between layers
    E1 -->|"HTTPRequest"| A1
    A1 -->|"uses"| A2
    A1 -->|"uses"| A3
    A1 -->|"uses"| A4
    A1 -->|"BusinessLogic"| D2
    D2 -->|"DataAccess"| I1
    I1 -->|"DBOperations"| I2
    I2 -->|"Persistence"| DB
    I3 -->|"Injects"| D2

    %% Testing connections (dashed)
    T1 -.->|"tests"| A1
    T2 -.->|"tests"| D2
    T3 -.->|"tests"| I1

    %% Deployment connections
    Dep1 -->|"Deploys"| Dep2
    Dep2 -->|"Hosts"| A1

    %% Click Events for API Layer
    click A1 "https://github.com/pjneethling/bookmon-api/tree/main/Source/Bookmon.API/Controllers"
    click A2 "https://github.com/pjneethling/bookmon-api/blob/main/Source/Bookmon.API/Middleware/ExceptionMiddleware.cs"
    click A3 "https://github.com/pjneethling/bookmon-api/blob/main/Source/Bookmon.API/Extensions/CacheExtensions.cs"
    click A4 "https://github.com/pjneethling/bookmon-api/blob/main/Source/Bookmon.API/RouteHelper.cs"

    %% Click Events for Domain Layer
    click D1 "https://github.com/pjneethling/bookmon-api/tree/main/Source/Bookmon.Domain/Entities"
    click D2 "https://github.com/pjneethling/bookmon-api/tree/main/Source/Bookmon.Domain/Interfaces"
    click D3 "https://github.com/pjneethling/bookmon-api/tree/main/Source/Bookmon.Domain/Validators"

    %% Click Events for Infrastructure Layer
    click I1 "https://github.com/pjneethling/bookmon-api/blob/main/Source/Bookmon.Infrastructure"
    click I2 "https://github.com/pjneethling/bookmon-api/tree/main/Source/Bookmon.Infrastructure/EntityFramework"
    click I3 "https://github.com/pjneethling/bookmon-api/tree/main/Source/Bookmon.Infrastructure/IoC"
    click I4 "https://github.com/pjneethling/bookmon-api/tree/main/Source/Bookmon.Infrastructure/Mappers"

    %% Click Events for Testing
    click T1 "https://github.com/pjneethling/bookmon-api/blob/main/Source/Tests/Bookmon.API.Tests"
    click T2 "https://github.com/pjneethling/bookmon-api/blob/main/Source/Tests/Bookmon.Domain.Tests"
    click T3 "https://github.com/pjneethling/bookmon-api/blob/main/Source/Tests/Bookmon.Infrastructure.Tests"

    %% Click Events for Deployment
    click Dep1 "https://github.com/pjneethling/bookmon-api/tree/main/Deployment"
    click Dep2 "https://github.com/pjneethling/bookmon-api/tree/main/Source/Dockerfile"

    %% Styles
    classDef apiLayer fill:#f9d,stroke:#333,stroke-width:2px;
    classDef domainLayer fill:#9df,stroke:#333,stroke-width:2px;
    classDef infraLayer fill:#dfd,stroke:#333,stroke-width:2px;
    classDef testing fill:#ffd,stroke:#333,stroke-width:2px;
    classDef deployment fill:#fd9,stroke:#333,stroke-width:2px;
    classDef external fill:#ccc,stroke:#333,stroke-width:2px;
```
