# satrapu/aspnet-core-logging architecture

> Architecture diagram of the GitHub repository satrapu/aspnet-core-logging, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/satrapu/aspnet-core-logging
- Repository: https://github.com/satrapu/aspnet-core-logging

## Overview

##### Project type and purpose
- This is a full-stack (server-side) ASP.NET Core 9 Web API for managing “Todo” items, instrumented with structured logging (Serilog/Seq) and distributed tracing (OpenTelemetry/Jaeger), secured by JWT, and backed by PostgreSQL. It’s organized as a multi-project .NET solution that demonstrates best practices around layering, dependency injection, EF Core migrations, Docker Compose, and CI/CD pipelines (Azure Pipelines).

##### File structure
- Top-level: solution files (`Todo.WebApi.sln`), build scripts (`Build/`), Docker Compose (`docker-compose.yml`), CI templates.
- `Sources/`: six class-library projects plus the Web API:
- `Todo.WebApi`: presentation layer (Controllers, Middleware, Startup, appsettings)
- `Todo.Services`: domain services (business logic, JWT service)
- `Todo.ApplicationFlows`: orchestrators for application flows (CRUD flows, JWT flow)
- `Todo.Persistence`: EF Core DbContext, entities, migrations
- `Todo.Telemetry`: HTTP and EF Core instrumentation, Serilog and OpenTelemetry configuration
- `Todo.Commons`: shared constants, startup helpers, diagnostics
- `Tests/`: acceptance, integration, architecture and unit tests using Docker Compose for test DBs.

##### README for additional insights
- Confirms use of PostgreSQL, pgAdmin, Seq, Jaeger via Docker Compose.
- Emphasizes JSON Web Token authentication with a simplified generation flow.
- Outlines local‐dev setup, EF Core migrations, and telemetry UIs.

