# hyraxhomie/fly-over-ts architecture

> Architecture diagram of the GitHub repository hyraxhomie/fly-over-ts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hyraxhomie/fly-over-ts
- Repository: https://github.com/hyraxhomie/fly-over-ts

## Overview

1. **Two runtime pieces**
   - The repo is split into a **browser client** (`src/`) and an optional **Node host server** (`server/index.mjs`).
   - The client is a Vite + React + TypeScript single-page app.
   - The server serves the built app and acts as an **OpenSky proxy/cache layer** for production/home hosting.

2. **Primary product shape**
   - This is a **flight-visualization dashboard**, not a general CRUD app.
   - The user enters an address, the app geocodes it, then shows aircraft near that point on a map.
   - The UI can run in **Live** mode from OpenSky or **Demo** mode from an internal simulation.

3. **Client-side architecture**
   - `src/main.tsx` bootstraps the app and `src/App.tsx` wires the top-level layout and state flow.
   - Most visible behavior is split into small presentational components:
     - `MapView.tsx` for the map and aircraft rendering
     - `FlightList.tsx` and `FlightDetail.tsx` for sidebar/list inspection
     - `SearchBar.tsx` for location entry
     - `StatusBar.tsx` for mode/feed status and controls

4. **Core orchestration hook**
   - `src/hooks/useFlights.ts` is the main client-side state engine.
   - It owns both data sources:
     - **Live**: periodically polls OpenSky for the current region
     - **Demo**: seeds and updates a self-contained mock fleet
   - It also drives smooth animation by advancing aircraft positions between polls with `requestAnimationFrame`.

5. **Data flow from address to aircraft**
   - User enters or selects an address in `SearchBar`.
   - The app geocodes the address via `src/lib/geocode.ts` using **Nominatim / OpenStreetMap**.
   - The resulting lat/lng becomes the home location, which is persisted locally and can be deep-linked via query parameters.
   - `src/lib/geo.ts` computes the bounding box around that home position for the aircraft query.

6. **Live aircraft pipeline**
   - `src/lib/opensky.ts` fetches OpenSky `/states/all` for the current bounding box.
   - Raw state vectors are normalized into app-specific `Flight` objects defined in `src/types.ts`.
   - `src/lib/mockFlights.ts` contains `deadReckonFlights`, which keeps motion fluid by extrapolating velocity between network updates.

7. **Map rendering boundary**
   - `src/components/MapView.tsx` is the visual boundary between app state and Leaflet.
   - It renders:
     - the selected home marker
     - a range/bounding ring
     - aircraft icons rotated by heading
   - The map uses **react-leaflet / Leaflet** with a dark CARTO basemap, so map rendering is a distinct subsystem from the flight logic.

8. **State persistence and user-facing continuity**
   - The app remembers the user’s address/location in **localStorage** so it reopens ready for use.
   - It also supports sharing/bookmarking via URL parameters (`lat`, `lng`, `label`), which makes location state part of the app boundary rather than ephemeral UI state.

9. **Live-vs-demo mode boundary**
   - `StatusBar.tsx` exposes the Live/Demo switch and feed status.
   - Demo mode is not just a UI mock; it uses the same display pipeline as live flights, which keeps the map and sidebar behavior consistent.
   - This makes the data source swappable while preserving the rest of the app architecture.

10. **Server responsibilities**
   - `server/index.mjs` is the production/home-serving boundary.
   - It has three jobs:
     - serve static built assets
     - proxy OpenSky requests
     - enforce bbox validation and short shared caching
   - In production, this is important because the browser cannot directly call OpenSky reliably due to CORS and rate limits.

11. **OpenSky credentials and rate control**
   - Anonymous OpenSky usage is constrained, so the server can authenticate with `OPENSKY_CLIENT_ID` and `OPENSKY_CLIENT_SECRET`.
   - The cache TTL and the client’s visibility-aware polling reduce upstream calls.
   - This means the architecture intentionally places sensitive credentials and upstream access **server-side only**.

12. **Development vs production path**
   - In development, Vite proxies `/opensky/*` directly to OpenSky.
   - In production/home hosting, the bundled Node server becomes the proxy and static host.
   - The client can also be pointed at a different proxy through `VITE_OPENSKY_BASE`, so the app is designed around a configurable API edge.

13. **Performance-sensitive behavior**
   - Aircraft marker positions are updated cheaply; the app avoids rebuilding map icons on every frame.
   - Motion is throttled with a configurable frame rate and pauses when the tab is hidden.
   - These choices matter because the main interaction is continuous animation, not static data display.

