# faisalbinahmed/mvgfahrinfo architecture

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

- Interactive diagram: https://gitdiagram.com/faisalbinahmed/mvgfahrinfo
- Repository: https://github.com/faisalbinahmed/mvgfahrinfo

## Overview

##### Project type and purpose
- This is a single‐binary, native CLI application (“MVG Fahrinfo”) written in Rust.
- It uses an (undocumented) MVG HTTP API to fetch departure data, renders a full‑screen terminal UI, and persists a station list in a local JSON file.

##### File structure
- Cargo.toml, src/, README.md, stations.json
- Top‑level “src” modules:
- main.rs: application entry point
- app.rs: application state and orchestration
- api.rs: MVG HTTP client logic (fetch stations & departures)
- update.rs: scheduling and triggering API updates
- event.rs: user‐input event production
- tui.rs / ui.rs: wiring Ratatui TUI framework to your app state
- components/: terminal UI widgets (station list, static widgets)
- stations.json: on‑disk cache of station metadata fetched at first run
- No separate frontend/backend: it is a monolithic CLI with clear internal module separation.

##### README for additional insights
- Uses Ratatui (a Rust terminal‐UI library).
- Automatically refreshes departures every 60 seconds.
- Allows station search, selection, saving.

a. Main components
- User (keyboard)
- Event Loop / Input Handler
- Application Core (app.rs)
- Update Scheduler (update.rs)
- API Client (api.rs) → External MVG API service
- Local Persistence (stations.json on file system)
- UI Renderer (tui.rs + ui.rs + components/*)
b. Relationships & data flows
1. User → Event Loop (event.rs)
2. Event Loop → Application Core
3. Application Core triggers:
– Update Scheduler: calls API Client
– Reads/Writes stations.json
– Updates in‑memory state
4. Application Core → UI Renderer → draws terminal interface
5. Periodic timer in Update Scheduler → API Client → parses JSON → feeds back to Application Core
c. Architectural patterns & principles
- Module separation by concern (api, ui, event, update) within a single process.
- Clean layering: input → core logic → output; side‐effects (HTTP, FS) only in dedicated modules.
d. Key technologies
- Rust (Cargo for build), Ratatui for TUI, reqwest or similar for HTTP, serde_json for (de)serialization.

##### Final advice
- Be exhaustive: include every Rust module as its own sub‐component if desired.

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Service
    ExternalAPI["MVG HTTP API Service"]:::ext

    %% Input Layer
    subgraph "Input Layer"
        UserKeyboard["User Keyboard"]:::input
        EventLoop["Event Loop\n(src/event.rs)"]:::input
    end

    %% Core Layer
    subgraph "Core Layer"
        Main["main.rs\n(src/main.rs)"]:::core
        AppCore["Application Core\n(src/app.rs)"]:::core
        UpdateScheduler["Update Scheduler\n(src/update.rs)"]:::core
        APIClient["API Client\n(src/api.rs)"]:::core
        Constants["Constants\n(src/constants.rs)"]:::core
    end

    %% UI Layer
    subgraph "UI Layer"
        UIRendererWire["TUI Wiring\n(src/tui.rs)"]:::ui
        UIRendererLayout["UI Layout\n(src/ui.rs)"]:::ui
        UIComponentsIndex["Components Module\n(src/components/mod.rs)"]:::ui
        StationListWidget["Station List Widget\n(src/components/station_list.rs)"]:::ui
        StaticWidgets["Static Widgets\n(src/components/static_widgets.rs)"]:::ui
    end

    %% Persistence & Docs
    subgraph "Persistence & Docs"
        StationsJSON[(stations.json)]:::storage
        CargoToml["Cargo.toml"]:::docs
        Readme["README.md"]:::docs
    end

    %% Data Flows
    UserKeyboard --> EventLoop
    EventLoop --> Main
    Main --> AppCore
    AppCore --> UpdateScheduler
    UpdateScheduler --> APIClient
    APIClient --> ExternalAPI
    APIClient --> AppCore
    AppCore --> StationsJSON
    StationsJSON --> AppCore
    AppCore --> UIRendererWire
    UIRendererWire --> UIRendererLayout
    UIRendererLayout --> UIComponentsIndex
    UIComponentsIndex --> StationListWidget
    UIComponentsIndex --> StaticWidgets
    Main --> Constants

    %% Click Events
    click EventLoop "https://github.com/faisalbinahmed/mvgfahrinfo/blob/main/src/event.rs"
    click Main "https://github.com/faisalbinahmed/mvgfahrinfo/blob/main/src/main.rs"
    click AppCore "https://github.com/faisalbinahmed/mvgfahrinfo/blob/main/src/app.rs"
    click UpdateScheduler "https://github.com/faisalbinahmed/mvgfahrinfo/blob/main/src/update.rs"
    click APIClient "https://github.com/faisalbinahmed/mvgfahrinfo/blob/main/src/api.rs"
    click UIRendererWire "https://github.com/faisalbinahmed/mvgfahrinfo/blob/main/src/tui.rs"
    click UIRendererLayout "https://github.com/faisalbinahmed/mvgfahrinfo/blob/main/src/ui.rs"
    click StationListWidget "https://github.com/faisalbinahmed/mvgfahrinfo/blob/main/src/components/station_list.rs"
    click StaticWidgets "https://github.com/faisalbinahmed/mvgfahrinfo/blob/main/src/components/static_widgets.rs"
    click UIComponentsIndex "https://github.com/faisalbinahmed/mvgfahrinfo/blob/main/src/components/mod.rs"
    click Constants "https://github.com/faisalbinahmed/mvgfahrinfo/blob/main/src/constants.rs"
    click CargoToml "https://github.com/faisalbinahmed/mvgfahrinfo/blob/main/Cargo.toml"
    click Readme "https://github.com/faisalbinahmed/mvgfahrinfo/blob/main/README.md"
    click StationsJSON "https://github.com/faisalbinahmed/mvgfahrinfo/blob/main/stations.json"

    %% Styling
    classDef input fill:#D6EFFF,stroke:#0284C7,stroke-width:1px
    classDef core fill:#D6F5D6,stroke:#28A745,stroke-width:1px
    classDef ui fill:#FFF3BF,stroke:#F59E0B,stroke-width:1px
    classDef storage fill:#FFE8D6,stroke:#FB923C,stroke-width:1px
    classDef ext fill:#E5E7EB,stroke:#6B7280,stroke-width:1px,stroke-dasharray: 5 5
    classDef docs fill:#FCE7F3,stroke:#DB2777,stroke-width:1px
```
