# thealexube/opentower architecture

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

- Interactive diagram: https://gitdiagram.com/thealexube/opentower
- Repository: https://github.com/thealexube/opentower

## Overview

OpenTower is a browser-based ATC simulator. The controller chooses a shift or approach scenario, handles pilot calls by text or voice, and issues clearances; the simulation updates aircraft and incidents, while the selected scope and radio UI present the results and a final debrief. The graph separates tower and TRACON simulation, shared airport/radio logic, and browser presentation. Source excerpts show the main wiring and key dependencies; other documented features, including offline PWA behavior, are represented where supported, without assuming unsampled implementation details.

Main entry points: [`src/ui.js`](https://github.com/thealexube/opentower/blob/main/src/ui.js) (UI and game loop), [`src/main.js`](https://github.com/thealexube/opentower/blob/main/src/main.js) (Application composition), [`src/engine.js`](https://github.com/thealexube/opentower/blob/main/src/engine.js) (Tower simulation), [`src/tracon.js`](https://github.com/thealexube/opentower/blob/main/src/tracon.js) (TRACON simulation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Browser application"]
  node_ui["UI and game loop<br/>[ui.js]"]
  node_main["Application composition<br/>[main.js]"]
  node_scenarios["Shift scenarios<br/>[scenarios.js]"]
  node_scorestate["Best-score state<br/>[scenario-state.js]"]
end

subgraph group_simulation["Simulation modes"]
  node_tower["Tower simulation<br/>[engine.js]"]
  node_approach["TRACON simulation<br/>[tracon.js]"]
end

subgraph group_shared["Shared ATC logic"]
  node_airport["Airport routes<br/>[airport.js]"]
  node_config["Airport and aircraft data<br/>[config.js]"]
  node_phraseology["Radio parser and readbacks<br/>[phraseology.js]"]
  node_weather["Weather and runway choice<br/>[weather.js]"]
end

subgraph group_presentation["Scopes and radio"]
  node_towercanvas["Tower scope renderer<br/>[render.js]"]
  node_approachcanvas["Approach radar renderer<br/>[tracon-renderer.js]"]
  node_scopebase["Scope projection and picking<br/>[scope-renderer.js]"]
  node_language["English and Spanish UI<br/>[i18n.js]"]
  node_voice["Pilot speech controls<br/>[voice.js]"]
end

subgraph group_platform["Browser services"]
  node_nws["NWS weather service"]
  node_browser["Browser speech APIs"]
  node_offline["Offline PWA cache<br/>[sw.js]"]
  node_storage[("Browser local storage")]
end

node_controller(("Air traffic controller"))

node_controller -->|"operates"| node_ui
node_main -->|"creates app"| node_ui
node_main -->|"provides engine"| node_tower
node_main -->|"provides engine"| node_approach
node_main -->|"provides renderer"| node_towercanvas
node_main -->|"provides renderer"| node_approachcanvas
node_ui -->|"selects scenario"| node_scenarios
node_ui -->|"keys best score"| node_scorestate
node_ui -->|"sends clearances"| node_tower
node_ui -->|"sends clearances"| node_approach
node_ui -->|"displays scope"| node_towercanvas
node_ui -->|"displays radar"| node_approachcanvas
node_ui -->|"fetches weather"| node_weather
node_ui -->|"configures voice"| node_voice
node_ui -->|"applies language"| node_language
node_ui -->|"reads and writes"| node_storage
node_tower -->|"uses routes"| node_airport
node_tower -->|"parses instructions"| node_phraseology
node_tower -->|"uses airport data"| node_config
node_approach -->|"matches callsigns"| node_phraseology
node_approach -->|"uses airport data"| node_config
node_approach -->|"chooses runway"| node_weather
node_weather -->|"fetches observations"| node_nws
node_towercanvas -->|"extends renderer"| node_scopebase
node_towercanvas -->|"uses final inset"| node_airport
node_towercanvas -->|"draws airport"| node_config
node_approachcanvas -->|"extends renderer"| node_scopebase
node_voice -->|"uses speech APIs"| node_browser
node_offline -.->|"caches app offline"| node_browser

click node_ui "https://github.com/thealexube/opentower/blob/main/src/ui.js"
click node_main "https://github.com/thealexube/opentower/blob/main/src/main.js"
click node_scenarios "https://github.com/thealexube/opentower/blob/main/src/scenarios.js"
click node_scorestate "https://github.com/thealexube/opentower/blob/main/src/scenario-state.js"
click node_tower "https://github.com/thealexube/opentower/blob/main/src/engine.js"
click node_approach "https://github.com/thealexube/opentower/blob/main/src/tracon.js"
click node_airport "https://github.com/thealexube/opentower/blob/main/src/airport.js"
click node_config "https://github.com/thealexube/opentower/blob/main/src/config.js"
click node_phraseology "https://github.com/thealexube/opentower/blob/main/src/phraseology.js"
click node_weather "https://github.com/thealexube/opentower/blob/main/src/weather.js"
click node_towercanvas "https://github.com/thealexube/opentower/blob/main/src/render.js"
click node_approachcanvas "https://github.com/thealexube/opentower/blob/main/src/tracon-renderer.js"
click node_scopebase "https://github.com/thealexube/opentower/blob/main/src/scope-renderer.js"
click node_language "https://github.com/thealexube/opentower/blob/main/src/i18n.js"
click node_voice "https://github.com/thealexube/opentower/blob/main/src/voice.js"
click node_offline "https://github.com/thealexube/opentower/blob/main/sw.js"

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_ui,node_main,node_scenarios,node_scorestate toneBlue
class node_tower,node_approach toneAmber
class node_airport,node_config,node_phraseology,node_weather toneMint
class node_towercanvas,node_approachcanvas,node_scopebase,node_language,node_voice toneRose
class node_nws,node_browser,node_offline,node_storage,node_controller toneIndigo
```

## Components

### Browser application

- [UI and game loop](https://github.com/thealexube/opentower/blob/main/src/ui.js): `src/ui.js`
- [Application composition](https://github.com/thealexube/opentower/blob/main/src/main.js): `src/main.js`
- [Shift scenarios](https://github.com/thealexube/opentower/blob/main/src/scenarios.js): `src/scenarios.js`
- [Best-score state](https://github.com/thealexube/opentower/blob/main/src/scenario-state.js): `src/scenario-state.js`

### Simulation modes

- [Tower simulation](https://github.com/thealexube/opentower/blob/main/src/engine.js): `src/engine.js`
- [TRACON simulation](https://github.com/thealexube/opentower/blob/main/src/tracon.js): `src/tracon.js`

### Shared ATC logic

- [Airport routes](https://github.com/thealexube/opentower/blob/main/src/airport.js): `src/airport.js`
- [Airport and aircraft data](https://github.com/thealexube/opentower/blob/main/src/config.js): `src/config.js`
- [Radio parser and readbacks](https://github.com/thealexube/opentower/blob/main/src/phraseology.js): `src/phraseology.js`
- [Weather and runway choice](https://github.com/thealexube/opentower/blob/main/src/weather.js): `src/weather.js`

### Scopes and radio

- [Tower scope renderer](https://github.com/thealexube/opentower/blob/main/src/render.js): `src/render.js`
- [Approach radar renderer](https://github.com/thealexube/opentower/blob/main/src/tracon-renderer.js): `src/tracon-renderer.js`
- [Scope projection and picking](https://github.com/thealexube/opentower/blob/main/src/scope-renderer.js): `src/scope-renderer.js`
- [English and Spanish UI](https://github.com/thealexube/opentower/blob/main/src/i18n.js): `src/i18n.js`
- [Pilot speech controls](https://github.com/thealexube/opentower/blob/main/src/voice.js): `src/voice.js`

### Browser services

- **NWS weather service**
- **Browser speech APIs**
- [Offline PWA cache](https://github.com/thealexube/opentower/blob/main/sw.js): `sw.js`
- **Browser local storage**

### Other components

- **Air traffic controller**

## Connections

- Air traffic controller → UI and game loop: operates (evidence: `README.md`)
- Application composition → UI and game loop: creates app (evidence: `src/main.js`)
- Application composition → Tower simulation: provides engine (evidence: `src/main.js`)
- Application composition → TRACON simulation: provides engine (evidence: `src/main.js`)
- Application composition → Tower scope renderer: provides renderer (evidence: `src/main.js`)
- Application composition → Approach radar renderer: provides renderer (evidence: `src/main.js`)
- UI and game loop → Shift scenarios: selects scenario (evidence: `src/ui.js`)
- UI and game loop → Best-score state: keys best score (evidence: `src/ui.js`)
- UI and game loop → Tower simulation: sends clearances (evidence: `README.md`)
- UI and game loop → TRACON simulation: sends clearances (evidence: `README.md`)
- UI and game loop → Tower scope renderer: displays scope (evidence: `README.md`)
- UI and game loop → Approach radar renderer: displays radar (evidence: `README.md`)
- UI and game loop → Weather and runway choice: fetches weather (evidence: `src/ui.js`)
- UI and game loop → Pilot speech controls: configures voice (evidence: `src/ui.js`)
- UI and game loop → English and Spanish UI: applies language (evidence: `src/ui.js`)
- UI and game loop → Browser local storage: reads and writes (evidence: `README.md`)
- Tower simulation → Airport routes: uses routes (evidence: `src/engine.js`)
- Tower simulation → Radio parser and readbacks: parses instructions (evidence: `src/engine.js`)
- Tower simulation → Airport and aircraft data: uses airport data (evidence: `src/engine.js`)
- TRACON simulation → Radio parser and readbacks: matches callsigns (evidence: `src/tracon.js`)
- TRACON simulation → Airport and aircraft data: uses airport data (evidence: `src/tracon.js`)
- TRACON simulation → Weather and runway choice: chooses runway (evidence: `src/tracon.js`)
- Weather and runway choice → NWS weather service: fetches observations (evidence: `src/weather.js`)
- Tower scope renderer → Scope projection and picking: extends renderer (evidence: `src/render.js`)
- Tower scope renderer → Airport routes: uses final inset (evidence: `src/render.js`)
- Tower scope renderer → Airport and aircraft data: draws airport (evidence: `src/render.js`)
- Approach radar renderer → Scope projection and picking: extends renderer (evidence: `src/tracon-renderer.js`)
- Pilot speech controls → Browser speech APIs: uses speech APIs (evidence: `README.md`)
- Offline PWA cache → Browser speech APIs: caches app offline
