Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI-Powered Virtual Smart City 🏙️

A fully virtual smart city simulation with IoT devices, real-time dashboard, and AI-based optimization.

🌟 Features

Backend (Python + FastAPI)

  • 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

Frontend (React + Socket.IO)

  • Real-time dashboard with live data visualization
  • Interactive charts using Recharts
  • AI insights and recommendations display
  • Responsive design for all screen sizes

📁 Project Structure

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

🚀 Getting Started

Backend Setup

  1. Navigate to backend directory:

    cd backend
  2. Create virtual environment (recommended):

    python -m venv venv
    
    # Windows
    venv\Scripts\activate
    
    # Linux/Mac
    source venv/bin/activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Run the server:

    uvicorn main:app --reload

    The backend will be available at:

Frontend Setup

  1. Navigate to frontend directory:

    cd frontend
  2. Install dependencies:

    npm install
  3. Run the development server:

    npm run dev

    The frontend will be available at http://localhost:3000

Running the Complete System

  1. Start the backend (in one terminal):

    cd backend
    python -m uvicorn main:app --host 0.0.0.0 --port 8000
  2. Start the frontend (in another terminal):

    cd frontend
    npm run dev
  3. Open your browser to http://localhost:3000

The dashboard will automatically connect to the backend WebSocket and start displaying real-time data!

📡 API Endpoints

REST API

  • GET / - API information and available endpoints
  • GET /api/traffic - Current traffic sensor data
  • GET /api/lights - Street light status and energy
  • GET /api/energy - Smart meter readings
  • GET /api/parking - Parking availability
  • GET /api/overview - City-wide statistics
  • GET /api/insights - AI-generated insights and recommendations

WebSocket

  • WS /ws - Real-time data stream (updates every 2 seconds)

🤖 AI Features

The AI optimizer analyzes data in real-time and provides:

  1. Traffic Optimization:

    • Congestion detection and alerts
    • Slow-moving traffic identification
    • Alternative route recommendations
  2. Energy Management:

    • High consumption alerts
    • Street light dimming suggestions
    • Power quality monitoring
  3. Parking Intelligence:

    • Low availability warnings
    • Overflow parking guidance
    • Real-time capacity monitoring

🎯 Simulated IoT Devices

Traffic Sensors (8 locations)

  • Realistic time-of-day traffic patterns
  • Rush hour simulation (7-9 AM, 5-7 PM)
  • Vehicle counting and speed monitoring

Street Lights (12 units)

  • Auto on/off based on time
  • Adaptive brightness (dimmed 10 PM - 6 AM)
  • Energy consumption tracking

Smart Meters (12 units)

  • 6 Residential, 4 Commercial, 2 Industrial
  • Building-specific consumption patterns
  • Power quality metrics

Parking Sensors (102 spots)

  • 5 parking locations across the city
  • Dynamic occupancy based on time
  • Duration tracking

🔧 Technology Stack

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

📊 Data Flow

  1. IoT devices generate simulated data every 2 seconds
  2. AI optimizer analyzes data and generates insights
  3. Data is aggregated and sent via WebSocket
  4. Frontend receives and visualizes real-time updates

🌐 WebSocket Data Format

{
  "type": "update",
  "timestamp": "2025-11-26T02:40:00",
  "data": {
    "traffic": [...],
    "lights": [...],
    "energy": [...],
    "parking": [...],
    "insights": [...],
    "overview": {...}
  }
}

📝 Development Notes

  • 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

✅ Project Status

  1. ✅ Backend with IoT simulation - COMPLETED
  2. ✅ Frontend React dashboard - COMPLETED
  3. ✅ Data visualization with Recharts - COMPLETED
  4. ⏳ 3D city visualization (optional enhancement)

🎨 Frontend Features

  • 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

📄 License

This project is open source and available for educational purposes.

🤝 Contributing

Feel free to fork this project and submit pull requests!


Built with ❤️ for smart city innovation

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages