How faisalbinahmed/mvgfahrinfo works
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.