Real-time traffic monitoring and congestion detection platform for smart cities — built with Flask, MongoDB, MySQL, and Apache Kafka, fully containerized with Docker.
A full-stack big data analytics system that simulates and analyzes live city traffic — vehicle GPS streams, speed tracking, congestion alerts, and an admin control panel — using a polyglot persistence architecture (MongoDB for high-volume traffic events, MySQL for relational user auth) connected through Kafka.
- 🗺️ Live city map — real-time vehicle positions rendered on an interactive grid
- 🚨 Automatic congestion detection — flags slow-traffic zones by road and severity
- 📊 Analytics dashboard — Chart.js visualizations for vehicle distribution & speed heatmaps
- 🔐 Role-based auth — separate user and admin panels with bcrypt password hashing
- ⚡ Data simulator — generates realistic rush-hour/night traffic patterns across 5 roads
- 🐳 One-command setup —
docker compose up --buildand you're running
- Docker Desktop installed and running
- VS Code with the Docker extension (optional but helpful)
cd Smart-City-Traffic-Analytics
docker compose up --buildFirst build takes ~2 min (downloading images + pip install). Subsequent starts take ~20 s.
| URL | Description |
|---|---|
| http://localhost:5000 | Login page |
| http://localhost:5000/dashboard.html | User dashboard |
| http://localhost:5000/admin-dashboard.html | Admin panel |
Regular user → click Create new account on the login page.
Admin user → click Admin registration, use secret key ADMIN123.
Once logged in, use the ⚡ Add 20 Records button on the dashboard, or wait ~15 s for the simulator container to auto-populate data.
| Service | Container | Host Port |
|---|---|---|
| Flask API | traffic_flask | 5000 |
| MongoDB | traffic_mongodb | 27017 |
| MySQL | traffic_mysql | 3306 |
| Kafka | traffic_kafka | 9092 |
| Zookeeper | traffic_zookeeper | 2181 |
| Simulator | traffic_simulator | — |
# Start (detached)
docker compose up -d --build
# View logs for the Flask API
docker compose logs -f flask
# View simulator output
docker compose logs -f simulator
# Stop everything
docker compose down
# Stop and DELETE all data (volumes)
docker compose down -v
# Rebuild only the Flask image (after code changes)
docker compose up --build flaskAll config lives in docker-compose.yml → flask.environment.
Change values there; no .env file is required.
| Variable | Default | Description |
|---|---|---|
| MONGO_URI | mongodb://mongodb:27017/ | MongoDB connection |
| MYSQL_HOST | mysql | MySQL hostname |
| MYSQL_PASSWORD | rootpassword | MySQL root password |
| ADMIN_SECRET | ADMIN123 | Admin registration key |
Browser
└─► Flask :5000 ──► MySQL :3306 (users / auth)
└──► MongoDB :27017 (traffic data)
Simulator ──► Flask API (HTTP /api/simulate-data)
└──► Kafka :29092 ──► (future Spark consumer)