14. **Diagram-friendly subsystem summary**
   - **Input layer:** address/search, URL params, localStorage
   - **Geocoding layer:** Nominatim
   - **Flight data layer:** OpenSky live feed or mock simulation
   - **Motion layer:** dead-reckoning / frame interpolation
   - **Presentation layer:** React UI + Leaflet map + flight sidebar
   - **Edge/server layer:** static hosting + authenticated cached OpenSky proxy

Main entry points: [`src/App.tsx`](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/App.tsx) (App shell), [`src/hooks/useFlights.ts`](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/hooks/useFlights.ts) (Flight engine), [`server/index.mjs`](https://github.com/hyraxhomie/fly-over-ts/blob/main/server/index.mjs) (Host server), [`src/components/SearchBar.tsx`](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/components/SearchBar.tsx) (Search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_main["Entry<br/>bootstrap<br/>[main.tsx]"]
  node_app["App shell<br/>composition<br/>[App.tsx]"]
  node_useflights{{"Flight engine<br/>state hook<br/>[useFlights.ts]"}}
  node_storage[("Local storage<br/>persistence")]
  node_urlstate["URL params<br/>share state"]
end

subgraph group_server["Node host"]
  node_serverindex["Host server<br/>node server<br/>[index.mjs]"]
end

subgraph group_data["Flight data"]
  node_geocode["Geocode<br/>nominatim client<br/>[geocode.ts]"]
  node_geo["Bounds<br/>geo math<br/>[geo.ts]"]
  node_opensky["OpenSky<br/>live fetch<br/>[opensky.ts]"]
  node_mockflights["Mock motion<br/>simulation<br/>[mockFlights.ts]"]
  node_types["Flight types<br/>domain model<br/>[types.ts]"]
end

subgraph group_ui["UI presentation"]
  node_searchbar["Search<br/>input component<br/>[SearchBar.tsx]"]
  node_statusbar["Status<br/>mode control<br/>[StatusBar.tsx]"]
  node_mapview["Map view<br/>leaflet boundary<br/>[MapView.tsx]"]
  node_flightlist["Flight list<br/>sidebar list<br/>[FlightList.tsx]"]
  node_flightdetail["Flight detail<br/>detail panel<br/>[FlightDetail.tsx]"]
  node_leaflet[("Leaflet map<br/>mapping library")]
  node_carto[("Dark basemap<br/>map tiles")]
end

node_main -->|"mounts"| node_app
node_app -->|"location input"| node_searchbar
node_app -->|"mode/status"| node_statusbar
node_app -->|"visualizes"| node_mapview
node_app -->|"lists"| node_flightlist
node_app -->|"inspects"| node_flightdetail
node_app -->|"state flow"| node_useflights
node_searchbar -->|"resolves"| node_geocode
node_searchbar -->|"deep link"| node_urlstate
node_app -->|"remembers"| node_storage
node_useflights -->|"queries area"| node_geo
node_useflights -->|"live feed"| node_opensky
node_useflights -->|"demo feed"| node_mockflights
node_useflights -->|"models"| node_types
node_mockflights -->|"emits"| node_types
node_opensky -->|"normalizes"| node_types
node_mapview -->|"renders on"| node_leaflet
node_mapview -->|"tiles"| node_carto
node_serverindex -->|"proxies"| node_opensky
node_serverindex -->|"serves build"| node_app
node_serverindex -.->|"server edge"| node_storage

click node_main "https://github.com/hyraxhomie/fly-over-ts/blob/main/src/main.tsx"
click node_app "https://github.com/hyraxhomie/fly-over-ts/blob/main/src/App.tsx"
click node_useflights "https://github.com/hyraxhomie/fly-over-ts/blob/main/src/hooks/useFlights.ts"
click node_searchbar "https://github.com/hyraxhomie/fly-over-ts/blob/main/src/components/SearchBar.tsx"
click node_statusbar "https://github.com/hyraxhomie/fly-over-ts/blob/main/src/components/StatusBar.tsx"
click node_mapview "https://github.com/hyraxhomie/fly-over-ts/blob/main/src/components/MapView.tsx"
click node_flightlist "https://github.com/hyraxhomie/fly-over-ts/blob/main/src/components/FlightList.tsx"
click node_flightdetail "https://github.com/hyraxhomie/fly-over-ts/blob/main/src/components/FlightDetail.tsx"
click node_geocode "https://github.com/hyraxhomie/fly-over-ts/blob/main/src/lib/geocode.ts"
click node_geo "https://github.com/hyraxhomie/fly-over-ts/blob/main/src/lib/geo.ts"
click node_opensky "https://github.com/hyraxhomie/fly-over-ts/blob/main/src/lib/opensky.ts"
click node_mockflights "https://github.com/hyraxhomie/fly-over-ts/blob/main/src/lib/mockFlights.ts"
click node_types "https://github.com/hyraxhomie/fly-over-ts/blob/main/src/types.ts"
click node_serverindex "https://github.com/hyraxhomie/fly-over-ts/blob/main/server/index.mjs"

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_main,node_app,node_useflights,node_storage,node_urlstate toneBlue
class node_serverindex toneAmber
class node_geocode,node_geo,node_opensky,node_mockflights,node_types toneMint
class node_searchbar,node_statusbar,node_mapview,node_flightlist,node_flightdetail,node_leaflet,node_carto toneRose
```

## Components

### Browser client

Vite + React SPA that geocodes a home location and visualizes nearby aircraft.

- [Entry](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/main.tsx): bootstrap · Bootstraps the browser app. · `src/main.tsx`
- [App shell](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/App.tsx): composition · Wires top-level layout, location state, and flight flow. · `src/App.tsx`
- [Flight engine](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/hooks/useFlights.ts): state hook · Main client-side state engine for live/demo data and animation. · `src/hooks/useFlights.ts`
- **Local storage**: persistence · Persists the last chosen location in the browser.
- **URL params**: share state · Carries lat, lng, and label for bookmarking and deep links.

### Node host

Optional production/home server that serves the app and proxies OpenSky.

- [Host server](https://github.com/hyraxhomie/fly-over-ts/blob/main/server/index.mjs): node server · Serves static assets and proxies cached OpenSky requests. · `server/index.mjs`

### Flight data

External and internal flight sources plus normalization and motion helpers.

- [Geocode](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/lib/geocode.ts): nominatim client · Resolves addresses to latitude and longitude via OpenStreetMap. · `src/lib/geocode.ts`
- [Bounds](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/lib/geo.ts): geo math · Computes the query bounding box around the home location. · `src/lib/geo.ts`
- [OpenSky](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/lib/opensky.ts): live fetch · Fetches and normalizes OpenSky state vectors for the current area. · `src/lib/opensky.ts`
- [Mock motion](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/lib/mockFlights.ts): simulation · Seeds demo flights and dead-reckons motion between updates. · `src/lib/mockFlights.ts`
- [Flight types](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/types.ts): domain model · Shared flight and app domain types. · `src/types.ts`

### UI presentation

Top-level UI shell and visible flight/map components.

- [Search](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/components/SearchBar.tsx): input component · Accepts and selects addresses for the home location. · `src/components/SearchBar.tsx`
- [Status](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/components/StatusBar.tsx): mode control · Shows feed status and toggles Live/Demo mode. · `src/components/StatusBar.tsx`
- [Map view](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/components/MapView.tsx): leaflet boundary · Renders the home marker, range ring, and aircraft on the map. · `src/components/MapView.tsx`
- [Flight list](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/components/FlightList.tsx): sidebar list · Lists nearby aircraft for inspection. · `src/components/FlightList.tsx`
- [Flight detail](https://github.com/hyraxhomie/fly-over-ts/blob/main/src/components/FlightDetail.tsx): detail panel · Shows selected aircraft details. · `src/components/FlightDetail.tsx`
- **Leaflet map**: mapping library · Interactive map rendering backend used by the map view.
- **Dark basemap**: map tiles · Dark CARTO tile layer used by the map.

## Connections

- Entry → App shell: mounts · Entry point renders the application shell.
- App shell → Search: location input · Top-level shell passes search interaction into the UI.
- App shell → Status: mode/status · Shell exposes feed state and Live/Demo switching.
- App shell → Map view: visualizes · Shell sends flight and home state to the map.
- App shell → Flight list: lists · Shell feeds nearby flights into the sidebar list.
- App shell → Flight detail: inspects · Shell routes selection into the detail panel.
- App shell → Flight engine: state flow · App delegates flight sourcing and animation to the hook.
- Search → Geocode: resolves · Address entry is turned into coordinates.
- Search → URL params: deep link · Location can be represented in query parameters.
- App shell → Local storage: remembers · Chosen location is persisted for reopening.
- Flight engine → Bounds: queries area · Home location becomes the aircraft search bounds.
- Flight engine → OpenSky: live feed · Live mode polls OpenSky for aircraft in range.
- Flight engine → Mock motion: demo feed · Demo mode seeds and advances a self-contained fleet.
- Flight engine → Flight types: models · Normalized flight state uses shared domain types.
- Mock motion → Flight types: emits · Demo simulation produces app flight objects.
- OpenSky → Flight types: normalizes · Raw OpenSky vectors are mapped into app models.
- Map view → Leaflet map: renders on · Map view is the React boundary around Leaflet.
- Map view → Dark basemap: tiles · Map uses a dark CARTO basemap.
- Host server → OpenSky: proxies · Server forwards and caches OpenSky requests.
- Host server → App shell: serves build · Server hosts the built client assets.
- Host server → Local storage: server edge · Sensitive credentials and upstream access stay server-side.
