# vkhorikov/dddinaction architecture

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

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

## Overview

##### Main Components

a. Domain/Business Logic Layer (DddInPractice.Logic)
- Contains sub-modules such as:
- Atms: Contains domain entities like Atm, AtmDto, repository, mapping, and domain events.
- SnackMachines: Similar structure with SnackMachine, Snack, Slot, SlotMap, SnackPile, etc.
- Management: Handles higher-level management processes involving BalanceChangedEventHandler and HeadOffice.
- Common and SharedKernel: Provides base classes (e.g., AggregateRoot, Entity, ValueObject) and domain events support which are used across the domains.
- Utils: Infrastructure utilities like EventListener, SessionFactory, and Initer.

b. Presentation Layer (DddInPractice.UI)
- Contains application configuration files (App.xaml, App.xaml.cs) and multiple UI modules:
- Atms: Contains AtmViewModel and its associated XAML view.
- SnackMachines: Contains SnackMachineViewModel, SnackPileViewModel, etc.
- Management: Contains the DashboardViewModel (with its XAML view).
- Common UI elements like commands, custom windows, dialog utilities, and resource files.

c. Testing Suite (DddInPractice.Tests)
- Contains unit tests for various domain functionalities (e.g., AtmSpecs, SnackMachineSpecs, MoneySpecs) to validate business logic.

d. Infrastructure / Configuration Files
- Includes the database creation script (DBCreationScript.txt) and project solution files.
- Git-related configuration and package references.

##### Relationships and Interactions Between Components

- The Presentation Layer (UI) acts as the front door and communicates with the Domain Layer to perform business operations. For instance, user actions in an Atm or SnackMachine UI view would trigger operations in their respective domain contexts.
- The Domain Layer is the core that encapsulates the business logic. Domain entities, repositories, domain events, and services (such as PaymentGateway) are defined here and are consumed by the UI.
- Domain events and their handlers (e.g., BalanceChangedEvent and its handler) create interactions within the business logic, promoting decoupling.
- The testing suite interacts with the domain layer to simulate user interactions and verify business rules.

##### Architectural Patterns & Design Principles

- Domain-Driven Design (DDD): Emphasizes separation of concerns with Organizing code into subdomains (Atms, SnackMachines, Management) and shared kernel elements.
- Layered Architecture: Different concerns are isolated (Domain, UI, Tests).
- Repository Pattern: Evident from repository classes in Atms, SnackMachines, and Management.
- Event-Driven Architecture: Noticeable through domain events and event listeners.
- MVVM (Model-View-ViewModel): The UI components (e.g., XAML files and their corresponding ViewModels) suggest an MVVM pattern in the presentation layer.

##### Final Checklist

- All Main Components (Domain Logic, UI, Testing, Infrastructure) are clearly labeled.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Domain Logic Layer
    subgraph "Domain Logic"
        D_atms["Atms Domain"]:::domain
        D_snack["SnackMachines Domain"]:::domain
        D_mgmt["Management Domain"]:::domain
        D_common["Common/SharedKernel"]:::domain
        D_utils["Infrastructure Utilities"]:::domain
    end

    %% User Interface Layer
    subgraph "User Interface"
        UI_atms["Atms UI"]:::ui
        UI_snack["SnackMachines UI"]:::ui
        UI_mgmt["Management UI"]:::ui
        UI_common["Common UI Elements"]:::ui
    end

    %% Testing Suite
    subgraph "Testing Suite"
        Tests["Tests"]:::testing
    end

    %% Infrastructure & Configuration
    subgraph "Infrastructure & Configuration"
        Infra["DB & Config Files"]:::infra
    end

    %% Interactions between UI and Domain
    UI_atms -->|"calls"| D_atms
    UI_snack -->|"calls"| D_snack
    UI_mgmt -->|"calls"| D_mgmt

    %% Domain Repository interactions with Infrastructure
    D_atms -->|"repository"| Infra
    D_snack -->|"repository"| Infra
    D_mgmt -->|"repository"| Infra

    %% Domain events between subdomains
    D_atms -->|"domainEvent"| D_mgmt
    D_snack -->|"domainEvent"| D_mgmt

    %% Domain Utilities support
    D_utils -->|"supports"| D_atms
    D_utils -->|"supports"| D_snack
    D_utils -->|"supports"| D_mgmt

    %% Testing Suite interacts with Domain Logic
    Tests --- D_atms
    Tests --- D_snack
    Tests --- D_mgmt

    %% Click Events for Component Mapping
    click D_atms "https://github.com/vkhorikov/dddinaction/tree/master/DddInPractice.Logic/Atms"
    click D_snack "https://github.com/vkhorikov/dddinaction/tree/master/DddInPractice.Logic/SnackMachines"
    click D_mgmt "https://github.com/vkhorikov/dddinaction/tree/master/DddInPractice.Logic/Management"
    click D_common "https://github.com/vkhorikov/dddinaction/tree/master/DddInPractice.Logic/Common and DddInPractice.Logic/SharedKernel"
    click D_utils "https://github.com/vkhorikov/dddinaction/tree/master/DddInPractice.Logic/Utils"
    click UI_atms "https://github.com/vkhorikov/dddinaction/tree/master/DddInPractice.UI/Atms"
    click UI_snack "https://github.com/vkhorikov/dddinaction/tree/master/DddInPractice.UI/SnackMachines"
    click UI_mgmt "https://github.com/vkhorikov/dddinaction/tree/master/DddInPractice.UI/Management"
    click UI_common "https://github.com/vkhorikov/dddinaction/tree/master/DddInPractice.UI/Common"
    click Tests "https://github.com/vkhorikov/dddinaction/blob/master/DddInPractice.Tests"
    click Infra "https://github.com/vkhorikov/dddinaction/blob/master/DBCreationScript.txt"

    %% Classes for Styling with Colors
    classDef domain fill:#a3d5ff,stroke:#333,stroke-width:2px;
    classDef ui fill:#d5ffa3,stroke:#333,stroke-width:2px;
    classDef testing fill:#ffd5a3,stroke:#333,stroke-width:2px;
    classDef infra fill:#f3d5ff,stroke:#333,stroke-width:2px;
```
