# ar1625517-gif/smart-ambulance-system architecture

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

- Interactive diagram: https://gitdiagram.com/ar1625517-gif/smart-ambulance-system
- Repository: https://github.com/ar1625517-gif/smart-ambulance-system

## Overview

This backend implements emergency dispatch and trip updates. A requester submits an SOS with location and emergency type; the dispatch route selects a nearby available ambulance and a nearby hospital with matching specialty and ER capacity, marks the ambulance busy, and returns trip details. Socket.IO separately relays driver location and patient vitals to clients joined to a trip. The tree shows no frontend source, so client behavior is represented only as external actors; persistence and runtime wiring are evidenced by the sampled server and route files.

Main entry points: [`smart-ambulance-system/backend/server.js`](https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/server.js) (HTTP and socket server), [`smart-ambulance-system/backend/routes/dispatch.js`](https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/routes/dispatch.js) (Dispatch route), [`smart-ambulance-system/backend/models/Ambulance.js`](https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/models/Ambulance.js) (Ambulance model), [`smart-ambulance-system/backend/models/Hospital.js`](https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/models/Hospital.js) (Hospital model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dispatch["SOS Dispatch"]
  node_dispatch_route["Dispatch route<br/>[dispatch.js]"]
end

subgraph group_records["Fleet And Hospitals"]
  node_ambulance_model["Ambulance model<br/>[Ambulance.js]"]
  node_hospital_model["Hospital model<br/>[Hospital.js]"]
  node_mongo[("MongoDB runtime")]
end

subgraph group_realtime["Trip Updates"]
  node_trip_room["Trip room<br/>[server.js]"]
  node_live_location["Live location relay<br/>[server.js]"]
  node_vitals_alert["Vitals alert relay<br/>[server.js]"]
end

subgraph group_runtime["Backend Runtime"]
  node_server["HTTP and socket server<br/>[server.js]"]
  node_sample_data["Sample data loader<br/>[seed.js]"]
end

node_requester(("Emergency requester"))
node_driver(("Driver client"))
node_hospital_client(("Hospital client"))

node_requester -->|"sends SOS"| node_server
node_server -->|"mounts routes"| node_dispatch_route
node_dispatch_route -->|"finds and updates"| node_ambulance_model
node_dispatch_route -->|"searches capacity"| node_hospital_model
node_server -->|"inserts samples"| node_ambulance_model
node_server -->|"inserts samples"| node_hospital_model
node_dispatch_route -->|"returns trip"| node_requester
node_driver -->|"sends updates"| node_server
node_hospital_client -->|"sends vitals"| node_server
node_server -->|"joins trip"| node_trip_room
node_server -->|"emits location"| node_live_location
node_server -->|"emits vitals"| node_vitals_alert
node_trip_room -->|"targets trip"| node_live_location
node_trip_room -->|"targets trip"| node_vitals_alert
node_sample_data -->|"seeds records"| node_ambulance_model
node_sample_data -->|"seeds records"| node_hospital_model

click node_dispatch_route "https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/routes/dispatch.js"
click node_ambulance_model "https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/models/Ambulance.js"
click node_hospital_model "https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/models/Hospital.js"
click node_trip_room "https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/server.js"
click node_live_location "https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/server.js"
click node_vitals_alert "https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/server.js"
click node_server "https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/server.js"
click node_sample_data "https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/seed.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_dispatch_route,node_driver,node_hospital_client toneBlue
class node_ambulance_model,node_hospital_model,node_mongo toneAmber
class node_trip_room,node_live_location,node_vitals_alert,node_requester toneMint
class node_server,node_sample_data toneRose
```

## Components

### SOS Dispatch

- [Dispatch route](https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/routes/dispatch.js): `smart-ambulance-system/backend/routes/dispatch.js`

### Fleet And Hospitals

- [Ambulance model](https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/models/Ambulance.js): `smart-ambulance-system/backend/models/Ambulance.js`
- [Hospital model](https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/models/Hospital.js): `smart-ambulance-system/backend/models/Hospital.js`
- **MongoDB runtime**

### Trip Updates

- [Trip room](https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/server.js): `smart-ambulance-system/backend/server.js`
- [Live location relay](https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/server.js): `smart-ambulance-system/backend/server.js`
- [Vitals alert relay](https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/server.js): `smart-ambulance-system/backend/server.js`

### Backend Runtime

- [HTTP and socket server](https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/server.js): `smart-ambulance-system/backend/server.js`
- [Sample data loader](https://github.com/ar1625517-gif/smart-ambulance-system/blob/main/smart-ambulance-system/backend/seed.js): `smart-ambulance-system/backend/seed.js`

### Other components

- **Emergency requester**
- **Driver client**
- **Hospital client**

## Connections

- Emergency requester → HTTP and socket server: sends SOS (evidence: `smart-ambulance-system/backend/server.js`)
- HTTP and socket server → Dispatch route: mounts routes (evidence: `smart-ambulance-system/backend/server.js`)
- Dispatch route → Ambulance model: finds and updates (evidence: `smart-ambulance-system/backend/routes/dispatch.js`)
- Dispatch route → Hospital model: searches capacity (evidence: `smart-ambulance-system/backend/routes/dispatch.js`)
- HTTP and socket server → Ambulance model: inserts samples (evidence: `smart-ambulance-system/backend/server.js`)
- HTTP and socket server → Hospital model: inserts samples (evidence: `smart-ambulance-system/backend/server.js`)
- Dispatch route → Emergency requester: returns trip (evidence: `smart-ambulance-system/backend/routes/dispatch.js`)
- Driver client → HTTP and socket server: sends updates (evidence: `smart-ambulance-system/backend/server.js`)
- Hospital client → HTTP and socket server: sends vitals (evidence: `smart-ambulance-system/backend/server.js`)
- HTTP and socket server → Trip room: joins trip (evidence: `smart-ambulance-system/backend/server.js`)
- HTTP and socket server → Live location relay: emits location (evidence: `smart-ambulance-system/backend/server.js`)
- HTTP and socket server → Vitals alert relay: emits vitals (evidence: `smart-ambulance-system/backend/server.js`)
- Trip room → Live location relay: targets trip (evidence: `smart-ambulance-system/backend/server.js`)
- Trip room → Vitals alert relay: targets trip (evidence: `smart-ambulance-system/backend/server.js`)
- Sample data loader → Ambulance model: seeds records (evidence: `smart-ambulance-system/backend/seed.js`)
- Sample data loader → Hospital model: seeds records (evidence: `smart-ambulance-system/backend/seed.js`)
