# rahulanugula/resq---ai architecture

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

- Interactive diagram: https://gitdiagram.com/rahulanugula/resq---ai
- Repository: https://github.com/rahulanugula/resq---ai

## Overview

ResQ AI is a disaster and emergency response platform for citizens, operators, and incident commanders. Citizens submit incidents, which the backend analyzes, checks for duplicates, identifies nearby response resources and hospitals, and returns dispatch information; operators manage incidents and resources while citizens and operators receive live updates. Separate capabilities cover authentication, analytics and administration, alerts, multilingual and voice assistance, family safety, volunteers, and risk mapping. The graph follows documented routing and source-index references; unsampled features are included where the README or tree supports them, without assuming their internal call paths.

Main entry points: [`backend/database.py`](https://github.com/rahulanugula/resq---ai/blob/main/backend/database.py) (Database and Fallback), [`backend/main.py`](https://github.com/rahulanugula/resq---ai/blob/main/backend/main.py) (FastAPI Application), [`backend/routes/emergencies.py`](https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/emergencies.py) (Incident Reporting), [`backend/services/websocket_manager.py`](https://github.com/rahulanugula/resq---ai/blob/main/backend/services/websocket_manager.py) (WebSocket Manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User Experience"]
  node_web_ui["Web Dashboards"]
  node_frontend_api["Frontend API Client<br/>[api.js]"]
end

subgraph group_incident["Incident Response"]
  node_incidents["Incident Reporting<br/>[emergencies.py]"]
  node_duplicate_detection["Duplicate Detection"]
  node_routing["Dispatch Routing<br/>[routing_service.py]"]
  node_hospitals["Hospital Finder<br/>[hospitals.py]"]
  node_websocket_route["Live Feed Endpoint"]
  node_osrm{{"OSRM Routing Service"}}
end

subgraph group_operations["Operations"]
  node_resources["Resource Management<br/>[resources.py]"]
  node_admin["Administration<br/>[admin.py]"]
  node_analytics["Incident Analytics<br/>[analytics.py]"]
  node_family_safety["Family Safety<br/>[family_safe.py]"]
  node_volunteers["Volunteer Coordination<br/>[volunteers.py]"]
  node_riskmap["Predictive Risk Map<br/>[riskmap.py]"]
end

subgraph group_assistance["AI and Assistance"]
  node_ai_analysis["Emergency AI Analysis<br/>[gemini_service.py]"]
  node_alerts["Public Alerts<br/>[alerts.py]"]
  node_multilingual["Multilingual Support<br/>[multilingual.py]"]
  node_voice_chat["Voice and Chat<br/>[voice.py]"]
  node_gemini{{"Google Gemini"}}
end

subgraph group_platform["Platform Services"]
  node_app["FastAPI Application<br/>[main.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_auth_middleware["JWT and Roles<br/>[auth_middleware.py]"]
  node_websocket_manager["WebSocket Manager"]
  node_database[("Database and Fallback<br/>[database.py]")]
end

node_citizens(("Citizens"))
node_operators(("Operators"))

node_citizens -->|"use dashboards"| node_web_ui
node_operators -->|"use dashboards"| node_web_ui
node_web_ui -.->|"request backend data"| node_frontend_api
node_frontend_api -.->|"call API"| node_app
node_app -->|"mounts router"| node_auth
node_app -->|"mounts router"| node_incidents
node_app -->|"mounts router"| node_resources
node_app -->|"mounts router"| node_hospitals
node_app -->|"mounts router"| node_analytics
node_app -->|"mounts router"| node_admin
node_app -->|"mounts router"| node_websocket_route
node_auth -->|"reads and writes users"| node_database
node_auth -->|"uses token functions"| node_auth_middleware
node_auth_middleware -->|"loads user"| node_database
node_incidents -->|"reads and writes incidents"| node_database
node_incidents -->|"analyzes reports"| node_ai_analysis
node_incidents -->|"checks duplicates"| node_duplicate_detection
node_incidents -->|"requests route"| node_routing
node_incidents -->|"finds nearby hospitals"| node_hospitals
node_incidents -->|"broadcasts updates"| node_websocket_manager
node_routing -->|"requests route"| node_osrm
node_hospitals -->|"reads hospital records"| node_database
node_hospitals -->|"requests route"| node_routing
node_resources -->|"manages resources"| node_database
node_admin -->|"manages platform data"| node_database
node_analytics -->|"queries incident metrics"| node_database
node_alerts -->|"generates alert text"| node_ai_analysis
node_alerts -->|"broadcasts alerts"| node_websocket_manager
node_alerts -->|"reads incident data"| node_database
node_multilingual -.->|"uses application data"| node_database
node_voice_chat -->|"requests AI responses"| node_ai_analysis
node_family_safety -->|"stores safety updates"| node_database
node_volunteers -->|"manages volunteer records"| node_database
node_riskmap -->|"reads incident data"| node_database
node_websocket_route -->|"connects clients"| node_websocket_manager
node_websocket_manager -.->|"pushes live updates"| node_operators
node_websocket_manager -.->|"pushes live updates"| node_citizens
node_ai_analysis -.->|"generates analysis"| node_gemini

click node_web_ui "https://github.com/rahulanugula/resq---ai/tree/main/frontend"
click node_frontend_api "https://github.com/rahulanugula/resq---ai/blob/main/frontend/js/api.js"
click node_app "https://github.com/rahulanugula/resq---ai/blob/main/backend/main.py"
click node_auth "https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/auth.py"
click node_auth_middleware "https://github.com/rahulanugula/resq---ai/blob/main/backend/middleware/auth_middleware.py"
click node_incidents "https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/emergencies.py"
click node_ai_analysis "https://github.com/rahulanugula/resq---ai/blob/main/backend/ai/gemini_service.py"
click node_duplicate_detection "https://github.com/rahulanugula/resq---ai/blob/main/backend/services/duplicate_detector.py"
click node_routing "https://github.com/rahulanugula/resq---ai/blob/main/backend/ai/routing_service.py"
click node_hospitals "https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/hospitals.py"
click node_resources "https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/resources.py"
click node_admin "https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/admin.py"
click node_analytics "https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/analytics.py"
click node_alerts "https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/alerts.py"
click node_multilingual "https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/multilingual.py"
click node_voice_chat "https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/voice.py"
click node_family_safety "https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/family_safe.py"
click node_volunteers "https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/volunteers.py"
click node_riskmap "https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/riskmap.py"
click node_websocket_route "https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/websocket_routes.py"
click node_websocket_manager "https://github.com/rahulanugula/resq---ai/blob/main/backend/services/websocket_manager.py"
click node_database "https://github.com/rahulanugula/resq---ai/blob/main/backend/database.py"

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_web_ui,node_frontend_api toneBlue
class node_incidents,node_duplicate_detection,node_routing,node_hospitals,node_websocket_route,node_osrm toneAmber
class node_resources,node_admin,node_analytics,node_family_safety,node_volunteers,node_riskmap toneMint
class node_ai_analysis,node_alerts,node_multilingual,node_voice_chat,node_gemini toneRose
class node_app,node_auth,node_auth_middleware,node_websocket_manager,node_database,node_citizens,node_operators toneIndigo
```

## Components

### User Experience

- [Web Dashboards](https://github.com/rahulanugula/resq---ai/tree/main/frontend): `frontend`
- [Frontend API Client](https://github.com/rahulanugula/resq---ai/blob/main/frontend/js/api.js): `frontend/js/api.js`

### Incident Response

- [Incident Reporting](https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/emergencies.py): `backend/routes/emergencies.py`
- [Duplicate Detection](https://github.com/rahulanugula/resq---ai/blob/main/backend/services/duplicate_detector.py): `backend/services/duplicate_detector.py`
- [Dispatch Routing](https://github.com/rahulanugula/resq---ai/blob/main/backend/ai/routing_service.py): `backend/ai/routing_service.py`
- [Hospital Finder](https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/hospitals.py): `backend/routes/hospitals.py`
- [Live Feed Endpoint](https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/websocket_routes.py): `backend/routes/websocket_routes.py`
- **OSRM Routing Service**

### Operations

- [Resource Management](https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/resources.py): `backend/routes/resources.py`
- [Administration](https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/admin.py): `backend/routes/admin.py`
- [Incident Analytics](https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/analytics.py): `backend/routes/analytics.py`
- [Family Safety](https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/family_safe.py): `backend/routes/family_safe.py`
- [Volunteer Coordination](https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/volunteers.py): `backend/routes/volunteers.py`
- [Predictive Risk Map](https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/riskmap.py): `backend/routes/riskmap.py`

### AI and Assistance

- [Emergency AI Analysis](https://github.com/rahulanugula/resq---ai/blob/main/backend/ai/gemini_service.py): `backend/ai/gemini_service.py`
- [Public Alerts](https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/alerts.py): `backend/routes/alerts.py`
- [Multilingual Support](https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/multilingual.py): `backend/routes/multilingual.py`
- [Voice and Chat](https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/voice.py): `backend/routes/voice.py`
- **Google Gemini**

### Platform Services

- [FastAPI Application](https://github.com/rahulanugula/resq---ai/blob/main/backend/main.py): `backend/main.py`
- [Authentication](https://github.com/rahulanugula/resq---ai/blob/main/backend/routes/auth.py): `backend/routes/auth.py`
- [JWT and Roles](https://github.com/rahulanugula/resq---ai/blob/main/backend/middleware/auth_middleware.py): `backend/middleware/auth_middleware.py`
- [WebSocket Manager](https://github.com/rahulanugula/resq---ai/blob/main/backend/services/websocket_manager.py): `backend/services/websocket_manager.py`
- [Database and Fallback](https://github.com/rahulanugula/resq---ai/blob/main/backend/database.py): `backend/database.py`

### Other components

- **Citizens**
- **Operators**

## Connections

- Citizens → Web Dashboards: use dashboards (evidence: `README.md`)
- Operators → Web Dashboards: use dashboards (evidence: `README.md`)
- Web Dashboards → Frontend API Client: request backend data
- Frontend API Client → FastAPI Application: call API
- FastAPI Application → Authentication: mounts router (evidence: `backend/main.py`)
- FastAPI Application → Incident Reporting: mounts router (evidence: `backend/main.py`)
- FastAPI Application → Resource Management: mounts router (evidence: `backend/main.py`)
- FastAPI Application → Hospital Finder: mounts router (evidence: `backend/main.py`)
- FastAPI Application → Incident Analytics: mounts router (evidence: `backend/main.py`)
- FastAPI Application → Administration: mounts router (evidence: `backend/main.py`)
- FastAPI Application → Live Feed Endpoint: mounts router (evidence: `backend/main.py`)
- Authentication → Database and Fallback: reads and writes users (evidence: `backend/routes/auth.py`)
- Authentication → JWT and Roles: uses token functions (evidence: `backend/routes/auth.py`)
- JWT and Roles → Database and Fallback: loads user (evidence: `backend/middleware/auth_middleware.py`)
- Incident Reporting → Database and Fallback: reads and writes incidents (evidence: `backend/routes/emergencies.py`)
- Incident Reporting → Emergency AI Analysis: analyzes reports (evidence: `backend/routes/emergencies.py`)
- Incident Reporting → Duplicate Detection: checks duplicates (evidence: `backend/routes/emergencies.py`)
- Incident Reporting → Dispatch Routing: requests route (evidence: `backend/routes/emergencies.py`)
- Incident Reporting → Hospital Finder: finds nearby hospitals (evidence: `backend/routes/emergencies.py`)
- Incident Reporting → WebSocket Manager: broadcasts updates (evidence: `backend/routes/emergencies.py`)
- Dispatch Routing → OSRM Routing Service: requests route (evidence: `backend/ai/routing_service.py`)
- Hospital Finder → Database and Fallback: reads hospital records (evidence: `backend/routes/hospitals.py`)
- Hospital Finder → Dispatch Routing: requests route (evidence: `backend/routes/hospitals.py`)
- Resource Management → Database and Fallback: manages resources (evidence: `backend/routes/resources.py`)
- Administration → Database and Fallback: manages platform data (evidence: `backend/routes/admin.py`)
- Incident Analytics → Database and Fallback: queries incident metrics (evidence: `backend/routes/analytics.py`)
- Public Alerts → Emergency AI Analysis: generates alert text (evidence: `backend/routes/alerts.py`)
- Public Alerts → WebSocket Manager: broadcasts alerts (evidence: `backend/routes/alerts.py`)
- Public Alerts → Database and Fallback: reads incident data (evidence: `backend/routes/alerts.py`)
- Multilingual Support → Database and Fallback: uses application data
- Voice and Chat → Emergency AI Analysis: requests AI responses (evidence: `backend/routes/voice.py`)
- Family Safety → Database and Fallback: stores safety updates (evidence: `backend/routes/family_safe.py`)
- Volunteer Coordination → Database and Fallback: manages volunteer records (evidence: `backend/routes/volunteers.py`)
- Predictive Risk Map → Database and Fallback: reads incident data (evidence: `backend/routes/riskmap.py`)
- Live Feed Endpoint → WebSocket Manager: connects clients (evidence: `backend/routes/websocket_routes.py`)
- WebSocket Manager → Operators: pushes live updates
- WebSocket Manager → Citizens: pushes live updates
- Emergency AI Analysis → Google Gemini: generates analysis
