# Metrovivo Santiago

Santiago's Metro network in 3D, every train in sync with the official timetable.

- Case: N° 02.01 · Open source
- Disciplines: AW (Web applications), FS (Full-stack development)
- Stack: JavaScript, three.js, GSAP, Vite, Vitest, Playwright, GTFS
- Live site: https://nsalloums.github.io/metrovivo-santiago/
- Repository: https://github.com/nsalloums/metrovivo-santiago
- URL: https://micodigo.cl/en/work/metrovivo-santiago

## Summary

Metrovivo draws Santiago's Metro network in 3D and 2D with a single three.js renderer. Every train sits where the official timetable says it should: its position is a deterministic function of the time in America/Santiago, derived from published headways and a physical speed profile, not from random animation. Click a train and the camera flies into its cab.

The data comes from DTPM's official GTFS feed. The script that downloads it rejects the undated file that still circulates in tutorials and refuses to run on an expired feed, because in this domain failure isn't a 404: it's a perfectly valid response full of stale data.

The simulation is a pure function, with no DOM and no renderer, which is why the whole engine is unit-tested. Everything else consumes a single contract, `PositionProvider`, which doesn't know where positions come from: it's the seam for the day real train data exists. Buses are the exception, since they do show measured positions, and that's why they're drawn blurrier than the trains: they're an uncertain measurement, not an exact fiction.

Metrovivo is not affiliated with Metro de Santiago or DTPM and doesn't use their logo. Train positions are simulated and must not be used to plan a trip.

## Problem

Santiago's Metro publishes no live train positions. For service status, the only feed a static site can read is a community API that answers 200 and "OK" with an empty network, reporting no issues even while a station is closed. Showing that false "all clear" would be worse than showing nothing.

## Decision

Simulate from the official timetable, and say so, rather than show live data that lies.

### Code excerpt

src/provider.js @ f5c74f2 — https://github.com/nsalloums/metrovivo-santiago/blob/f5c74f2d206a3dc469c35e9221d6a2884cdca7f5/src/provider.js#L21-L31

```js
export class ScheduleProvider {
  constructor(sim) {
    this._engine = sim;
  }

  /** Posiciones = f(hora oficial en America/Santiago). */
  update(sec, day) { return this._engine.update(sec, day); }

  get trains() { return this._engine.trains; }
  get byKey() { return this._engine.byKey; }
  get byId() { return this._engine.byId; }
```
- Line 21: Today's only implementation is the timetable. Everything else consumes the contract and never learns where positions come from.
- Line 27: Positions are a function of official time in America/Santiago.

## Numbers

- 7 lines
- 126 stations

## Architecture

- DTPM GTFS feed → scripts/build-data.js
- scripts/build-data.js → data/network.json
- data/network.json → Simulation: f(time, day type)
- Simulation: f(time, day type) → PositionProvider
- PositionProvider → Network · Trains · Cab · LED

micodigo.cl: https://micodigo.cl

---

- Page: https://micodigo.cl/en/work/metrovivo-santiago
- En español: https://micodigo.cl/trabajo/metrovivo-santiago.md
- Index for agents: https://micodigo.cl/llms.txt
