# disaster-warning-system/disaster-warning-backend architecture

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

- Interactive diagram: https://gitdiagram.com/disaster-warning-system/disaster-warning-backend
- Repository: https://github.com/disaster-warning-system/disaster-warning-backend

## Overview

Disaster Warning Backend is an Express/MongoDB API for hazard reports, officer verification, emergency-alert dispatch, shelter operations, and user authentication. Citizens submit reports and hazard photos; duty officers review reports, while officers can issue alerts to resolved recipients over simulated SMS and Push channels. District Officers manage shelters and their images, including occupancy history. The graph follows documented routes and sampled calls; some service and route wiring is supported only by the SOURCE INDEX, and unsampled capabilities are included where the README documents them.

Main entry points: [`src/server.js`](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/server.js) (Express API), [`src/controllers/alertController.js`](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/alertController.js) (Alert workflow), [`src/controllers/hazardReportController.js`](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/hazardReportController.js) (Report submission), [`src/controllers/verificationController.js`](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/verificationController.js) (Officer review)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_server["Express API<br/>[server.js]"]
  node_auth["JWT access<br/>[authMiddleware.js]"]
  node_users["Account handlers<br/>[userController.js]"]
end

subgraph group_reports["Hazard reports"]
  node_report_routes["Report routes"]
  node_report_handler["Report submission"]
  node_report_validation["Report validation"]
  node_photo_api["Hazard photo API"]
  node_verification_routes["Review routes"]
  node_verification_handler["Officer review"]
end

subgraph group_alerts["Warning dispatch"]
  node_alert_routes["Alert routes<br/>[alertRoutes.js]"]
  node_alert_handler["Alert workflow<br/>[alertController.js]"]
  node_recipient_resolver["Recipient resolution"]
  node_citizen_repo[("Simulated citizens")]
  node_dispatch["Channel dispatch"]
  node_sms["SMS adapter<br/>[smsAdapter.js]"]
  node_push["Push adapter<br/>[pushAdapter.js]"]
end

subgraph group_shelters["Shelter operations"]
  node_shelter_routes["Shelter routes<br/>[shelterRoutes.js]"]
  node_shelter_handler["Shelter operations"]
  node_shelter_service["Shelter service<br/>[shelterService.js]"]
  node_shelter_validation["Shelter validation"]
  node_shelter_image_handler["Shelter image API"]
  node_shelter_image_store[("Shelter image storage")]
end

subgraph group_persistence["Persistence and media"]
  node_user_model[("User records<br/>[User.js]")]
  node_report_model[("Hazard reports<br/>[HazardReport.js]")]
  node_gridfs[("Hazard photo files<br/>[gridfsService.js]")]
  node_verification_model[("Review history<br/>[Verification.js]")]
  node_alert_model[("Alert records<br/>[Alert.js]")]
  node_shelter_model[("Shelter records<br/>[Shelter.js]")]
  node_database[("MongoDB connection<br/>[database.js]")]
end

node_citizens(("Citizens"))
node_officers(("Duty officers"))
node_district_staff(("District Officers"))

node_citizens -->|"submit requests"| node_server
node_officers -->|"review reports"| node_server
node_district_staff -->|"manage shelters"| node_server
node_server -->|"connects"| node_database
node_server -->|"mounts"| node_report_routes
node_server -->|"mounts"| node_verification_routes
node_server -->|"mounts"| node_alert_routes
node_server -->|"mounts"| node_shelter_routes
node_server -->|"mounts auth API"| node_users
node_users -->|"reads and writes"| node_user_model
node_report_routes -->|"protects routes"| node_auth
node_report_routes -->|"routes requests"| node_report_handler
node_report_handler -->|"validates input"| node_report_validation
node_report_handler -->|"creates reports"| node_report_model
node_report_handler -->|"checks photo file"| node_gridfs
node_citizens -->|"upload or fetch photo"| node_photo_api
node_photo_api -->|"stores and streams"| node_gridfs
node_verification_routes -->|"protects routes"| node_auth
node_verification_routes -->|"routes review"| node_verification_handler
node_verification_handler -->|"updates decisions"| node_report_model
node_verification_handler -->|"records decisions"| node_verification_model
node_verification_handler -->|"loads reporter"| node_user_model
node_alert_routes -->|"protects routes"| node_auth
node_alert_routes -->|"routes requests"| node_alert_handler
node_alert_handler -->|"checks source report"| node_report_model
node_alert_handler -->|"resolves recipients"| node_recipient_resolver
node_recipient_resolver -->|"queries simulated registry"| node_citizen_repo
node_alert_handler -->|"persists alert status"| node_alert_model
node_alert_handler -->|"dispatches channels"| node_dispatch
node_dispatch -->|"sends SMS"| node_sms
node_dispatch -->|"sends Push"| node_push
node_shelter_routes -->|"guards staff actions"| node_auth
node_shelter_routes -->|"routes operations"| node_shelter_handler
node_shelter_routes -->|"mounts image routes"| node_shelter_image_handler
node_shelter_handler -->|"validates input"| node_shelter_validation
node_shelter_handler -->|"delegates operations"| node_shelter_service
node_shelter_service -->|"reads and updates"| node_shelter_model
node_shelter_service -->|"manages images"| node_shelter_image_store
node_shelter_image_handler -->|"stores and retrieves"| node_shelter_image_store
node_shelter_image_handler -->|"updates image reference"| node_shelter_model

