# shivam-kumar-emf-portrait/health-emergency-app architecture

> Architecture diagram of the GitHub repository shivam-kumar-emf-portrait/health-emergency-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shivam-kumar-emf-portrait/health-emergency-app
- Repository: https://github.com/shivam-kumar-emf-portrait/health-emergency-app

## Overview

Health Assist is a hospital-capacity and emergency-coordination system, with hospital staff tools and a user-facing health chat. The principal emergency workflow is exposed through the Express API: emergency requests are handled by the emergency controller and matcher, while hospitals manage cases and operational resources through protected endpoints. The README also documents availability, blood-bank, equipment, and doctor-availability capabilities. Source excerpts do not show the browser-to-API wiring or all controller implementations, so those links are omitted where they cannot be supported.

Main entry points: [`backend/src/app.js`](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/app.js) (Express application), [`backend/src/controllers/staffController.js`](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/staffController.js) (Shifts and attendance), [`backend/src/controllers/emergencyController.js`](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/emergencyController.js) (Emergency case handling), [`backend/src/controllers/hospitalController.js`](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/hospitalController.js) (Hospital operations and cases)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_express_app["Express application<br/>[app.js]"]
  node_auth_routes["Authentication routes<br/>[authRoutes.js]"]
  node_auth_controller["Account registration and login<br/>[authController.js]"]
  node_auth_middleware["Token authorization<br/>[authMiddleware.js]"]
  node_user_model[("User records<br/>[User.js]")]
end

subgraph group_emergency["Emergency coordination"]
  node_emergency_routes["Emergency routes<br/>[emergencyRoutes.js]"]
  node_emergency_controller["Emergency case handling"]
  node_emergency_matcher["Hospital matching"]
  node_distance["Distance calculation<br/>[distance.js]"]
  node_case_model[("Emergency case records<br/>[EmergencyCase.js]")]
end

subgraph group_hospital["Hospital operations"]
  node_hospital_model[("Hospital records and resources<br/>[Hospital.js]")]
  node_hospital_routes["Hospital routes<br/>[hospitalRoutes.js]"]
  node_hospital_controller["Hospital operations and cases"]
end

subgraph group_staff["Staff management"]
  node_doctor_model[("Doctor records<br/>[Doctor.js]")]
  node_doctor_controller["Doctor management"]
  node_staff_routes["Staff routes<br/>[staffRoutes.js]"]
  node_staff_controller["Shifts and attendance<br/>[staffController.js]"]
  node_shift_model[("Shift records<br/>[Shift.js]")]
  node_attendance_model[("Attendance records<br/>[Attendance.js]")]
  node_nurse_controller["Nurse management<br/>[nurseController.js]"]
  node_nurse_model[("Nurse records<br/>[Nurse.js]")]
end

subgraph group_chat["Health chat"]
  node_normal_routes["Normal-mode routes"]
  node_normal_controller["Health chat handling"]
  node_chat_session[("Chat sessions<br/>[ChatSession.js]")]
  node_openrouter["OpenRouter chat service"]
end

node_user(("Patient or visitor"))
node_hospital_admin(("Hospital administrator"))

node_express_app -->|"mounts routes"| node_auth_routes
node_express_app -->|"mounts routes"| node_emergency_routes
node_express_app -->|"mounts routes"| node_hospital_routes
node_express_app -->|"mounts routes"| node_staff_routes
node_express_app -->|"mounts routes"| node_normal_routes
node_auth_routes -->|"dispatches to"| node_auth_controller
node_auth_controller -->|"reads and creates"| node_user_model
node_auth_controller -->|"reads and creates"| node_hospital_model
node_emergency_routes -->|"dispatches to"| node_emergency_controller
node_emergency_routes -->|"protects routes"| node_auth_middleware
node_emergency_controller -->|"requests matching"| node_emergency_matcher
node_emergency_controller -->|"reads hospitals"| node_hospital_model
node_emergency_controller -->|"reads and writes cases"| node_case_model
node_emergency_matcher -->|"uses distance"| node_distance
node_hospital_routes -->|"dispatches to"| node_hospital_controller
node_hospital_routes -->|"protects routes"| node_auth_middleware
node_hospital_controller -->|"reads and updates"| node_hospital_model
node_hospital_controller -->|"reads and updates"| node_case_model
node_hospital_controller -->|"assigns and queries"| node_doctor_model
node_staff_routes -->|"dispatches to"| node_staff_controller
node_staff_routes -->|"protects routes"| node_auth_middleware
node_staff_controller -->|"creates and reads"| node_shift_model
node_staff_controller -->|"records and reads"| node_attendance_model
node_staff_controller -->|"references staff"| node_doctor_model
node_staff_controller -->|"references staff"| node_nurse_model
node_normal_routes -->|"dispatches to"| node_normal_controller
node_normal_routes -->|"protects routes"| node_auth_middleware
node_normal_controller -->|"requests chat response"| node_openrouter
node_normal_controller -->|"reads and writes"| node_chat_session
node_doctor_controller -->|"manages doctors"| node_doctor_model
node_nurse_controller -->|"manages nurses"| node_nurse_model

