# sreevanib05/trackify420-public architecture

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

- Interactive diagram: https://gitdiagram.com/sreevanib05/trackify420-public
- Repository: https://github.com/sreevanib05/trackify420-public

## Overview

1. **Overall shape**
   Trackify420 is a multi-client bus tracking system with one shared backend and three frontends: a React admin dashboard, a Flutter student app, and a Flutter driver app. The backend is the central authority for identity/session validation, trip state, route metadata, alerts, and live tracking.

2. **Backend as the system core**
   The Node.js/Express backend owns the public API surface under `/api/*`, Socket.IO on `/socket.io`, and a separate raw WebSocket bridge under `/ws`. It is also responsible for Firebase Admin integration, JWT/session handling, and in-memory/managed state for live operational data.

3. **Identity and session boundary**
   Firebase Auth is the primary identity provider for both Flutter apps and the dashboard. Backend middleware and auth routes convert that identity into application sessions/tokens, with a shared client key used by the mobile apps and backend to validate requests. This creates a clear boundary between Firebase-issued identity and Trackify-specific authorization/session state.

4. **Operational state inside the backend**
   The backend has a dedicated `state/` layer for live bus and trip logic: live locations, route reach timing, bus locks, trip start alerts, stopped-alert detection, attendance, announcements, ended trips, and the route catalog. These modules are the main data model for realtime operations and are what make the system more than a simple CRUD API.

5. **Realtime tracking data flow**
   Driver-side location updates are published to the backend, which then updates live location/trip state and broadcasts changes to subscribed clients via Socket.IO. The admin dashboard and student app consume those updates for live maps, status cards, and arrival/boarding alerts. The raw `/ws` bridge exists as a secondary realtime channel for admin-oriented integration or compatibility scenarios.

6. **Driver app responsibilities**
   The Flutter driver app is focused on authenticated session management, permissions, and foreground/background location publishing. Its services show the key flow: login/signup, session storage, route option selection, background location service, and socket publishing. The driver app is the upstream source of bus telemetry.

7. **Student app responsibilities**
   The Flutter student app is a consumer-facing app for login/signup, profile completion, route selection, live map tracking, announcements, and push/boarding alerts. It uses backend APIs for session validation, student profile and trips data, and Socket.IO for live trip updates. It also bundles route JSON assets, so route visualization can work with local route geometry instead of relying only on the server.

8. **Admin dashboard responsibilities**
   The React/Vite dashboard is the operational console for fleet monitoring, dashboards, attendance, drivers, students, announcements, and tracking views. It combines REST for persistent data, Socket.IO for realtime status, and a map component for live bus visualization. Its UI layer is split into pages, shared components, and small service modules that keep API/realtime access isolated.

9. **Persistent vs transient data**
   Persistent data lives behind backend APIs and Firebase-backed services; transient data lives in backend state modules and websocket broadcasts. This split is important: user accounts, profiles, trips, routes, and announcements are API-backed, while live locations, lock decisions, alert windows, and reach-time calculations are realtime stateful concerns.

10. **Route and map data**
   Route definitions are represented in two places: server-side route catalog/state and client-side assets. The student app includes many bundled route JSON files, while the dashboard includes route-specific data for map views. This suggests route geometry and route-option presentation are shared concepts but are not fully centralized in one datastore.

11. **Notifications and alerts**
   The backend’s alert/announcement modules drive operational messaging, and the student app includes push notification services plus announcement read state. The system therefore separates broadcast/operational events from normal trip tracking, but both are part of the same backend-driven event model.

12. **Tooling, tests, and deployment boundaries**
   The repo is structured as multiple independently runnable apps, each with its own package/configuration and platform build artifacts. The backend has tests for rate limiting, bus locks, reach times, and alert engines, indicating those are critical business rules. Deployment hints show a Render-style backend and a Vercel-style dashboard, while the Flutter apps target Android/iOS and use Firebase mobile config files.

