# misiukanis/simple-shop architecture

> Architecture diagram of the GitHub repository misiukanis/simple-shop, 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/misiukanis/simple-shop
- Repository: https://github.com/misiukanis/simple-shop

## Overview

##### Main Components
- User Interface (Presentation Layer):
- The “Shop” project contains the Blazor components (pages, layouts, components), controllers (CustomersController, OrdersController, ProductsController), and the associated configuration (appsettings, Launch Settings, etc.).
- Application Layer:
- “Shop.Application” implements the CQRS pattern by having separate directories for commands, queries, event handlers, DTOs, and validators. It also contains Automapper profiles and behavior filters like the “ValidationBehavior”.
- Domain Layer:
- “Shop.Domain” holds your core business logic including aggregates (CustomerAggregate, OrderAggregate, ProductAggregate), shared core concepts (entities, aggregate roots, value objects, domain events), and domain-specific exceptions.
- Infrastructure Layer:
- “Shop.Infrastructure” includes implementations for persistence (repositories, MongoDbContext, DatabaseInitializer) and domain event dispatching (DomainEventDispatcher). The infrastructure is also integrated with external systems (EventStoreDB and MongoDB).
- Shared/Resources:
- “Shop.Shared” and “Shop.Resources” include constants, settings, and localization resources that support the entire system.
- Tests:
- “Shop.UnitTests” contains unit tests, such as for command handler testing, which verifies the core logic in the application layer.

##### Relationships and Interactions
- The Presentation Layer interacts with both the API controllers and Blazor components, which call into the Application Layer.
- The Application Layer leverages MediatR to execute commands, handle queries, validate inputs (using FluentValidation), and orchestrate responses from the domain.
- Domain events propagate from the Domain Layer and are handled in the Application Layer via event handlers, following the DDD and event sourcing patterns.
- The Infrastructure Layer provides the concrete implementations for repositories (both for MongoDB and EventStoreDB) and acts as the bridge for persistence and external system integrations.
- Dependency Injection is set up across layers to allow for loose coupling and ease of testing, also mentioned under “DependencyInjection.cs” files in the Shop, Shop.Application, and Shop.Infrastructure projects.

##### Architectural Patterns and Technologies
- Use of DDD for structuring the business logic, where Aggregates in the Domain layer encapsulate core behaviors.
- CQRS architecture: separate command and query paths in Shop.Application, complete with Validators, Handlers, and Mediator integration (MediatR).
- Event Sourcing where events (e.g., CustomerCreatedEvent, OrderCreatedEvent, ProductDeletedEvent) are stored and dispatched via the Infrastructure’s dispatcher.
- AutoMapper for mapping between domain models, DTOs, and read models.
- Mention logging (NLog), validations (FluentValidation), and web technologies (.NET 9.0, C# 13, and Blazor Server).

- Presentation Layer (Shop): Show UI components, controllers, and static assets (wwwroot).
- Application Layer (Shop.Application): Illustrate components such as Command Handlers, Query Handlers, Validators, DTOs, and Automapper Profiles.
- Domain Layer (Shop.Domain): Represent Aggregates (Customer, Order, Product), Domain Events, Entities, and Value Objects.
- Infrastructure Layer (Shop.Infrastructure): Represent Persistence (MongoDBContext, Repositories for MongoDB and EventStoreDB) and the Domain Event Dispatcher.
- Shared/Resources: Include support libraries such as Settings (from Shop.Shared) and Messages (from Shop.Resources).
- From the Presentation Layer to the Application Layer (calls from UI or API endpoints to command/query execution).
- From the Application Layer to the Domain Layer (invocations of domain logic and event generation).
- From the Domain Layer back to the Application Layer via domain events and event handlers.
- From the Application/Domain to the Infrastructure Layer (interaction with persistence mechanisms and external services).
- Use additional markers to indicate:
- Usage of architectural principles like CQRS and DDD.
- The flow of data (e.g., user initiates a command, command reaches an appropriate handler, business logic executes, events are triggered and stored).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        Pres1["Blazor Components"]:::presentation
        Pres2["API Controllers"]:::presentation
        Pres3["Static Assets & Config"]:::presentation
    end

    subgraph "Application Layer"
        App1["Commands/Queries/Handlers/Validators"]:::application
        App2["AutoMapper Profiles & Dependency Injection"]:::application
    end

    subgraph "Domain Layer"
        Dom1["Aggregates & Domain Core"]:::domain
        Dom2["Domain Exceptions & Interfaces"]:::domain
    end

    subgraph "Infrastructure Layer"
        Infra1["Persistence, Repositories & Event Dispatcher"]:::infrastructure
    end

    subgraph "Shared & Resources"
        Shared1["Shared Settings"]:::shared
        Shared2["Resource Localization"]:::shared
    end

    subgraph "Unit Testing"
        Test1["Command Handler Tests"]:::testing
    end

    %% Connections between layers
    Pres1 -->|"calls"| App1
    Pres2 -->|"calls"| App1
    Pres3 -->|"calls"| App2

    App1 -->|"invokes"| Dom1
    App2 -->|"invokes"| Dom1
    App1 -->|"uses"| Dom2

    Dom1 -->|"triggers"| App1

    App1 -->|"persists"| Infra1
    Dom1 -->|"storesEvents"| Infra1

    Shared1 -.->|"supports"| Pres1
    Shared1 -.->|"supports"| App1
    Shared1 -.->|"supports"| Dom1
    Shared1 -.->|"supports"| Infra1
    Shared2 -.->|"supports"| Pres2
    Shared2 -.->|"supports"| App2

    App1 -->|"testedBy"| Test1

    %% Click Events for Component Mapping
    click Pres1 "https://github.com/misiukanis/simple-shop/tree/master/Shop/Components"
    click Pres2 "https://github.com/misiukanis/simple-shop/tree/master/Shop/Controllers"
    click Pres3 "https://github.com/misiukanis/simple-shop/tree/master/Shop"
    click App1 "https://github.com/misiukanis/simple-shop/blob/master/Shop/Shop.Application"
    click App2 "https://github.com/misiukanis/simple-shop/blob/master/Shop/Shop.Application"
    click Dom1 "https://github.com/misiukanis/simple-shop/blob/master/Shop/Shop.Domain"
    click Dom2 "https://github.com/misiukanis/simple-shop/blob/master/Shop/Shop.Domain"
    click Infra1 "https://github.com/misiukanis/simple-shop/blob/master/Shop/Shop.Infrastructure"
    click Shared1 "https://github.com/misiukanis/simple-shop/blob/master/Shop/Shop.Shared"
    click Shared2 "https://github.com/misiukanis/simple-shop/blob/master/Shop/Shop.Resources"
    click Test1 "https://github.com/misiukanis/simple-shop/blob/master/Shop/Shop.UnitTests"

    %% Styles
    classDef presentation fill:#f6d6ad,stroke:#d67d15,stroke-width:2px;
    classDef application fill:#c7e9c0,stroke:#4caf50,stroke-width:2px;
    classDef domain fill:#b3d4fc,stroke:#2196f3,stroke-width:2px;
    classDef infrastructure fill:#fbc4ab,stroke:#ff5722,stroke-width:2px;
    classDef shared fill:#d1c4e9,stroke:#673ab7,stroke-width:2px;
    classDef testing fill:#ffcc80,stroke:#ff9800,stroke-width:2px;
```
