This is the NodeJS server providing data for the FerryTempo. It fetches data from the WSDOT Traveler Information API, specifically the ferry vessel location endpoint. Then, it processes that ferry data into the FerryTempo data object format. Finally, it provides HTTP endpoints for fetching ferry data on a per-route basis.
If you'd like to run FTServer locally, follow these instructions:
- Clone this repo (see clone instructions).
- Install NodeJS (see install instructions).
- Run
npm ito install the dependencies. - Create a
.envfile in the project root containingWSDOT_API_KEY=<API KEY>(ask a team member for the key). - Run
npm run devto start the server in development mode with hot reloading. or - Run
npm run startto start the server in production mode.
The day's sailing logs, day averages and completed-departure metrics live in memory. To keep them across deploys and restarts, attach a persistent disk and set:
STATE_DIR: the disk's mount path, for example/var/data. The server restoresftserver-state.jsonfrom it at startup, saves it every minute, and saves it on shutdown (SIGTERM). When unset, state is kept in memory only.NOTIFICATION_DB_PATH: put the notification subscriptions on the same disk, for example/var/data/notifications.sqlite. Otherwise they're stored in the app directory, which a deploy replaces.
/debug/devices counts the devices (by cid) requesting route data. To show each device's
approximate location (usually the city) from its IP address, set GEOIP_ENABLED=true. The server
then downloads the free DB-IP "IP to City Lite" database (about 60 MB to
download, roughly 130 MB in memory) and refreshes it monthly. It is saved in GEOIP_DIR, else
STATE_DIR, else data/. IP addresses are looked up on the server and never shown on the page.
/api/v1/route/:routeId serves two views of the same data:
view=full(the default): every field, for the app and the website.view=device: only the fields FerryClock firmware reads, about 600 bytes instead of about 20 KB. Clocks without PSRAM have roughly 60 KB of RAM left for an HTTPS request, so the response must stay small.
A request with cid and no view gets the device view, so clocks already in the field get it
without a firmware update. Unknown views return 400.
The device view is an allowlist (DEVICE_BOAT_FIELDS and DEVICE_PORT_FIELDS in
src/RouteEndpointHelpers.js): fields added for the app never reach clocks unless they're added
there. Add a field only together with a firmware release that reads it.
We auto-generate schema documentation based on the JSON Schema. That documentation is available in the /docs directory.
To help contribute to FTServer, please read and follow the guidelines in Contributing.md.
The route API keeps its boatData and portData dictionaries. LastStop beside
StopTimerAverage is the vessel's latest completed stop. PortLastStop beside
PortStopTimerAverage is the latest completed stop at that route terminal, across
vessels. Both measure seconds from the first observed docked timestamp to WSF
LeftDock, or the first observed underway timestamp when LeftDock is missing.
An unobserved arrival, incomplete stop, terminal mismatch, or negative duration
cannot produce a stop value.
StopTimerAverage and PortStopTimerAverage average completed turnarounds
only when the server observes both the arrival and following departure within
the same 3am-Pacific sailing day. The initial docked interval before a vessel's
first sailing and overnight stops are excluded, so idle time does not inflate
active-service averages. The persistent daily averages still reset at the next
sailing-day boundary.
PortLastDepartureDelay is the latest completed terminal departure's LeftDock
minus ScheduledDeparture in seconds; both WSF timestamps and an underway vessel
are required. Zero and negative (early) delays are valid. It remains distinct from
vessel-specific LastDepartureDelay. PortDepartureDelay still prefers a docked
vessel's current delay, otherwise the latest departed vessel; its cached value and
PortDepartureDelayAverage retain their existing behavior.
NextScheduledDeparture is the terminal's next sailing however late, from the boats: a boat docked
there departs on the sailing WSF reports for it until it leaves (unless that boat's own next sailing has
already passed, a sign of stale WSF data); a boat crossing there departs on its vessel position's next
sailing there after the one it's on. The earliest of those, otherwise the next scheduled slot. Never a
cancelled sailing, nor one more than 3 hours past.
PortSailingLog rows are [scheduledDeparture, departureDelay, crossingTime, vesselPosition], with a
fifth status element when there is one: "cancelled" (WSF terminal sailing space IsCancelled, recorded
while WSF lists it and kept for the sailing day) or "skipped" (never departed, though the same vessel
position departed this terminal both before and after it). Rows without a status stay four elements long.
PortSailingStates reads "unseen" for a past sailing never seen leaving, once a later sailing from that
terminal has left or 3 hours after its time (as after a restart), so "upcoming" means still to leave.
New completed metrics are ordered by actual departure time, use the existing WSF
sailing-day boundary (3am Pacific), and are null until a qualifying event is
observed that day. They use in-memory observation history, which resets on server
restart. Port metrics do not require a vessel position assignment and exclude
vessels off duty. Provisional or incomplete PortSailingLog rows do not supply
completed metrics. New fields also pass through the device-filtered route response
and triangle leg dictionaries. This repository does not own client decoders.
King County Water Taxi (kcwt-…), Staten Island Ferry (sif), Kitsap Fast Ferries (kff-…, with its foot
ferries), San Francisco Bay Ferry (sfb-…) and Golden Gate Ferry (ggf-…) come from src/systems, not WSDOT,
and are served like WSF's. Their routes are in data/systems/SystemRoutes.js, their boats in SystemFleets.js.
Systems and routes are in the app's order, grouped by state (systemNames, systemStates), everywhere.
test/SystemRegistry.test.js checks every one. To add one, use the app repository's add-ferry-system skill.
- Timetables: built from each system's GTFS (
src/systems/GtfsTimetableBuilder.js, feed URLs there). The server downloads and rebuilds them daily (TimetableRefresh.js; saved underSTATE_DIR/systems), keeps the current one until a new one's first day (one missing a route waits until the current one ends), and logs when one runs out within 14 days. A trip with several stops is a sailing per leg, and a leg no route serves is skipped.data/systems/<system>-timetable.jsonare the bundled fallbacks:node scripts/build-system-timetables.js <system>=<gtfs-dir> ...updates them. - Schedule paths: each port's
PortScheduleRunslists today's and tomorrow's sailings as[departure, run]. A run is one boat's back-and-forth sailings on the route (its GTFS block; Staten Island's are chained from its timetable). It comes from the timetable alone, so it's there before any boat is.VesselPositionnames the boat making a sailing, once one is seen. WSF routes don't have it. - Exact days: the reference schedule's weekday and weekend times are only typical. Its
DatedDepartureshas each terminal's exact departures for the next 14 sailing days, and the app shows days from those (holidays, odd weekdays, days without service). WSF's doesn't have it. - Kitsap's trip updates (
https://kttracker.com/gtfsrt/trips, every 30 seconds,KitsapFeed.js): the boat a trip names (before it leaves) takes that sailing and route, at Pier 50 too; its predicted arrival is the boat'sEta; a trip it cancels is cancelled for the day (setFeedCancellations), until listed running again. Port Orchard's temporary timetable has no trip IDs, so it gets none of this while that's in force. - Leaving a dock: a boat has left only once it's 0.8 km closer to the far terminal of one of its routes from that dock, or 0.3 km closer at 6 knots (beyond 1.5 km, whichever way), timed from its first report off the berth: a boat manoeuvring at the berth, moving between berths, or a jumping position doesn't take a sailing.
- Crossing times: on these routes a logged crossing counts unless it's faster than the route's path at
40 knots (
minimumCrossingSeconds); the timetable's crossing time is a schedule block, not a speed. - Position history:
/debug/positions/<system>/<boat name>lists a boat's raw positions over the last 8 hours, to replay a problem throughbuildSystemData. - Sailing audit:
src/systems/SailingAudit.jsjudges each sailing 45 minutes after its time: did a shown boat leave on it, and if not, was a boat the server hid (or didn't match) moving on the route, or an alert in effect? It also flags two boats given one sailing. Sailings while the server was down or no boat reported aren't judged./debug/auditlists today's and yesterday's; Needs attention shows routes with a hidden boat moving, two or more sailings without a boat, or a doubled sailing. It's saved with the state (STATE_DIR). - Service changes: what operators post but their feeds don't have (
data/systems/ServiceChanges.js; applied bysrc/systems/ServiceChanges.js): cancelled service, and temporary weekday timetables. Cancelled sailings arecancelledinPortSailingStates, listed for today and tomorrow inPortCancelledDepartures, and not inPortScheduleRunsorDatedDepartures; no boat is given one. A temporary timetable replaces the route's on weekdays it runs, for one feed version. Both add a route alert. Each change's page is checked hourly for its text: Needs attention says when it's gone, can't be read, or is due to be read again. Nothing is lifted by itself. - Fares: the reference schedule's
Fares(data/systems/SystemFares.js: each price from the operator's page or the feed, with its source and the date it was checked). The feed's own adult fares are read with each timetable: if they differ, that route's fares aren't served and it's on Needs attention, as are fares not checked in six months. Null when none are listed. - Positions: the Water Taxis from WSDOT VesselWatch's Water Taxi layer (
VesselsKCM.ashx, polled every 10 s), the Staten Island ferries from AIS (the AIS worker forwards their MMSIs,data/systems/SystemFleets.js). The Water Taxis' AIS reports are a second source. Kitsap's ferries from Kitsap Transit's GTFS-realtime vehicle positions (KitsapFeed.js): by name, every few seconds, and in service with the GTFS trip they're on, which binds them to that sailing. Data under Kitsap Transit's Developer User Agreement (non-commercial; no Kitsap logos with the data). San Francisco Bay Ferry's from 511 (SF511.js; needsSF511_API_KEY), with AIS as a second source for some boats. Golden Gate Ferry's from AIS only. Both timetables come from 511, which must be credited in the app. - Sailings: where a feed doesn't give a boat's trip,
SystemVessels.jsdecides which sailing it makes: a boat at a terminal is on the next sailing no other boat can make sooner, and keeps it until it leaves. Spares laid up at a terminal are off duty until a sailing needs them. - The results are WSDOT-shaped vessel records and schedules, processed by
FerryTempo.jsin their own pass after WSF's (SystemPass.js: a failure there leaves WSF's update untouched and keeps the systems' last data), so delays, sailing logs, ETAs, pings and Live Activities work the same. WSF-only code (WSDOT requests, the WSF AIS route assignment) skips these routes (isWsfRoute). - Alerts: the Water Taxi's operator message (when not routine) and Metro's, Kitsap's and San Francisco Bay Ferry's GTFS-realtime alerts are route alerts. Staten Island and Golden Gate have no feed.
- Sailing days still turn at 3:00 Pacific for every route (the logs share one day): Staten Island's day resets at 6:00 Eastern.
/api/v1/tides/:resource/:year and /api/v1/sky/:resource/:year serve a year of tides (6-minute
heights from NOAA, high/lows interpolated for subordinate stations) and sky (sun and moon, computed), by the
app's resource names (src/environment/EnvironmentData.js maps them to NOAA stations and places). Years
from last year to two ahead; each is built once, kept gzipped under STATE_DIR/environment, and this
year's and next year's are built shortly after startup. The format is the app's former bundled files.
/api/v1/route/:routeId/weather/:terminalAbbrev gives a terminal's temperature (the current hour's NWS
forecast, else the grid value covering now) with the day's high and low, from the terminal's coordinates in
the route data. Each place is fetched from NWS at most every 10 minutes (src/environment/Weather.js).
NWS covers the US only.
The home page lists what needs attention (src/attention/AttentionItems.js) and the deployed commit (Render's
RENDER_GIT_COMMIT). Problems clear themselves: another system's timetable ending within 14 days with no
gap-free successor, its update rejected or failing twice in a row, a route with no sailings, no boat reporting
during an hour or more of sailings, or SF511_API_KEY not set. Other tasks are in data/MaintenanceTasks.js;
remove each when it's done. The page and the file are public, so keep them free of private details.
A scheduled task in the Claude app reads the list, looks into it and reports; dated items are highlighted from 3 days before.
Sailing pings go to iOS through APNs (APNS_* variables) and to Android through Firebase Cloud Messaging.
For Android, create a service account key in the Firebase console (project ferrytempo-7f0f8 → Project settings → Service accounts → Generate new private key) and give the server either:
FCM_SERVICE_ACCOUNT_PATH: the path to the key file. On Render, add it as a Secret File namedfirebase-service-account.jsonand setFCM_SERVICE_ACCOUNT_PATH=/etc/secrets/firebase-service-account.json.FCM_SERVICE_ACCOUNT_JSON: the key file's contents.
Without either, Android notifications are skipped (and logged once). The key grants send access to the Firebase project, so keep it out of the repository.