A fully virtual smart city simulation with IoT devices, real-time dashboard, and AI-based optimization.
-
Simulated IoT Devices:
- 🚦 Traffic Sensors: Monitor vehicle flow, speed, and congestion
- 💡 Street Lights: Adaptive brightness with energy tracking
- ⚡ Smart Meters: Energy consumption monitoring for buildings
🅿️ Parking Sensors: Real-time parking availability
-
REST API: Complete endpoints for all device data
-
WebSocket Streaming: Real-time data updates every 2 seconds
-
AI Optimization: Rule-based logic for traffic, energy, and parking management
- Real-time dashboard with live data visualization
- Interactive charts using Recharts
- AI insights and recommendations display
- Responsive design for all screen sizes
IOTPJCT/
├── backend/
│ ├── main.py # FastAPI application
│ ├── requirements.txt # Python dependencies
│ ├── models/
│ │ └── schemas.py # Pydantic data models
│ ├── devices/
│ │ ├── traffic_sensor.py # Traffic simulation
│ │ ├── street_light.py # Street light simulation
│ │ ├── smart_meter.py # Energy meter simulation
│ │ └── parking_sensor.py # Parking simulation
│ └── ai/
│ └── optimizer.py # AI optimization logic
├── frontend/
│ ├── src/
│ │ ├── App.jsx # Main application component
│ │ ├── components/
│ │ │ ├── TrafficMonitor.jsx
│ │ │ ├── EnergyDashboard.jsx
│ │ │ ├── ParkingStatus.jsx
│ │ │ └── AIInsights.jsx
│ │ └── services/
│ │ └── api.js # API and WebSocket services
│ ├── package.json
│ └── vite.config.js
├── README.md
└── .gitignore
-
Navigate to backend directory:
cd backend -
Create virtual environment (recommended):
python -m venv venv # Windows venv\Scripts\activate # Linux/Mac source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Run the server:
uvicorn main:app --reload
The backend will be available at:
- API: http://localhost:8000
- API Docs: http://localhost:8000/docs
- WebSocket: ws://localhost:8000/ws
-
Navigate to frontend directory:
cd frontend -
Install dependencies:
npm install
-
Run the development server:
npm run dev
The frontend will be available at http://localhost:3000
-
Start the backend (in one terminal):
cd backend python -m uvicorn main:app --host 0.0.0.0 --port 8000 -
Start the frontend (in another terminal):
cd frontend npm run dev -
Open your browser to http://localhost:3000
The dashboard will automatically connect to the backend WebSocket and start displaying real-time data!
GET /- API information and available endpointsGET /api/traffic- Current traffic sensor dataGET /api/lights- Street light status and energyGET /api/energy- Smart meter readingsGET /api/parking- Parking availabilityGET /api/overview- City-wide statisticsGET /api/insights- AI-generated insights and recommendations
WS /ws- Real-time data stream (updates every 2 seconds)
The AI optimizer analyzes data in real-time and provides:
-
Traffic Optimization:
- Congestion detection and alerts
- Slow-moving traffic identification
- Alternative route recommendations
-
Energy Management:
- High consumption alerts
- Street light dimming suggestions
- Power quality monitoring
-
Parking Intelligence:
- Low availability warnings
- Overflow parking guidance
- Real-time capacity monitoring
- Realistic time-of-day traffic patterns
- Rush hour simulation (7-9 AM, 5-7 PM)
- Vehicle counting and speed monitoring
- Auto on/off based on time
- Adaptive brightness (dimmed 10 PM - 6 AM)
- Energy consumption tracking
- 6 Residential, 4 Commercial, 2 Industrial
- Building-specific consumption patterns
- Power quality metrics
- 5 parking locations across the city
- Dynamic occupancy based on time
- Duration tracking
Backend:
- FastAPI - Modern Python web framework
- Uvicorn - ASGI server
- WebSockets - Real-time communication
- Pydantic - Data validation
Frontend (Coming next):
- React 18
- Socket.IO Client
- Recharts
- Axios
- IoT devices generate simulated data every 2 seconds
- AI optimizer analyzes data and generates insights
- Data is aggregated and sent via WebSocket
- Frontend receives and visualizes real-time updates
{
"type": "update",
"timestamp": "2025-11-26T02:40:00",
"data": {
"traffic": [...],
"lights": [...],
"energy": [...],
"parking": [...],
"insights": [...],
"overview": {...}
}
}- All IoT data is simulated - no real devices required
- Devices use realistic patterns based on time of day
- AI uses rule-based logic (can be extended to ML models)
- WebSocket automatically reconnects on disconnection
- ✅ Backend with IoT simulation - COMPLETED
- ✅ Frontend React dashboard - COMPLETED
- ✅ Data visualization with Recharts - COMPLETED
- ⏳ 3D city visualization (optional enhancement)
- Real-time Dashboard: Live updates every 2 seconds via WebSocket
- Traffic Monitor: Area charts showing vehicle counts and congestion levels
- Energy Dashboard: Bar charts for building consumption and street light status
- Parking Status: Pie charts and location-based availability tracking
- AI Insights: Real-time alerts and recommendations with severity indicators
- Responsive Design: Works on desktop, tablet, and mobile devices
- Dark Theme: Modern, premium UI with smooth animations
This project is open source and available for educational purposes.
Feel free to fork this project and submit pull requests!
Built with ❤️ for smart city innovation