# huarox/luftlinie architecture

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

- Interactive diagram: https://gitdiagram.com/huarox/luftlinie
- Repository: https://github.com/huarox/luftlinie

## Overview

1. **Repository shape**
   - This repo is intentionally minimal: a single `index.html` contains the entire application, with only README, license, and ignore rules alongside it.
   - Architecturally, it is a **client-side monolith** hosted as static files, with no build step and no custom backend service.

2. **Primary runtime boundary**
   - The app runs entirely in the **browser on mobile devices** and desktop spectators.
   - All game logic, UI state, GPS handling, and rendering live in the frontend; persistence and synchronization are delegated to external services.

3. **Core app roles**
   - The game is split into three user-facing roles:
     - **Host**: creates the game, selects target placement, and controls game settings.
     - **Navigator**: joins on a phone and receives only distance/direction feedback while moving in the real world.
     - **Spectator**: watches a live map view with player routes and status.
   - These roles are represented as different UI states over the same underlying shared game session.

4. **Real-time game state subsystem**
   - Shared session state is stored in **Firebase Realtime Database**.
   - Firebase is the central coordination layer for:
     - game codes and session metadata
     - player presence and position updates
     - target position changes
     - timers, elimination events, and mode-specific transitions
   - Because updates are pushed in real time, the app does not rely on polling.

5. **Location and motion subsystem**
   - The navigator experience depends on **browser GPS/geolocation** updates.
   - The app continuously converts current GPS position into:
     - straight-line distance to target
     - arrival detection
     - movement/velocity feedback for modes like Hot & Cold
     - compass-relative bearing for Sailor mode
   - GPS accuracy is surfaced as a first-class UI signal, including blocked/poor/live states.

6. **Map and route rendering subsystem**
   - The spectator/results views use **Leaflet** with **CartoDB tile layers** for the map base.
   - Player tracks, target markers, and color-coded routes are rendered on top of the map.
   - Route shapes are likely fetched from an external routing service rather than computed locally.

7. **External data services**
   - **OSRM public API** is used for routing-related path visualization.
   - **Overpass API** is used by Smart target placement to find realistic road-based targets near the desired distance.
   - These APIs materially affect the game experience: target placement is road-aware, and spectator maps can show route context rather than just points.

8. **Mode engine**
   - The application contains multiple game modes that alter how the shared session state is interpreted and what navigators see:
     - Standard
     - Elimination
     - Whisper
     - Hot & Cold
     - Sailor
     - Multi-Target
     - Dynamic
   - These modes are not separate subsystems; they are **behavioral overlays** on the same core game/session model.

9. **Results, replay, and sharing**
   - After game completion, the app switches to a results flow that includes:
     - winner and leaderboard
     - route stats
     - replay of player trails
     - shareable vertical result card image
   - This is a distinct post-game UI boundary built from the same stored session history and player track data.

10. **Local persistence and continuity**
    - The app uses **localStorage** for persistent player stats across sessions.
    - Rejoin support and session recovery are also client-managed, allowing a player to reconnect after reload within a limited window.
    - This is separate from Firebase session state: local storage is for personal history and convenience, while Firebase is for live multiplayer state.

11. **Progressive-web-app concerns**
    - The repository supports **PWA-style installability** and mobile-first operation.
    - Because GPS access requires HTTPS, deployment is expected on a static HTTPS host such as **GitHub Pages**.

12. **Security and trust model**
    - There is no authentication layer described; the game relies on open Realtime Database rules during development or permissive production rules.
    - The README emphasizes validation rules to prevent malformed writes, but not access control.
    - That means the architecture is intentionally lightweight and trust-based, suitable for small multiplayer sessions rather than hardened public tenancy.

13. **Recommended diagram boundaries**
    - A good architecture diagram would show:
      - browser clients for host/navigator/spectator
      - a shared Firebase Realtime Database in the center
      - browser GPS / device sensors feeding navigator state
      - external APIs for Overpass, OSRM, and map tiles
      - localStorage as a per-device persistence layer
      - GitHub Pages or any static host as the delivery mechanism for `index.html`

