- Project overview
- Architecture & file structure
- Key technologies and tools
- Local setup (dev environment)
- Running & debugging# Integrated Disaster Management and Response System (IDMRS)
Full-stack web app for disaster alerts, incident reporting, interactive maps, SOS, hospital locator, and NGO collaboration.
client/: React (Vite) + TypeScript + Tailwind + shadcn-ui + i18next + Leafletserver/: Express + Mongoose + REST API
- Node.js
- MongoDB (local or Atlas)
This repository contains a full-stack demo application for disaster alerts, incident reporting, mapping of disaster zones, hospital/NGO directories, and an SOS flow. It is built as a developer-friendly monorepo with two main packages:
client/— React + TypeScript frontend (Vite) with Tailwind CSS and Leaflet mapsserver/— Node.js + Express backend with Mongoose models for MongoDB
This README explains how the project is organized, how it works, how to run it locally, and useful troubleshooting steps.
- API reference
- How the map & data flow work
- Common issues & troubleshooting (CORS, duplicate React, map blank)
- Development workflow & testing
- Contributing
IDMRS is a small integrated system that lets users view disaster alerts, report incidents, view disaster-prone zones and resources on a map, request emergency SOS, and browse or register NGOs and hospitals. It's meant as a working prototype and developer exercise for integrating mapping, real-time-ish data flows, and CRUD APIs.
Core user-facing features
- Browse an interactive Leaflet map with disaster zones, incident markers and hospital locations
- Report an incident which will appear on the map
- Send an SOS request (uses browser geolocation) and post to backend
- Simple NGO & hospital directory pages
Top-level layout
-
client/— frontend appsrc/main.tsx— bootstraps the React appsrc/App.tsx— routes and providers (React Query, Context, Router)src/context/DisasterContext.tsx— central client-side data source & fetches API datasrc/pages/DisasterMap.tsx— map page usingreact-leafletsrc/components/— UI components (shadcn-style primitives)public/— static assets
-
server/— backend APIserver.js— Express app and route wiringroutes/*.js— express routes (alerts, incidents, hospitals, ngos, sos)controllers/*.js— request handlers (business logic)models/*.js— Mongoose schemasseed/seed.js— script to create demo data
-
Frontend
- React 18 + TypeScript
- Vite (dev server & build)
- Tailwind CSS (utility-first styling)
- shadcn/ui style components (Radix + Tailwind primitives)
- react-leaflet + leaflet for interactive maps
- react-i18next for localization
- TanStack React Query (optional)
-
Backend
- Node.js + Express
- Mongoose (MongoDB ODM)
- cors middleware for cross-origin requests
-
Tooling
- npm for package management
- nodemon for backend development
- curl / Invoke-RestMethod for API checks
Prerequisites
- Node.js (>= 18 recommended)
- MongoDB (local or Atlas) or set
MONGO_URIto your cluster
Install dependencies
- From the repository root (monorepo):
cd C:\Users\Akash\sahayog\sahayog
npm install- (Optional) Install subpackages separately if needed:
npm --prefix server install
npm --prefix client installEnvironment configuration
- Server: copy
server/env.exampletoserver/.envand setMONGO_URI(if you use Atlas) npm --prefix client run dev ```f your frontend cannot reach the backend, ensure the backend process is running and check CORS settings (server uses a CORS middleware allowinglocalhost:8080).
All endpoints are mounted under /api
- GET /api/alerts — list available alerts
- GET /api/incidents — list incidents
- POST /api/incidents — create incident { type, description, location: { lat, lng } }
- GET /api/hospitals — list hospitals
- GET /api/ngos — list NGOs
- POST /api/ngos — create NGO
- POST /api/sos — send an SOS request (expects userLocation)
and optionally
PORT. - Client: copy
client/env.exampletoclient/.envand setVITE_API_BASE_URLif your backend uses a non-default URL.
Seed demo data (optional)
npm --prefix server run seedRun the app in development
# from repository root
npm run dev
# or run packages individually
npm --prefix server run dev
Use `curl` or `Invoke-RestMethod` for quick checks:
```powershell
curl http://localhost:5001/api/hospitalsDefault dev URLs
- Frontend (Vite): http://localhost:8080 (or port printed by Vite)
- Backend (Express): http://localhost:5001 (default in server.js)
client/src/context/DisasterContext.tsxfetches initial data from the API when the app mounts (alerts, incidents, hospitals, ngos). It exposes this data through a React Context (useDisaster) used by pages and components.DisasterMap.tsxusesreact-leafletcomponents (MapContainer, TileLayer, Marker, Circle) to render:- Tile layer from OpenStreetMap
- Circles for disaster zones (static example data)
- Markers for incidents and hospitals from
DisasterContext
- When the user reports an incident (Report page), the client posts to
/api/incidents, and the returned incident is added to the context so it immediately appears on the map. - SOS uses
navigator.geolocation.getCurrentPosition()and posts to/api/soswith the coordinates.
Styling & CSS notes
- Leaflet requires its CSS to be loaded before the map mounts (imported in
main.tsx). The project includes.leaflet-container { height: 100%; }and ensureshtml, body, #root { height: 100%; }to avoid zero-height map containers.
server/server.jscreates an Express app, connects to MongoDB usingMongoose, and wires routes under/api.- Routes delegate to controllers that use Mongoose models (e.g.,
models/Hospital.js) to query and send JSON responses. - A
seed/seed.jshelper can populate example hospitals/incidents to test the UI.
-
Map is blank but page loads
- Check browser console for React errors. A common server-side cause is duplicate React installs in a monorepo (context provider/consumer runtime mismatch). Run
npm ls reactat the repo root and ensure only one version is installed. If duplicates exist, remove localfile:dependencies or dedupe. - Ensure Leaflet CSS is loaded and
.leaflet-containerhas height. Inspect DOM →.leaflet-containercomputed height.
- Check browser console for React errors. A common server-side cause is duplicate React installs in a monorepo (context provider/consumer runtime mismatch). Run
-
API requests failing with status 0 or blocked (CORS)
- Confirm the backend is running and reachable at the URL configured in
VITE_API_BASE_URLor the defaulthttp://localhost:5001. - Check server logs and confirm CORS middleware is active (server includes explicit CORS configuration to allow
localhost:8080during development).
- Confirm the backend is running and reachable at the URL configured in
-
Tile images not loading
- Inspect Network tab for requests to
tile.openstreetmap.org. If blocked or returning 403, try a different tile provider or check network restrictions.
- Inspect Network tab for requests to
- Use the monorepo scripts to install and run both packages:
npm install
npm run dev- Recommended iterative workflow
- Run backend with
npm --prefix server run devand confirmServer running on port 5001. - Run frontend with
npm --prefix client run devand open the map page. - Use the browser DevTools Network & Console tabs for real-time debugging.
- Run backend with
Automated tests
- There are no automated unit tests included in the template. For production-grade projects add Jest/React Testing Library and backend tests.
- Fork and create feature branches. Open a PR with a clear description and tests for behavior changes.
- Follow the existing code style: TypeScript on the client, JSDoc or comments on server controllers, Tailwind utility classes for styles.
- Frontend map code:
client/src/pages/DisasterMap.tsx - Data provider:
client/src/context/DisasterContext.tsx - Backend routes:
server/routes/*.js - Controllers:
server/controllers/*.js - Seed data:
server/seed/seed.js