# netcorepal/netcorepal-cloud-framework architecture

> Architecture diagram of the GitHub repository netcorepal/netcorepal-cloud-framework, 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/netcorepal/netcorepal-cloud-framework
- Repository: https://github.com/netcorepal/netcorepal-cloud-framework

## Overview

##### Main Components
- Web/Application Layer: This includes the ASP.NET Core–based front-end and gateway components (for example, the NetCorePal.Web project and related ASP.NET Core utilities).
- Application/Command-Query Layer: Illustrate the CQRS pattern where commands, queries, and integration events are defined. This is supported by components in the “AspNetCore” and “Primitives” folders.
- Domain Layer: Emphasize the Domain-Driven Design elements such as Domain Entities, Aggregates, Domain Events, and StronglyTypedId support. The “Domain.Abstractions” folder and related projects play a major role here.
- Infrastructure/Persistence: Include repositories based on EntityFrameworkCore (under “Repository.EntityFrameworkCore” etc.), distributed locks (Redis locks, etc.), and transaction management. This includes sections from the “DistributedTransactions” directories.
- Service Discovery and External Integrations: Show connections to service discovery modules (like Microsoft and Kubernetes based discovery), as well as external message brokers (CAP for distributed events, RabbitMQ integrations) and ID generation (Snowflake with various back-ends such as Redis, Etcd, or Consul).
- Context Passing: Highlight components enabling context propagation (HTTP, HttpClient, and CAP integrations under “Context.Abstractions”, “Context.AspNetCore”, “Context.CAP”, and “Context.Shared”).
- Cross-Cutting Concerns: Factor in aspects such as logging, diagnostics, exception handling (evidenced by KnownException middleware and diagnostic components), and validation.

##### Relationships and Interactions
- Inter-module dependencies: For example, how Domain Events are published and then processed by distributed transaction handlers or integration event converters.
- Separation boundaries between different modular libraries, emphasizing that modules like IdGeneration, Service Discovery, and Context Passing are plugged into the core workflow.
- Out that the service discovery components interact with external systems, and the distributed transaction modules (utilizing CAP or outbox patterns) wrap interactions with databases and external messaging systems.

##### Architectural Patterns and Design Principles
- Domain-Driven Design (DDD): Identify domain entities, aggregates, domain events, and repositories clearly.
- CQRS and Event-Driven Architecture: Represent the separation of command handling, query processing, and the propagation of events.
- Modular and Extensible Design: Each major module (e.g., Distributed Locks, IdGeneration, Service Discovery) is self-contained and can be replaced or extended as needed.
- Multi-Tenant and Multi-Environment Support: Indicate that there is infrastructure to support tenant context and deployment configurations (e.g., “env”, “multi-env” directories).
- Use dependency injection consistently across layers.

##### Incorporate Relevant Technologies, Frameworks, and Libraries
- ASP.NET Core, EntityFrameworkCore, MediatR, DotNetCore.CAP, Hangfire, and service discovery libraries (such as KubernetesClient).
- Integration with Docker for deployment/testing and any external dependencies (e.g., Redis, MySQL, PostgreSQL for persistence and distributed locking).
- Use of Source Generators for StronglyTypedId.

##### Granularity
- Core DDD elements as well as integrations with CAP for distributed transaction handling, RabbitMQ for event-driven messaging, and various sources for ID generation.

Follow these guidelines and use appropriate visual notations to convey data flow, dependencies, and module boundaries. This will provide a comprehensive and accurate visual representation of the system architecture tailored specifically to the netcorepal-cloud-framework project.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Web/Application Layer
    subgraph "Web/Application Layer"
        APIGateway["Web/API Gateway"] 
        WebTest["Web Tests"]
    end

    %% Application/Command-Query Layer
    subgraph "Application/Command-Query Layer"
        CommandQuery["CQRS & Integration Events"]
    end

    %% Domain Layer
    subgraph "Domain Layer"
        Domain["Domain Entities & Events"]
    end

    %% Infrastructure/Persistence
    subgraph "Infrastructure/Persistence"
        EF_Core["EF Core Repositories"]
        Identity["EF Identity Repositories"]
        Snowflake["EF Snowflake Repositories"]
    end

    %% Service Discovery & External Integrations
    subgraph "Service Discovery & External Integrations"
        ServiceDiscovery["Service Discovery"]
        K8sDiscovery["K8s Discovery"]
        MicrosoftDiscovery["Microsoft Service Discovery"]
    end

    %% Context Passing Components
    subgraph "Context Passing"
        CA["Context.Abstractions"]
        CAPNode["Context.AspNetCore"]
        C_CAP["Context.CAP"]
        C_Shared["Context.Shared"]
    end

    %% Cross-Cutting Concerns
    subgraph "Cross-Cutting Concerns"
        ExceptionHandling["Exception Handling & Validation"]
        AttributesNode["AOP & DI Attributes"]
        JsonConversion["JSON Converters"]
    end

    %% Distributed Transactions & Event-driven Patterns
    subgraph "Distributed Transactions & Events"
        DT_Abstractions["DistributedTransactions.Abstractions"]
        DT_CAP["DistributedTransactions.CAP"]
    end

    %% Testing Infrastructure
    subgraph "Testing Infrastructure"
        Testing["Test Suites & Docker Configurations"]
    end

    %% Connections between layers
    APIGateway -->|"HTTPRequest"| CommandQuery
    WebTest -->|"TestRequest"| APIGateway

    CommandQuery -->|"Execute"| Domain

    Domain -->|"Uses"| EF_Core
    Domain -->|"Uses"| Identity
    Domain -->|"Uses"| Snowflake

    EF_Core -->|"Transact"| DT_Abstractions
    Identity -->|"Transact"| DT_Abstractions
    Snowflake -->|"Transact"| DT_Abstractions

    DT_Abstractions -->|"Triggers"| DT_CAP

    APIGateway -->|"PassesContext"| CA
    APIGateway -->|"PassesContext"| CAPNode
    CommandQuery -->|"PassesContext"| C_CAP
    CommandQuery -->|"PassesContext"| C_Shared

    ServiceDiscovery -->|"Discovers"| APIGateway
    K8sDiscovery -->|"Integrates"| ServiceDiscovery
    MicrosoftDiscovery -->|"Integrates"| ServiceDiscovery

    ExceptionHandling --- APIGateway
    ExceptionHandling --- CommandQuery
    AttributesNode --- Domain
    JsonConversion --- Domain

    Testing --- APIGateway
    Testing --- CommandQuery
    Testing --- Domain
    Testing --- EF_Core
    Testing --- DT_CAP

    %% Click Events
    click APIGateway "https://github.com/netcorepal/netcorepal-cloud-framework/tree/main/src/AspNetCore"
    click WebTest "https://github.com/netcorepal/netcorepal-cloud-framework/blob/main/test/NetCorePal.Web"
    click CommandQuery "https://github.com/netcorepal/netcorepal-cloud-framework/tree/main/src/Primitives"
    click Domain "https://github.com/netcorepal/netcorepal-cloud-framework/blob/main/src/Domain.Abstractions"
    click EF_Core "https://github.com/netcorepal/netcorepal-cloud-framework/blob/main/src/Repository.EntityFrameworkCore"
    click Identity "https://github.com/netcorepal/netcorepal-cloud-framework/blob/main/src/Repository.EntityFrameworkCore.Identity"
    click Snowflake "https://github.com/netcorepal/netcorepal-cloud-framework/blob/main/src/Repository.EntityFrameworkCore.Snowflake"
    click ServiceDiscovery "https://github.com/netcorepal/netcorepal-cloud-framework/blob/main/src/ServiceDiscovery.Abstractions"
    click K8sDiscovery "https://github.com/netcorepal/netcorepal-cloud-framework/blob/main/src/ServiceDiscovery.K8s"
    click MicrosoftDiscovery "https://github.com/netcorepal/netcorepal-cloud-framework/blob/main/src/NetCorePal.Extensions.MicrosoftServiceDiscovery"
    click CA "https://github.com/netcorepal/netcorepal-cloud-framework/blob/main/src/Context.Abstractions"
    click CAPNode "https://github.com/netcorepal/netcorepal-cloud-framework/blob/main/src/Context.AspNetCore"
    click C_CAP "https://github.com/netcorepal/netcorepal-cloud-framework/blob/main/src/Context.CAP"
    click C_Shared "https://github.com/netcorepal/netcorepal-cloud-framework/blob/main/src/Context.Shared"
    click ExceptionHandling "https://github.com/netcorepal/netcorepal-cloud-framework/tree/main/src/AspNetCore/KnownExceptionHandleMiddleware"
    click AttributesNode "https://github.com/netcorepal/netcorepal-cloud-framework/tree/main/src/Attributes"
    click JsonConversion "https://github.com/netcorepal/netcorepal-cloud-framework/tree/main/src/NewtonsoftJson"
    click DT_Abstractions "https://github.com/netcorepal/netcorepal-cloud-framework/blob/main/src/DistributedTransactions.Abstractions"
    click DT_CAP "https://github.com/netcorepal/netcorepal-cloud-framework/blob/main/src/DistributedTransactions.CAP"
    click Testing "https://github.com/netcorepal/netcorepal-cloud-framework/tree/main/test"

    %% Styles
    classDef webLayer fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef appLayer fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef domainLayer fill:#FFFFE0,stroke:#000,stroke-width:1px;
    classDef persistenceLayer fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef serviceLayer fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef contextLayer fill:#FFCCCB,stroke:#000,stroke-width:1px;
    classDef crossLayer fill:#F0E68C,stroke:#000,stroke-width:1px;
    classDef distributedLayer fill:#20B2AA,stroke:#000,stroke-width:1px;
    classDef testingLayer fill:#E0FFFF,stroke:#000,stroke-width:1px;

    class APIGateway,WebTest webLayer;
    class CommandQuery appLayer;
    class Domain domainLayer;
    class EF_Core,Identity,Snowflake persistenceLayer;
    class ServiceDiscovery,K8sDiscovery,MicrosoftDiscovery serviceLayer;
    class CA,CAPNode,C_CAP,C_Shared contextLayer;
    class ExceptionHandling,AttributesNode,JsonConversion crossLayer;
    class DT_Abstractions,DT_CAP distributedLayer;
    class Testing testingLayer;
```
