Skip to content

RoyRoki/SadakAI

Repository files navigation

SadakAI 🚧

Real-time Indian Road Hazard Detection & Crowdsourced Mapping Platform

License: MIT Python Next.js FastAPI

SadakAI is a comprehensive road hazard detection and mapping platform designed specifically for Indian roads. It uses computer vision (YOLOv8) to detect potholes, cracks, speed breakers, and waterlogging from images uploaded by users.

SadakAI Dashboard

✨ Features

Core Features

  • πŸ—ΊοΈ Interactive Map - View all reported hazards on an interactive Leaflet map
  • πŸ“Έ Image Detection - Upload images for AI-powered hazard detection
  • πŸ“Š Statistics Dashboard - Comprehensive stats and trends visualization
  • πŸ“„ Report Generation - Export hazard data as CSV reports
  • πŸ“± Mobile-First - Fully responsive PWA design
  • πŸ” Advanced Filtering - Filter by severity, type, and status

Technical Features

  • πŸ€– YOLOv8 Model - State-of-the-art object detection
  • πŸ—„οΈ PostgreSQL + PostGIS - Geospatial database for location data
  • ☁️ Cloudflare R2 - S3-compatible object storage
  • 🐳 Docker - Containerized deployment
  • ⚑ FastAPI - High-performance async backend
  • 🌐 Next.js 14 - Modern React frontend

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    FRONTEND (Next.js 14)                    β”‚
β”‚  Dashboard β”‚ Map View β”‚ Upload β”‚ Reports β”‚ Stats            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚ REST API
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    BACKEND (FastAPI)                         β”‚
β”‚  /detect β”‚ /hazards β”‚ /reports β”‚ /stats β”‚ /upload           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚          β”‚                  β”‚
       β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β” β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
       β”‚ YOLOv8  β”‚ β”‚ PostgreSQL β”‚  β”‚ Cloudflare β”‚
       β”‚ Model   β”‚ β”‚ + PostGIS  β”‚  β”‚ R2 Storage β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

SadakAI/
β”œβ”€β”€ model/                    # Machine Learning
β”‚   β”œβ”€β”€ data/               # Dataset configuration
β”‚   β”œβ”€β”€ notebooks/          # Training notebooks (Colab)
β”‚   β”œβ”€β”€ scripts/           # Dataset preparation scripts
β”‚   └── weights/           # Trained model weights
β”‚
β”œβ”€β”€ api/                    # Backend API (FastAPI)
β”‚   β”œβ”€β”€ config.py          # Configuration settings
β”‚   β”œβ”€β”€ main.py            # Application entry point
β”‚   β”œβ”€β”€ models/            # Database models & schemas
β”‚   β”œβ”€β”€ routers/           # API endpoints
β”‚   β”œβ”€β”€ services/          # Business logic
β”‚   β”œβ”€β”€ seed.py            # Demo data seeder
β”‚   └── requirements.txt   # Python dependencies
β”‚
β”œβ”€β”€ dashboard/              # Frontend (Next.js 14)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/          # App router pages
β”‚   β”‚   β”œβ”€β”€ components/   # React components
β”‚   β”‚   β”œβ”€β”€ hooks/        # Custom React hooks
β”‚   β”‚   └── lib/          # Utilities & API client
β”‚   └── package.json
β”‚
β”œβ”€β”€ docker-compose.yml      # Docker orchestration
β”œβ”€β”€ .env.example           # Environment variables template
└── README.md              # This file

πŸš€ Quick Start

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • PostgreSQL 15+ (with PostGIS extension)
  • Docker & Docker Compose (optional)

Option 1: Local Development

1. Clone the repository

git clone https://github.com/your-username/SadakAI.git
cd SadakAI

2. Set up the backend

cd api

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Copy environment variables
cp .env.example .env

# Run the API server
uvicorn api.main:app --reload

The API will be available at http://localhost:8000

  • API Documentation: http://localhost:8000/docs
  • Health Check: http://localhost:8000/health

3. Set up the frontend

cd dashboard

# Install dependencies
npm install

# Copy environment variables
cp .env.example .env

# Run development server
npm run dev

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

Option 2: Docker Compose

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

πŸ“– API Endpoints

Detection

Method Endpoint Description
POST /api/detect Upload image for hazard detection
POST /api/detect/batch Batch detection for multiple images

Hazards

Method Endpoint Description
GET /api/hazards List all hazards (paginated)
GET /api/hazards/{id} Get hazard details
PATCH /api/hazards/{id} Update hazard status
DELETE /api/hazards/{id} Delete hazard (soft delete)
GET /api/hazards/nearby Get hazards near a location
GET /api/hazards/bbox Get hazards in bounding box

Statistics

Method Endpoint Description
GET /api/stats/overview Get overview statistics
GET /api/stats/trends Get hazard trends over time
GET /api/stats/worst-roads Get worst areas by hazard count

πŸ”§ Configuration

Environment Variables

Create a .env file in the api/ directory:

# Database
DATABASE_URL=postgresql://user:password@localhost:5432/sadakai

# Cloudflare R2 Storage (optional)
R2_ENDPOINT=https://your-account.r2.cloudflarestorage.com
R2_ACCESS_KEY=your_access_key
R2_SECRET_KEY=your_secret_key
R2_BUCKET=sadakai-images

# API
API_KEY=your_api_key_here
MODEL_PATH=model/weights/best.pt

# Frontend
NEXT_PUBLIC_API_URL=http://localhost:8000

πŸ€– Training the Model

Dataset Preparation

The model is trained on publicly available road damage datasets:

Dataset Source Description
RDD2022 IEEE Big Data Cup 47,000+ images
Indian Pothole Dataset Roboflow Universe 1,500+ Indian potholes
Speed Breaker Dataset Roboflow Universe 500+ speed breakers

Training Steps

  1. Download datasets from the sources above
  2. Place images in model/data/images/{train,val,test}/
  3. Run dataset preparation:
    python model/scripts/prepare_dataset.py
  4. Open model/notebooks/train.ipynb in Google Colab
  5. Run the training notebook with T4 GPU
  6. Download trained weights to model/weights/best.pt

Supported Hazard Classes

  • pothole - Road potholes
  • crack - Road cracks
  • speed_breaker - Speed breakers
  • waterlogging - Water accumulation

πŸ“± Mobile Features

  • πŸ“ GPS Location - Auto-detect current location
  • πŸ“Έ Camera Capture - Take photos directly
  • πŸ“‹ Clipboard Paste - Paste images from clipboard
  • πŸ–ΌοΈ Photo Library - Select from gallery

πŸ§ͺ Testing

Backend Tests

cd api
pytest

Frontend Tests

cd dashboard
npm test

🚒 Deployment

Production Build

# Frontend
cd dashboard
npm run build

# Backend
cd api
pip install -r requirements.txt
gunicorn api.main:app -w 4 -k uvicorn.workers.UvicornWorker

Recommended Hosting

Service Purpose Free Tier
Vercel Frontend βœ…
Railway/Render Backend βœ…
Neon/Supabase PostgreSQL βœ…
Cloudflare R2 Storage βœ…

See DEPLOYMENT.md for detailed deployment instructions.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

See CONTRIBUTING.md for details.

πŸ“ License

This project is licensed under the MIT License - see LICENSE for details.

πŸ™ Acknowledgments

πŸ“§ Contact


Made with ❀️ for safer Indian roads

About

SadakAI is a comprehensive road hazard detection and mapping platform designed specifically for Indian roads. It uses computer vision (YOLOv8) to detect potholes, cracks, speed breakers, and waterlogging from images uploaded by users.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors