# d3nhatv0lam/ctu-graph-theory architecture

> Architecture diagram of the GitHub repository d3nhatv0lam/ctu-graph-theory, 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/d3nhatv0lam/ctu-graph-theory
- Repository: https://github.com/d3nhatv0lam/ctu-graph-theory

## Overview

##### Main Components
a. Desktop UI Layer:
- CTU Graph Theory.Desktop: This is the project that holds the entry point (Program.cs) and the application manifest. It is essentially the startup assembly that boots the UI.
- Views (in the “Views” directory): Contains all the .axaml files for different screens (MainWindow, MainView, and individual algorithm views such as BFSView, DFSView, etc.), which represent your presentation layer.
- ViewLocator and associated resources that assist in binding Views to ViewModels.
b. Application Core (Business Logic):
- Algorithms: Contains implementations of various graph algorithms. These classes (e.g., BFS.cs, DFSRecursive.cs, Kruskal.cs, etc.) represent the core processing engine.
- Base classes (in Algorithms/Base) that provide common functionality for algorithms.
- Interfaces: Define contracts for algorithm requirements and view models (e.g., IAlgorithmViewModel, IPathVertexRun, etc.) enforcing consistency across different algorithm implementations.
c. Models & Data Structures:
- Models: Include classes such as CustomGraph, Vertex, ShowableEdge, and RequestOfAlgorithm. These are the data representations that hold the state of graphs, vertices, and edges.
d. Auxiliary Layers:
- Converters: Used to transform data for UI presentation (e.g., converting graph types to strings or handling empty vertices).
- Behaviors: E.g., DocumentTextBindingBehavior for handling interactions between UI elements.
- ViewModels: All MVVM view models (e.g., BFSViewModel, MainViewModel, etc.) that bind the logic to the UI.

##### Relationships and Interactions
- The Desktop project (with its entry point) launches the application by initializing the UI based on Avalonia.
- The MVVM structure ties the Views (UI) with their corresponding ViewModels. Each ViewModel interacts with Models and may invoke methods from the Algorithms layer.
- When a user selects an algorithm (for example, BFS), the corresponding ViewModel (BFSViewModel) activates the BFS algorithm logic (BFS.cs) from the Algorithms folder, processing the graph data from the Models.
- Converters and Behaviors serve as auxiliary helpers to ensure that data displayed in the Views is appropriately formatted and that UI interactions are seamlessly managed.
- The overall data flow follows a dependency chain: UI Event → ViewModel (binding/command handling) → Core Algorithm (processing) → Model update → UI refresh.

##### Architectural Patterns & Design Principles
- MVVM Pattern: Separates UI (Views) from business logic (ViewModels) and data structures (Models).
- Separation of Concerns: The project cleanly distinguishes between algorithm implementations and visualization.
- Abstraction and Interfaces: The use of interfaces in the Algorithms and ViewModels directories ensures that new graph algorithms can be added or swapped with minimal changes to the UI or core logic.
- Modular Component Design: Each algorithm and its corresponding ViewModel and View are separate modules, allowing focused updates and maintenance.

- Presence of the configuration and properties files (e.g., Directory.Build.props) which guide the project builds and settings if they are relevant to system-level configurations or deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        subgraph "Desktop Startup"
            A["Program.cs"]:::ui
            B["app.manifest"]:::ui
        end
        V["Views (.axaml files)"]:::ui
        C["Converters (UI Data Transformation)"]:::ui
        BH["Behaviors (UI Interaction Helpers)"]:::ui
    end

    subgraph "Application Layer"
        VM["ViewModels (MVVM)"]:::vm
        VL["ViewLocator"]:::vm
    end

    subgraph "Core Logic"
        AL["Algorithms (Graph Processing)"]:::core
        AB["Algorithm Base Classes"]:::core
        IF["Interfaces for Algorithms/ViewModels"]:::core
    end

    subgraph "Data Layer"
        M["Models & Data Structures"]:::data
    end

    %% Connections within Presentation Layer
    A --> V
    B --> V
    V -->|"bindsTo"| VM
    V -->|"utilizes"| C
    V -->|"utilizes"| BH
    
    %% Connections between Application Layer and other layers
    VL --> VM
    VL --> V
    VM -->|"executes"| AL
    VM -->|"updates"| M
    
    %% Core Logic internal connections
    AL --> AB
    AL --> IF
    
    %% Data Layer feedback
    M -->|"triggersRefresh"| V

    %% Click Events
    click A "https://github.com/d3nhatv0lam/ctu-graph-theory/blob/master/CTU Graph Theory.Desktop/Program.cs"
    click B "https://github.com/d3nhatv0lam/ctu-graph-theory/blob/master/CTU Graph Theory.Desktop/app.manifest"
    click V "https://github.com/d3nhatv0lam/ctu-graph-theory/tree/master/CTU Graph Theory/Views"
    click C "https://github.com/d3nhatv0lam/ctu-graph-theory/tree/master/CTU Graph Theory/Converters"
    click BH "https://github.com/d3nhatv0lam/ctu-graph-theory/blob/master/CTU Graph Theory/Behaviors/DocumentTextBindingBehavior.cs"
    click VM "https://github.com/d3nhatv0lam/ctu-graph-theory/tree/master/CTU Graph Theory/ViewModels"
    click VL "https://github.com/d3nhatv0lam/ctu-graph-theory/blob/master/CTU Graph Theory/ViewLocator.cs"
    click AL "https://github.com/d3nhatv0lam/ctu-graph-theory/tree/master/CTU Graph Theory/Algorithms"
    click AB "https://github.com/d3nhatv0lam/ctu-graph-theory/tree/master/CTU Graph Theory/Algorithms/Base"
    click IF "https://github.com/d3nhatv0lam/ctu-graph-theory/tree/master/CTU Graph Theory/Interfaces"
    click M "https://github.com/d3nhatv0lam/ctu-graph-theory/tree/master/CTU Graph Theory/Models"

    %% Style Classes
    classDef ui fill:#AED6F1,stroke:#005f73,stroke-width:2px;
    classDef vm fill:#A9DFBF,stroke:#086375,stroke-width:2px;
    classDef core fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef data fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
```
