# prabhatbhatiaa/yatrashield architecture

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

- Interactive diagram: https://gitdiagram.com/prabhatbhatiaa/yatrashield
- Repository: https://github.com/prabhatbhatiaa/yatrashield

## Overview

YatraShield is a role-based incident reporting and response platform. Tourists submit incidents (including SOS), then track updates; responders work assigned incidents, while supervisors/admins review queues, assign responders, and advance statuses. The backend persists users/incidents, computes priority, emits Socket.IO notifications, and periodically escalates overdue work. The frontend provides role-specific dashboards, geolocation/maps, authentication, and safety information. Edges reflect README contracts and shown imports/calls; unsampled paths and runtime wiring are represented conservatively.

Main entry points: [`frontend/src/App.jsx`](https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/App.jsx) (App routing), [`backend/server.js`](https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/server.js) (API server), [`backend/controllers/incident.controller.js`](https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/controllers/incident.controller.js) (Incident operations), [`frontend/src/hooks/useIncidents.js`](https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/hooks/useIncidents.js) (Incident feed)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_app["App routing<br/>[App.jsx]"]
  node_authui["Auth screens<br/>[Login.jsx]"]
  node_report["Report and SOS<br/>[ReportIncident.jsx]"]
  node_tourist["Tourist dashboard"]
  node_authority["Authority dashboard"]
  node_detail["Incident detail<br/>[IncidentDetail.jsx]"]
  node_safety["Safety information<br/>[SafetyInfo.jsx]"]
  node_maps["Incident maps<br/>[MapView.jsx]"]
end

subgraph group_client["Client services"]
  node_authstate["Session state<br/>[AuthContext.jsx]"]
  node_api_client["HTTP client<br/>[api.js]"]
  node_incident_hook["Incident feed<br/>[useIncidents.js]"]
  node_socket_client["Live socket<br/>[socket.js]"]
end

subgraph group_api["Backend API"]
  node_express["API server<br/>[server.js]"]
  node_auth_routes["Auth routes<br/>[auth.routes.js]"]
  node_incident_routes["Incident routes<br/>[incident.routes.js]"]
  node_user_routes["User routes<br/>[user.routes.js]"]
  node_auth_controller["Authentication<br/>[auth.controller.js]"]
  node_user_controller["User operations<br/>[user.controller.js]"]
end

subgraph group_domain["Incident domain"]
  node_incident_controller["Incident operations"]
  node_priority["Priority engine<br/>[priorityEngine.js]"]
  node_escalation["Overdue escalation"]
  node_incident_store[("Incident records<br/>[incident.js]")]
  node_user_store[("User records<br/>[user.js]")]
end

subgraph group_runtime["Runtime services"]
  node_db[("Mongo connection<br/>[db.js]")]
  node_socket_io["Socket.IO service<br/>[server.js]"]
end

node_user(("Platform user"))
node_mongo[("MongoDB")]

node_user -->|"uses"| node_app
node_app -->|"routes to"| node_authui
node_app -->|"routes to"| node_tourist
node_app -->|"routes to"| node_report
node_app -->|"routes to"| node_authority
node_app -->|"routes to"| node_detail
node_app -->|"routes to"| node_safety
node_user -.->|"signs in"| node_authui
node_authui -->|"updates session"| node_authstate
node_authstate -->|"calls auth API"| node_api_client
node_report -->|"creates incident"| node_api_client
node_tourist -->|"loads incidents"| node_incident_hook
node_authority -->|"loads incidents"| node_incident_hook
node_authority -->|"assigns responders"| node_api_client
node_detail -->|"loads incident"| node_incident_hook
node_incident_hook -->|"fetches incidents"| node_api_client
node_incident_hook -->|"subscribes events"| node_socket_client
node_tourist -->|"renders locations"| node_maps
node_authority -->|"renders queue map"| node_maps
node_api_client -->|"HTTP requests"| node_express
node_socket_client -->|"connects events"| node_socket_io
node_express -->|"mounts routes"| node_auth_routes
node_express -->|"mounts routes"| node_incident_routes
node_express -->|"mounts routes"| node_user_routes
node_auth_routes -->|"dispatches"| node_auth_controller
node_incident_routes -->|"dispatches"| node_incident_controller
node_user_routes -->|"dispatches"| node_user_controller
node_incident_controller -->|"computes priority"| node_priority
node_incident_controller -->|"reads and writes"| node_incident_store
node_incident_controller -->|"looks up responders"| node_user_store
node_auth_controller -->|"reads and writes"| node_user_store
node_user_controller -->|"reads users"| node_user_store
node_express -->|"checks overdue"| node_escalation
node_escalation -->|"updates incidents"| node_incident_store
node_escalation -->|"reads responders"| node_user_store
node_db -.->|"connects"| node_mongo
node_express -->|"starts connection"| node_db
node_express -->|"hosts sockets"| node_socket_io
node_incident_controller -->|"emits updates"| node_socket_io

