Skip to content
mateusmorgadoPublic

Repository files navigation

NextTram

👉 Open the app: app.nexttram.morgado.tech

What it is and how it works: nexttram.morgado.tech

Animation: tapping a stop card tracks that tram, back to fastest, then the trip back   NextTram on a phone, light mode: go to Torgauer Platz, Tram 3 in 6 minutes, leave in 2 minutes   Animation: an Add to watch face cycling through Google Assistant (soon), Claude, ChatGPT, Gemini, Alexa and Siri above the watch view stepping through the next trams

Tracking a tram and the trip back, light mode, and the watch, which you can also ask through your assistant. Screenshots use sample departures.

"When is the next tram?" answered with zero friction: which of your nearby stops to walk to, which tram you can still catch, and when to leave the house.

Live departures for Leipzig (LVB / MDV), Berlin (BVG / VBB) and Altenburg, Thüringen (THÜSAC buses). A link can add a ready-made route: ?add=abg-busbahnhof&lang=de (see PRESET_ROUTES in src/data/stops.ts). No backend, no database, no API keys. It comes as:

  • an installable PWA for Android phones and Wear OS watches,
  • an MCP server so Claude (or any MCP client) can answer "next tram",
  • an Alexa skill, live in the Alexa Skills Store ("Alexa, ask next tram when is the next tram"),
  • a Siri Shortcut ("Hey Siri, when is the next tram") that answers out loud on iPhone and Apple Watch.

The app, the MCP server and the voice endpoints share one TypeScript module, src/transit/.

Languages

The app speaks English, Deutsch and Português (Brasil). It starts in the browser's language; the footer switches it and remembers the choice. All text lives in src/i18n/{en,de,pt}.ts (npm test checks that the three have the same keys). The phrases people are told to say (voice.*) are real utterances of the Alexa models in alexa/, and a test checks that. To add a language, copy en.js, translate it, and register it in src/i18n/index.ts.

How it decides

  • Two home stops in parallel. A route starts with one stop; + Add a second stop adds another, each with its own walk time (default: Edlichstraße 2 min with Tram 7, Torgauer Platz 4 min with Trams 3 and 8). Both are checked at the same time and the results are merged.
  • Time your walk. Each stop has a ⏱ Time my walk stopwatch: tap Start at your front door and Stop at the stop, and the exact time (say 3:42) becomes that stop's walk. Timing the real walk beats guessing. The count survives a locked phone.
  • Spare time. Settings → Spare time on each walk: none, 15 s, 30 s or 1 min on top of every walk, for all routes. The app, Alexa, Claude and ChatGPT all plan with walk + spare time.
  • Run or missed. Running saves you at most 1 minute of the walk (and at most half of a short walk). So with 1 min left, a 2 min walk is still a "🏃 Run now", but a 3 min walk is a missed tram. Missed trams disappear from the countdown, the list and the voice answer, even one you tapped. Trams you'd have to run for say "run" in the list, and assistants say "Run now for …". Settings → Run for a tram: "If it's the only way" (default) or "Never", which only shows trams you make walking, in the app and in the voice answers.
  • Punctuality as words. early (yellow), on time, late (1–3 min), +late (4–7), ++late (8+). Tap a label for the explanation.
  • Leave advice. "🚶 Leave in 4 min" while you have time, "🏃 Leave now" once departure ≤ walk time, "🏃 Run now" when only running gets you there.
  • Tap to track. Tap any upcoming departure or stop card to lock the countdown onto that tram until it leaves or you can't make it any more. "Back to fastest" returns to automatic mode.
  • Trip back (⇅). Reverses the route: from the destination to both home stops, so you take whichever gets you home first. No walk by default; + Add a walk for the trip back sets one.
  • Engines. Leipzig uses Transitous (MOTIS, full MDV/LVB data with real time) and falls back to DB HAFAS (v6.db.transport.rest). Berlin uses BVG HAFAS (v6.bvg.transport.rest) and falls back to Transitous. A departure only counts if it boards at the stop you chose, not at another stop nearby.
  • Stop names. edlichstr, Edlichstr., Edlichstrasse and Edlichstraße all match. Exact stop IDs are looked up once and remembered on the device.

Run the app

