How d3nhatv0lam/ctu-graph-theory works
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.