click node_express_app "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/app.js"
click node_auth_routes "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/routes/authRoutes.js"
click node_auth_controller "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/authController.js"
click node_auth_middleware "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/middleware/authMiddleware.js"
click node_user_model "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/User.js"
click node_hospital_model "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/Hospital.js"
click node_emergency_routes "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/routes/emergencyRoutes.js"
click node_emergency_controller "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/emergencyController.js"
click node_emergency_matcher "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/services/emergencyMatcher.js"
click node_distance "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/utils/distance.js"
click node_case_model "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/EmergencyCase.js"
click node_hospital_routes "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/routes/hospitalRoutes.js"
click node_hospital_controller "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/hospitalController.js"
click node_doctor_model "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/Doctor.js"
click node_doctor_controller "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/doctorController.js"
click node_staff_routes "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/routes/staffRoutes.js"
click node_staff_controller "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/staffController.js"
click node_shift_model "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/Shift.js"
click node_attendance_model "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/Attendance.js"
click node_nurse_controller "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/nurseController.js"
click node_nurse_model "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/Nurse.js"
click node_normal_routes "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/routes/normalModeRoutes.js"
click node_normal_controller "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/normalModeController.js"
click node_chat_session "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/ChatSession.js"
click node_openrouter "https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/services/openRouterService.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_express_app,node_auth_routes,node_auth_controller,node_auth_middleware,node_user_model toneBlue
class node_emergency_routes,node_emergency_controller,node_emergency_matcher,node_distance,node_case_model toneAmber
class node_hospital_model,node_hospital_routes,node_hospital_controller toneMint
class node_doctor_model,node_doctor_controller,node_staff_routes,node_staff_controller,node_shift_model,node_attendance_model,node_nurse_controller,node_nurse_model toneRose
class node_normal_routes,node_normal_controller,node_chat_session,node_openrouter,node_user,node_hospital_admin toneIndigo
```

## Components

### API and access

- [Express application](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/app.js): `backend/src/app.js`
- [Authentication routes](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/routes/authRoutes.js): `backend/src/routes/authRoutes.js`
- [Account registration and login](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/authController.js): `backend/src/controllers/authController.js`
- [Token authorization](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/middleware/authMiddleware.js): `backend/src/middleware/authMiddleware.js`
- [User records](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/User.js): `backend/src/models/User.js`

### Emergency coordination

- [Emergency routes](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/routes/emergencyRoutes.js): `backend/src/routes/emergencyRoutes.js`
- [Emergency case handling](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/emergencyController.js): `backend/src/controllers/emergencyController.js`
- [Hospital matching](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/services/emergencyMatcher.js): `backend/src/services/emergencyMatcher.js`
- [Distance calculation](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/utils/distance.js): `backend/src/utils/distance.js`
- [Emergency case records](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/EmergencyCase.js): `backend/src/models/EmergencyCase.js`

### Hospital operations

- [Hospital records and resources](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/Hospital.js): `backend/src/models/Hospital.js`
- [Hospital routes](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/routes/hospitalRoutes.js): `backend/src/routes/hospitalRoutes.js`
- [Hospital operations and cases](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/hospitalController.js): `backend/src/controllers/hospitalController.js`

### Staff management

- [Doctor records](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/Doctor.js): `backend/src/models/Doctor.js`
- [Doctor management](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/doctorController.js): `backend/src/controllers/doctorController.js`
- [Staff routes](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/routes/staffRoutes.js): `backend/src/routes/staffRoutes.js`
- [Shifts and attendance](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/staffController.js): `backend/src/controllers/staffController.js`
- [Shift records](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/Shift.js): `backend/src/models/Shift.js`
- [Attendance records](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/Attendance.js): `backend/src/models/Attendance.js`
- [Nurse management](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/nurseController.js): `backend/src/controllers/nurseController.js`
- [Nurse records](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/Nurse.js): `backend/src/models/Nurse.js`

### Health chat

- [Normal-mode routes](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/routes/normalModeRoutes.js): `backend/src/routes/normalModeRoutes.js`
- [Health chat handling](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/controllers/normalModeController.js): `backend/src/controllers/normalModeController.js`
- [Chat sessions](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/models/ChatSession.js): `backend/src/models/ChatSession.js`
- [OpenRouter chat service](https://github.com/shivam-kumar-emf-portrait/health-emergency-app/blob/main/backend/src/services/openRouterService.js): `backend/src/services/openRouterService.js`

### Other components

- **Patient or visitor**
- **Hospital administrator**

## Connections

- Express application → Authentication routes: mounts routes (evidence: `backend/src/app.js`)
- Express application → Emergency routes: mounts routes (evidence: `backend/src/app.js`)
- Express application → Hospital routes: mounts routes (evidence: `backend/src/app.js`)
- Express application → Staff routes: mounts routes (evidence: `backend/src/app.js`)
- Express application → Normal-mode routes: mounts routes (evidence: `backend/src/app.js`)
- Authentication routes → Account registration and login: dispatches to (evidence: `backend/src/routes/authRoutes.js`)
- Account registration and login → User records: reads and creates (evidence: `backend/src/controllers/authController.js`)
- Account registration and login → Hospital records and resources: reads and creates (evidence: `backend/src/controllers/authController.js`)
- Emergency routes → Emergency case handling: dispatches to (evidence: `backend/src/routes/emergencyRoutes.js`)
- Emergency routes → Token authorization: protects routes (evidence: `backend/src/routes/emergencyRoutes.js`)
- Emergency case handling → Hospital matching: requests matching (evidence: `backend/src/controllers/emergencyController.js`)
- Emergency case handling → Hospital records and resources: reads hospitals (evidence: `backend/src/controllers/emergencyController.js`)
- Emergency case handling → Emergency case records: reads and writes cases (evidence: `backend/src/controllers/emergencyController.js`)
- Hospital matching → Distance calculation: uses distance (evidence: `backend/src/services/emergencyMatcher.js`)
- Hospital routes → Hospital operations and cases: dispatches to (evidence: `backend/src/routes/hospitalRoutes.js`)
- Hospital routes → Token authorization: protects routes (evidence: `backend/src/routes/hospitalRoutes.js`)
- Hospital operations and cases → Hospital records and resources: reads and updates (evidence: `backend/src/controllers/hospitalController.js`)
- Hospital operations and cases → Emergency case records: reads and updates (evidence: `backend/src/controllers/hospitalController.js`)
- Hospital operations and cases → Doctor records: assigns and queries (evidence: `backend/src/controllers/hospitalController.js`)
- Staff routes → Shifts and attendance: dispatches to (evidence: `backend/src/routes/staffRoutes.js`)
- Staff routes → Token authorization: protects routes (evidence: `backend/src/routes/staffRoutes.js`)
- Shifts and attendance → Shift records: creates and reads (evidence: `backend/src/controllers/staffController.js`)
- Shifts and attendance → Attendance records: records and reads (evidence: `backend/src/controllers/staffController.js`)
- Shifts and attendance → Doctor records: references staff (evidence: `backend/src/controllers/staffController.js`)
- Shifts and attendance → Nurse records: references staff (evidence: `backend/src/controllers/staffController.js`)
- Normal-mode routes → Health chat handling: dispatches to (evidence: `backend/src/routes/normalModeRoutes.js`)
- Normal-mode routes → Token authorization: protects routes (evidence: `backend/src/routes/normalModeRoutes.js`)
- Health chat handling → OpenRouter chat service: requests chat response (evidence: `backend/src/controllers/normalModeController.js`)
- Health chat handling → Chat sessions: reads and writes (evidence: `backend/src/controllers/normalModeController.js`)
- Doctor management → Doctor records: manages doctors (evidence: `backend/src/controllers/doctorController.js`)
- Nurse management → Nurse records: manages nurses (evidence: `backend/src/controllers/nurseController.js`)
