Skip to content

Mahakisore7/Dev-Hack-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

46 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš’ ResQ-AI Backend (Server)

Agentic Incident Response & Real-Time Coordination System


๐Ÿ“Œ Overview

ResQ-AI Backend is a high-performance Node.js server powering the ResQ-AI platform.
It enables real-time emergency incident reporting, AI-assisted severity triage, duplicate consolidation, and live command-center updates using WebSockets.

The system is designed for smart cities, emergency services, and disaster-response coordination, ensuring fast, credible, and scalable incident handling.


โœจ Key Features

๐Ÿ›ก๏ธ Dual-Role Authentication

  • Secure JWT-based authentication
  • Two user roles:
    • Citizen โ€“ Mobile app users who report incidents
    • Admin โ€“ Command Center operators who validate and manage incidents

๐Ÿง  AI Severity Triage

  • Lightweight heuristic NLP engine
  • Automatically assigns severity during incident creation:
    • High โ€“ Fire, Blood, Explosion, Accident
    • Medium โ€“ Smoke, Traffic, Crowd
    • Low โ€“ Pothole, Noise, Garbage

๐Ÿ”— Consolidation Engine (Merge Logic)

  • Detects duplicate incident reports using geospatial proximity
  • Uses atomic MongoDB transactions
  • Merges duplicates into a single verified incident
  • Converts duplicate reports into verification votes (+1 credibility)

๐Ÿ‘ Consensus & Credibility System

  • Citizens can:
    • Upvote (Verify) โ†’ +1
    • Downvote (Reject) โ†’ -1
  • Automatic rejection when vote score โ‰ค -5
  • Net score determines whether an incident is valid or rejected

๐Ÿ“ก Real-Time Event Loop

  • Socket.io integration
  • Live push updates to Admin Dashboard:
    • New incidents
    • Incident merges
    • Status updates
    • Vote changes

๐ŸŒ Geospatial Core

  • MongoDB 2dsphere indexing
  • Enables:
    • Radius-based searches
    • Location clustering
    • Duplicate detection using proximity

๐Ÿ› ๏ธ Tech Stack

Layer Technology
Runtime Node.js
Framework Express.js
Database MongoDB
ODM Mongoose
Real-Time Socket.io
Security JWT, BCrypt, CORS
Architecture MVC with Service Layer

๐Ÿš€ Getting Started

1๏ธโƒฃ Prerequisites

  • Node.js v18+
  • MongoDB (Local installation or Atlas URI)

2๏ธโƒฃ Installation

git clone <repository_url>
cd Dev-Hack-Backend
npm install

3๏ธโƒฃ Environment Configuration

Create a .env file in the root directory:

PORT=5000
MONGO_URI=mongodb://localhost:27017/resq_ai_db
JWT_SECRET=your_super_secret_key_change_this
NODE_ENV=development

4๏ธโƒฃ Seed Admin User

The public API only allows Citizen registration.
To create the first Admin, run:

node createAdmin.js

5๏ธโƒฃ Run the Server

# Development mode (with nodemon)
npm run dev

# Production mode
npm start

๐Ÿ”Œ API Documentation

๐ŸŸข Authentication (/api/auth)

Method Endpoint Description Access
POST /signup Register a new Citizen Public
POST /login Login (Returns JWT + Role) Public

๐Ÿšจ Incidents (/api/incidents)

Method Endpoint Description Access
POST / Report a new incident (Auto severity) Citizen
GET / Get local incident feed (Newest first) Citizen
POST /:id/upvote Verify an incident (+1) Citizen
POST /:id/downvote Reject an incident (-1) Citizen

๐Ÿ‘ฎ Admin Command Center (/api/admin)

Method Endpoint Description Access
GET /feed Priority feed (Severity โ†’ Votes) Admin
PATCH /:id Update status or add notes Admin
POST /merge Merge duplicate incidents Admin
GET /seed Generate demo test data Admin

๐Ÿ“ก Socket.io Events (Real-Time)

Event Name Payload Trigger
new-incident { incidentObject } Citizen submits a report
incident-updated { incidentObject } Status, notes, or votes updated
incident-merged { primaryId, duplicateId } Admin merges incidents

๐Ÿ“‚ Project Structure

Dev-Hack-Backend/
โ”œโ”€โ”€ controllers/
โ”œโ”€โ”€ middleware/
โ”œโ”€โ”€ models/
โ”œโ”€โ”€ routes/
โ”œโ”€โ”€ lib/
โ”œโ”€โ”€ server.js
โ””โ”€โ”€ createAdmin.js

๐Ÿงช Testing the Merge Logic (Demo)

  1. Create Incident A โ€“ Fire at Lab (10.0, 10.0)
  2. Create Incident B โ€“ Smoke at Lab (10.0001, 10.0001)
  3. Login as Admin
  4. Merge using POST /api/admin/merge
{
  "primaryId": "ID_OF_A",
  "duplicateId": "ID_OF_B"
}

๐Ÿ“Œ Summary

ResQ-AI Backend provides:

  • Low-latency emergency coordination
  • High incident credibility through consensus
  • Scalable real-time architecture
  • Production-grade geospatial intelligence

๐Ÿ“ธ Project Screenshots

๐Ÿ” Login Screen

Login Screen

๐Ÿ—บ๏ธ Full Screen Map (Admin Command Center)

Admin Map

๐Ÿ“ Verified vs Unverified Incidents

Unverified Incident Verified Incident
Unverified Verified

๐Ÿšจ Incident Details

Map Popup

About

Backend Deployment Link

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors