# sswconsulting/ssw.cleanarchitecture architecture

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

- Interactive diagram: https://gitdiagram.com/sswconsulting/ssw.cleanarchitecture
- Repository: https://github.com/sswconsulting/ssw.cleanarchitecture

## Overview

##### Main Components
- Infrastructure Layer (src/Infrastructure): Handles cross-cutting concerns such as persistence (ApplicationDbContext, migrations), Interceptors, Middleware (like EventualConsistencyMiddleware), and integration with external resources (like the database). Represent this as “Infrastructure”.
- Tests: Represent the testing strategy separately (Unit Tests, Integration Tests, Architecture Tests) to show the validation of the system’s design and behavior.

##### Relationships & Interactions
- The WebAPI layer communicates directly with the Application layer to dispatch commands and queries.
- The Application layer, while orchestrating business logic, interacts with the Domain layer. Domain classes and events are used to enforce business rules.
- The Infrastructure layer acts as a support system (e.g., EF Core for persistence, interceptors for domain events) and is usually injected into the Application layer. Illustrate dependency flow (often via dependency inversion) from Application to Infrastructure.
- Tools are used during development or deployment (e.g., for migrations) and are external to the runtime flow.

##### Architectural Patterns and Key Design Principles
- Clean Architecture: Emphasize the separation of concerns and dependency inversion, where the inner layers (Domain, Application) have no dependency on outer layers (Infrastructure, Presentation).
- CQRS: Separate reading (queries) from writing (commands) in the Application layer.
- Additional Patterns: Use of Mediator (MediatR) for decoupling, Specification Pattern to encapsulate business rules, and a fluent result (ErrorOr) pattern to handle errors instead of using exceptions.

##### Relevant Technologies & Frameworks
- .NET (the entire solution is built on Dotnet 9).
- Entity Framework Core for ORM and persistence.
- MediatR for the CQRS messaging pattern.
- FluentValidation for validation, and potentially ErrorOr for result handling.
- OpenAPI/Scalar documentation for documenting API endpoints.
- The use of GitHub Actions for CI/CD (build, test, publish).

- Presentation/WebAPI Layer: Include endpoints (HeroEndpoints, TeamEndpoints), health checks, global exception handling.
- Application Layer: Commands, queries for Heroes and Teams, common behaviors (LoggingBehavior, ValidationErrorOrResultBehaviour, etc.).
- Domain Layer: Core business entities (Hero, Team), base classes (AggregateRoot, Entity), domain events (e.g., PowerLevelUpdatedEvent).
- Infrastructure Layer: Persistence (ApplicationDbContext, EF Core migrations), configurations (HeroConfiguration, TeamConfiguration), interceptors.
- Tools Layer: MigrationService, AppHost for running commands and orchestrating the environment.
- External Dependencies: Database, potential external APIs, and deployment tools.
- Flow from WebAPI to Application.
- Application calls into Domain for business processing.
- Application uses Infrastructure to handle interactions with persistence or external services.
- Dependency injection flows where Infrastructure is injected into Application or WebAPI.
- Annotations:
- Brief notes on each layer’s responsibilities and any key patterns (like CQRS, DDD).
- That the inner core (Domain) remains independent and technology-agnostic compared to outer layers.

This level of detail will help in visualizing and understanding the overall architecture while also serving as a communication tool for future development and onboarding. Start by sketching out these major components, then refine with interactions and dependencies until all essential architectural elements are captured.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        webapi["Presentation (WebAPI)\nHeroEndpoints, HealthChecks, GlobalExceptionHandling"]
    end

    subgraph "Application Layer"
        app["Application\nCommands, Queries, Behaviors (Logging, Validation, Exception Handling)"]
    end

    subgraph "Domain Layer"
        domain["Domain\nEntities (Hero, Team), Aggregates, DomainEvents, ValueObjects"]
    end

    subgraph "Infrastructure Layer"
        infra["Infrastructure\nPersistence (ApplicationDbContext, EF Core Migrations), Middleware, Interceptors"]
    end

    subgraph "Tools & Testing"
        tools["Tools\n(MigrationService, AppHost)"]
        tests["Testing\n(Unit, Integration, Architecture Tests)"]
    end

    %% Connections between layers
    webapi -->|"dispatches"| app
    app -->|"executes"| domain
    app -->|"interacts"| infra

    %% Supporting tools and testing interactions
    tools -.->|"assists"| infra
    tests -.->|"validates"| webapi
    tests -.->|"validates"| app
    tests -.->|"validates"| domain
    tests -.->|"validates"| infra

    %% Click Events
    click webapi "https://github.com/sswconsulting/ssw.cleanarchitecture/tree/main/src/WebApi"
    click app "https://github.com/sswconsulting/ssw.cleanarchitecture/tree/main/src/Application"
    click domain "https://github.com/sswconsulting/ssw.cleanarchitecture/tree/main/src/Domain"
    click infra "https://github.com/sswconsulting/ssw.cleanarchitecture/tree/main/src/Infrastructure"
    click tools "https://github.com/sswconsulting/ssw.cleanarchitecture/tree/main/tools"
    click tests "https://github.com/sswconsulting/ssw.cleanarchitecture/tree/main/tests"

    %% Styles
    classDef presentation fill:#f9c,stroke:#333,stroke-width:2px;
    classDef application fill:#fc9,stroke:#333,stroke-width:2px;
    classDef domain fill:#bbf,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#cfc,stroke:#333,stroke-width:2px;
    classDef tools fill:#ffc,stroke:#333,stroke-width:2px;
    classDef testing fill:#ecc,stroke:#333,stroke-width:2px;

    class webapi presentation;
    class app application;
    class domain domain;
    class infra infrastructure;
    class tools tools;
    class tests testing;
```