Main entry points: [`backend/src/index.js`](https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/index.js) (Server entry), [`backend/src/routes/buses.js`](https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/routes/buses.js) (Core APIs), [`backend/src/ws/socket.js`](https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/ws/socket.js) (Socket.IO), [`admin-dashboard/src/App.jsx`](https://github.com/sreevanib05/trackify420-public/blob/main/admin-dashboard/src/App.jsx) (Dashboard app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_backend_entry["Server entry<br/>express bootstrap<br/>[index.js]"]
  node_backend_config["Config<br/>[config.js]"]
  node_backend_firebase["Firebase admin<br/>identity adapter<br/>[firebase.js]"]
  node_backend_auth_mw["Auth middleware<br/>request boundary<br/>[firebaseAuth.js]"]
  node_backend_auth_routes["Auth API<br/>session api<br/>[auth.js]"]
  node_backend_core_routes["Core APIs<br/>resource api<br/>[buses.js]"]
  node_backend_routes_catalog["Route catalog<br/>route metadata<br/>[routesCatalog.js]"]
  node_backend_live_state["Live state<br/>realtime state<br/>[liveLocations.js]"]
  node_backend_trip_alerts["Trip alerts<br/>event engine<br/>[tripStartAlerts.js]"]
  node_backend_announce["Announcements<br/>broadcast state<br/>[announcements.js]"]
  node_backend_socket(("Socket.IO<br/>realtime gateway<br/>[socket.js]"))
  node_backend_ws["Raw WS bridge<br/>compat bridge<br/>[rawSocket.js]"]
end

subgraph group_admin["Admin Dashboard"]
  node_dashboard_app["Dashboard app<br/>react console<br/>[App.jsx]"]
  node_dashboard_api["API client<br/>rest client<br/>[api.js]"]
  node_dashboard_rt["Realtime client<br/>socket client<br/>[realtime.js]"]
  node_dashboard_map["Tracking map<br/>map view<br/>[TrackingMap.jsx]"]
  node_dashboard_store["UI store<br/>client state"]
end

subgraph group_driver["Driver App"]
  node_driver_entry["Driver app<br/>flutter client<br/>[main.dart]"]
  node_driver_auth["Driver auth<br/>session flow"]
  node_driver_location["Location service<br/>telemetry publisher"]
  node_driver_socket["Driver socket<br/>realtime client"]
end

subgraph group_student["Student App"]
  node_student_entry["Student app<br/>flutter client<br/>[main.dart]"]
  node_student_auth["Student auth<br/>session flow"]
  node_student_routes["Route assets<br/>local geometry"]
  node_student_live["Live tracking<br/>realtime client"]
  node_student_alerts["Alerts & notices<br/>notification layer"]
end

node_backend_entry -->|"loads"| node_backend_config
node_backend_entry -->|"uses"| node_backend_auth_mw
node_backend_entry -->|"mounts"| node_backend_auth_routes
node_backend_entry -->|"mounts"| node_backend_core_routes
node_backend_entry -->|"opens"| node_backend_socket
node_backend_entry -->|"opens"| node_backend_ws
node_backend_auth_routes -->|"verifies"| node_backend_firebase
node_backend_auth_mw -->|"checks"| node_backend_firebase
node_backend_core_routes -->|"reads"| node_backend_routes_catalog
node_backend_core_routes -->|"reads/writes"| node_backend_live_state
node_backend_core_routes -->|"uses"| node_backend_trip_alerts
node_backend_core_routes -->|"uses"| node_backend_announce
node_backend_socket -->|"broadcasts"| node_backend_live_state
node_backend_socket -->|"emits"| node_backend_trip_alerts
node_backend_ws -->|"bridges"| node_backend_live_state
node_dashboard_app -->|"calls"| node_dashboard_api
node_dashboard_app -->|"subscribes"| node_dashboard_rt
node_dashboard_app -->|"uses"| node_dashboard_store
node_dashboard_app -->|"renders"| node_dashboard_map
node_dashboard_api -->|"requests"| node_backend_core_routes
node_dashboard_rt -->|"connects"| node_backend_socket
node_driver_entry -->|"uses"| node_driver_auth
node_driver_entry -->|"publishes"| node_driver_location
node_driver_entry -->|"connects"| node_driver_socket
node_driver_auth -->|"authenticates"| node_backend_auth_routes
node_driver_socket -->|"streams"| node_backend_socket
node_driver_location -->|"updates"| node_backend_live_state
node_student_entry -->|"uses"| node_student_auth
node_student_entry -->|"loads"| node_student_routes
node_student_entry -->|"subscribes"| node_student_live
node_student_entry -->|"shows"| node_student_alerts
node_student_auth -->|"authenticates"| node_backend_auth_routes
node_student_live -->|"listens"| node_backend_socket
node_student_alerts -->|"syncs"| node_backend_announce
node_student_routes -.->|"matches"| node_backend_routes_catalog

click node_backend_entry "https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/index.js"
click node_backend_config "https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/config.js"
click node_backend_firebase "https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/firebase.js"
click node_backend_auth_mw "https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/middleware/firebaseAuth.js"
click node_backend_auth_routes "https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/routes/auth.js"
click node_backend_core_routes "https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/routes/buses.js"
click node_backend_routes_catalog "https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/state/routesCatalog.js"
click node_backend_live_state "https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/state/liveLocations.js"
click node_backend_trip_alerts "https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/state/tripStartAlerts.js"
click node_backend_announce "https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/state/announcements.js"
click node_backend_socket "https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/ws/socket.js"
click node_backend_ws "https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/ws/rawSocket.js"
click node_dashboard_app "https://github.com/sreevanib05/trackify420-public/blob/main/admin-dashboard/src/App.jsx"
click node_dashboard_api "https://github.com/sreevanib05/trackify420-public/blob/main/admin-dashboard/src/services/api.js"
click node_dashboard_rt "https://github.com/sreevanib05/trackify420-public/blob/main/admin-dashboard/src/services/realtime.js"
click node_dashboard_map "https://github.com/sreevanib05/trackify420-public/blob/main/admin-dashboard/src/components/map/TrackingMap.jsx"
click node_dashboard_store "https://github.com/sreevanib05/trackify420-public/blob/main/admin-dashboard/src/store/useTrackifyStore.js"
click node_driver_entry "https://github.com/sreevanib05/trackify420-public/blob/main/flutter/driver_app/lib/main.dart"
click node_driver_auth "https://github.com/sreevanib05/trackify420-public/blob/main/flutter/driver_app/lib/services/auth_session_service.dart"
click node_driver_location "https://github.com/sreevanib05/trackify420-public/blob/main/flutter/driver_app/lib/services/background_location_service.dart"
click node_driver_socket "https://github.com/sreevanib05/trackify420-public/blob/main/flutter/driver_app/lib/services/socket_service.dart"
click node_student_entry "https://github.com/sreevanib05/trackify420-public/blob/main/flutter/student_app/lib/main.dart"
click node_student_auth "https://github.com/sreevanib05/trackify420-public/blob/main/flutter/student_app/lib/services/auth_session_service.dart"
click node_student_routes "https://github.com/sreevanib05/trackify420-public/blob/main/flutter/student_app/lib/services/route_asset_service.dart"
click node_student_live "https://github.com/sreevanib05/trackify420-public/blob/main/flutter/student_app/lib/services/socket_service.dart"
click node_student_alerts "https://github.com/sreevanib05/trackify420-public/blob/main/flutter/student_app/lib/services/push_notification_service.dart"

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_backend_entry,node_backend_config,node_backend_firebase,node_backend_auth_mw,node_backend_auth_routes,node_backend_core_routes,node_backend_routes_catalog,node_backend_live_state,node_backend_trip_alerts,node_backend_announce,node_backend_socket,node_backend_ws toneBlue
class node_dashboard_app,node_dashboard_api,node_dashboard_rt,node_dashboard_map,node_dashboard_store toneAmber
class node_driver_entry,node_driver_auth,node_driver_location,node_driver_socket toneMint
class node_student_entry,node_student_auth,node_student_routes,node_student_live,node_student_alerts toneRose
```

## Components

### Backend

Shared Node.js/Express API, auth, realtime, and operational state.

- [Server entry](https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/index.js): express bootstrap · Starts the API server and wires routes, middleware, and realtime channels. · `backend/src/index.js`
- [Config](https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/config.js): runtime config · Central backend configuration and environment wiring. · `backend/src/config.js`
- [Firebase admin](https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/firebase.js): identity adapter · Backend Firebase integration used for token and session validation. · `backend/src/firebase.js`
- [Auth middleware](https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/middleware/firebaseAuth.js): request boundary · Validates Firebase identity and access tokens before API handlers run. · `backend/src/middleware/firebaseAuth.js`
- [Auth API](https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/routes/auth.js): session api · Converts external identity into Trackify-specific auth and session state. · `backend/src/routes/auth.js`
- [Core APIs](https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/routes/buses.js): resource api · Primary REST surface for buses, drivers, students, routes, trips, alerts, and announcements. · `backend/src/routes/buses.js`
- [Route catalog](https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/state/routesCatalog.js): route metadata · Shared catalog of route definitions used by operational logic and clients. · `backend/src/state/routesCatalog.js`
- [Live state](https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/state/liveLocations.js): realtime state · Operational state for live locations, reach times, locks, alerts, attendance, and ended trips. · `backend/src/state/liveLocations.js`
- [Trip alerts](https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/state/tripStartAlerts.js): event engine · Trip start and stop-alert logic that drives operational notifications. · `backend/src/state/tripStartAlerts.js`
- [Announcements](https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/state/announcements.js): broadcast state · Announcement lifecycle and read/visibility state for operational messaging. · `backend/src/state/announcements.js`
- [Socket.IO](https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/ws/socket.js): realtime gateway · Primary realtime channel for live tracking updates and status broadcasts. · `backend/src/ws/socket.js`
- [Raw WS bridge](https://github.com/sreevanib05/trackify420-public/blob/main/backend/src/ws/rawSocket.js): compat bridge · Secondary WebSocket endpoint for admin compatibility or integration scenarios. · `backend/src/ws/rawSocket.js`

### Admin Dashboard

React/Vite operational console for monitoring and management.

- [Dashboard app](https://github.com/sreevanib05/trackify420-public/blob/main/admin-dashboard/src/App.jsx): react console · Vite-based admin UI shell for fleet operations and tracking. · `admin-dashboard/src/App.jsx`
- [API client](https://github.com/sreevanib05/trackify420-public/blob/main/admin-dashboard/src/services/api.js): rest client · Dashboard service layer for REST-backed data access. · `admin-dashboard/src/services/api.js`
- [Realtime client](https://github.com/sreevanib05/trackify420-public/blob/main/admin-dashboard/src/services/realtime.js): socket client · Dashboard realtime integration for live bus and trip updates. · `admin-dashboard/src/services/realtime.js`
- [Tracking map](https://github.com/sreevanib05/trackify420-public/blob/main/admin-dashboard/src/components/map/TrackingMap.jsx): map view · Live bus visualization and map-centric tracking UI. · `admin-dashboard/src/components/map/TrackingMap.jsx`
- [UI store](https://github.com/sreevanib05/trackify420-public/blob/main/admin-dashboard/src/store/useTrackifyStore.js): client state · Shared dashboard state for buses, students, drivers, and tracking views. · `admin-dashboard/src/store/useTrackifyStore.js`

### Driver App

Flutter client that authenticates and publishes bus telemetry.

- [Driver app](https://github.com/sreevanib05/trackify420-public/blob/main/flutter/driver_app/lib/main.dart): flutter client · Driver-facing Flutter app for auth, permissions, and telemetry publishing. · `flutter/driver_app/lib/main.dart`
- [Driver auth](https://github.com/sreevanib05/trackify420-public/blob/main/flutter/driver_app/lib/services/auth_session_service.dart): session flow · Login, signup, session storage, and session guarding for drivers. · `flutter/driver_app/lib/services/auth_session_service.dart`
- [Location service](https://github.com/sreevanib05/trackify420-public/blob/main/flutter/driver_app/lib/services/background_location_service.dart): telemetry publisher · Foreground/background location collection and publish flow from the driver device. · `flutter/driver_app/lib/services/background_location_service.dart`
- [Driver socket](https://github.com/sreevanib05/trackify420-public/blob/main/flutter/driver_app/lib/services/socket_service.dart): realtime client · Publishes telemetry and session updates to the backend realtime channel. · `flutter/driver_app/lib/services/socket_service.dart`

### Student App

Flutter client that consumes live tracking, announcements, and profile data.

- [Student app](https://github.com/sreevanib05/trackify420-public/blob/main/flutter/student_app/lib/main.dart): flutter client · Student-facing Flutter app for tracking, route selection, and alerts. · `flutter/student_app/lib/main.dart`
- [Student auth](https://github.com/sreevanib05/trackify420-public/blob/main/flutter/student_app/lib/services/auth_session_service.dart): session flow · Login, signup, profile completion, and session handling for students. · `flutter/student_app/lib/services/auth_session_service.dart`
- [Route assets](https://github.com/sreevanib05/trackify420-public/blob/main/flutter/student_app/lib/services/route_asset_service.dart): local geometry · Bundled route JSON and route asset loading for offline-capable map presentation. · `flutter/student_app/lib/services/route_asset_service.dart`
- [Live tracking](https://github.com/sreevanib05/trackify420-public/blob/main/flutter/student_app/lib/services/socket_service.dart): realtime client · Consumes live trip updates and alert events from the backend. · `flutter/student_app/lib/services/socket_service.dart`
- [Alerts & notices](https://github.com/sreevanib05/trackify420-public/blob/main/flutter/student_app/lib/services/push_notification_service.dart): notification layer · Push notifications, announcement state, and boarding alert presentation. · `flutter/student_app/lib/services/push_notification_service.dart`

## Connections

- Server entry → Config: loads · Bootstrapping depends on runtime configuration.
- Server entry → Auth middleware: uses · API requests pass through authentication middleware.
- Server entry → Auth API: mounts · Exposes auth/session endpoints.
- Server entry → Core APIs: mounts · Exposes the main REST API surface.
- Server entry → Socket.IO: opens · Serves the primary Socket.IO realtime channel.
- Server entry → Raw WS bridge: opens · Serves the secondary raw WebSocket bridge.
- Auth API → Firebase admin: verifies · Translates Firebase identity into application auth state.
- Auth middleware → Firebase admin: checks · Validates Firebase-issued tokens and session claims.
- Core APIs → Route catalog: reads · Route-related endpoints depend on route metadata.
- Core APIs → Live state: reads/writes · Operational endpoints update and read live trip state.
- Core APIs → Trip alerts: uses · Trip endpoints trigger alert and reach-time logic.
- Core APIs → Announcements: uses · Announcement endpoints manage broadcast state.
- Socket.IO → Live state: broadcasts · Realtime updates are emitted from live operational state.
- Socket.IO → Trip alerts: emits · Alert engine events are pushed to connected clients.
- Raw WS bridge → Live state: bridges · Secondary realtime channel reflects live state updates.
- Dashboard app → API client: calls · Dashboard pages load persistent data through REST.
- Dashboard app → Realtime client: subscribes · Dashboard listens for live bus and trip changes.
- Dashboard app → UI store: uses · UI state coordinates operational views and filters.
- Dashboard app → Tracking map: renders · Tracking pages visualize live movement on a map.
- API client → Core APIs: requests · Dashboard REST calls target the backend API.
- Realtime client → Socket.IO: connects · Dashboard realtime client connects to Socket.IO.
- Driver app → Driver auth: uses · Driver UI depends on session and auth state.
- Driver app → Location service: publishes · Driver app collects and streams location telemetry.
- Driver app → Driver socket: connects · Driver app sends realtime updates through sockets.
- Driver auth → Auth API: authenticates · Driver sessions are established through backend auth endpoints.
- Driver socket → Socket.IO: streams · Driver telemetry feeds the realtime backend.
- Location service → Live state: updates · Location updates drive live bus and trip state.
- Student app → Student auth: uses · Student UI depends on account and session state.
- Student app → Route assets: loads · Student maps use bundled route geometry assets.
- Student app → Live tracking: subscribes · Student app consumes live trip updates.
- Student app → Alerts & notices: shows · Student app surfaces announcements and boarding alerts.
- Student auth → Auth API: authenticates · Student identity is converted into Trackify sessions.
- Live tracking → Socket.IO: listens · Student app receives live tracking events from Socket.IO.
- Alerts & notices → Announcements: syncs · Announcement and alert state is backed by the server.
- Route assets → Route catalog: matches · Bundled client routes mirror server route metadata.
