# pino-the-bird/trains architecture

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

- Interactive diagram: https://gitdiagram.com/pino-the-bird/trains
- Repository: https://github.com/pino-the-bird/trains

## Overview

This is a browser-based 3D railway simulator for riding real UK railway lines, with a network timetable, multiple train types, cab and external views, signals, a railway map, scenery, and generated sound. The main workflow is the simulator loading a line and its scenery, constructing track and terrain, running trains, and presenting a ride through the available views. The excerpts show several simulator-owned registrations and rendering helpers; other interactions and some capability wiring are not sampled, so those links are omitted or marked unverified.

Main entry points: [`sim.js`](https://github.com/pino-the-bird/trains/blob/main/sim.js) (Simulator), [`ground.js`](https://github.com/pino-the-bird/trains/blob/main/ground.js) (Terrain), [`geo.js`](https://github.com/pino-the-bird/trains/blob/main/geo.js) (Geographic frame), [`draw.js`](https://github.com/pino-the-bird/trains/blob/main/draw.js) (Render helpers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Simulation runtime"]
  node_sim["Simulator<br/>[sim.js]"]
end

subgraph group_railway["Railway model"]
  node_line["Line geometry<br/>[line.js]"]
  node_railway_model["Timetable railway<br/>[railway.js]"]
  node_train_kinds["Train kinds<br/>[kinds.js]"]
  node_train_models["Train models<br/>[stock.js]"]
  node_line_data["Line datasets"]
end

subgraph group_world["World rendering"]
  node_geography["Geographic frame<br/>[geo.js]"]
  node_terrain["Terrain<br/>[ground.js]"]
  node_lineside["Lineside scenery<br/>[land.js]"]
  node_living_world["World activity<br/>[life.js]"]
  node_render_helpers["Render helpers<br/>[draw.js]"]
end

subgraph group_experience["Ride experience"]
  node_driving["Signals and driving<br/>[driving.js]"]
  node_cab["Driver cab<br/>[cab.js]"]
  node_map_view["Network map<br/>[map.js]"]
  node_sound["Generated sound<br/>[sound.js]"]
  node_seat_view["Ride views<br/>[seat.js]"]
  node_appearance["Visual style<br/>[look.js]"]
  node_title_ui["Title interface<br/>[title.js]"]
end

node_rider(("Rider"))
node_elevation_tiles[("Elevation tiles")]
node_imagery_tiles[("Satellite imagery")]

node_rider -.->|"interacts with"| node_sim
node_sim -->|"loads line data"| node_line_data
node_sim -->|"constructs"| node_line
node_sim -->|"registers line"| node_terrain
node_sim -->|"registers line"| node_living_world
node_sim -->|"registers line"| node_lineside
node_sim -->|"uses"| node_railway_model
node_sim -->|"uses"| node_train_models
node_sim -->|"uses"| node_driving
node_sim -->|"uses"| node_cab
node_sim -->|"uses"| node_map_view
node_sim -->|"uses"| node_sound
node_sim -->|"uses"| node_seat_view
node_sim -->|"uses"| node_appearance
node_sim -->|"uses"| node_title_ui
node_railway_model -->|"gets train length"| node_train_kinds
node_train_models -->|"uses definitions"| node_train_kinds
node_train_models -->|"uses drawing"| node_render_helpers
node_driving -->|"uses drawing"| node_render_helpers
node_cab -->|"uses drawing"| node_render_helpers
node_lineside -->|"uses drawing"| node_render_helpers
node_line -->|"converts coordinates"| node_geography
node_terrain -->|"converts coordinates"| node_geography
node_living_world -->|"uses coordinates"| node_geography
node_map_view -->|"converts coordinates"| node_geography
node_map_view -->|"formats clock"| node_railway_model
node_terrain -.->|"reads elevation"| node_elevation_tiles
node_terrain -.->|"uses imagery"| node_imagery_tiles

click node_sim "https://github.com/pino-the-bird/trains/blob/main/sim.js"
click node_line "https://github.com/pino-the-bird/trains/blob/main/line.js"
click node_railway_model "https://github.com/pino-the-bird/trains/blob/main/railway.js"
click node_train_kinds "https://github.com/pino-the-bird/trains/blob/main/kinds.js"
click node_train_models "https://github.com/pino-the-bird/trains/blob/main/stock.js"
click node_line_data "https://github.com/pino-the-bird/trains/tree/main/lines"
click node_geography "https://github.com/pino-the-bird/trains/blob/main/geo.js"
click node_terrain "https://github.com/pino-the-bird/trains/blob/main/ground.js"
click node_lineside "https://github.com/pino-the-bird/trains/blob/main/land.js"
click node_living_world "https://github.com/pino-the-bird/trains/blob/main/life.js"
click node_render_helpers "https://github.com/pino-the-bird/trains/blob/main/draw.js"
click node_driving "https://github.com/pino-the-bird/trains/blob/main/driving.js"
click node_cab "https://github.com/pino-the-bird/trains/blob/main/cab.js"
click node_map_view "https://github.com/pino-the-bird/trains/blob/main/map.js"
click node_sound "https://github.com/pino-the-bird/trains/blob/main/sound.js"
click node_seat_view "https://github.com/pino-the-bird/trains/blob/main/seat.js"
click node_appearance "https://github.com/pino-the-bird/trains/blob/main/look.js"
click node_title_ui "https://github.com/pino-the-bird/trains/blob/main/title.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_sim toneBlue
class node_line,node_railway_model,node_train_kinds,node_train_models,node_line_data,node_elevation_tiles,node_imagery_tiles toneAmber
class node_geography,node_terrain,node_lineside,node_living_world,node_render_helpers toneMint
class node_driving,node_cab,node_map_view,node_sound,node_seat_view,node_appearance,node_title_ui toneRose
class node_rider toneIndigo
```

## Components

### Simulation runtime

- [Simulator](https://github.com/pino-the-bird/trains/blob/main/sim.js): `sim.js`

### Railway model

- [Line geometry](https://github.com/pino-the-bird/trains/blob/main/line.js): `line.js`
- [Timetable railway](https://github.com/pino-the-bird/trains/blob/main/railway.js): `railway.js`
- [Train kinds](https://github.com/pino-the-bird/trains/blob/main/kinds.js): `kinds.js`
- [Train models](https://github.com/pino-the-bird/trains/blob/main/stock.js): `stock.js`
- [Line datasets](https://github.com/pino-the-bird/trains/tree/main/lines): `lines`

### World rendering

- [Geographic frame](https://github.com/pino-the-bird/trains/blob/main/geo.js): `geo.js`
- [Terrain](https://github.com/pino-the-bird/trains/blob/main/ground.js): `ground.js`
- [Lineside scenery](https://github.com/pino-the-bird/trains/blob/main/land.js): `land.js`
- [World activity](https://github.com/pino-the-bird/trains/blob/main/life.js): `life.js`
- [Render helpers](https://github.com/pino-the-bird/trains/blob/main/draw.js): `draw.js`

### Ride experience

- [Signals and driving](https://github.com/pino-the-bird/trains/blob/main/driving.js): `driving.js`
- [Driver cab](https://github.com/pino-the-bird/trains/blob/main/cab.js): `cab.js`
- [Network map](https://github.com/pino-the-bird/trains/blob/main/map.js): `map.js`
- [Generated sound](https://github.com/pino-the-bird/trains/blob/main/sound.js): `sound.js`
- [Ride views](https://github.com/pino-the-bird/trains/blob/main/seat.js): `seat.js`
- [Visual style](https://github.com/pino-the-bird/trains/blob/main/look.js): `look.js`
- [Title interface](https://github.com/pino-the-bird/trains/blob/main/title.js): `title.js`

### Other components

- **Rider**
- **Elevation tiles**
- **Satellite imagery**

## Connections

- Rider → Simulator: interacts with
- Simulator → Line datasets: loads line data (evidence: `sim.js`)
- Simulator → Line geometry: constructs (evidence: `sim.js`)
- Simulator → Terrain: registers line (evidence: `sim.js`)
- Simulator → World activity: registers line (evidence: `sim.js`)
- Simulator → Lineside scenery: registers line (evidence: `sim.js`)
- Simulator → Timetable railway: uses (evidence: `sim.js`)
- Simulator → Train models: uses (evidence: `sim.js`)
- Simulator → Signals and driving: uses (evidence: `sim.js`)
- Simulator → Driver cab: uses (evidence: `sim.js`)
- Simulator → Network map: uses (evidence: `sim.js`)
- Simulator → Generated sound: uses (evidence: `sim.js`)
- Simulator → Ride views: uses (evidence: `sim.js`)
- Simulator → Visual style: uses (evidence: `sim.js`)
- Simulator → Title interface: uses (evidence: `sim.js`)
- Timetable railway → Train kinds: gets train length (evidence: `railway.js`)
- Train models → Train kinds: uses definitions (evidence: `stock.js`)
- Train models → Render helpers: uses drawing (evidence: `stock.js`)
- Signals and driving → Render helpers: uses drawing (evidence: `driving.js`)
- Driver cab → Render helpers: uses drawing (evidence: `cab.js`)
- Lineside scenery → Render helpers: uses drawing (evidence: `land.js`)
- Line geometry → Geographic frame: converts coordinates (evidence: `line.js`)
- Terrain → Geographic frame: converts coordinates (evidence: `ground.js`)
- World activity → Geographic frame: uses coordinates (evidence: `life.js`)
- Network map → Geographic frame: converts coordinates (evidence: `map.js`)
- Network map → Timetable railway: formats clock (evidence: `map.js`)
- Terrain → Elevation tiles: reads elevation (evidence: `ground.js`)
- Terrain → Satellite imagery: uses imagery (evidence: `ground.js`)
