- TypeScript 86.5%
- CSS 6.4%
- JavaScript 2.9%
- Shell 2.4%
- Dockerfile 1.5%
- Other 0.3%
|
All checks were successful
/ porter-deploy (push) Successful in 1m58s
Reviewed-on: #6 |
||
|---|---|---|
| .forgejo/workflows | ||
| docker | ||
| public | ||
| scripts | ||
| server | ||
| shared | ||
| src | ||
| .dockerignore | ||
| .gitignore | ||
| compose.full.yaml | ||
| compose.yaml | ||
| Dockerfile | ||
| index.html | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| vite.config.ts | ||
PTT: NYC transit planner with Uber switch-over
A mobile-friendly web app for planning NYC subway and Metro-North trips, Google-Maps style. You can see how time and price change if you bail out at any stop and take an Uber for the rest of the trip. Destinations beyond walking distance of any station get transit to the nearest stations plus an Uber for the last stretch.
Run it
npm install
npm run fetch-data # downloads the MTA subway and Metro-North GTFS feeds into data/
npm run dev # API on :8787, web on http://localhost:5173 (also exposed on your LAN for phone testing)
Production: npm run build && npm start serves the built app and API from port 8787. The build
bundles the server into dist-server/index.js, which needs only Node, dist/ and data/.
Docker
The Dockerfile builds one image with the frontend, the bundled server and the timetables baked
in (~320 MB). Docker caches the timetable download, so pass a new GTFS_VERSION to fetch fresh
ones, e.g. from a weekly job:
docker compose build --build-arg GTFS_VERSION=$(date +%F) && docker compose up -d
There are two compose files:
-
compose.yaml: just the app, on port 8787 (PTT_PORTto change), using the public services for driving times, address search and map tiles.docker compose up -d --build -
compose.full.yaml: the app plus self-hosted OSRM, Nominatim, Photon and an OpenStreetMap tile server, so nothing depends on free public services (except NYC GeoSearch, the city's own address API; setGEOSEARCH_URL=to turn it off).NOMINATIM_PASSWORD=<something> docker compose -f compose.full.yaml up -d --buildThe first start downloads the New York, New Jersey and Connecticut extracts from Geofabrik (~900 MB), clips them to the NYC + Metro-North area (
OSM_EXTRACTS,OSM_BBOX) and imports them into each service.upwaits for the downloading and the OSRM and tile imports; Nominatim and then Photon keep importing in the background (docker compose -f compose.full.yaml logs -f). Until a service is ready, the app falls back to straight-line driving estimates and the other geocoders. Data lives in named volumes, so restarts skip the imports; delete the volumes to re-import fresh map data. The services are only reachable inside the compose network; map tiles reach the browser through the app's/tiles/proxy.Tested end to end on a small Midtown-only area (
OSM_BBOX=-74.0,40.745,-73.97,40.765), where everything was ready in a few minutes; even then the services used ~1.5 GB of RAM and the tile database ~4.6 GB of disk, mostly fixed overhead. The default region is far larger and hasn't been run in full: plan on hours for the first import and a machine with at least 16 GB RAM and 100 GB of SSD to be safe. ShrinkingOSM_BBOXis the easiest way to cut that down.
Settings are environment variables read in server/config.ts: PORT, OSRM_URL, PHOTON_URL,
NOMINATIM_URL, NOMINATIM_MIN_INTERVAL_MS (0 for a self-hosted Nominatim), GEOSEARCH_URL,
TILE_URL (tile template for the browser) and TILE_UPSTREAM (a tile server to proxy).
How it works
- Routing:
server/router.tsruns the Connection Scan Algorithm over the GTFS feeds listed inFEEDS(server/config.ts), currently the subway and Metro-North. The loader (server/gtfs.ts) collapses platforms into stations and keeps each feed's ids separate. It respects pick-up-only and drop-off-only stops, uses in-station transfer times fromtransfers.txt, and adds walking transfers between stations within 400 m, plus extra time when changing between systems. It follows service calendars, including trips that run past midnight. It returns up to 3 itineraries plus a walking option. - Last stop + Uber: if no station is within walking distance of the destination, the router plans to the 10 stations nearest the destination and ends the trip with an Uber leg. The Uber leg is first estimated from straight-line distance, then re-priced with real driving times.
- Route options: the search panel has toggle chips for each transit system and for
last-mile Uber, in any combination. The server lists them at
GET /api/options(PLAN_OPTIONSinserver/config.ts): one per feed inFEEDS, pluslastMileUber. The client sends the enabled ids as/api/plan?options=subway,mnr,lastMileUber; leaving the parameter out uses the defaults. The browser remembers the choice, and new options start at their default. To add an option, add an entry toPLAN_OPTIONSand read it inparsePlanOptions; a new feed gets a toggle automatically. - Fares: one subway fare per trip (transfers are free). Metro-North fares are estimated
from track distance and peak/off-peak, because the feed has no fare data. Trips entirely
within NYC use the flat CityTicket fare (
server/fares.ts). - Uber switch-over:
server/planner.tstreats every stop along each itinerary as a possible switch point: get off, walk up to the street, wait for a car, then drive to the destination. Drive times come from OSRM in one batched table request. They are scaled by a time-of-day traffic factor and priced with an approximate UberX NYC rate card that includes the NYS congestion surcharge and the Congestion Relief Zone fee (server/uber.ts). - Geocoding: NYC addresses and places come from NYC Planning's
GeoSearch, the city's own address database (fast, five
boroughs only). Photon (OpenStreetMap) runs in parallel for the wider Metro-North region and
more points of interest. If Photon is slow or down, or misses an exact house number, the
server falls back to Nominatim (throttled to 1 request/second). Apartment, suite and floor
details (USPS Pub 28 unit designators like
Apt 4B,Ste 2000,Floor 20,#12) are stripped first, since geocoders only know buildings (server/address.ts). You can also tap the map. - Frontend: React + Leaflet. On phones it shows a bottom sheet; on desktop, a sidebar. A slider picks the switch point, and a table compares every option.
All the tunable assumptions (fares, rate card, walk speed, wait times, traffic factors) are in
server/config.ts.
Limitations / next steps
- Subway and Metro-North only. LIRR, MTA buses, PATH and ferries can be added as more entries
in
FEEDS(plus fare rules). - If the start is far from any station, there's no Uber for the first stretch yet. Only the last stretch gets one.
- Lines are drawn station to station, so express trains cut straight across the map. Using
shapes.txtwould follow the real track. - Uses static schedules. Add GTFS-Realtime (MTA feeds are keyless) for live delays and service changes.
- Uber prices are estimates, because Uber's price-estimate API is restricted to approved partners.
- The public OSRM/Photon demo servers are rate-limited. Self-host them (
OSRM_URL,PHOTON_URL) for real use. - Routing is earliest-arrival only. It does not optimise for fewer transfers or less walking.