# vkhorikov/cqrsinpractice architecture

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

- Interactive diagram: https://gitdiagram.com/vkhorikov/cqrsinpractice
- Repository: https://github.com/vkhorikov/cqrsinpractice

## Overview

##### Project type and purpose
- This is a sample full-stack demonstration app for learning CQRS (Command Query Responsibility Segregation). It consists of:
- A WPF desktop UI (“UI” folder)
- An ASP.NET Core Web API (“Api” folder)
- A domain/logic layer implementing CQRS (“Logic” folder)
- A relational database (SQL scripts at root)

##### File structure
- Top level:
- After/  — final refactored CQRS version
- Before/ — original monolithic version
- Each version has three main projects under src/:
- Api: controllers, startup, exception handling, envelope utils
- Logic: AppServices (commands & queries), domain entities & maps, decorators (audit, retry), NHibernate utils
- UI: WPF views & view-models, command infrastructure, ApiClient
- Ancillary files: solution file (CqrsInPractice.sln), database scripts (DatabaseInitial.sql, DatabaseReads.sql), config files.

##### README insights
- Two complete versions (“Before” vs “After”) to compare non-CQRS vs CQRS architecture.
- Requires a SQL database; connection string lives in Api/appsettings.json.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers
    subgraph "Client (WPF App)"
        direction TB
        UI["WPF Desktop UI"]:::frontend
        UIcsproj["UI.csproj"]:::frontend
        UIStudents["Views & ViewModels"]:::frontend
        UICommon["MVVM & Commands"]:::frontend
    end

    subgraph "API (ASP.NET Core)" 
        direction TB
        APIproj["Api Project"]:::api
        APIctrl["Controllers"]:::api
        APIstartup["Startup & Configuration"]:::api
        APIconfig["appsettings.json"]:::api
        APIutils["Envelope & Exception Handler"]:::api
    end

    subgraph "Logic (CQRS Layer)"
        direction TB
        Logic["Logic Project"]:::logic
        AppServices["Command & Query Handlers"]:::logic
        Decorators["Decorators (Audit, Retry)"]:::decorator
        Domain["Domain Entities & NHibernate Maps"]:::logic
        LogicUtils["NHibernate & Data Access Utils"]:::logic
    end

    subgraph "Database"
        direction TB
        DBInit["DatabaseInitial.sql"]:::db
        DBReads["DatabaseReads.sql"]:::db
    end

    %% Connections
    UI -->|"HTTP(S) via ApiClient"| APIproj
    APIproj -->|"routes to"| APIctrl
    APIctrl -->|"wrap in Envelope"| APIutils
    APIutils -->|"dispatch"| AppServices
    AppServices -->|"intercept"| Decorators
    AppServices -->|"use"| LogicUtils
    AppServices -->|"map/load"| Domain
    LogicUtils -->|"execute SQL"| DBInit
    LogicUtils -->|"execute SQL"| DBReads

    %% Click Events
    click UI "https://github.com/vkhorikov/cqrsinpractice/tree/master/After/src/UI/"
    click UIcsproj "https://github.com/vkhorikov/cqrsinpractice/blob/master/After/src/UI/UI.csproj"
    click UIStudents "https://github.com/vkhorikov/cqrsinpractice/tree/master/After/src/UI/Students/"
    click UICommon "https://github.com/vkhorikov/cqrsinpractice/tree/master/After/src/UI/Common/"
    click APIproj "https://github.com/vkhorikov/cqrsinpractice/tree/master/After/src/Api/"
    click APIctrl "https://github.com/vkhorikov/cqrsinpractice/tree/master/After/src/Api/Controllers/"
    click APIstartup "https://github.com/vkhorikov/cqrsinpractice/blob/master/After/src/Api/Startup.cs"
    click APIconfig "https://github.com/vkhorikov/cqrsinpractice/blob/master/After/src/Api/appsettings.json"
    click APIutils "https://github.com/vkhorikov/cqrsinpractice/tree/master/After/src/Api/Utils/"
    click Logic "https://github.com/vkhorikov/cqrsinpractice/tree/master/After/src/Logic/"
    click AppServices "https://github.com/vkhorikov/cqrsinpractice/tree/master/After/src/Logic/AppServices/"
    click Decorators "https://github.com/vkhorikov/cqrsinpractice/tree/master/After/src/Logic/Decorators/"
    click Domain "https://github.com/vkhorikov/cqrsinpractice/tree/master/After/src/Logic/Students/"
    click LogicUtils "https://github.com/vkhorikov/cqrsinpractice/tree/master/After/src/Logic/Utils/"
    click DBInit "https://github.com/vkhorikov/cqrsinpractice/blob/master/After/DatabaseInitial.sql"
    click DBReads "https://github.com/vkhorikov/cqrsinpractice/blob/master/After/DatabaseReads.sql"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366d6,color:#000
    classDef api fill:#D4F5D4,stroke:#28a745,color:#000
    classDef logic fill:#FFE8C1,stroke:#f39c12,color:#000
    classDef decorator fill:#FFFFFF,stroke-dasharray: 5 5,stroke:#e74c3c,color:#000
    classDef db fill:#E0E0E0,stroke:#7f8c8d,color:#000
```
