How isoughtajam-learns/gtfs-realtime works
GTFS Realtime is a FastAPI backend for ingesting transit schedules and live GTFS-Realtime feeds, then serving live positions, trip details, service alerts, and transit-system metadata. The main user path is a client request to the API, which obtains cached or freshly fetched realtime data, enriches it with schedule data where applicable, and returns an SSE stream or API response. Schedule ingestion is a separate operational path. The graph follows the README and source-index references; some runtime wiring is not shown in the excerpts.
Main entry points: main.py FastAPI endpoints · database.py Database engine · quota_group_scheduler.py Quota scheduler · fetcher.py Schedule ingestion
Components 21
API delivery
- FastAPI endpoints
src/main.py - System registry
src/services/transit_system_detail.py - Trip detail
src/services/trip_detail.py - Alert assembly
src/services/service_alerts.py
Realtime processing
- Position mapping
src/services/positioning.py - Recent positions
src/services/recent_events_cache.py - Realtime feed cache
src/services/realtime_feed_cache.py - Regional feed split
src/services/regional_feed.py
Schedule data
- Schedule cache
src/services/schedule_cache.py - Schedule utilities
src/services/schedule_utils.py - Schedule ingestion
src/commands/fetcher.py
Operations and state
- Database engine
src/database.py - Transit data models
src/models.py - Quota scheduler
src/services/quota_group_scheduler.py - Shared feed quota
src/services/shared_feed_quota.py - Scheduled fetch tasks
src/tasks.py - Application settings
src/settings.py - Log telemetry
src/telemetry.py
Other components
- Transit clients
- GTFS feed providers
- Postgres
Connections 27
- Transit clients → FastAPI endpoints: requests streams
README.md - FastAPI endpoints → System registry: looks up systems
src/main.py - FastAPI endpoints → Realtime feed cache: gets feeds
src/main.py - FastAPI endpoints → Recent positions: replays positions
src/main.py - FastAPI endpoints → Position mapping: maps positions
src/main.py - FastAPI endpoints → Schedule cache: enriches events
src/main.py - FastAPI endpoints → Trip detail: builds trip detail
src/main.py - FastAPI endpoints → Alert assembly: assembles alerts
src/main.py - FastAPI endpoints → GTFS feed providers: fetches realtime feeds
README.md - Trip detail → Database engine: queries schedule
src/services/trip_detail.py - Alert assembly → Database engine: loads alert details
src/services/service_alerts.py - Schedule cache → Database engine: loads schedule
src/services/schedule_cache.py - Schedule ingestion → GTFS feed providers: downloads schedules
README.md - Schedule ingestion → Schedule utilities: uses schedule helpers
src/commands/fetcher.py - Schedule ingestion → Database engine: upserts schedule
README.md - FastAPI endpoints → Quota scheduler: starts schedulers
src/main.py - Quota scheduler → Realtime feed cache: warms feeds
src/services/quota_group_scheduler.py - Quota scheduler → Shared feed quota: uses shared budget
src/services/quota_group_scheduler.py - Quota scheduler → Regional feed split: demuxes regional feed
src/services/quota_group_scheduler.py - Regional feed split → Realtime feed cache: sets feed entries
src/services/quota_group_scheduler.py - Scheduled fetch tasks → Schedule ingestion: runs schedule fetch
src/tasks.py - Scheduled fetch tasks → System registry: lists active systems
src/tasks.py - System registry → Database engine: queries registry
src/services/transit_system_detail.py - Database engine → Application settings: configures connection
src/database.py - Transit data models → Postgres: defines stored records
- FastAPI endpoints → Log telemetry: emits telemetry
src/main.py - Log telemetry → Application settings: reads configuration
src/telemetry.py