A full-stack geospatial intelligence platform that mimics how ride-sharing companies like Grab manage high-demand areas using geospatial data.
- 🗺️ Interactive map visualization with zone partitioning using H3 hexagonal grid cells
- 🚗 Real-time tracking of simulated drivers with smooth animation
- 📊 Dynamic surge pricing based on supply and demand
- 🔔 Geofencing to detect when drivers enter or leave surge zones
- 📈 Historical data analysis and simple demand prediction
- ⚡ Real-time WebSocket communication for live updates
- 🗄️ MongoDB geospatial database for efficient spatial queries
- Backend: FastAPI with async support
- Database: MongoDB with geospatial indexing
- Frontend: HTML/CSS/JavaScript with Leaflet.js for mapping
- Real-time: WebSockets for live updates
- Geospatial: H3 library for hexagonal grid cells
- Python 3.8+
- MongoDB 4.2+
- Node.js 14+ (optional, for development)
- Clone the repository:
git clone https://github.com/yourusername/smartzone.git
cd smartzone- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Install and start MongoDB if not already running:
# If using Docker:
docker run -d -p 27017:27017 --name mongodb mongo:latest- Configure environment variables:
- Copy
.env.exampleto.env - Update values as needed (especially MongoDB connection settings)
- Copy
- Seed the database with initial data:
python data/seed_data.py- Start the FastAPI server:
python app.py- Open the application in your browser:
http://localhost:8000
- Start Simulation: Click the "Start Simulation" button to begin the simulation
- Map Navigation: Zoom and pan to explore different areas
- Zone Details: Click on a zone to see its details (demand level, driver count, etc.)
- Driver Tracking: Watch drivers move around the map in real-time
- Surge Zones: Surge pricing zones are highlighted in red
- Change Map Style: Use the dropdown to switch between different map styles
app.py: Main application entry pointconfig.py: Configuration settingsbackend/: Backend codedatabase.py: MongoDB connection and helpersmodels.py: Pydantic models for data validationgeo_utils.py: Geospatial utility functionssimulation.py: Data simulation logicroutes/: API and WebSocket routesapi.py: REST API endpointswebsocket.py: WebSocket handlers
services/: Business logic servicesgeofencing.py: Geofencing detectionsurge_detection.py: Surge pricing logicprediction.py: Demand prediction with ML
frontend/: Frontend codestatic/: Static assets (JavaScript, CSS)js/: JavaScript filesmap.js: Map rendering and interactionswebsocket.js: WebSocket clientui.js: UI controls and displays
css/: Stylesheets
templates/: HTML templates
data/: Data scripts and sample dataseed_data.py: Data generation script
tests/: Test files
GET /api/zones: Get all zones with their current statusGET /api/zones/{zone_id}: Get a specific zonePOST /api/initialize-zones: Initialize zones for a city center
GET /api/drivers: Get all driversGET /api/drivers/{driver_id}: Get a specific driver
GET /api/ride-requests: Get all ride requestsGET /api/ride-requests/{request_id}: Get a specific ride request
POST /api/simulation/start: Start the simulationPOST /api/simulation/stop: Stop the simulation
GET /api/stats/surge-history: Get surge history for the past X hoursGET /api/stats/demand-by-zone: Get current demand levels for all zones
GET /api/geospatial/drivers-in-bounds: Get drivers within map boundsGET /api/geospatial/requests-in-bounds: Get ride requests within map bounds
The application uses WebSockets for real-time updates. The following message types are supported:
driver_updates: Updates on driver positions and statuszone_updates: Updates on zone demand levels and surge statusrequest_updates: Updates on ride requests
