# candiath/ets2-mobile-route-advisor architecture

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

- Interactive diagram: https://gitdiagram.com/candiath/ets2-mobile-route-advisor
- Repository: https://github.com/candiath/ets2-mobile-route-advisor

## Overview

##### Main Components
- External Data Source: The ETS2 Telemetry Server (an external dependency). This is where the telemetry data (such as truck position, speed, navigation details, etc.) originates.
- Mobile Route Advisor UI: The core of this project. Include the following subcomponents:
- Dashboard Interface: Represented by dashboard.html and linked scripts (dashboard.js) that manage the overall UI.
- & Navigation Module: The “maps” directory (especially maps/ats/js/map.js, ol.js, and cities.js) handles displaying interactive maps, navigation overlays, and tile rendering.
- Styling & Theming: The “css” directory containing style sheets (ol.css, dashboard.css) that define the visual presentation.
- Localization: The “language” directory with JSON files (e.g., en-US.json) that support multi-language capabilities.
- Additional Assets: The “flags” and “flags-usa” directories provide country flags and similar graphical resources.
- Configuration: The root “config.json” (and maps/ats/config.json) to control various settings and options for the skin.

##### Relationships and Data Flow
- Interaction Between Modules:
- The Dashboard Interface (HTML/JS) communicates with the Map & Navigation module to render live maps and navigation overlays.
- The configuration files feed settings to the UI logic, influencing behavior (like auto zoom based on speed or tile loading preferences).
- Localization resources are referenced by the Dashboard logic to present texts in the appropriate language.
- Asset Loading: Illustrate that static resources (CSS, flags, images) support the look and feel, and are loaded by the browser as part of the UI rendering.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Different folders clearly separate styles (CSS), logic (JavaScript in dashboard.js and map-related files), and static resources (flags, maps tiles).
- Client-Side Rendering: The system heavily relies on browser rendering, driven by JavaScript and HTML templates.
- Extensibility: With separate configuration and language files, it’s built in a modular way to allow easy customization and localization.

##### Relevant Technologies and Libraries
- Frontend Web Technologies: HTML, CSS, and JavaScript.
- Rendering: The “ol.js” (possibly referencing OpenLayers or a custom mapping library) which is central to rendering map tiles and interactive navigation.
- Configuration via JSON: Using JSON for both overall configuration and localization.
- External Interaction: The ETS2 Telemetry Server is referenced as a source of real-time data, though it is not part of this codebase; rather, it is integrated via API or WebSocket communication.

##### Putting It All Together
- Data/Configuration Layer: Represent JSON config files.
- Business Logic/UI Layer: Show the dashboard HTML/JS and map module.
- Presentation/Resource Layer: Represent the CSS, images, flags, and language JSON.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Service
    Telemetry["ETS2 Telemetry Server"]:::external

    %% Mobile Route Advisor UI
    subgraph "Mobile Route Advisor UI"
        
        %% Dashboard Interface Subgraph
        subgraph "Dashboard Interface"
            DHTML["dashboard.html"]:::ui
            DJS["dashboard.js"]:::ui
        end

        %% Map & Navigation Module Subgraph
        subgraph "Map & Navigation Module"
            MMapJS["maps/ats/js/map.js"]:::ui
            MOLJS["maps/ats/js/ol.js"]:::ui
            CitiesJS["maps/ats/js/cities.js"]:::ui
        end

        %% Resources Subgraph
        subgraph "Resources"
            %% Styling & Theming Subgraph
            subgraph "Styling & Theming"
                DashboardCSS["css/dashboard.css"]:::resource
                OlCSS["css/ol.css"]:::resource
            end
            Localization["language/en-US.json"]:::resource
            %% Additional Assets Subgraph
            subgraph "Additional Assets"
                Flags["flags"]:::asset
                FlagsUSA["flags-usa"]:::asset
            end
            %% Configuration Subgraph
            subgraph "Configuration"
                ConfigRoot["config.json"]:::config
                MapsConfig["maps/ats/config.json"]:::config
            end
        end

    end

    %% Data Flow
    Telemetry -->|"providesTelemetryData"| DHTML

    %% Interaction within Dashboard Interface
    DHTML -->|"triggersLogic"| DJS

    %% Dashboard Interface interacts with Map Module
    DJS -->|"rendersMaps"| MMapJS
    DJS -->|"rendersMaps"| MOLJS
    DJS -->|"rendersCities"| CitiesJS

    %% Dashboard Interface uses Configuration and Localization
    DJS -->|"readsSettings"| ConfigRoot
    DJS -->|"readsSettings"| MapsConfig
    DJS -->|"fetchesText"| Localization

    %% Map Module uses Configuration
    MMapJS -->|"readsSettings"| MapsConfig

    %% Styling applied to UI components
    DashboardCSS -->|"stylesDashboard"| DHTML
    OlCSS -->|"stylesMaps"| MOLJS

    %% Dashboard loads additional assets
    DHTML -->|"loadsFlagAssets"| Flags
    DHTML -->|"loadsFlagAssets"| FlagsUSA

    %% Styling & configuration also support Map Module
    MOLJS -->|"appliesStyling"| OlCSS

    %% Click Events for Dashboard Interface
    click DHTML "https://github.com/candiath/ets2-mobile-route-advisor/blob/master/dashboard.html"
    click DJS "https://github.com/candiath/ets2-mobile-route-advisor/blob/master/dashboard.js"

    %% Click Events for Map & Navigation Module
    click MMapJS "https://github.com/candiath/ets2-mobile-route-advisor/blob/master/maps/ats/js/map.js"
    click MOLJS "https://github.com/candiath/ets2-mobile-route-advisor/blob/master/maps/ats/js/ol.js"
    click CitiesJS "https://github.com/candiath/ets2-mobile-route-advisor/blob/master/maps/ats/js/cities.js"

    %% Click Events for Styling & Theming
    click DashboardCSS "https://github.com/candiath/ets2-mobile-route-advisor/blob/master/css/dashboard.css"
    click OlCSS "https://github.com/candiath/ets2-mobile-route-advisor/blob/master/css/ol.css"

    %% Click Event for Localization
    click Localization "https://github.com/candiath/ets2-mobile-route-advisor/blob/master/language/en-US.json"

    %% Click Events for Additional Assets
    click Flags "https://github.com/candiath/ets2-mobile-route-advisor/tree/master/flags"
    click FlagsUSA "https://github.com/candiath/ets2-mobile-route-advisor/tree/master/flags-usa"

    %% Click Events for Configuration
    click ConfigRoot "https://github.com/candiath/ets2-mobile-route-advisor/blob/master/config.json"
    click MapsConfig "https://github.com/candiath/ets2-mobile-route-advisor/blob/master/maps/ats/config.json"

    %% Class Definitions for coloring
    classDef external fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef ui fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef resource fill:#d5f5e3,stroke:#28b463,stroke-width:2px;
    classDef asset fill:#fcf3cf,stroke:#f1c40f,stroke-width:2px;
    classDef config fill:#fadbd8,stroke:#e74c3c,stroke-width:2px;
```