Written in TypeScript (strict). Needs Node 22.18+, which runs .ts files directly; the browser app is bundled with esbuild into dist/:

npm start          # builds, then serves http://localhost:8080
npm run typecheck  # tsc, strict
npm test           # unit tests for the transit logic and the Alexa handler
npm run build      # dist/ (what Vercel deploys)

To install it on Android it must be served over HTTPS. It is deployed on Vercel: every push to main goes live, and every pull request gets its own preview URL. vercel.json runs npm run build, serves dist/ and the api/ functions, and keeps the service worker and manifest uncached so updates show up right away; .vercelignore leaves the MCP server, Alexa skill, tests and docs out of the deployment. Open the URL in Chrome → menu → Install app. Long-press the home-screen icon for shortcuts straight to a route (?route=lej-hbf, ?route=lej-hbf&back=1).

Watch: on screens 380 px wide or less (Wear OS browsers) the app switches to a round, glanceable layout automatically. Tap the route name to cycle favorites, tap the countdown to refresh. The ⌚ button previews it on a phone or desktop.

Android & Wear OS apps

Prebuilt APKs are published automatically on the android-latest release:

  • Phone (NextTram.apk): Trusted Web Activity wrapper around the live PWA plus a home-screen widget, “Leave now” & delay notifications, lock-screen Live Updates countdown (Android 16 ProgressStyle / fallback on Android 7–15), Quick Settings tile, long-press app shortcuts, location-aware stop switching, Google Assistant / Gemini App Actions, and an in-app updater. Download and install directly on your phone, then long-press the app icon → Alerts & sync to paste your sync code and enable alerts.
  • Wear OS watch (NextTram-wear.apk): Standalone watch app + native Wear OS departure countdown tile.

Installing NextTram-wear.apk on a Wear OS watch

Wear OS doesn't have a built-in browser APK installer, so sideload it over Wi-Fi using Wireless debugging (keep your watch and phone/PC on the same Wi-Fi):

  1. Enable Wireless debugging on the watch:
    • Open Settings → About watch → Software information and tap Software version 7 times until Developer mode is enabled.
    • Go to Settings → Developer options and turn on ADB debugging and Wireless debugging (tap Wireless debugging to see the IP:port and Pair new device).
  2. Send the APK to the watch:
    • From your Android phone (no PC needed): Download NextTram-wear.apk on your phone, install Wear Installer 2 (or Bugjaeger) from the Play Store, pick NextTram-wear.apk in the Custom APK tab, enter the watch's Wireless debugging IP/port and pairing code, and tap Install.
    • From a PC (ADB):
      adb pair <watch-ip>:<pair-port>     # enter the 6-digit pairing code
      adb connect <watch-ip>:<connect-port>
      adb install NextTram-wear.apk
      (Use the pairing port from Pair new device for adb pair, and the main Wireless debugging port for adb connect.)
  3. Finish setup on the watch:
    • Turn Wireless debugging back off on the watch to save battery.
    • Open NextTram on the watch to enter your sync code (optional).
    • Swipe on the watch face → + Add tile (or in the Galaxy Wearable app on your phone → Tiles) and add NextTram.

Favorites

Three routes are built in (see src/data/stops.ts):

id route
lej-hbf Edlichstraße / Torgauer Platz → Leipzig Hauptbahnhof
ber-strassmann Straßmannstr. → U Eberswalder Str. (Berlin)

Tap the active chip (or the sliders icon) to edit a route, + New to add one. Your routes are stored only in the browser (localStorage).

Assistants follow your first favorite

The app saves your favorites online under a personal code. Tap AI in the app for the step-by-step guide for Claude, ChatGPT, Gemini, Siri and Alexa: each one only needs a personal link (Alexa: a 2-digit number), and the assistant then answers for your first favorite. Without a code they use the built-in routes.

The links point at two Vercel functions that need nothing installed:

  • api/mcp.js: online MCP server (Streamable HTTP, stateless JSON). Claude: Customize → Connectors → + → Add custom connector (no sign-in; "Continue anyway" if the check warns). ChatGPT: Developer mode → Create. URL https://app.nexttram.morgado.tech/api/mcp/<code>.
  • api/alexa.ts: the public Alexa skill's HTTPS endpoint, https://app.nexttram.morgado.tech/api/alexa. It verifies Amazon's request signature (src/server/alexa-verify.ts). api/alexa-link.ts links an Alexa user to a personal code ("pair" → 2-digit number → typed into the app).