click node_server "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/server.js"
click node_auth "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/middleware/authMiddleware.js"
click node_users "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/userController.js"
click node_user_model "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/models/User.js"
click node_report_routes "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/routes/hazardReportRoutes.js"
click node_report_handler "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/hazardReportController.js"
click node_report_validation "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/validators/hazardReportValidator.js"
click node_report_model "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/models/HazardReport.js"
click node_photo_api "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/uploadController.js"
click node_gridfs "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/services/gridfsService.js"
click node_verification_routes "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/routes/verificationRoutes.js"
click node_verification_handler "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/verificationController.js"
click node_verification_model "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/models/Verification.js"
click node_alert_routes "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/routes/alertRoutes.js"
click node_alert_handler "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/alertController.js"
click node_recipient_resolver "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/services/recipientResolver.js"
click node_citizen_repo "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/repositories/mockCitizenRepository.js"
click node_dispatch "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/services/alertDispatchService.js"
click node_sms "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/adapters/smsAdapter.js"
click node_push "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/adapters/pushAdapter.js"
click node_alert_model "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/models/Alert.js"
click node_shelter_routes "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/routes/shelterRoutes.js"
click node_shelter_handler "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/shelterController.js"
click node_shelter_service "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/services/shelterService.js"
click node_shelter_validation "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/validators/shelterValidator.js"
click node_shelter_model "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/models/Shelter.js"
click node_shelter_image_handler "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/shelterImageController.js"
click node_shelter_image_store "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/services/shelterImageStorageService.js"
click node_database "https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/config/database.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_server,node_auth,node_users toneBlue
class node_report_routes,node_report_handler,node_report_validation,node_photo_api,node_verification_routes,node_verification_handler toneAmber
class node_alert_routes,node_alert_handler,node_recipient_resolver,node_citizen_repo,node_dispatch,node_sms,node_push toneMint
class node_shelter_routes,node_shelter_handler,node_shelter_service,node_shelter_validation,node_shelter_image_handler,node_shelter_image_store toneRose
class node_user_model,node_report_model,node_gridfs,node_verification_model,node_alert_model,node_shelter_model,node_database,node_citizens,node_officers,node_district_staff toneIndigo
```

## Components

### API and access

- [Express API](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/server.js): `src/server.js`
- [JWT access](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/middleware/authMiddleware.js): `src/middleware/authMiddleware.js`
- [Account handlers](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/userController.js): `src/controllers/userController.js`

### Hazard reports

- [Report routes](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/routes/hazardReportRoutes.js): `src/routes/hazardReportRoutes.js`
- [Report submission](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/hazardReportController.js): `src/controllers/hazardReportController.js`
- [Report validation](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/validators/hazardReportValidator.js): `src/validators/hazardReportValidator.js`
- [Hazard photo API](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/uploadController.js): `src/controllers/uploadController.js`
- [Review routes](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/routes/verificationRoutes.js): `src/routes/verificationRoutes.js`
- [Officer review](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/verificationController.js): `src/controllers/verificationController.js`

### Warning dispatch

- [Alert routes](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/routes/alertRoutes.js): `src/routes/alertRoutes.js`
- [Alert workflow](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/alertController.js): `src/controllers/alertController.js`
- [Recipient resolution](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/services/recipientResolver.js): `src/services/recipientResolver.js`
- [Simulated citizens](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/repositories/mockCitizenRepository.js): `src/repositories/mockCitizenRepository.js`
- [Channel dispatch](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/services/alertDispatchService.js): `src/services/alertDispatchService.js`
- [SMS adapter](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/adapters/smsAdapter.js): `src/adapters/smsAdapter.js`
- [Push adapter](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/adapters/pushAdapter.js): `src/adapters/pushAdapter.js`

### Shelter operations

- [Shelter routes](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/routes/shelterRoutes.js): `src/routes/shelterRoutes.js`
- [Shelter operations](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/shelterController.js): `src/controllers/shelterController.js`
- [Shelter service](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/services/shelterService.js): `src/services/shelterService.js`
- [Shelter validation](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/validators/shelterValidator.js): `src/validators/shelterValidator.js`
- [Shelter image API](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/controllers/shelterImageController.js): `src/controllers/shelterImageController.js`
- [Shelter image storage](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/services/shelterImageStorageService.js): `src/services/shelterImageStorageService.js`

### Persistence and media

- [User records](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/models/User.js): `src/models/User.js`
- [Hazard reports](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/models/HazardReport.js): `src/models/HazardReport.js`
- [Hazard photo files](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/services/gridfsService.js): `src/services/gridfsService.js`
- [Review history](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/models/Verification.js): `src/models/Verification.js`
- [Alert records](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/models/Alert.js): `src/models/Alert.js`
- [Shelter records](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/models/Shelter.js): `src/models/Shelter.js`
- [MongoDB connection](https://github.com/disaster-warning-system/disaster-warning-backend/blob/main/src/config/database.js): `src/config/database.js`

### Other components

- **Citizens**
- **Duty officers**
- **District Officers**

## Connections

- Citizens → Express API: submit requests (evidence: `README.md`)
- Duty officers → Express API: review reports (evidence: `README.md`)
- District Officers → Express API: manage shelters (evidence: `README.md`)
- Express API → MongoDB connection: connects (evidence: `src/server.js`)
- Express API → Report routes: mounts (evidence: `src/server.js`)
- Express API → Review routes: mounts (evidence: `src/server.js`)
- Express API → Alert routes: mounts (evidence: `src/server.js`)
- Express API → Shelter routes: mounts (evidence: `src/server.js`)
- Express API → Account handlers: mounts auth API (evidence: `src/server.js`)
- Account handlers → User records: reads and writes (evidence: `src/controllers/userController.js`)
- Report routes → JWT access: protects routes (evidence: `src/routes/hazardReportRoutes.js`)
- Report routes → Report submission: routes requests (evidence: `src/routes/hazardReportRoutes.js`)
- Report submission → Report validation: validates input (evidence: `src/controllers/hazardReportController.js`)
- Report submission → Hazard reports: creates reports (evidence: `src/controllers/hazardReportController.js`)
- Report submission → Hazard photo files: checks photo file (evidence: `src/controllers/hazardReportController.js`)
- Citizens → Hazard photo API: upload or fetch photo (evidence: `README.md`)
- Hazard photo API → Hazard photo files: stores and streams (evidence: `src/controllers/uploadController.js`)
- Review routes → JWT access: protects routes (evidence: `src/routes/verificationRoutes.js`)
- Review routes → Officer review: routes review (evidence: `src/routes/verificationRoutes.js`)
- Officer review → Hazard reports: updates decisions (evidence: `src/controllers/verificationController.js`)
- Officer review → Review history: records decisions (evidence: `src/controllers/verificationController.js`)
- Officer review → User records: loads reporter (evidence: `src/controllers/verificationController.js`)
- Alert routes → JWT access: protects routes (evidence: `src/routes/alertRoutes.js`)
- Alert routes → Alert workflow: routes requests (evidence: `src/routes/alertRoutes.js`)
- Alert workflow → Hazard reports: checks source report (evidence: `src/controllers/alertController.js`)
- Alert workflow → Recipient resolution: resolves recipients (evidence: `src/controllers/alertController.js`)
- Recipient resolution → Simulated citizens: queries simulated registry (evidence: `src/services/recipientResolver.js`)
- Alert workflow → Alert records: persists alert status (evidence: `src/controllers/alertController.js`)
- Alert workflow → Channel dispatch: dispatches channels (evidence: `src/controllers/alertController.js`)
- Channel dispatch → SMS adapter: sends SMS (evidence: `src/services/alertDispatchService.js`)
- Channel dispatch → Push adapter: sends Push (evidence: `src/services/alertDispatchService.js`)
- Shelter routes → JWT access: guards staff actions (evidence: `src/routes/shelterRoutes.js`)
- Shelter routes → Shelter operations: routes operations (evidence: `src/routes/shelterRoutes.js`)
- Shelter routes → Shelter image API: mounts image routes (evidence: `src/routes/shelterRoutes.js`)
- Shelter operations → Shelter validation: validates input (evidence: `src/controllers/shelterController.js`)
- Shelter operations → Shelter service: delegates operations (evidence: `src/controllers/shelterController.js`)
- Shelter service → Shelter records: reads and updates (evidence: `src/services/shelterService.js`)
- Shelter service → Shelter image storage: manages images (evidence: `src/services/shelterService.js`)
- Shelter image API → Shelter image storage: stores and retrieves (evidence: `src/controllers/shelterImageController.js`)
- Shelter image API → Shelter records: updates image reference (evidence: `src/controllers/shelterImageController.js`)
