# vinura2006/ceylon-track architecture

> Architecture diagram of the GitHub repository vinura2006/ceylon-track, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vinura2006/ceylon-track
- Repository: https://github.com/vinura2006/ceylon-track

## Overview

Ceylon Track is a real-time passenger information system for Sri Lanka Railways. Passengers use schedule and station information, follow journeys, and receive live train status and disruption alerts; staff and administrators manage train operations and GPS sharing. The backend is an Express API backed by PostgreSQL, with WebSocket updates and scheduled jobs. The graph preserves the README’s major capabilities and the indexed route modules. Some route internals were not excerpted, so those links show documented mounting or indexed references rather than inferred calls between features.

Main entry points: [`backend/index.js`](https://github.com/vinura2006/ceylon-track/blob/main/backend/index.js) (Express API), [`backend/db/pool.js`](https://github.com/vinura2006/ceylon-track/blob/main/backend/db/pool.js) (PostgreSQL), [`backend/routes/auth.js`](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/auth.js) (Account and login), [`backend/routes/schedules.js`](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/schedules.js) (Train schedules)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API and realtime"]
  node_api["Express API<br/>[index.js]"]
  node_websocket["WebSocket updates<br/>[websocket.js]"]
  node_database[("PostgreSQL<br/>[pool.js]")]
end

subgraph group_identity["Identity and access"]
  node_auth["Account and login<br/>[auth.js]"]
  node_mfa["Multi-factor auth<br/>[mfa.js]"]
  node_sessions["GPS sessions<br/>[sessions.js]"]
  node_authn["Token verification<br/>[authenticate.js]"]
  node_authz["Role authorization<br/>[authorize.js]"]
  node_validation["Request validation<br/>[validate.js]"]
end

subgraph group_rail["Rail information"]
  node_schedules["Train schedules<br/>[schedules.js]"]
  node_timetable["Timetable and routes<br/>[timetable.js]"]
  node_stations["Station directory<br/>[stations.js]"]
  node_disruptions["Disruption feed<br/>[disruptions.js]"]
  node_journeywatch["Journey watches<br/>[journeywatch.js]"]
  node_watch["Watch subscriptions<br/>[watch.js]"]
end

subgraph group_operations["Live operations"]
  node_gps["GPS updates<br/>[gps.js]"]
  node_staff_ops["Staff operations<br/>[staff.js]"]
  node_assignments["Assignments<br/>[assignments.js]"]
  node_laststop["Last-stop status<br/>[laststop.js]"]
  node_admin["Administration<br/>[admin.js]"]
end

subgraph group_support["Alerts and internals"]
  node_notifications_job["Watcher notifier"]
  node_email["Email delivery<br/>[notifications.js]"]
  node_reliability["Reliability refresh"]
  node_cache["TTL cache<br/>[simpleCache.js]"]
  node_audit["Audit logging<br/>[auditLogger.js]"]
end

node_passengers(("Passengers"))
node_staff(("Rail staff"))
node_gps_device(("GPS hardware"))

node_passengers -->|"request information"| node_api
node_staff -->|"manage operations"| node_api
node_gps_device -->|"push coordinates"| node_api
node_api -->|"mounts routes"| node_auth
node_api -->|"mounts routes"| node_mfa
node_api -->|"mounts routes"| node_schedules
node_api -->|"mounts routes"| node_stations
node_api -->|"mounts routes"| node_watch
node_api -->|"mounts routes"| node_staff_ops
node_api -->|"mounts routes"| node_gps
node_api -->|"mounts routes"| node_disruptions
node_api -->|"mounts routes"| node_assignments
node_api -->|"mounts routes"| node_laststop
node_api -->|"mounts routes"| node_timetable
node_api -->|"mounts routes"| node_journeywatch
node_api -->|"mounts routes"| node_admin
node_api -.->|"mounts routes"| node_sessions
node_api -->|"attaches server"| node_websocket
node_api -->|"queries health"| node_database
node_auth -->|"reads and writes"| node_database
node_auth -->|"authenticates requests"| node_authn
node_auth -->|"checks roles"| node_authz
node_authn -->|"checks revocation"| node_database
node_mfa -->|"queries records"| node_database
node_sessions -->|"manages sessions"| node_database
node_schedules -->|"queries schedules"| node_database
node_schedules -->|"caches results"| node_cache
node_timetable -->|"queries timetable"| node_database
node_stations -->|"queries stations"| node_database
node_stations -->|"caches results"| node_cache
node_disruptions -->|"queries disruptions"| node_database
node_journeywatch -->|"queries journeys"| node_database
node_watch -.->|"stores watches"| node_database
node_gps -->|"stores coordinates"| node_database
node_staff_ops -->|"updates operations"| node_database
node_assignments -->|"queries assignments"| node_database
node_laststop -->|"queries status"| node_database
node_admin -->|"manages records"| node_database
node_notifications_job -->|"reads watches"| node_database
node_notifications_job -->|"sends alerts"| node_email
node_reliability -->|"refreshes cache table"| node_database
node_api -.->|"schedules refresh job"| node_reliability
node_websocket -->|"reads train data"| node_database
node_auth -->|"logs actions"| node_audit
node_staff_ops -->|"logs actions"| node_audit
node_admin -->|"logs actions"| node_audit

click node_api "https://github.com/vinura2006/ceylon-track/blob/main/backend/index.js"
click node_websocket "https://github.com/vinura2006/ceylon-track/blob/main/backend/websocket.js"
click node_database "https://github.com/vinura2006/ceylon-track/blob/main/backend/db/pool.js"
click node_auth "https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/auth.js"
click node_mfa "https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/mfa.js"
click node_sessions "https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/sessions.js"
click node_authn "https://github.com/vinura2006/ceylon-track/blob/main/backend/middleware/authenticate.js"
click node_authz "https://github.com/vinura2006/ceylon-track/blob/main/backend/middleware/authorize.js"
click node_validation "https://github.com/vinura2006/ceylon-track/blob/main/backend/middleware/validate.js"
click node_schedules "https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/schedules.js"
click node_timetable "https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/timetable.js"
click node_stations "https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/stations.js"
click node_disruptions "https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/disruptions.js"
click node_journeywatch "https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/journeywatch.js"
click node_watch "https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/watch.js"
click node_gps "https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/gps.js"
click node_staff_ops "https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/staff.js"
click node_assignments "https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/assignments.js"
click node_laststop "https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/laststop.js"
click node_admin "https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/admin.js"
click node_notifications_job "https://github.com/vinura2006/ceylon-track/blob/main/backend/jobs/notificationChecker.js"
click node_email "https://github.com/vinura2006/ceylon-track/blob/main/backend/services/notifications.js"
click node_reliability "https://github.com/vinura2006/ceylon-track/blob/main/backend/jobs/reliabilityRefresh.js"
click node_cache "https://github.com/vinura2006/ceylon-track/blob/main/backend/utils/simpleCache.js"
click node_audit "https://github.com/vinura2006/ceylon-track/blob/main/backend/utils/auditLogger.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_websocket,node_database toneBlue
class node_auth,node_mfa,node_sessions,node_authn,node_authz,node_validation toneAmber
class node_schedules,node_timetable,node_stations,node_disruptions,node_journeywatch,node_watch toneMint
class node_gps,node_staff_ops,node_assignments,node_laststop,node_admin toneRose
class node_notifications_job,node_email,node_reliability,node_cache,node_audit,node_passengers,node_staff,node_gps_device toneIndigo
```

## Components

### API and realtime

- [Express API](https://github.com/vinura2006/ceylon-track/blob/main/backend/index.js): `backend/index.js`
- [WebSocket updates](https://github.com/vinura2006/ceylon-track/blob/main/backend/websocket.js): `backend/websocket.js`
- [PostgreSQL](https://github.com/vinura2006/ceylon-track/blob/main/backend/db/pool.js): `backend/db/pool.js`

### Identity and access

- [Account and login](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/auth.js): `backend/routes/auth.js`
- [Multi-factor auth](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/mfa.js): `backend/routes/mfa.js`
- [GPS sessions](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/sessions.js): `backend/routes/sessions.js`
- [Token verification](https://github.com/vinura2006/ceylon-track/blob/main/backend/middleware/authenticate.js): `backend/middleware/authenticate.js`
- [Role authorization](https://github.com/vinura2006/ceylon-track/blob/main/backend/middleware/authorize.js): `backend/middleware/authorize.js`
- [Request validation](https://github.com/vinura2006/ceylon-track/blob/main/backend/middleware/validate.js): `backend/middleware/validate.js`

### Rail information

- [Train schedules](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/schedules.js): `backend/routes/schedules.js`
- [Timetable and routes](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/timetable.js): `backend/routes/timetable.js`
- [Station directory](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/stations.js): `backend/routes/stations.js`
- [Disruption feed](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/disruptions.js): `backend/routes/disruptions.js`
- [Journey watches](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/journeywatch.js): `backend/routes/journeywatch.js`
- [Watch subscriptions](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/watch.js): `backend/routes/watch.js`

### Live operations

- [GPS updates](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/gps.js): `backend/routes/gps.js`
- [Staff operations](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/staff.js): `backend/routes/staff.js`
- [Assignments](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/assignments.js): `backend/routes/assignments.js`
- [Last-stop status](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/laststop.js): `backend/routes/laststop.js`
- [Administration](https://github.com/vinura2006/ceylon-track/blob/main/backend/routes/admin.js): `backend/routes/admin.js`

### Alerts and internals

- [Watcher notifier](https://github.com/vinura2006/ceylon-track/blob/main/backend/jobs/notificationChecker.js): `backend/jobs/notificationChecker.js`
- [Email delivery](https://github.com/vinura2006/ceylon-track/blob/main/backend/services/notifications.js): `backend/services/notifications.js`
- [Reliability refresh](https://github.com/vinura2006/ceylon-track/blob/main/backend/jobs/reliabilityRefresh.js): `backend/jobs/reliabilityRefresh.js`
- [TTL cache](https://github.com/vinura2006/ceylon-track/blob/main/backend/utils/simpleCache.js): `backend/utils/simpleCache.js`
- [Audit logging](https://github.com/vinura2006/ceylon-track/blob/main/backend/utils/auditLogger.js): `backend/utils/auditLogger.js`

### Other components

- **Passengers**
- **Rail staff**
- **GPS hardware**

## Connections

- Passengers → Express API: request information
- Rail staff → Express API: manage operations
- GPS hardware → Express API: push coordinates
- Express API → Account and login: mounts routes (evidence: `backend/index.js`)
- Express API → Multi-factor auth: mounts routes (evidence: `backend/index.js`)
- Express API → Train schedules: mounts routes (evidence: `backend/index.js`)
- Express API → Station directory: mounts routes (evidence: `backend/index.js`)
- Express API → Watch subscriptions: mounts routes (evidence: `backend/index.js`)
- Express API → Staff operations: mounts routes (evidence: `backend/index.js`)
- Express API → GPS updates: mounts routes (evidence: `backend/index.js`)
- Express API → Disruption feed: mounts routes (evidence: `backend/index.js`)
- Express API → Assignments: mounts routes (evidence: `backend/index.js`)
- Express API → Last-stop status: mounts routes (evidence: `backend/index.js`)
- Express API → Timetable and routes: mounts routes (evidence: `backend/index.js`)
- Express API → Journey watches: mounts routes (evidence: `backend/index.js`)
- Express API → Administration: mounts routes (evidence: `backend/index.js`)
- Express API → GPS sessions: mounts routes (evidence: `backend/index.js`)
- Express API → WebSocket updates: attaches server (evidence: `backend/index.js`)
- Express API → PostgreSQL: queries health (evidence: `backend/index.js`)
- Account and login → PostgreSQL: reads and writes (evidence: `backend/routes/auth.js`)
- Account and login → Token verification: authenticates requests (evidence: `backend/routes/auth.js`)
- Account and login → Role authorization: checks roles (evidence: `backend/routes/auth.js`)
- Token verification → PostgreSQL: checks revocation (evidence: `backend/middleware/authenticate.js`)
- Multi-factor auth → PostgreSQL: queries records (evidence: `backend/routes/mfa.js`)
- GPS sessions → PostgreSQL: manages sessions (evidence: `backend/routes/sessions.js`)
- Train schedules → PostgreSQL: queries schedules (evidence: `backend/routes/schedules.js`)
- Train schedules → TTL cache: caches results (evidence: `backend/routes/schedules.js`)
- Timetable and routes → PostgreSQL: queries timetable (evidence: `backend/routes/timetable.js`)
- Station directory → PostgreSQL: queries stations (evidence: `backend/routes/stations.js`)
- Station directory → TTL cache: caches results (evidence: `backend/routes/stations.js`)
- Disruption feed → PostgreSQL: queries disruptions (evidence: `backend/routes/disruptions.js`)
- Journey watches → PostgreSQL: queries journeys (evidence: `backend/routes/journeywatch.js`)
- Watch subscriptions → PostgreSQL: stores watches
- GPS updates → PostgreSQL: stores coordinates (evidence: `backend/routes/gps.js`)
- Staff operations → PostgreSQL: updates operations (evidence: `backend/routes/staff.js`)
- Assignments → PostgreSQL: queries assignments (evidence: `backend/routes/assignments.js`)
- Last-stop status → PostgreSQL: queries status (evidence: `backend/routes/laststop.js`)
- Administration → PostgreSQL: manages records (evidence: `backend/routes/admin.js`)
- Watcher notifier → PostgreSQL: reads watches (evidence: `backend/jobs/notificationChecker.js`)
- Watcher notifier → Email delivery: sends alerts (evidence: `backend/jobs/notificationChecker.js`)
- Reliability refresh → PostgreSQL: refreshes cache table (evidence: `backend/jobs/reliabilityRefresh.js`)
- Express API → Reliability refresh: schedules refresh job (evidence: `backend/index.js`)
- WebSocket updates → PostgreSQL: reads train data (evidence: `backend/websocket.js`)
- Account and login → Audit logging: logs actions (evidence: `backend/routes/auth.js`)
- Staff operations → Audit logging: logs actions (evidence: `backend/routes/staff.js`)
- Administration → Audit logging: logs actions (evidence: `backend/routes/admin.js`)
