A modern React web application that visualizes global population density data on an interactive world map with heat colors. Connect to MongoDB to manage and display country statistics with an intuitive, visually appealing interface.
- Interactive World Map: Pan, zoom, and explore the world map with smooth animations
- Heat Color Visualization: Dynamic color scaling based on selected metrics
- Multiple Metrics: Toggle between population density, life expectancy, total population, and land area
- Country Details: Click on countries to view detailed statistics
- Top Rankings: Real-time top 10 country rankings based on selected metric
- Responsive Design: Beautiful dark-themed UI with Tailwind CSS
- Dark Mode: Eye-friendly dark theme optimized for data visualization
- MongoDB Integration: Backend API for managing country data
- React 18 - UI framework
- Vite - Build tool and dev server
- Leaflet - Map library
- React-Leaflet - React wrapper for Leaflet
- Tailwind CSS - Utility-first CSS framework
- Axios - HTTP client for API calls
- Node.js & Express - Server framework
- MongoDB - NoSQL database
- Mongoose - MongoDB ODM
- CORS - Cross-origin resource sharing
- Node.js (v14 or higher)
- MongoDB (local or cloud instance)
- npm or yarn
- Clone the repository
git clone <repository-url>
cd population-density-app- Install dependencies
npm install- Configure environment variables
# Copy the example env file
cp .env.example .env
# Edit .env with your MongoDB URI
# For local MongoDB:
MONGODB_URI=mongodb://localhost:27017/population_density
PORT=5000- Start MongoDB (if running locally)
# On Windows with MongoDB installed
mongod- Install backend dependencies
# If backend has separate package.json
cd server && npm install && cd ..- Run the application
Development mode (both frontend and backend):
# Terminal 1 - Start Vite dev server (Frontend on port 5173)
npm run dev
# Terminal 2 - Start Express server (Backend on port 5000)
npm run serverBuild for production:
npm run build
npm run previewAll data lives in MongoDB and is keyed by ISO country codes (cca3).
Core population + geography data.
{
country: String, // "India"
cca2: String, // "IN"
cca3: String, // "IND" (primary key)
pop2025: Number,
pop2050: Number,
area: Number, // total area
landAreaKm: Number, // land area in kmΒ²
density: Number, // people per kmΒ²
growthRate: Number, // decimal (e.g., 0.0089)
worldPercentage: Number, // share of world population
rank: Number,
createdAt: Date,
updatedAt: Date
}Economic & development metrics (most recent year per country is used in analytics).
{
countryCode: String, // cca3
year: Number,
gdpPerCapita: Number,
gdpTotal: Number,
urbanizationRate: Number,
lifeExpectancy: Number,
createdAt: Date,
updatedAt: Date
}Grouping of countries for aggregates.
{
name: String, // e.g., "Asia"
type: String, // "continent" | "subregion" | "economic_zone"
countries: [String], // array of cca3 codes
totalPopulation2025: Number,
totalPopulation2050: Number,
averageDensity: Number,
averageGrowthRate: Number,
totalArea: Number,
createdAt: Date,
updatedAt: Date
}GET /api/countriesβ all countriesGET /api/countries/:cca3β one country by ISO3POST /api/countriesβ create (use schema above)PUT /api/countries/:cca3β updateDELETE /api/countries/:cca3β deleteGET /api/countries/stats/summaryβ aggregate snapshot
GET /api/analytics/high-growth-with-economicsGET /api/analytics/regional-analysisGET /api/analytics/overcrowding-analysisGET /api/analytics/projection-by-developmentGET /api/analytics/economic-population-correlationGET /api/analytics/regional-comparison
The heat map uses a dynamic color scale:
- Blue (#001f3f) - Low values
- Green (#00d084) - Medium-low values
- Yellow (#ffdc00) - Medium-high values
- Red (#e74c3c) - High values
Colors are normalized based on the min/max values of the selected metric across all countries.
- +/- Buttons: Zoom in and out
- β² Button: Reset to world view
- Mouse Wheel: Zoom with scroll
- Click & Drag: Pan around the map
- Hover: Preview country information
- Click Country: Select and view details in sidebar
- Interactive Leaflet map with GeoJSON features
- Dynamic styling based on selected metric
- Popup information on click
- Custom zoom controls
- Selected country details
- Top 10 rankings list
- Real-time statistics
- Responsive layout
- Metric selection dropdown
- Visual feedback for current metric
- Help text and instructions
- Backend exposes country + analytics endpoints (see above)
- Frontend fetches countries and renders heat-map markers by selected metric
- Sidebar/top lists update on selection; analytics panel calls aggregation endpoints
- Import/refresh countries: use your data import (CSV or manual); ensure
cca3codes align with map markers. - Add a missing country quickly:
POST /api/countrieswith the country schema. - Economic data: import via
server/scripts/importCSV.js(configure paths/mappings). - Update region aggregates:
npm run update-region-stats(fromserver/). - Verify collections:
node server/scripts/verifyData.js.
- Missing map points: ensure the country exists in
country_stats_2025and has a centroid inMapComponent.jsx(centroid map). The basemap tile layer supplies boundaries; markers come from countries data. - Region stats zeroed: run
npm run update-region-stats(fromserver/). - Mongo connection issues: confirm
MONGODB_URIin.envand that MongoDB is running.
- Ensure MongoDB is running:
mongod - Check MONGODB_URI in .env file
- Verify database credentials
- Frontend: Runs on port 5173 (configurable in vite.config.js)
- Backend: Runs on port 5000 (configurable in .env)
- Ensure CORS is enabled in server/index.js
- Verify proxy configuration in vite.config.js
- Check browser console for errors
- Verify Leaflet CSS is imported
- Ensure GeoJSON data is properly formatted
- React Documentation
- Leaflet Documentation
- Tailwind CSS Documentation
- MongoDB Documentation
- Express.js Guide
MIT License - feel free to use this project for personal or commercial purposes.
Contributions are welcome! Please feel free to submit a Pull Request.
For issues or questions, please open an issue in the repository.
Happy mapping! πβ¨