# discip1es/distancecalculator architecture

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

- Interactive diagram: https://gitdiagram.com/discip1es/distancecalculator
- Repository: https://github.com/discip1es/distancecalculator

## Overview

##### Main components
- Views: Represented by files like MainWindow.xaml and its code-behind (MainWindow.xaml.cs), plus other view classes in the Views directory (e.g., ViewModelBase.cs).
- ViewModels: Encapsulated in ViewModels/MainViewModel.cs, which binds the UI to the underlying logic.
- Models: Define the data structure, such as Models/City.cs, which represents each city's coordinates.
- Commands: The Commands directory includes RelayCommand.cs, which implements command functionality that the UI will use to interact with the ViewModel.
- Data Layer: The “data” directory holding cities.json, which acts as the persistent storage for city data.

##### Relationships and interactions
- The Views (front end) render the UI and bind to properties/events in the ViewModel.
- The ViewModels serve as the intermediary between the Views and Models, handling business logic and data manipulation.
- The Models hold the application's data (city information), loaded from the JSON file.
- RelayCommand and related command implementations encapsulate user actions that trigger logic in the ViewModels.
- Data flows from cities.json into the Models and then into the ViewModels which in turn update the Views.

##### Architectural patterns/design principles
- MVVM (Model-View-ViewModel) Pattern: Emphasize clear separation between the UI (Views), business logic (ViewModels), and data (Models).
- Data Binding: Integrated through XAML, allowing for responsive UI updates as the underlying data changes.
- Command Pattern: Implemented via RelayCommand to decouple user actions from the UI logic.

##### Incorporate relevant technologies and frameworks
- WPF for the desktop UI.
- C# as the programming language, with .NET framework assembly files typical in projects like App.xaml.cs and AssemblyInfo.cs.
- JSON for data interchange and city configuration (data/cities.json).

##### Detail and clarity
- Every component is clearly labeled with its directory/file label and role in the system.
- Do not shy away from including every identified sub-component; sometimes a detailed map of even RelayCommand or small classes might provide clarity on the command pattern usage.
- If applicable, include notes or annotations that briefly describe the function of each module, especially if it might not be obvious from the file name.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        Data_Cities["cities.json (Data)"]:::data
        Model_City["City.cs (Model)"]:::data
    end

    %% Application Layer
    subgraph "Application Layer"
        VM_Main["MainViewModel.cs (ViewModel)"]:::app
        Cmd_Relay["RelayCommand.cs (Command)"]:::app
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        View_MainWindow["MainWindow.xaml (View)"]:::view
        View_CodeBehind["MainWindow.xaml.cs (Code-behind)"]:::view
        View_Base["ViewModelBase.cs (Base View)"]:::view
    end

    %% Data Flow Connections
    Data_Cities -->|"load_data"| Model_City
    Model_City -->|"bind_data"| VM_Main
    VM_Main -->|"update_UI"| View_MainWindow

    %% User Interaction Connections
    View_MainWindow -->|"user_input"| VM_Main
    View_CodeBehind -->|"init_viewModel"| VM_Main
    Cmd_Relay -->|"trigger_command"| VM_Main

    %% Styles
    classDef view fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef app fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef data fill:#FFA500,stroke:#000,stroke-width:2px;

    %% Click Events for Component Mapping
    click View_MainWindow "https://github.com/discip1es/distancecalculator/blob/main/MainWindow.xaml"
    click View_CodeBehind "https://github.com/discip1es/distancecalculator/blob/main/MainWindow.xaml.cs"
    click View_Base "https://github.com/discip1es/distancecalculator/blob/main/Views/ViewModelBase.cs"
    click VM_Main "https://github.com/discip1es/distancecalculator/blob/main/ViewModels/MainViewModel.cs"
    click Cmd_Relay "https://github.com/discip1es/distancecalculator/blob/main/Commands/RelayCommand.cs"
    click Model_City "https://github.com/discip1es/distancecalculator/blob/main/Models/City.cs"
    click Data_Cities "https://github.com/discip1es/distancecalculator/blob/main/data/cities.json"

    %% Legend
    subgraph "Legend"
        LEG1["Presentation: Blue"]:::view
        LEG2["Application: Green"]:::app
        LEG3["Data: Orange"]:::data
    end
    LEG1 --- LEG2
    LEG2 --- LEG3
```