Main entry points: [`index.html`](https://github.com/huarox/luftlinie/blob/main/index.html) (App shell), [`README.md`](https://github.com/huarox/luftlinie/blob/main/README.md) (README)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_delivery["Delivery"]
  node_static_host["Static host<br/>hosting"]
  node_readme["README<br/>docs<br/>[README.md]"]
end

subgraph group_client["Browser client"]
  node_index_html["App shell<br/>single-page app<br/>[index.html]"]
  node_host_ui["Host view<br/>role state<br/>[index.html]"]
  node_navigator_ui["Navigator view<br/>role state<br/>[index.html]"]
  node_spectator_ui["Spectator view<br/>role state<br/>[index.html]"]
  node_results_flow["Results flow<br/>post-game ui<br/>[index.html]"]
  node_mode_engine["Mode engine<br/>rules overlay<br/>[index.html]"]
  node_gps_sensor(("GPS sensor<br/>device API"))
  node_distance_calc["Distance calc<br/>navigation logic<br/>[index.html]"]
  node_map_renderer["Map renderer<br/>leaflet view<br/>[index.html]"]
  node_route_logic["Route logic<br/>path visualization<br/>[index.html]"]
end

subgraph group_state["Shared state"]
  node_firebase_db[("Realtime DB<br/>live session store")]
  node_local_storage[("Local stats<br/>device storage")]
end

subgraph group_services["External services"]
  node_overpass_api["Overpass API<br/>target search"]
  node_osrm_api["OSRM API<br/>routing api"]
  node_tile_layers["Carto tiles<br/>map tiles"]
end

node_static_host -->|"serves"| node_index_html
node_index_html -->|"renders"| node_host_ui
node_index_html -->|"renders"| node_navigator_ui
node_index_html -->|"renders"| node_spectator_ui
node_index_html -->|"renders"| node_results_flow
node_index_html -->|"applies"| node_mode_engine
node_navigator_ui -->|"reads"| node_gps_sensor
node_gps_sensor -->|"feeds"| node_distance_calc
node_mode_engine -->|"modifies"| node_distance_calc
node_distance_calc -->|"updates"| node_firebase_db
node_host_ui -->|"writes"| node_firebase_db
node_spectator_ui -->|"subscribes"| node_firebase_db
node_firebase_db -->|"streams"| node_map_renderer
node_map_renderer -->|"uses"| node_tile_layers
node_route_logic -->|"queries"| node_osrm_api
node_mode_engine -->|"queries"| node_overpass_api
node_results_flow -->|"reads/writes"| node_local_storage
node_results_flow -->|"shows"| node_route_logic
node_route_logic -->|"draws"| node_map_renderer
node_readme -.->|"describes"| node_index_html

click node_index_html "https://github.com/huarox/luftlinie/blob/main/index.html"
click node_host_ui "https://github.com/huarox/luftlinie/blob/main/index.html"
click node_navigator_ui "https://github.com/huarox/luftlinie/blob/main/index.html"
click node_spectator_ui "https://github.com/huarox/luftlinie/blob/main/index.html"
click node_results_flow "https://github.com/huarox/luftlinie/blob/main/index.html"
click node_mode_engine "https://github.com/huarox/luftlinie/blob/main/index.html"
click node_distance_calc "https://github.com/huarox/luftlinie/blob/main/index.html"
click node_map_renderer "https://github.com/huarox/luftlinie/blob/main/index.html"
click node_route_logic "https://github.com/huarox/luftlinie/blob/main/index.html"
click node_readme "https://github.com/huarox/luftlinie/blob/main/README.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_static_host,node_readme toneBlue
class node_index_html,node_host_ui,node_navigator_ui,node_spectator_ui,node_results_flow,node_mode_engine,node_gps_sensor,node_distance_calc,node_map_renderer,node_route_logic toneAmber
class node_firebase_db,node_local_storage toneMint
class node_overpass_api,node_osrm_api,node_tile_layers toneRose
```

## Components

### Delivery

Static hosting and repository docs

- **Static host**: hosting · HTTPS static delivery for the app
- [README](https://github.com/huarox/luftlinie/blob/main/README.md): docs · Project description and operational notes · `README.md`

### Browser client

Single-page app and in-browser runtime boundaries

- [App shell](https://github.com/huarox/luftlinie/blob/main/index.html): single-page app · Client-side monolith containing the full application · `index.html`
- [Host view](https://github.com/huarox/luftlinie/blob/main/index.html): role state · Creates sessions, chooses placement, and controls settings · `index.html`
- [Navigator view](https://github.com/huarox/luftlinie/blob/main/index.html): role state · Mobile play view with live distance, direction, and GPS feedback · `index.html`
- [Spectator view](https://github.com/huarox/luftlinie/blob/main/index.html): role state · Live map and route monitoring for observers · `index.html`
- [Results flow](https://github.com/huarox/luftlinie/blob/main/index.html): post-game ui · Winner, leaderboard, replay, and share card screens · `index.html`
- [Mode engine](https://github.com/huarox/luftlinie/blob/main/index.html): rules overlay · Standard, elimination, whisper, hot and cold, sailor, multi-target, and dynamic behaviors · `index.html`
- **GPS sensor**: device API · Browser geolocation input and accuracy states
- [Distance calc](https://github.com/huarox/luftlinie/blob/main/index.html): navigation logic · Computes distance, bearing, arrival, and motion feedback · `index.html`
- [Map renderer](https://github.com/huarox/luftlinie/blob/main/index.html): leaflet view · Leaflet map with routes, markers, and live trails · `index.html`
- [Route logic](https://github.com/huarox/luftlinie/blob/main/index.html): path visualization · Builds route context for spectator and results views · `index.html`

### Shared state

Live multiplayer coordination and local persistence

- **Realtime DB**: live session store · Shared game codes, presence, targets, timers, and updates
- **Local stats**: device storage · Per-device persistence for player history and rejoin continuity

### External services

Third-party APIs for maps, routing, and target placement

- **Overpass API**: target search · Road-aware nearby target discovery
- **OSRM API**: routing api · External routing source for path visualization
- **Carto tiles**: map tiles · Basemap tiles used by the map view

## Connections

- Static host → App shell: serves · Static host delivers the single-page app
- App shell → Host view: renders · Host role is a UI state in the app
- App shell → Navigator view: renders · Navigator role is a UI state in the app
- App shell → Spectator view: renders · Spectator role is a UI state in the app
- App shell → Results flow: renders · Post-game screens reuse the same client state
- App shell → Mode engine: applies · Mode-specific behavior overlays the shared session model
- Navigator view → GPS sensor: reads · Navigator view consumes device location updates
- GPS sensor → Distance calc: feeds · Location and accuracy drive navigation calculations
- Mode engine → Distance calc: modifies · Modes adjust feedback and elimination logic
- Distance calc → Realtime DB: updates · Live position and status are synchronized in realtime
- Host view → Realtime DB: writes · Creates and configures shared sessions
- Spectator view → Realtime DB: subscribes · Spectator view watches live session state
- Realtime DB → Map renderer: streams · Routes, trails, and target state update the map
- Map renderer → Carto tiles: uses · Leaflet renders on top of Carto basemaps
- Route logic → OSRM API: queries · Route shapes are sourced externally
- Mode engine → Overpass API: queries · Smart target placement searches for realistic roads
- Results flow → Local stats: reads/writes · Persistent player stats and continuity live on device
- Results flow → Route logic: shows · Replay and route stats are assembled from stored tracks
- Route logic → Map renderer: draws · Replay paths and route context are visualized on the map
- README → App shell: describes · Repository documentation points to the single-file app
