Real-time emergency reporting and responder dispatch across a Next.js frontend and an Express/Prisma backend.
This repository contains two apps:
frontend: Next.js app for login, signup, civilian alert reporting, and responder dashboardsprimary-backend: Express + WebSocket backend for authentication, alert persistence, and real-time delivery
Implemented behavior in the current codebase includes:
- email/password signup and signin
- Google sign-in flow through NextAuth
- civilian alert creation from the map-based reporting UI
- role-based responder dashboards for
POLICE,FIRE, andMEDICAL - real-time alert delivery over WebSockets
- Postgres persistence via Prisma
- Redis-backed alert caching
- optional Kafka/Redpanda integration, with direct database fallback when Kafka credentials are not configured
- Frontend: Next.js 14, React 18, NextAuth, Tailwind CSS, Framer Motion, Leaflet
- Backend: Node.js, Express, WebSocket (
ws), Prisma, PostgreSQL, Redis, KafkaJS - Validation: Node test runner, TypeScript, ESLint, GitHub Actions
.
├── frontend/ # Next.js app
├── primary-backend/ # Express + WebSocket + Prisma backend
├── .github/workflows/ci.yml # CI for backend and frontend validation
└── package.json # Root convenience scripts
- Node.js 20 recommended
- PostgreSQL
- Redis
Kafka credentials are optional. If they are not set, the backend continues without Kafka and stores alerts directly in Postgres.
Create local env files from the provided examples:
cp primary-backend/.env.example primary-backend/.env
cp frontend/.env.example frontend/.envDefined in primary-backend/.env.example:
PORT=5000
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/emergency_alert_system
JWT_SECRET=change-me
REDIS_URL=redis://localhost:6379
KAFKA_BROKERS=
KAFKA_SASL_MECHANISM=scram-sha-256
KAFKA_USERNAME=
KAFKA_PASSWORD=Defined in frontend/.env.example:
NEXT_PUBLIC_BACKEND_URL=http://localhost:5000/api/v1
NEXT_PUBLIC_WS_URL=ws://localhost:5000
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=change-me
GOOGLE_CLIENT_ID=change-me
GOOGLE_CLIENT_SECRET=change-meInstall dependencies for each app:
cd primary-backend && npm ci
cd ../frontend && npm ciRun the backend:
cd primary-backend
npm run devRun the frontend:
cd frontend
npm run devThe backend listens on PORT from primary-backend/.env. The frontend reads its API and WebSocket targets from NEXT_PUBLIC_BACKEND_URL and NEXT_PUBLIC_WS_URL.
Root convenience scripts:
npm run build
npm run test
npm run validateApp-level scripts:
cd primary-backend && npm run typecheck && npm test
cd frontend && npm run validateCurrent CI runs:
- backend
npm ci,npm run typecheck,npm test - frontend
npm ci,npm run validate
Backend user routes are mounted at /api/v1/user.
Implemented routes include:
GET /check-emailGET /by-emailPOST /signupPOST /signinPOST /google-signup
Clients connect to:
{WS_URL}/{userId}/?{ROLE}
Example:
ws://localhost:5000/user123/?POLICE
Clients send new alerts over the WebSocket connection using the NEW_ALERT event shape used by the current backend:
{
"type": "NEW_ALERT",
"payload": {
"id": "alert-001",
"type": "CRIME",
"reportedBy": "user123",
"assignedTo": "POLICE",
"status": "REPORTED",
"priority": "HIGH",
"description": "Suspicious activity spotted",
"timeStamp": "2026-01-01T12:00:00.000Z",
"location": {
"lat": 28.6139,
"long": 77.2090
}
}
}The backend also handles alert status updates and cancellations, then broadcasts updates to connected clients.
- The frontend handles authentication and routing for civilian and responder views.
- The backend exposes user auth endpoints and runs the WebSocket server on the same HTTP server.
- Prisma models live in
primary-backend/prisma/schema.prisma. - Redis stores alert snapshots keyed by alert ID.
- Kafka producer and consumer initialization is conditional on credentials being present.
- Responder dashboards load pending alerts for their assigned role when they connect.
This repository currently reflects a web-based system. Mobile clients, SMS, and email delivery are not implemented in the codebase.