{"id":31077646,"url":"https://github.com/cdfer/led-rails-backend","last_synced_at":"2025-10-25T11:44:46.986Z","repository":{"id":284096815,"uuid":"953806492","full_name":"CDFER/LED-Rails-Backend","owner":"CDFER","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-08T02:12:02.000Z","size":256,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-08T03:31:38.260Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CDFER.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-24T05:30:13.000Z","updated_at":"2025-09-08T02:12:05.000Z","dependencies_parsed_at":"2025-06-21T03:19:51.589Z","dependency_job_id":"a03ba5a3-1dea-460a-9088-76c42b5a1dab","html_url":"https://github.com/CDFER/LED-Rails-Backend","commit_stats":null,"previous_names":["cdfer/gtfs-realtime-cache-server"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CDFER/LED-Rails-Backend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CDFER%2FLED-Rails-Backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CDFER%2FLED-Rails-Backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CDFER%2FLED-Rails-Backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CDFER%2FLED-Rails-Backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CDFER","download_url":"https://codeload.github.com/CDFER/LED-Rails-Backend/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CDFER%2FLED-Rails-Backend/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275384106,"owners_count":25454910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-16T02:00:10.229Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-16T07:52:25.466Z","updated_at":"2025-09-16T07:52:29.294Z","avatar_url":"https://github.com/CDFER.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LED-Rails-Backend\n\nA backend service for real-time rail vehicle tracking for Live LED maps. Built with TypeScript, Express, and Bun.\n\nThis project is built for the Live Train Maps that I sell through my store: [keastudios.co.nz](https://keastudios.co.nz)\n\n## Features\n\n- **Multi-city Support:** Currently I have Auckland and Wellington rail networks but it should be easy to add more cities, with separate config folders containing `trackBlocks.kml` and `config.json` files.\n- **Real-time GTFS Data Fetching:** Periodically fetches and caches GTFS-realtime vehicle data for supported cities.\n- **LED Map Generation:** Computes and serves LED board updates based on train positions and track block occupancy.\n- **Train Pair Detection:** Identifies and tracks pairs of trains running in close proximity.\n- **Train Blocks:** The `trackBlocks.kml` file can be edited with Google Earth for custom block layouts.\n- **API Endpoints:** RESTful endpoints for vehicle, train, and LED map data.\n- **Rate Limiting \u0026 Compression:** Built-in gzip/brotli compression, and configurable rate limiting.\n- **Docker Support:** Ready-to-run with Docker Compose for easy deployment.\n\n## Project Structure\n\n- `server.ts` — Main Express server, API endpoints, and periodic data refresh logic.\n- `railNetwork.ts` — City-specific configuration loader and documentation for `config.json` structure.\n- `trackBlocks.ts` — KML parsing, block occupancy, and LED map update logic.\n- `trainPairs.ts` — Train pair detection and caching.\n- `cache.ts` — Caching to and from gzipped JSON files.\n- `customUtils.ts` — Utility functions, including colorized logging.\n- `map.html` — Leaflet-based web map for visualizing live train positions and track blocks (for debugging).\n\n### Currently Supported Networks\n\n- `railNetworks/AKL/` — Auckland config and track block files.\n- `railNetworks/WLG/` — Wellington config and track block files.\n\n## API Endpoints\n\nEndpoints use city code (e.g. AKL or WLG) and version (e.g. 100 for V1.0.0):\n\n| Endpoint                      | Description                        |\n|-------------------------------|------------------------------------|\n| `/`                           | Basic server status                |\n| `/status`                     | Server metrics and uptime          |\n| `/city/api/vehicles`          | All active vehicle entities        |\n| `/city/api/vehicles/trains`   | Filtered list of active trains     |\n| `/city-ltm/version.json`      | LED map update for the city board  |\n\nAll endpoints are rate-limited by default.\n\n## Configuration\n\nSet environment variables in `.env`:\n\n- `PORT`: Server port (default: 3000)\n- `RATE_LIMIT_WINDOW_MS`: Rate limit window (default: 60000)\n- `RATE_LIMIT_MAX`: Max requests per window (default: 20)\n- `AKL`, `WLG`: Add API keys for each city using their city ID\n\nCity-specific configurations are in `railNetworks/` and the documentation for the structure of `config.json` is at the top of `railNetwork.ts`.\n\n### Editing Track Blocks\n\n- Edit `trackBlocks.kml` in Google Earth to customize block layouts for each city.\n- Update `config.json` for each city to change API settings, colors, and thresholds.\n\n## License\n\nMIT License. See [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdfer%2Fled-rails-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdfer%2Fled-rails-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdfer%2Fled-rails-backend/lists"}