π¨ Real-Time Disaster Alert & Rescue Coordination System
CS04DS
HackBits
NMAM Institute of Technology
During disasters, communication breakdowns, delayed rescue coordination, and lack of real-time situational awareness often lead to loss of lives. Existing disaster management systems are largely one-way and fail to provide offline access, real-time escalation, and effective coordination between authorities, volunteers, and affected citizens at scale.
The system is a real-time disaster communication and coordination platform. Authorities broadcast disaster alerts and safety instructions to affected areas. Citizens send SOS rescue requests and view alerts; volunteers receive nearby SOS requests and accept/complete rescues; authorities monitor danger zones, manage escalated cases, and manually assign volunteers. Safety guides are cached in the browser for offline reading after they have been loaded once online.
The solution provides a unified, multi-role platform: real-time alerting, SOS creation with automatic volunteer matching by proximity, volunteer coordination with live location and status updates, and rule-based danger zone risk scoring. Safety guide content is cached in localStorage so users can read it when offline.
Frontend:
- Next.js 15 (TypeScript)
- Tailwind CSS
- No service worker or PWA manifest; offline support is limited to cached safety guide content in localStorage
Backend:
- tRPC for end-to-end type-safe APIs
- Polling for updates (5β30 second intervals depending on dashboard and data type)
Database:
- PostgreSQL with Prisma ORM
Authentication:
- Firebase Authentication with role-based access (USER, VOLUNTEER, AUTHORITY) implemented using Firebase custom claims and backend authorization checks.
- Google OAuth and credentials (email + password) providers
- New users get USER role by default; VOLUNTEER and AUTHORITY roles are assigned via admin (e.g. promote API or database)
Maps & Location:
- Leaflet with OpenStreetMap tiles
- Volunteer live location tracking with periodic server updates
- Geospatial rescue request assignment (2 km β 5 km β 10 km radius search)
Notifications:
- In-app visual and audio notifications for new volunteer alerts
- Firebase configuration is present in env but not used for push/SMS
- No mock SMS in UI; console logging may exist in code
Deployment:
- Vercel-ready configuration
Users:
- Citizens (USER role): receive disaster alerts, send SOS, cancel with βIβm Safe,β read safety guides (cached for offline)
- Volunteers (VOLUNTEER role): accept nearby SOS, update rescue status, share location, create safe zones
- Authorities (AUTHORITY role): create alerts and safety guides, view danger zones and risk scores, handle escalated cases, manually assign volunteers
Impact: The system improves situational awareness and coordination during disasters by linking citizens, volunteers, and authorities in one workflow with real-time polling and proximity-based assignment.
- SOS (Need Help): Send rescue request with automatic geolocation capture. Only one active request per user; duplicate is blocked.
- Iβm Safe: Cancel active rescue request (marks it completed and frees volunteer if assigned).
- ETA display: Estimated help arrival time (minβmax minutes) and confidence (HIGH/MEDIUM/LOW). Rule-based prediction using distance, volunteer status, system load, and disaster severity. Shown when a volunteer is assigned.
- Alert feed: Location-based disaster alerts; only alerts within whose radius the user falls are shown. Auto-refresh every 30 s when online. Requires network; no offline alert list.
- Safety guides: One guide per disaster type (Flood, Earthquake, Fire). Fetched when online; content is cached in localStorage and shown when offline or when server is unavailable.
- Alerts map: Map of nearby alerts and user location (when location and alerts are available).
- Training link: Navigate to training page.
- Emergency Chat: Opens real-time communication UI (realtime channels/messaging).
- Profile: Navigate to profile; profile completion flow (name, phone, address, location) for new users.
- Unified request list: Single polling query (every 5 s) for assigned, pending, and escalated (NO_VOLUNTEER) rescue requests.
- Accept request: Accept pending or NO_VOLUNTEER requests (up to 3 active assignments per volunteer).
- Status updates: Set rescue status to In Progress or Completed.
- ETA: ETA and confidence shown on assigned requests; rule-based prediction on accept and on assignment.
- Location tracking: GPS sent to server on start and on position updates (periodic, e.g. 15 s). Availability toggle (available/unavailable) for assignment eligibility.
- Live map: Map of assigned user location(s) and volunteer location with distance; βLocate meβ and fullscreen controls; marker click zooms and shows popup.
- New-alert notifications: Visual banner and optional audio when new alerts appear in the list.
- Safe zone creation: Create shelters, camps, or hospitals with name, type, location, optional capacity; visible to authority map.
- Resource nodes: Add and view resource nodes (e.g. boat, generator, water, food, medical); view nearby resources; used in coordination.
- Training: Training dashboard and modules.
- Emergency Chat: Real-time communication UI.
- Command / live map: Map showing danger zones (risk-colored), safe zones, and rescue/volunteer data (e.g. AuthorityCommandMap, live map, predictive analytics map components).
- Danger zones: Rule-based risk scoring from recent RescueRequests (grid aggregation). Formula:
(Recent SOS Γ 3) + (Unknown Users Γ 4) + (Growth Rate Γ 5). Risk levels: HIGH (>25), MEDIUM (13β25), LOW (β€12). Recent window 15 minutes; growth = recent vs previous 15 minutes. - Escalated cases: List of NO_VOLUNTEER requests; ETA and details shown; manual assignment to a volunteer.
- Manual assignment: Assign a specific volunteer to an escalated (or eligible) request; ETA recalculated after assign.
- Volunteer list: All volunteers with location and availability; used for manual assign and overview.
- Alert broadcasting: Create alerts with title, message, disaster type (Flood, Earthquake, Fire), center (lat/lng), and radius (5β30 km). Alerts shown to users inside radius.
- Safety guide management: Create/update one safety guide per disaster type (FLOOD, EARTHQUAKE, FIRE). Users and volunteers fetch by type; USER dashboard caches content for offline.
- All rescue requests: List of non-completed requests for operations overview.
- Safe zones: View all safe zones (shelters, camps, hospitals) on map and in lists.
- Drone / social / training: Drone swarm dashboard, social media dashboard, training dashboard, real-time communication UI (demo/supplementary features).
- Auto-assignment: On SOS create (and on public createSOS), search for available volunteers in 2 km, then 5 km, then 10 km; assign closest. If none found, request stays PENDING. Authority dashboard lists escalated (NO_VOLUNTEER) requests for manual assignment; NO_VOLUNTEER can be set in the database or by an external process. Volunteer max 3 active assignments; availability flag respected.
- ETA prediction: Rule-based (no external ML model). Inputs: distance, volunteer busy flag, active rescues count, disaster type, volunteer availability. Output: min/max minutes, confidence, and factors list. Used on assign and on accept.
- Real-time polling: Volunteer dashboard 5 s; user alerts 30 s; authority data 10β30 s depending on query.
- Geospatial: Haversine distance for volunteerβrequest matching and display.
- Role-based API: Procedures check session role (USER, VOLUNTEER, AUTHORITY); routes /user, /volunteer, /authority protected by middleware (auth required).
- Offline: Safety guides cached in localStorage after first fetch; no offline SOS queue wired in the UI (queue logic exists in lib but is not used by SOS flow).
- Responsive UI: Mobile-friendly layout for emergency use.
- Node.js 18+
- PostgreSQL database
- npm or pnpm
-
Copy the example environment file:
cp .env.example .env
-
Update the
.envfile with your database URL:DATABASE_URL="postgresql://postgres:password@localhost:5432/hack-bits" AUTH_SECRET="your-secret-key-here" -
Install dependencies:
npm install
-
Generate Prisma client and push schema to database:
npx prisma generate npx prisma db push
-
Start the development server:
npm run dev
-
Open http://localhost:3000 in your browser.
- Sign in with email + password (or Google / GitHub). New users are created with USER role.
- There is no βselect roleβ on the login page. To use VOLUNTEER or AUTHORITY dashboards, assign the role in the database or via the promote API:
POST /api/admin/promotewith body{ "email": "user@example.com", "secretKey": "PROMOTE_ADMIN_SECRET_2024" }(creates or promotes user to AUTHORITY). VOLUNTEER must be set in the database (e.g.User.role = VOLUNTEER).
| Role | Access |
|---|---|
| USER | Send SOS, cancel with βIβm Safe,β view location-based alerts, read safety guides (cached for offline) |
| VOLUNTEER | Accept rescues, update status, track location, create safe zones and resources, manage assignments |
| AUTHORITY | Create alerts and safety guides, view danger zones and risk, handle escalated cases, manually assign volunteers |
src/
βββ app/
β βββ api/
β β βββ auth/[...nextauth]/ # NextAuth API route
β β βββ trpc/[trpc]/ # tRPC API route
β βββ authority/ # Authority dashboard
β βββ components/ # Shared components
β βββ dashboard/ # Role-based redirect
β βββ user/ # User dashboard
β βββ volunteer/ # Volunteer dashboard
β βββ layout.tsx
β βββ page.tsx # Login page
βββ lib/
β βββ offline.ts # localStorage caching for safety guides
β βββ offline-queue.ts # Offline SOS queue (not wired to UI)
β βββ eta-prediction.ts # Rule-based ETA prediction
βββ server/
β βββ api/
β β βββ routers/
β β β βββ alert.ts # Alert CRUD
β β β βββ guide.ts # Safety guide CRUD
β β β βββ rescue.ts # SOS / rescue request flow, auto-assign, ETA
β β β βββ volunteer.ts # Volunteer location & availability
β β β βββ dangerZone.ts # Risk scoring for danger zones
β β β βββ safeZone.ts # Safe zone management
β β βββ root.ts # tRPC router
β β βββ trpc.ts # tRPC context & procedures
β βββ auth/ # NextAuth configuration
β βββ db.ts # Prisma client
βββ trpc/ # tRPC client setup
βββ middleware.ts # Route protection (auth required for /user, /volunteer, /authority)
βββ styles/
prisma/
βββ schema.prisma # Database schema