a. Main components
- External Clients (e.g., Web/Mobile UI, Postman)
- Todo.WebApi (ASP.NET Core HTTP pipeline)
- Todo.Services (business-level services)
- Todo.ApplicationFlows (flow orchestrators)
- Todo.Persistence (EF Core data-access)
- PostgreSQL database
- Telemetry: Serilog → Seq; OpenTelemetry → Jaeger
- Infrastructure: Docker Compose network; Azure Pipelines
b. Relationships and interactions
- Clients → HTTP request → WebApi Controllers
- Controllers → invoke Services via DI
- Services → orchestrate flows in ApplicationFlows
- ApplicationFlows → call Persistence (DbContext)
- DbContext → SQL queries → PostgreSQL
- WebApi & Persistence emit logs/traces → Telemetry library
- Telemetry library exports logs to Seq and traces to Jaeger
- Build & deployment via Azure Pipelines, Docker Compose hosts DB, pgAdmin, Seq, Jaeger
c. Architectural patterns & design principles
- Layered architecture (Presentation → Service → ApplicationFlow → Data)
- Dependency Injection across all layers
- Single-responsibility modules (Services vs Flows vs Persistence)
- EF Core Code-First migrations
- Middleware for exception handling, authorization, telemetry
d. Key technologies, frameworks, libraries
- ASP.NET Core 9, Controllers, Middleware
- Microsoft DI, Options pattern
- EF Core (Npgsql provider), Code-First Migrations
- Serilog (structured logging)
- OpenTelemetry (.NET SDK)
- Docker Compose, PostgreSQL, pgAdmin, Seq, Jaeger
- Azure DevOps Pipelines

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients
    ExternalClients["External Clients (Web/Mobile/Postman)"]:::external

    %% Presentation Layer
    subgraph "Presentation Layer"
        subgraph "Todo.WebApi"
            WC["Controllers"]:::presentation
            WH["Exception Handling Middleware"]:::presentation
            WA["Authorization Policies & Handers"]:::presentation
            WS["Startup & Program"]:::presentation
            WCF["Configuration Files (appsettings*.json)"]:::presentation
        end
    end

    %% Business Logic
    subgraph "Business Layer"
        subgraph "Todo.Services"
            BS1["TodoItemManagement Service"]:::business
            BS2["JWT Service & Security"]:::business
        end
        subgraph "Todo.Commons"
            BC1["Constants"]:::business
            BC2["Startup Helpers & Diagnostics"]:::business
        end
    end

    %% Application Flows
    subgraph "ApplicationFlows Layer"
        subgraph "Todo.ApplicationFlows"
            AF1["Todo Item Flows (CRUD & Migrations)"]:::flow
            AF2["JWT Generation Flow"]:::flow
            AF3["ApplicationFlows DI Module"]:::flow
        end
    end

    %% Data Access Layer
    subgraph "Data Layer"
        subgraph "Todo.Persistence"
            PD1["EF Core DbContext"]:::data
            PD2["Entities & Configurations"]:::data
            PD3["Migrations"]:::data
            PD4["Persistence DI Module"]:::data
        end
    end

    %% Telemetry
    subgraph "Telemetry"
        subgraph "Todo.Telemetry"
            TM1["Serilog Config & Policies"]:::telemetry
            TM2["OpenTelemetry Config"]:::telemetry
            TM3["HTTP Instrumentation Middleware"]:::telemetry
            TM4["Telemetry DI Module"]:::telemetry
        end
    end

    %% Infrastructure
    subgraph "Infrastructure"
        Postgres["PostgreSQL DB"]:::external
        PgAdmin["pgAdmin"]:::external
        Seq["Seq"]:::external
        Jaeger["Jaeger"]:::external
        DockerCompose["Docker Compose"]:::infra
        AzurePipelines["Azure Pipelines"]:::infra
    end

    %% Connections
    ExternalClients -->|HTTP Request| WC
    WC -->|calls| BS1
    BS1 -->|uses| AF1
    BS2 -->|uses| AF2
    WA -->|policies| WS
    WS -->|configures| BS1
    WS -->|configures| BS2
    WS -->|configures| AF3
    WS -->|configures| PD4
    WS -->|configures| TM4
    AF1 -->|calls DbContext| PD1
    PD1 -->|queries| Postgres
    PD2 -->|maps| PD1
    PD3 -->|migrations| PD1
    TM3 -->|wraps HTTP| WC
    WS -->|adds Middleware| TM3
    WS -->|adds Middleware| WH
    WS -->|adds Middleware| WA
    TM1 -->|logs| Seq
    TM2 -->|traces| Jaeger
    PD1 -.->|emits logs/traces| TM2
    WC -.->|emits logs| TM1
    DockerCompose -->|hosts| Postgres
    DockerCompose -->|hosts| PgAdmin
    DockerCompose -->|hosts| Seq
    DockerCompose -->|hosts| Jaeger
    AzurePipelines -->|deploys using| DockerCompose

    %% Click Events
    click WC "https://github.com/satrapu/aspnet-core-logging/tree/master/Sources/Todo.WebApi/Controllers"
    click WH "https://github.com/satrapu/aspnet-core-logging/tree/master/Sources/Todo.WebApi/ExceptionHandling"
    click WA "https://github.com/satrapu/aspnet-core-logging/tree/master/Sources/Todo.WebApi/Authorization"
    click WS "https://github.com/satrapu/aspnet-core-logging/blob/master/Sources/Todo.WebApi/Startup.cs"
    click WS "https://github.com/satrapu/aspnet-core-logging/blob/master/Sources/Todo.WebApi/Program.cs"
    click WCF "https://github.com/satrapu/aspnet-core-logging/blob/master/Sources/Todo.WebApi/appsettings.json"
    click BS1 "https://github.com/satrapu/aspnet-core-logging/tree/master/Sources/Todo.Services/TodoItemManagement"
    click BS2 "https://github.com/satrapu/aspnet-core-logging/tree/master/Sources/Todo.Services/Security"
    click AF1 "https://github.com/satrapu/aspnet-core-logging/tree/master/Sources/Todo.ApplicationFlows/TodoItems"
    click AF2 "https://github.com/satrapu/aspnet-core-logging/blob/master/Sources/Todo.ApplicationFlows/Security/GenerateJwtFlow.cs"
    click AF3 "https://github.com/satrapu/aspnet-core-logging/blob/master/Sources/Todo.ApplicationFlows/DependencyInjection/ApplicationFlowsModule.cs"
    click PD1 "https://github.com/satrapu/aspnet-core-logging/blob/master/Sources/Todo.Persistence/TodoDbContext.cs"
    click PD2 "https://github.com/satrapu/aspnet-core-logging/tree/master/Sources/Todo.Persistence/Entities"
    click PD3 "https://github.com/satrapu/aspnet-core-logging/tree/master/Sources/Todo.Persistence/Migrations"
    click PD4 "https://github.com/satrapu/aspnet-core-logging/blob/master/Sources/Todo.Persistence/DependencyInjection/PersistenceModule.cs"
    click TM1 "https://github.com/satrapu/aspnet-core-logging/tree/master/Sources/Todo.Telemetry/Serilog"
    click TM2 "https://github.com/satrapu/aspnet-core-logging/tree/master/Sources/Todo.Telemetry/OpenTelemetry"
    click TM3 "https://github.com/satrapu/aspnet-core-logging/blob/master/Sources/Todo.Telemetry/Http/HttpLoggingMiddleware.cs"
    click TM3 "https://github.com/satrapu/aspnet-core-logging/blob/master/Sources/Todo.Telemetry/Http/ConversationIdProviderMiddleware.cs"
    click TM4 "https://github.com/satrapu/aspnet-core-logging/blob/master/Sources/Todo.Telemetry/DependencyInjection/TelemetryModule.cs"
    click BC1 "https://github.com/satrapu/aspnet-core-logging/tree/master/Sources/Todo.Commons/Constants"
    click BC2 "https://github.com/satrapu/aspnet-core-logging/tree/master/Sources/Todo.Commons/StartupLogic"
    click BC2 "https://github.com/satrapu/aspnet-core-logging/tree/master/Sources/Todo.Commons/Diagnostics"
    click DockerCompose "https://github.com/satrapu/aspnet-core-logging/blob/master/docker-compose.yml"
    click DockerCompose "https://github.com/satrapu/aspnet-core-logging/blob/master/Build/db4tests/docker-compose.yml"
    click AzurePipelines "https://github.com/satrapu/aspnet-core-logging/blob/master/Build/azure-pipelines.yml"
    click AzurePipelines "https://github.com/satrapu/aspnet-core-logging/blob/master/Build/azure-pipelines.job-template.yml"

    %% Styles
    classDef presentation fill:#E3F2FD,stroke:#1E88E5,color:#0D47A1
    classDef business fill:#F1F8E9,stroke:#43A047,color:#1B5E20
    classDef flow fill:#FFF8E1,stroke:#F9A825,color:#FF6F00
    classDef data fill:#F3E5F5,stroke:#8E24AA,color:#4A148C
    classDef telemetry fill:#E0F7FA,stroke:#00ACC1,color:#006064
    classDef infra fill:#ECEFF1,stroke:#546E7A,color:#263238
    classDef external fill:#FFEBEE,stroke:#E53935,color:#B71C1C
```
