|
Where technology meets urgency. A production-ready emergency dispatch platform that connects citizens, ambulance drivers, hospitals, dispatchers and administrators through real-time coordination. |
See the emergency as it unfolds. Route, dispatch and coordinate. Measure what the system is doing. Move the right resource, fast. Design for the failure nobody planned for. |
Understand the emergency before the system responds.
The Emergency Response System (ERS) is a real-time dispatch platform designed to reduce the time between an emergency request and coordinated medical response.
The platform supports one-click emergency requests, GPS-based ambulance discovery, automated dispatch, real-time tracking, ETA updates, hospital coordination, medical records, notifications and operational analytics.
┌──────────┐ ┌────────────┐ ┌────────────┐
│ CITIZEN │ ───→ │ DISPATCH │ ───→ │ AMBULANCE │
└──────────┘ └────────────┘ └─────┬──────┘
↑ │ │
│ ↓ ↓
│ ┌────────────┐ ┌────────────┐
└──────────── │ HOSPITAL │ ←─── │ REAL-TIME │
└────────────┘ │ TRACKING │
└────────────┘
| System | Capability |
|---|---|
SOS |
Create and manage emergency requests |
DISPATCH |
Priority-based ambulance allocation |
GPS |
Live ambulance location and distance calculation |
ETA |
Road-network ETA with routing fallback |
TRACKING |
Real-time status and location updates |
HOSPITAL |
Request acceptance and patient coordination |
MEDICAL |
Secure medical record upload and sharing |
ANALYTICS |
Performance, latency and operational metrics |
ALERTING |
Slack, email and webhook system alerts |
Engineering the path from SOS to care.
┌──────────────────────┐
│ CLIENTS │
│ Citizen · Driver │
│ Hospital · Admin │
└──────────┬───────────┘
│
HTTP / WebSocket
│
┌──────────▼───────────┐
│ EXPRESS / NODE.JS │
│ Auth · Routes · API │
└──────────┬───────────┘
│
┌─────────────────────┼─────────────────────┐
│ │ │
┌──────▼──────┐ ┌──────▼──────┐ ┌──────▼──────┐
│ DISPATCH │ │ REALTIME │ │ ANALYTICS │
│ Engine/Queue│ │ Socket.IO │ │ Metrics │
└──────┬──────┘ └──────┬──────┘ └──────┬──────┘
│ │ │
└─────────────────────┼─────────────────────┘
│
┌───────────────┼───────────────┐
│ │
┌──────▼──────┐ ┌──────▼──────┐
│ MongoDB │ │ Redis │
│ Persistence │ │ Queue/Cache │
└─────────────┘ └─────────────┘
Ambulance/
├── controllers/ # Auth, emergency, dispatch, ambulance, admin, analytics
├── middleware/ # JWT, RBAC, validation, sessions, uploads, errors
├── models/ # User, Ambulance, EmergencyRequest, Hospital, MedicalRecord
├── routes/ # Domain-specific API routers
├── utils/ # Dispatch engine, ETA, queues, caching, monitoring
├── public/ # Citizen, driver, hospital and admin interfaces
├── tests/ # Unit, integration, security and system tests
├── scripts/ # Load tests, migrations and validation utilities
├── config/ # Swagger and application configuration
├── server.js # Application/server integration
├── index.js # Application bootstrap
├── docker-compose.yml # Container orchestration
├── dockerfile # Production container image
└── README.md # You are here
Measure the system. Find the bottleneck. Improve the response.
| Layer | Technologies |
|---|---|
| Runtime | Node.js 18+ |
| API | Express.js |
| Database | MongoDB · Mongoose |
| Realtime | Socket.IO |
| Cache / Queue | Redis · BullMQ |
| Authentication | JWT · httpOnly cookies · bcrypt |
| Routing | OSRM · Haversine fallback |
| Uploads | Multer · Cloudinary |
| Notifications | Nodemailer · Twilio · Slack/Webhooks |
| Observability | Winston · Prometheus metrics |
| Security | Helmet · CORS · MongoDB sanitization · rate limiting |
| Testing | Jest · Supertest · MongoDB Memory Server |
| Deployment | Docker · Nginx · Render-ready configuration |
The dispatch layer combines distance, availability, priority and ambulance state to determine an appropriate response path. Geospatial calculations use the Haversine formula, while ETA calculation can use road-network routing and fall back when routing is unavailable.
NORMAL LOAD
│
▼
┌──────────────┐
│ Dispatch │
│ Queue │
└──────┬───────┘
│
┌──────▼───────┐
│ Available │
│ Ambulance │
└──────────────┘
HIGH LOAD / FAILURE
│
┌──────▼────────┐
│ Rate Limiter │
├───────────────┤
│ Load Shedder │
├───────────────┤
│ Circuit Break │
├───────────────┤
│ Retry / Queue │
└───────────────┘
- JWT authentication with revocation support
httpOnly+SameSite: Strictcookies- Role-based access control across protected routes
- Password hashing with bcrypt
- Helmet security headers
- CORS controls
- Input and coordinate validation
- Pagination limits and analytics export caps
- Rate limiting against abusive request volume
- Immutable audit logging for sensitive operations
From a citizen's SOS to a completed emergency request.
A citizen creates an emergency request through the public interface.
The system receives the emergency coordinates and evaluates available response resources.
The dispatch engine and queue determine an appropriate ambulance response.
The driver receives the assignment and can accept or reject the response.
Ambulance location and response state can be updated in real time through Socket.IO-backed coordination.
The patient is transported while ETA and emergency state remain visible to the relevant roles.
The driver completes the request and the system retains operational history for later analysis.
| Role | Responsibility |
|---|---|
CITIZEN |
Create emergencies, track requests, view history and manage own medical records |
DRIVER |
Receive assignments, update ambulance status and GPS location |
HOSPITAL |
Accept emergency requests and access shared patient records |
DISPATCHER |
Monitor requests and ambulances, manage dispatch operations |
ADMIN |
User management, system oversight and analytics |
CITIZEN,DRIVERandHOSPITALcan self-register.DISPATCHERandADMINroles require administrative assignment.
Authentication · /api/auth
| Method | Endpoint | Purpose |
|---|---|---|
POST |
/register |
Register user |
POST |
/login |
Login with email or phone |
GET |
/me |
Current user |
POST |
/logout |
Revoke session |
POST |
/refresh |
Refresh JWT |
Emergency · /api/emergency
| Method | Endpoint | Purpose |
|---|---|---|
POST |
/ |
Create SOS request |
GET |
/ |
List role-filtered requests |
GET |
/history |
Citizen request history |
GET |
/:id |
Retrieve emergency |
PUT |
/:id/accept |
Hospital accepts request |
PUT |
/:id/complete |
Driver completes request |
Dispatch · /api/dispatch
| Method | Endpoint | Purpose |
|---|---|---|
POST |
/request |
Create and auto-dispatch emergency |
GET |
/active |
Current active request |
GET |
/assignments |
Driver assignments |
PUT |
/:id/response |
Accept/reject assignment |
PATCH |
/:id/track |
Update location/status |
DELETE |
/:id |
Cancel request |
Ambulances · /api/ambulances
| Method | Endpoint | Purpose |
|---|---|---|
POST |
/ |
Register/update ambulance |
GET |
/ |
List ambulances |
GET |
/:id |
Retrieve ambulance |
PATCH |
/:id/status |
Update ambulance status |
PATCH |
/:id/location |
Update GPS location |
Admin · /api/admin
| Method | Endpoint | Purpose |
|---|---|---|
GET |
/users |
List users |
GET |
/users/:id |
Retrieve user |
PUT |
/users/:id/role |
Change role |
DELETE |
/users/:id |
Delete user |
GET |
/ambulances |
List ambulances |
GET |
/stats |
System statistics |
Analytics · /api/analytics
| Method | Endpoint | Purpose |
|---|---|---|
GET |
/latency |
Response latency |
GET |
/performance |
Daily performance |
GET |
/export |
JSON/CSV export with row cap |
Medical Records · /api/medical
| Method | Endpoint | Purpose |
|---|---|---|
POST |
/upload |
Upload medical file |
GET |
/:userId |
Retrieve records |
GET |
/record/:id |
Retrieve one record |
DELETE |
/record/:id |
Delete record |
POST |
/share/:recordId |
Share with hospital |
The system should remain useful when the situation stops being predictable.
REQUEST RATE ────────┐
ERROR RATE ──────────┤
P50 / P95 / P99 ─────┤
QUEUE DEPTH ─────────┼──→ METRICS DASHBOARD
MEMORY / CPU ────────┤
DB HEALTH ───────────┘
Live metrics are available at:
/metrics-dashboard
Health and readiness endpoints:
curl http://localhost:3000/health
curl http://localhost:3000/ready# Default load test
npm run test:load
# 100 simulated users · 60 seconds
npm run test:load:quick
# 1000 simulated users · 5 minutes
npm run test:load:fullThe repository includes unit, integration, system and security coverage.
npm test
npm run test:integration
npm run test:all
npm run test:cov
npm run lint# Install
npm install
# Development
npm run dev
# Production
npm startDocker:
docker build -t ers:latest .
docker-compose up -d| Variable | Required | Purpose |
|---|---|---|
MONGODB_URI |
✅ | MongoDB connection |
JWT_SECRET |
✅ | JWT signing secret |
JWT_EXPIRE |
— | Token lifetime; defaults to 7d |
PORT |
— | HTTP port; defaults to 3000 |
NODE_ENV |
— | development / production |
REDIS_URL |
— | Redis connection for multi-instance operation |
CLOUDINARY_CLOUD_NAME |
— | Medical file storage |
CLOUDINARY_API_KEY |
— | Cloudinary authentication |
CLOUDINARY_API_SECRET |
— | Cloudinary authentication |
OSRM_ROUTING_URL |
— | Road-network routing endpoint |
FRONTEND_URL |
— | CORS origin |
Additional engineering documentation lives in:
SYSTEM_VISION.md— system mission and scale blueprintAPI_DOCS.md— API documentationREALTIME_TRACKING.md— real-time tracking architecturePERFORMANCE_OPTIMIZATIONS.md— performance workPRODUCTION_AUDIT.md— production audit and hardeningDEPLOYMENT_GUIDE.md— deployment guidance