# seakyy/casinowpf architecture

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

- Interactive diagram: https://gitdiagram.com/seakyy/casinowpf
- Repository: https://github.com/seakyy/casinowpf

## Overview

##### Project type and purpose
- This is a desktop application written in C# using .NET 8.0 and WPF.
- It simulates two casino games (Slot Machine and Blackjack) with user interactions, game history, and modular, testable logic.
- It follows the MVVM architectural pattern and uses Commands, Services, and the Observer pattern to decouple UI and business logic.

##### File structure
- Top-level “src/CasinoWPF” contains:
- Models: domain objects (Card, Player, GameResult, etc.) and enums
- Games: core game logic (SlotMachine, BlackJack, GameFactory)
- Services: orchestration and cross-cutting concerns (GameManager, Session, GameLogService, ComputerPlayer, Observer, RelayCommand)
- ViewModels: UI controllers that expose Models/Services to Views (MainViewModel, GameSelectionViewModel, SlotMachineViewModel, BlackJackViewModel, etc.)
- Views: WPF XAML files and code-behind for each page or window
- Converters: value converters for bindings (CountToBooleanConverter, Visibility converters)
- “src/CasinoWPF-Tests” holds MSTest unit tests for the two games.
- CI/CD configurations live in “.github/workflows” and “.gitlab-ci.yml”.

##### README for additional insights
- Architecture is MVVM with Commands and Observer pattern.
- CI/CD pipelines run build and tests automatically.

a. Main components
- UI Layer (Views)
- Presentation Layer (ViewModels + RelayCommand)
- Application Services Layer (GameManager, Session, GameLogService, Observer, ComputerPlayer)
- Domain Layer (Models + Enums + Game classes via GameFactory)
- Test Suite (CasinoWPF-Tests)
- CI/CD Pipeline (GitHub Actions / GitLab CI)
b. Relationships and data flows
- Views bind (two-way) to properties and commands on ViewModels
- ViewModels invoke Commands (RelayCommand) which call into Services
- Services manage game state (Session) and orchestrate gameplay via GameFactory → Domain objects
- Observer pattern propagates state changes (e.g., game round completion) back to ViewModels
- GameLogService persists history and exposes data to a GameLogView
- Tests invoke Domain/Game classes directly to verify business rules
c. Architectural patterns
- MVVM (separate UI, binding, and logic)
- Dependency Injection (services passed into ViewModels)
- Factory pattern (GameFactory creates game instances)
- Observer pattern (for state notifications)
- Command pattern (RelayCommand for user actions)
d. Key technologies/frameworks
- .NET 8.0, WPF (XAML)
- MSTest for unit testing
- GitHub Actions / GitLab CI for build & test

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI Layer"
        Views["Views"]:::ui
        Converters["Converters"]:::ui
    end

    subgraph "Presentation Layer"
        VM["ViewModels"]:::vm
        Relay["RelayCommand"]:::vm
    end

    subgraph "Application Services Layer"
        GameManager["GameManager"]:::svc
        Session["Session"]:::svc
        GameLogService["GameLogService"]:::svc
        ComputerPlayer["ComputerPlayer"]:::svc
        Observer["Observer"]:::svc
    end

    subgraph "Domain Layer"
        Models["Models"]:::domain
        Games["Games"]:::domain
        Factory["GameFactory"]:::domain
    end

    TestSuite["CasinoWPF-Tests"]:::test
    subgraph "CI/CD Pipeline"
        GH["GitHub Actions"]:::ci
        GL["GitLab CI"]:::ci
    end

    Views <-->|"binds to"| VM
    Converters -->|"converts data"| Views
    Converters -->|"converts data"| VM

    VM -->|"invokes"| Relay
    Relay -->|"executes"| GameManager
    VM -->|"uses"| GameManager

    GameManager -->|"manages state"| Session
    GameManager -->|"orchestrates games"| Factory
    GameManager -->|"logs history"| GameLogService
    GameManager -->|"publishes event"| Observer
    GameManager -->|"uses AI"| ComputerPlayer

    Factory -->|"creates instances"| Games
    Games -->|"use domain objects"| Models

    Observer -->|"notifies"| VM

    TestSuite -->|"tests business logic"| Games
    TestSuite -->|"tests models"| Models

    GH -->|"build & test"| TestSuite
    GL -->|"build & test"| TestSuite

    click Views "https://github.com/seakyy/casinowpf/tree/main/src/CasinoWPF/Views"
    click Converters "https://github.com/seakyy/casinowpf/tree/main/src/CasinoWPF/Converters"
    click VM "https://github.com/seakyy/casinowpf/tree/main/src/CasinoWPF/ViewModels"
    click Relay "https://github.com/seakyy/casinowpf/blob/main/src/CasinoWPF/Services/RelayCommand.cs"
    click GameManager "https://github.com/seakyy/casinowpf/blob/main/src/CasinoWPF/Services/GameManager.cs"
    click Session "https://github.com/seakyy/casinowpf/blob/main/src/CasinoWPF/Services/Session.cs"
    click GameLogService "https://github.com/seakyy/casinowpf/blob/main/src/CasinoWPF/Services/GameLog.cs"
    click ComputerPlayer "https://github.com/seakyy/casinowpf/blob/main/src/CasinoWPF/Services/ComputerPlayer.cs"
    click Observer "https://github.com/seakyy/casinowpf/blob/main/src/CasinoWPF/Services/Observer.cs"
    click Models "https://github.com/seakyy/casinowpf/tree/main/src/CasinoWPF/Models"
    click Games "https://github.com/seakyy/casinowpf/tree/main/src/CasinoWPF/Games"
    click Factory "https://github.com/seakyy/casinowpf/blob/main/src/CasinoWPF/Games/GameFactory.cs"
    click TestSuite "https://github.com/seakyy/casinowpf/tree/main/src/CasinoWPF-Tests"
    click GH "https://github.com/seakyy/casinowpf/blob/main/.github/workflows/dotnet.yml"
    click GL "https://github.com/seakyy/casinowpf/blob/main/.gitlab-ci.yml"

    classDef ui fill:#bbdefb,stroke:#333,stroke-width:1px
    classDef vm fill:#c8e6c9,stroke:#333,stroke-width:1px
    classDef svc fill:#ffe0b2,stroke:#333,stroke-width:1px
    classDef domain fill:#fff9c4,stroke:#333,stroke-width:1px
    classDef test fill:#cfd8dc,stroke:#333,stroke-width:1px
    classDef ci fill:#eceff1,stroke:#333,stroke-width:1px
```