Storage is Upstash Redis on the Vercel project: Vercel → Storage → Upstash for Redis → connect it to next-tram. That sets KV_REST_API_URL/KV_REST_API_TOKEN (or UPSTASH_REDIS_REST_*), which api/favorites.js reads. Whoever knows a code can read and replace that list; only stop names, coordinates and walk times are stored.

MCP server on your own computer (optional)

The tools live in src/assistants/mcp-tools.ts; mcp-server.mjs serves them over stdio:

{
  "mcpServers": {
    "next-tram": {
      "command": "node",
      "args": ["C:/Users/mateu/Documents/projects/next-tram/mcp-server.mjs"],
      "env": { "NEXT_TRAM_CODE": "your-code-from-the-app" }
    }
  }
}

Tools: get_next_tram (no arguments needed; optional route, back, a custom from/from2/to, language: "de"), search_stops, list_routes. Set NEXT_TRAM_ROUTE=ber-strassmann to change the default.

Alexa skill

Enable it: https://www.amazon.de/dp/B0HQ7KN3S1/ (or in the Alexa app: Skills & Games → search "NextTram").

One public custom skill, hosted on Vercel (api/alexa.ts), no AWS needed. Console setup, store listing texts and certification: docs/alexa-skill.md. Privacy policy: public/privacy.html.

  • "Alexa, ask next tram when is the next tram" / "Alexa, frag next tram wann kommt die nächste Bahn". "…home" uses the trip back.
  • "Alexa, open next tram": until this Alexa is paired, it says a 2-digit number; type it in the app (AI → Alexa) and Alexa follows your first favorite. After that, "open next tram" answers with the next tram. "…for a new code" pairs again, "…forget my stops" undoes it.
  • Optional env ALEXA_SKILL_ID (comma-separated) makes the endpoint accept only your skill.

Siri (Apple Shortcuts)

Siri reads the answer aloud through api/say, which returns one spoken sentence as plain text.

  1. Open Shortcuts on your iPhone → + → Add Action → Get Contents of URL.
  2. URL: https://app.nexttram.morgado.tech/api/say?code=<your code> (the app's AI → Siri screen fills in your code; add &back=1 for the trip back, &route=<id> for another favorite, &lang=de for German).
  3. Add the action Speak Text, name the shortcut When is the next tram. Now "Hey Siri, when is the next tram" says when to leave, on the iPhone, Apple Watch and in CarPlay.

Google Assistant / Gemini

Google shut down custom voice actions (Conversational Actions) in 2023, so a Google speaker can't ask NextTram anything. On an Android phone, install the PWA and say "Hey Google, open NextTram". Gemini on the web can add MCP servers as "custom apps" (US only, English, for now); api/mcp?code= is the link once that reaches more countries.

Files

Folder / file What it is
src/app/ The PWA: main.ts starts it; screens/ (hero, compare, upcoming, intro, assistants), setup/ (route editor), components/, wiring/ (event handlers), store.ts (saved state)
src/transit/ API clients and parsers (parse/), stop matching, walk-buffer planning and catch rule, spoken summary. Shared by the app, MCP and Alexa
src/data/ Cities, stops, default routes, line colors
src/i18n/ English, German and Portuguese text
src/assistants/ MCP tools and the Alexa skill handler
src/server/ Pieces for the online endpoints: Alexa signature check, pairing, storage, local stdio MCP server
src/sync/ Favorites online under your code; call counts
api/ Vercel functions: MCP, Alexa, Siri (say), favorites
public/ index.html, CSS, service worker, manifest, icons, privacy policy: copied into dist/
android/ Native Android (:app), Wear OS (:wear), and shared Kotlin transit (:shared) Gradle modules
scripts/ build.ts (esbuild bundle and offline file list) and serve.ts (local server)
mcp-server.mjs Starts the local MCP server over stdio
alexa/, docs/alexa-skill.md Alexa voice models and the publishing guide
public/privacy.html Privacy policy (app, assistants, Alexa skill)
test/ node --test suites

Releases

Packages

Contributors

Languages