# sanjaykumar9441/safetrack architecture

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

- Interactive diagram: https://gitdiagram.com/sanjaykumar9441/safetrack
- Repository: https://github.com/sanjaykumar9441/safetrack

## Overview

SafeTrack combines onboard hazard sensing and GPS telemetry with Firebase-backed passenger tracking, fleet administration, and emergency response. The documented vehicle-to-cloud workflow is sensor telemetry through the ESP32 gateway into Firestore; passenger and administrative clients consume live records, while driver SOS can dispatch notifications. Mobile implementation paths and the FPGA/IoT source directories are absent from the supplied tree, so their nodes use only the existing enclosing mobile-app path or null; those branches rely on README documentation.

Main entry points: [`admin-dashboard/src/App.js`](https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/App.js) (Dashboard router), [`admin-dashboard/functions/index.js`](https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/functions/index.js) (Cloud Functions), [`mobile-app`](https://github.com/sanjaykumar9441/safetrack/tree/main/mobile-app) (Flutter app), [`admin-dashboard/src/firebase.js`](https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/firebase.js) (Firebase client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_vehicle["Vehicle safety"]
  node_sensors["FPGA sensors"]
  node_gateway["ESP32 gateway"]
end

subgraph group_cloud["Cloud services"]
  node_firestore[("Firebase Firestore")]
  node_auth["Firebase Auth"]
  node_functions["Cloud Functions<br/>[index.js]"]
end

subgraph group_passenger["Passenger app"]
  node_mobile["Flutter app"]
  node_live_tracking["Live tracking"]
  node_route_search["Route search"]
  node_nearby_stops["Nearby stops"]
  node_safety_chat["Safety assistant"]
end

subgraph group_admin["Fleet dashboard"]
  node_app["Dashboard router<br/>[App.js]"]
  node_login["Role login<br/>[LoginPage.jsx]"]
  node_auth_context["Auth context<br/>[AuthContext.jsx]"]
  node_firebase["Firebase client<br/>[firebase.js]"]
  node_fleet_crud["Bus management<br/>[CreateBus.jsx]"]
  node_route_crud["Route management<br/>[CreateRoute.jsx]"]
  node_driver_terminal["Driver terminal<br/>[DriverTerminal.jsx]"]
  node_dashboard_views["Fleet monitoring<br/>[DashboardHome.jsx]"]
end

node_groq["Groq AI"]
node_twilio["Twilio calls"]
node_slack["Slack alerts"]
node_telegram["Telegram alerts"]
node_passenger(("Passenger"))
node_admin_user(("Fleet operator"))

node_sensors -.->|"sends telemetry"| node_gateway
node_gateway -.->|"uploads telemetry"| node_firestore
node_passenger -->|"uses"| node_mobile
node_mobile -->|"opens"| node_live_tracking
node_mobile -->|"opens"| node_route_search
node_mobile -->|"opens"| node_nearby_stops
node_mobile -->|"opens"| node_safety_chat
node_live_tracking -.->|"streams telemetry"| node_firestore
node_route_search -.->|"reads routes"| node_firestore
node_nearby_stops -.->|"reads stops"| node_firestore
node_safety_chat -.->|"requests advice"| node_functions
node_functions -.->|"queries model"| node_groq
node_admin_user -->|"uses"| node_app
node_app -->|"routes login"| node_login
node_login -->|"signs in through"| node_auth_context
node_auth_context -->|"authenticates"| node_auth
node_auth_context -.->|"loads role"| node_firestore
node_app -->|"routes fleet"| node_fleet_crud
node_app -->|"routes services"| node_route_crud
node_app -->|"routes driver"| node_driver_terminal
node_app -->|"routes monitoring"| node_dashboard_views
node_fleet_crud -->|"uses client"| node_firebase
node_route_crud -->|"uses client"| node_firebase
node_driver_terminal -->|"uses client"| node_firebase
node_dashboard_views -->|"uses client"| node_firebase
node_firebase -.->|"reads and writes"| node_firestore
node_driver_terminal -.->|"dispatches SOS"| node_functions
node_functions -.->|"places calls"| node_twilio
node_functions -.->|"posts alerts"| node_slack
node_functions -.->|"sends alerts"| node_telegram

click node_functions "https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/functions/index.js"
click node_mobile "https://github.com/sanjaykumar9441/safetrack/tree/main/mobile-app"
click node_live_tracking "https://github.com/sanjaykumar9441/safetrack/tree/main/mobile-app"
click node_route_search "https://github.com/sanjaykumar9441/safetrack/tree/main/mobile-app"
click node_nearby_stops "https://github.com/sanjaykumar9441/safetrack/tree/main/mobile-app"
click node_safety_chat "https://github.com/sanjaykumar9441/safetrack/tree/main/mobile-app"
click node_app "https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/App.js"
click node_login "https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/components/Auth/LoginPage.jsx"
click node_auth_context "https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/context/AuthContext.jsx"
click node_firebase "https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/firebase.js"
click node_fleet_crud "https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/components/Bus/CreateBus.jsx"
click node_route_crud "https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/components/Route/CreateRoute.jsx"
click node_driver_terminal "https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/components/Driver/DriverTerminal.jsx"
click node_dashboard_views "https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/components/Dashboard/DashboardHome.jsx"

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_sensors,node_gateway toneBlue
class node_firestore,node_auth,node_functions toneAmber
class node_mobile,node_live_tracking,node_route_search,node_nearby_stops,node_safety_chat toneMint
class node_app,node_login,node_auth_context,node_firebase,node_fleet_crud,node_route_crud,node_driver_terminal,node_dashboard_views toneRose
class node_groq,node_twilio,node_slack,node_telegram,node_passenger,node_admin_user toneIndigo
```

## Components

### Vehicle safety

- **FPGA sensors**
- **ESP32 gateway**

### Cloud services

- **Firebase Firestore**
- **Firebase Auth**
- [Cloud Functions](https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/functions/index.js): `admin-dashboard/functions/index.js`

### Passenger app

- [Flutter app](https://github.com/sanjaykumar9441/safetrack/tree/main/mobile-app): `mobile-app`
- [Live tracking](https://github.com/sanjaykumar9441/safetrack/tree/main/mobile-app): `mobile-app`
- [Route search](https://github.com/sanjaykumar9441/safetrack/tree/main/mobile-app): `mobile-app`
- [Nearby stops](https://github.com/sanjaykumar9441/safetrack/tree/main/mobile-app): `mobile-app`
- [Safety assistant](https://github.com/sanjaykumar9441/safetrack/tree/main/mobile-app): `mobile-app`

### Fleet dashboard

- [Dashboard router](https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/App.js): `admin-dashboard/src/App.js`
- [Role login](https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/components/Auth/LoginPage.jsx): `admin-dashboard/src/components/Auth/LoginPage.jsx`
- [Auth context](https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/context/AuthContext.jsx): `admin-dashboard/src/context/AuthContext.jsx`
- [Firebase client](https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/firebase.js): `admin-dashboard/src/firebase.js`
- [Bus management](https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/components/Bus/CreateBus.jsx): `admin-dashboard/src/components/Bus/CreateBus.jsx`
- [Route management](https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/components/Route/CreateRoute.jsx): `admin-dashboard/src/components/Route/CreateRoute.jsx`
- [Driver terminal](https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/components/Driver/DriverTerminal.jsx): `admin-dashboard/src/components/Driver/DriverTerminal.jsx`
- [Fleet monitoring](https://github.com/sanjaykumar9441/safetrack/blob/main/admin-dashboard/src/components/Dashboard/DashboardHome.jsx): `admin-dashboard/src/components/Dashboard/DashboardHome.jsx`

### Other components

- **Groq AI**
- **Twilio calls**
- **Slack alerts**
- **Telegram alerts**
- **Passenger**
- **Fleet operator**

## Connections

- FPGA sensors → ESP32 gateway: sends telemetry
- ESP32 gateway → Firebase Firestore: uploads telemetry
- Passenger → Flutter app: uses
- Flutter app → Live tracking: opens
- Flutter app → Route search: opens
- Flutter app → Nearby stops: opens
- Flutter app → Safety assistant: opens
- Live tracking → Firebase Firestore: streams telemetry
- Route search → Firebase Firestore: reads routes
- Nearby stops → Firebase Firestore: reads stops
- Safety assistant → Cloud Functions: requests advice
- Cloud Functions → Groq AI: queries model
- Fleet operator → Dashboard router: uses
- Dashboard router → Role login: routes login
- Role login → Auth context: signs in through
- Auth context → Firebase Auth: authenticates
- Auth context → Firebase Firestore: loads role
- Dashboard router → Bus management: routes fleet
- Dashboard router → Route management: routes services
- Dashboard router → Driver terminal: routes driver
- Dashboard router → Fleet monitoring: routes monitoring
- Bus management → Firebase client: uses client
- Route management → Firebase client: uses client
- Driver terminal → Firebase client: uses client
- Fleet monitoring → Firebase client: uses client
- Firebase client → Firebase Firestore: reads and writes
- Driver terminal → Cloud Functions: dispatches SOS
- Cloud Functions → Twilio calls: places calls
- Cloud Functions → Slack alerts: posts alerts
- Cloud Functions → Telegram alerts: sends alerts