click node_app "https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/App.jsx"
click node_authui "https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/pages/Login.jsx"
click node_report "https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/pages/ReportIncident.jsx"
click node_tourist "https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/pages/TouristDashboard.jsx"
click node_authority "https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/pages/AuthorityDashboard.jsx"
click node_detail "https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/pages/IncidentDetail.jsx"
click node_safety "https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/pages/SafetyInfo.jsx"
click node_maps "https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/components/MapView.jsx"
click node_authstate "https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/context/AuthContext.jsx"
click node_api_client "https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/api/api.js"
click node_incident_hook "https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/hooks/useIncidents.js"
click node_socket_client "https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/api/socket.js"
click node_express "https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/server.js"
click node_auth_routes "https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/routes/auth.routes.js"
click node_incident_routes "https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/routes/incident.routes.js"
click node_user_routes "https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/routes/user.routes.js"
click node_auth_controller "https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/controllers/auth.controller.js"
click node_incident_controller "https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/controllers/incident.controller.js"
click node_user_controller "https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/controllers/user.controller.js"
click node_priority "https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/utils/priorityEngine.js"
click node_escalation "https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/services/escalationService.js"
click node_incident_store "https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/models/incident.js"
click node_user_store "https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/models/user.js"
click node_db "https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/config/db.js"
click node_socket_io "https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/server.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_app,node_authui,node_report,node_tourist,node_authority,node_detail,node_safety,node_maps,node_user toneBlue
class node_authstate,node_api_client,node_incident_hook,node_socket_client,node_mongo toneAmber
class node_express,node_auth_routes,node_incident_routes,node_user_routes,node_auth_controller,node_user_controller toneMint
class node_incident_controller,node_priority,node_escalation,node_incident_store,node_user_store toneRose
class node_db,node_socket_io toneIndigo
```

## Components

### Web experience

- [App routing](https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Auth screens](https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/pages/Login.jsx): `frontend/src/pages/Login.jsx`
- [Report and SOS](https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/pages/ReportIncident.jsx): `frontend/src/pages/ReportIncident.jsx`
- [Tourist dashboard](https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/pages/TouristDashboard.jsx): `frontend/src/pages/TouristDashboard.jsx`
- [Authority dashboard](https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/pages/AuthorityDashboard.jsx): `frontend/src/pages/AuthorityDashboard.jsx`
- [Incident detail](https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/pages/IncidentDetail.jsx): `frontend/src/pages/IncidentDetail.jsx`
- [Safety information](https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/pages/SafetyInfo.jsx): `frontend/src/pages/SafetyInfo.jsx`
- [Incident maps](https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/components/MapView.jsx): `frontend/src/components/MapView.jsx`

### Client services

- [Session state](https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [HTTP client](https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/api/api.js): `frontend/src/api/api.js`
- [Incident feed](https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/hooks/useIncidents.js): `frontend/src/hooks/useIncidents.js`
- [Live socket](https://github.com/prabhatbhatiaa/yatrashield/blob/main/frontend/src/api/socket.js): `frontend/src/api/socket.js`

### Backend API

- [API server](https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/server.js): `backend/server.js`
- [Auth routes](https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/routes/auth.routes.js): `backend/routes/auth.routes.js`
- [Incident routes](https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/routes/incident.routes.js): `backend/routes/incident.routes.js`
- [User routes](https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/routes/user.routes.js): `backend/routes/user.routes.js`
- [Authentication](https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/controllers/auth.controller.js): `backend/controllers/auth.controller.js`
- [User operations](https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/controllers/user.controller.js): `backend/controllers/user.controller.js`

### Incident domain

- [Incident operations](https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/controllers/incident.controller.js): `backend/controllers/incident.controller.js`
- [Priority engine](https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/utils/priorityEngine.js): `backend/utils/priorityEngine.js`
- [Overdue escalation](https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/services/escalationService.js): `backend/services/escalationService.js`
- [Incident records](https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/models/incident.js): `backend/models/incident.js`
- [User records](https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/models/user.js): `backend/models/user.js`

### Runtime services

- [Mongo connection](https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/config/db.js): `backend/config/db.js`
- [Socket.IO service](https://github.com/prabhatbhatiaa/yatrashield/blob/main/backend/server.js): `backend/server.js`

### Other components

- **Platform user**
- **MongoDB**

## Connections

- Platform user → App routing: uses (evidence: `frontend/src/App.jsx`)
- App routing → Auth screens: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Tourist dashboard: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Report and SOS: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Authority dashboard: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Incident detail: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Safety information: routes to (evidence: `frontend/src/App.jsx`)
- Platform user → Auth screens: signs in
- Auth screens → Session state: updates session (evidence: `frontend/src/context/AuthContext.jsx`)
- Session state → HTTP client: calls auth API (evidence: `frontend/src/context/AuthContext.jsx`)
- Report and SOS → HTTP client: creates incident
- Tourist dashboard → Incident feed: loads incidents (evidence: `frontend/src/pages/TouristDashboard.jsx`)
- Authority dashboard → Incident feed: loads incidents (evidence: `frontend/src/pages/AuthorityDashboard.jsx`)
- Authority dashboard → HTTP client: assigns responders (evidence: `frontend/src/pages/AuthorityDashboard.jsx`)
- Incident detail → Incident feed: loads incident (evidence: `frontend/src/pages/IncidentDetail.jsx`)
- Incident feed → HTTP client: fetches incidents (evidence: `frontend/src/hooks/useIncidents.js`)
- Incident feed → Live socket: subscribes events (evidence: `frontend/src/hooks/useIncidents.js`)
- Tourist dashboard → Incident maps: renders locations (evidence: `frontend/src/pages/TouristDashboard.jsx`)
- Authority dashboard → Incident maps: renders queue map (evidence: `frontend/src/pages/AuthorityDashboard.jsx`)
- HTTP client → API server: HTTP requests
- Live socket → Socket.IO service: connects events
- API server → Auth routes: mounts routes (evidence: `backend/server.js`)
- API server → Incident routes: mounts routes (evidence: `backend/server.js`)
- API server → User routes: mounts routes (evidence: `backend/server.js`)
- Auth routes → Authentication: dispatches (evidence: `backend/routes/auth.routes.js`)
- Incident routes → Incident operations: dispatches (evidence: `backend/routes/incident.routes.js`)
- User routes → User operations: dispatches (evidence: `backend/routes/user.routes.js`)
- Incident operations → Priority engine: computes priority (evidence: `backend/controllers/incident.controller.js`)
- Incident operations → Incident records: reads and writes (evidence: `backend/controllers/incident.controller.js`)
- Incident operations → User records: looks up responders (evidence: `backend/controllers/incident.controller.js`)
- Authentication → User records: reads and writes (evidence: `backend/controllers/auth.controller.js`)
- User operations → User records: reads users (evidence: `backend/controllers/user.controller.js`)
- API server → Overdue escalation: checks overdue (evidence: `backend/server.js`)
- Overdue escalation → Incident records: updates incidents (evidence: `backend/services/escalationService.js`)
- Overdue escalation → User records: reads responders (evidence: `backend/services/escalationService.js`)
- Mongo connection → MongoDB: connects
- API server → Mongo connection: starts connection (evidence: `backend/server.js`)
- API server → Socket.IO service: hosts sockets (evidence: `backend/server.js`)
- Incident operations → Socket.IO service: emits updates (evidence: `backend/controllers/incident.controller.js`)
