CrisisLink is a realβtime emergency coordination platform that connects citizens, volunteers, and administrators to speed up rescue and resource delivery during crises.
Frontend: React + Vite + Tailwind + MUI + Leaflet + Socket.IO client Backend: Node.js + Express + MongoDB (Mongoose) + JWT + Socket.IO
- π‘ SOS alerts with geolocation (GeoJSON) and live status: Pending β In Progress β Resolved.
- πΊοΈ Map view (Leaflet) for locating incidents & volunteers in real time.
- π Live updates via Socket.IO (volunteer location updates, SOS accepted notifications).
- π€ Authentication (register/login/logout), JWT in cookie/headers, password hashing with bcrypt.
- π Roleβbased access:
user,volunteer,admin. - π Admin dashboard: user counts, SOS stats (7βday metrics).
- π± PWAβready frontend (Vite PWA plugin) with manifest and autoβupdate.
- π§° Developer experience: ESLint, modular API wrapper, contexts for Auth/Socket.
CrisisLink/
ββ frontend/ # React app (Vite)
β ββ src/
β β ββ pages/
β β β ββ Home.jsx, About.jsx
β β β ββ auth/ # Login, Signup
β β β ββ dashboard/
β β β ββ UserDashboard.jsx, VolunteerDashboard.jsx, AdminDashboard.jsx
β β β ββ user/ # UserHome, ...
β β β ββ volunteer/ # NearbySOS, MapView, ...
β β β ββ admin/ # AdminOverview, UserManagement, SOSManagement
β β ββ components/
β β β ββ Layout, Navbar, Footer, DashboardLayout, ProtectedRoute
β β β ββ emergency/ # SOSButton, LocationTracker, EmergencyContacts
β β β ββ admin/ # StatsCards, SOSChart, UserManagement
β β ββ context/ # AuthContext, SocketContext
β β ββ lib/ # axios instance, API wrappers, socket utils
β β ββ services/ # (api.js for legacy calls)
β ββ vite.config.js # PWA config, chunk analyzer
β ββ tailwind.config.js
β
ββ backend/ # Node/Express server
ββ server.js # Express + Socket.IO entrypoint
ββ src/
ββ config/db.js # Mongo connection
ββ middleware/ # auth.js, roles.js
ββ models/ # User.js, SOS.js (2dsphere index)
ββ routes/ # authRoutes.js, sosRoutes.js, adminRoutes.js, testRoutes.js
Note:
backend/package.jsoncurrently points tosrc/server.js. The real entry file isbackend/server.js. Update the scripts (below) if needed.
- Node.js β₯ 18 and npm (or pnpm/yarn)
- MongoDB (Atlas or local) β a connection string
Create two .env files β one in /backend and one in /frontend.
# Server
PORT=5000
CLIENT_ORIGIN=http://localhost:5173
# Database
MONGODB_URI=mongodb+srv://<user>:<password>@<cluster>/<db>?retryWrites=true&w=majority
# Auth
JWT_SECRET=<generate_a_long_random_secret>
JWT_EXPIRES_IN=7d# API base
VITE_API_URL=http://localhost:5000/api
VITE_SOCKET_URL=http://localhost:5000
# App metadata (optional)
VITE_APP_VERSION=1.0.0
VITE_APP_NAME=CrisisLinkπ Security tip: Never commit real secrets. If a
.envwas committed at any point, rotate those credentials immediately and add.envto.gitignore.
Open two terminals from the project root.
cd backend
npm install
# If the existing script errors with src/server.js missing, use the fixed scripts below
npm run dev # uses nodemon
# OR
node server.js # direct startFix backend scripts (recommended): edit backend/package.json β
{
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
}
}cd frontend
npm install
npm run devVisit: http://localhost:5173
Base URL: http://localhost:5000/api
| Method | Path | Body | Notes | ||
|---|---|---|---|---|---|
| POST | /register |
{ name, email, password, role? } |
role β `user |
volunteer | admin(defaultsuser`) |
| POST | /login |
{ email, password } |
returns { user, token } and sets httpOnly cookie |
||
| POST | /logout |
β | clears cookie | ||
| GET | /me |
β (auth) | current user profile |
| Method | Path | Body / Query | Roles | ||
|---|---|---|---|---|---|
| POST | / |
{ type?, description?, location: { lat, lng } } |
user | ||
| GET | /my |
β | user/volunteer/admin | ||
| GET | /nearby |
?lat=β¦&lng=β¦&radiusKm=β¦ |
volunteer | ||
| POST | /:id/accept |
β | volunteer | ||
| PATCH | /:id/status |
`{ status: "Pending" | "In Progress" | "Resolved" }` | auth |
| GET | /:id |
β | auth |
| Method | Path | Notes |
|---|---|---|
| GET | /stats |
counts + last 7βday metrics |
| GET | /users |
list users (filter/status ready) |
| GET | /sos |
list all SOS |
| PATCH | /users/:id/status |
activate/deactivate user |
| DELETE | /users/:id |
remove user |
| PATCH | /sos/:id/status |
update SOS status |
Extra:
GET /api/test/ping(health),GET /api/test/protected(JWT required).
Client β Server
register_userβ{ userId, role, name }location_updateβ{ userId, coords: { lat, lng } }sos_acceptedβ{ sosId }(volunteer accepts)
Server β Client
registration_successβ ack after authvolunteer_location_updatedβ{ userId, coords }sos_accepted/sos_accepted_by_volunteerβ notify relevant usersvolunteer_disconnected
The server authenticates socket connections with the same JWT (
Authorization/cookie) and rejects missing/invalid tokens.
User
{
name: String!,
email: String! (unique, lowercase),
password: String! (bcrypt hashed),
role: 'user' | 'volunteer' | 'admin',
phone?: String,
location?: { lat?: Number, lng?: Number },
isActive: Boolean,
timestamps: true
}SOS
{
user: ObjectId<User>!,
type: String, // e.g., Medical / Accident / Fire / Harassment / Other
description?: String,
status: 'Pending' | 'In Progress' | 'Resolved',
volunteer?: ObjectId<User>,
location: { // GeoJSON Point
type: 'Point',
coordinates: [lng, lat]
},
timestamps: true
}
// Index
sosSchema.index({ location: '2dsphere' })- Routing:
react-router-dom@7with protected routes. - State/Context:
AuthContextfor auth lifecycle,SocketContextfor live updates. - UI: MUI components + Tailwind utility classes; charts via
chart.js+react-chartjs-2. - Map:
react-leaflet(remember its CSS import is present inMapComponent). - Notifications:
react-hot-toast/react-toastify. - PWA: configured in
vite.config.jswith manifest, icons and autoβupdate.
# Health check
curl http://localhost:5000/api/test/ping
# Register (user)
curl -X POST http://localhost:5000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"name":"Test User","email":"test@example.com","password":"secret"}'
# Login (grab token from response)
curl -X POST http://localhost:5000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com","password":"secret"}'Frontend
cd frontend
npm run build # outputs dist/
npm run preview # optional local previewServe dist/ behind your API server or from a static host (Netlify, Vercel, S3, β¦). Update VITE_API_URL & VITE_SOCKET_URL to your production URLs.
Backend
- Ensure environment variables are set on the server.
- Use a process manager (PM2, Docker, systemd) to run
node server.js. - Configure HTTPS and CORS
CLIENT_ORIGINcorrectly.
src/server.jsnot found: update backend scripts to targetserver.jsat root of/backend.- CORS errors: set
CLIENT_ORIGINin backend.envto your frontend URL. - Socket not connecting: confirm
VITE_SOCKET_URLmatches your backend host/port and JWT is present. - Leaflet markers missing: ensure the default marker images are reachable (already handled in
MapComponent). - Mongo Geo queries: ensure the
SOScollection has the2dsphereindex (created by the model on startup).
- Fork the repo & create a feature branch:
git checkout -b feature/awesome - Commit with conventional messages:
feat: add volunteer heatmap - Push & open a Pull Request.
This project is licensed under the ISC License (see backend/package.json). You may switch to MIT if preferred.
- React, Vite, Tailwind CSS, MUI
- Leaflet & ReactβLeaflet
- Socket.IO
- Express, Mongoose
Built to help communities respond faster when it matters most.