# leancodepl/corelibrary architecture

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

- Interactive diagram: https://gitdiagram.com/leancodepl/corelibrary
- Repository: https://github.com/leancodepl/corelibrary

## Overview

##### Main Components
- Core Modules – Represent the primary building blocks:
▫ The “Core” projects (found in src/Core) which handle bootstrapping and composition (Autofac and Microsoft DI).
▫ The “Domain” projects (in src/Domain) that implement DDD models, aggregates, identifiers, value objects, and more.
▫ The “Infrastructure” projects (in src/Infrastructure) which include integrations (audit logs, Azure identity, Firebase, logging, etc.), external service connectors as well as utilities for migration and force updates.
▫ The “CQRS” submodule (found in src/CQRS) which contains libraries that enable the CQRS pattern (commands, queries, operations) with specific ASP.NET Core support, middleware, and even MassTransit-based relays.
▫ “Helpers” (in src/Helpers) – small utility projects (e.g., user ID extractors, URL helpers).
▫ “Tools” – build-time enhancement tools such as code analyzers and code fix providers.
▫ “Testing” – dedicated testing helpers and integration test support.
- Cross-Cutting Aspects:
▫ CI/CD and Build System – The GitHub workflows and .NET build scripts (Directory.Build.props, Directory.Packages.props) that centrally manage properties and dependency versions.
▫ Documentation and Integration Infrastructure – The “docs” folder and cloud-tests-infrastructure which help ensure code quality and documentation delivery.

##### Relationships and Interactions
- That the “Core” layer acts as the bootstrapper and configuration arena that wires up the Domain, Infrastructure, and CQRS modules.
- “Domain” layer as the heart of business logic and DDD—used by both Core and Infrastructure.
- That “CQRS” serves as an application pattern layer with its own subdivisions (annotations, ASP.NET Core integration, execution, MassTransit relay, remote HTTP client, etc.) and that it communicates with the Domain models.
- That “Infrastructure” is segmented into multiple integrations (e.g., Audit Logs, Firebase, Kratos, Localization, Logging, etc.) that are consumed by client applications and potentially injected via the Core configuration.
- Demonstrate test modules as the supporting layer that exercises each of these modules and are structured similarly to the source code.
- An “External Systems” node to show integrations with services such as external APIs, databases, messaging systems, and observability layers.

##### Architectural Patterns & Design Principles
- Use of CQRS: separate Command, Query, and Operation handlers land in the src/CQRS folder.
- Domain-Driven Design approach in the Domain projects, with aggregates, entities, value objects, and domain events.
- How the Infrastructure layer provides loosely coupled integrations (via dependency injection) to external services.
- Central configuration management using MSBuild’s central package management and shared build configuration files.
- Optionally, note that the testing structure mirrors the source code layout, maintaining separation of concerns.

##### Relevant Technologies and Frameworks
- .NET Core and ASP.NET Core (including DI containers like Autofac and Microsoft DI).
- Middleware-based processing (in CQRS and Infrastructure).
- Code analyzers and tooling built with Roslyn (as seen in the Tools directory).
- CI/CD tools (GitHub workflows, Docker, docker-compose for integration tests).
- External systems like MassTransit and Firebase, along with third-party libraries (SendGrid, ConfigCat, OpenTelemetry).

##### Essential Elements
- Clear labels: Each component (e.g., “Core – Bootstrapping”, “Domain – DDD Models”, “CQRS – Commands/Queries”, “Infrastructure – Audit Logs, Azure Identity, etc.”).
- Annotations for architectural patterns: For example, add a note near the CQRS modules to indicate “Middleware processing,” or near the Domain modules to highlight “Aggregate Roots, Domain Events.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD & Documentation Layer
    subgraph "CI/CD & Documentation"
        CI["CI/CD - Build workflows and central build configuration"]:::ci
        Docs["Documentation - Project docs & cloud test infrastructure"]:::doc
    end

    %% Core Layer
    subgraph "Core Layer"
        Core["Core - Bootstrapping and Composition"]:::core
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        Domain["Domain - DDD Models and Business Logic"]:::domain
    end

    %% Application Pattern Layer
    subgraph "Application Pattern"
        CQRS["CQRS - Command/Query/Operations and Middleware"]:::cqrs
    end

    %% Integration Layer
    subgraph "Integration Layer"
        Infra["Infrastructure - External Integrations (Audit Logs, Azure, Firebase, Logging...)"]:::infra
        ExtSys["External Systems - External APIs, DBs, Messaging, Observability"]:::external
    end

    %% Support & Utilities Layer
    subgraph "Support & Utilities"
        Helpers["Helpers - Utility Libraries (URL Helpers, User ID Extractors)"]:::helpers
        Tools["Tools - Build-time Enhancements, Code Analyzers, Code Fix Providers"]:::tools
        Testing["Testing - Integration and Unit Test Support"]:::testing
    end

    %% Relationships
    CI -->|"feeds"| Core
    Docs -->|"supports"| Core

    Core -->|"configures"| Domain
    Core -->|"configures"| CQRS
    Core -->|"injects"| Infra
    Core -->|"includes"| Helpers
    Core -->|"includes"| Tools

    CQRS -->|"operates on"| Domain

    Infra -->|"integrates with"| ExtSys

    Testing -->|"tests"| Core
    Testing -->|"tests"| Domain
    Testing -->|"tests"| CQRS
    Testing -->|"tests"| Infra

    %% Styles
    classDef ci fill:#cccccc,stroke:#333,stroke-width:2px;
    classDef doc fill:#9966cc,stroke:#333,stroke-width:2px;
    classDef core fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef domain fill:#98fb98,stroke:#333,stroke-width:2px;
    classDef cqrs fill:#ffdab9,stroke:#333,stroke-width:2px;
    classDef infra fill:#87cefa,stroke:#333,stroke-width:2px;
    classDef helpers fill:#ffff99,stroke:#333,stroke-width:2px;
    classDef tools fill:#b0e0e6,stroke:#333,stroke-width:2px;
    classDef testing fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef external fill:#ffb6c1,stroke:#333,stroke-width:2px;

    %% Click Events
    click CI "https://github.com/leancodepl/corelibrary/blob/v9.0-preview/ .github"
    click Docs "https://github.com/leancodepl/corelibrary/tree/v9.0-preview/docs"
    click Core "https://github.com/leancodepl/corelibrary/tree/v9.0-preview/src/Core"
    click Domain "https://github.com/leancodepl/corelibrary/tree/v9.0-preview/src/Domain"
    click CQRS "https://github.com/leancodepl/corelibrary/tree/v9.0-preview/src/CQRS"
    click Infra "https://github.com/leancodepl/corelibrary/tree/v9.0-preview/src/Infrastructure"
    click Helpers "https://github.com/leancodepl/corelibrary/tree/v9.0-preview/src/Helpers"
    click Tools "https://github.com/leancodepl/corelibrary/tree/v9.0-preview/src/Tools"
    click Testing "https://github.com/leancodepl/corelibrary/tree/v9.0-preview/src/Testing"
```
