Skip to content

Latest commit

Β 

History

25 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

SafeRoute AI πŸ›‘οΈ

A cutting-edge AI-powered navigation system that prioritizes user safety through machine learning route analysis, crime data integration, and real-time emergency response features.

🌟 Features

Core Navigation

  • AI Safety Routing Engine: Custom A* algorithm with dynamic cost calculation
  • Dual Route Modes: Safest route (weighted for safety) vs Fastest route (shortest distance)
  • Real-time Safety Metrics: Live safety scores, lighting levels, crowd density analysis
  • AI Safety Prediction: Machine learning model for location-based safety scoring

3D Visualization

  • Mapbox GL Integration: Stunning 3D map with dark cyberpunk theme
  • 3D Building Extrusion: Immersive skyscraper visualization on zoom
  • Crime Heatmap Layer: Glowing neon red/orange danger zones
  • Neon Route Display: Dynamic green (safest) and cyan (fastest) route lines with glow effects

Safety Features

  • Crime Hotspot Analysis: High/Medium/Low severity zones with radius-based penalties
  • Safety Node Network: Lighting level and crowd density tracking
  • User Report System: Dynamic penalty calculation based on recent suspicious activity
  • SOS Emergency System: One-click emergency alert with full-screen red overlay
  • AI Explainability: Detailed risk factor breakdown and confidence scores

Hackathon-Ready Demo

  • Quick Demo Mode: Instant AI value demonstration for judges
  • 30-Second Demo Flow: Perfect judge presentation script
  • Demo Scenarios: High Risk Area, Safe Corridor, and Quick Demo modes
  • Presentation Guide: Complete talking points and Q&A preparation

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Frontend (Next.js)                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚   Sidebar    β”‚  β”‚     Map      β”‚  β”‚   SOS Panel  β”‚     β”‚
β”‚  β”‚  (React/TS)  β”‚  β”‚  (Mapbox GL) β”‚  β”‚  (Emergency) β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚ REST API
                         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Backend (FastAPI)                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚   Routing    β”‚  β”‚  AI/ML Model β”‚  β”‚     SOS      β”‚     β”‚
β”‚  β”‚   Service    β”‚  β”‚  (Scikit-learn)β”‚  β”‚   Service   β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Database (SQLite)                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚ Safety Nodes β”‚  β”‚Crime Hotspotsβ”‚  β”‚ User Reports β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Python 3.8+
  • Node.js 18+
  • Mapbox Access Token (get one at mapbox.com)

Backend Setup

cd backend

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

# Install dependencies
pip install -r requirements.txt

# Initialize database with mock data
python -m app.utils.generate_mock_data

# Start the server
uvicorn app.main:app --reload

The backend will be available at http://localhost:8000 API documentation: http://localhost:8000/docs

Frontend Setup

cd frontend

# Install dependencies
npm install

# Configure environment variables
# Edit .env.local and add your Mapbox token:
# NEXT_PUBLIC_MAPBOX_TOKEN=your_mapbox_token_here

# Start the development server
npm run dev

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

πŸ“ Project Structure

saferoute-ai/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   └── v1/
β”‚   β”‚   β”‚       β”œβ”€β”€ routing.py      # Route calculation endpoint
β”‚   β”‚   β”‚       β”œβ”€β”€ sos.py          # SOS emergency endpoint
β”‚   β”‚   β”‚       └── ai.py           # AI safety score endpoint
β”‚   β”‚   β”œβ”€β”€ db/
β”‚   β”‚   β”‚   β”œβ”€β”€ models.py           # SQLAlchemy models
β”‚   β”‚   β”‚   └── session.py          # Database session management
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   └── routing.py         # AI safety routing algorithm
β”‚   β”‚   β”œβ”€β”€ schemas/
β”‚   β”‚   β”‚   β”œβ”€β”€ routing.py         # Pydantic schemas
β”‚   β”‚   β”‚   └── sos.py             # SOS request schemas
β”‚   β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”‚   └── generate_mock_data.py  # Mock data generator
β”‚   β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”‚   └── config.py          # Configuration management
β”‚   β”‚   └── main.py                # FastAPI application
β”‚   β”œβ”€β”€ ml/
β”‚   β”‚   β”œβ”€β”€ safety_model.py        # ML model implementation
β”‚   β”‚   β”œβ”€β”€ feature_engineering.py # Feature extraction
β”‚   β”‚   └── train_model.py         # Model training
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── init_db.py                 # Database initialization
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”‚   β”œβ”€β”€ page.tsx           # Main application page
β”‚   β”‚   β”‚   β”œβ”€β”€ layout.tsx         # Root layout
β”‚   β”‚   β”‚   └── globals.css        # Global styles
β”‚   β”‚   └── components/
β”‚   β”‚       β”œβ”€β”€ Sidebar.tsx        # Glassmorphic sidebar with SOS
β”‚   β”‚       └── Map.tsx            # 3D Mapbox component
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ tailwind.config.ts
β”‚   └── .env.local                 # Environment variables
β”œβ”€β”€ HACKATHON_PRESENTATION.md      # Demo guide for judges
β”œβ”€β”€ DEPLOYMENT.md                  # Deployment documentation
β”œβ”€β”€ API_DOCUMENTATION.md           # API reference
└── README.md

πŸ”§ API Endpoints

Route Calculation

POST /api/v1/calculate
Content-Type: application/json

{
  "source": {
    "latitude": 28.6315,
    "longitude": 77.2167
  },
  "destination": {
    "latitude": 28.6350,
    "longitude": 77.2200
  },
  "safety_weight": 0.7
}

AI Safety Score

GET /api/v1/ai/safety-score?latitude=28.6315&longitude=77.2167&radius=1000

SOS Emergency Alert

POST /api/v1/sos/trigger
Content-Type: application/json

{
  "latitude": 28.6315,
  "longitude": 77.2167,
  "timestamp": "2026-06-04T01:00:00Z"
}

Health Check

GET /health

🧠 AI/ML Pipeline

Feature Engineering

  • Lighting Level Analysis: Street light density and coverage
  • Crime Hotspot Detection: Proximity to reported crime locations
  • Crowd Density Assessment: Real-time crowd estimation
  • Historical Incident Data: Past safety incidents in area
  • Time-based Factors: Safety varies by time of day

Model Architecture

  • Algorithm: Random Forest Regressor
  • Features: 15+ engineered safety features
  • Output: Safety score between 0.0 (unsafe) and 1.0 (safe)
  • Confidence: Model reliability metrics (87% average)
  • Fallback: Rule-based system when AI unavailable

Routing Algorithm

Cost = Distance + Safety Penalty

Safety Penalties:
- Crime Hotspots: HIGH (2500), MEDIUM (500), LOW (100)
- Low Lighting: 50
- Sparse Crowd: 30
- Recent User Reports: Dynamic (decays over time)
- AI Safety Score: Integrated into cost calculation

🎨 Design Philosophy

  • Cyberpunk Aesthetic: Dark theme with neon accents
  • Glassmorphism: Frosted glass UI elements
  • Smooth Animations: Cinematic transitions with Framer Motion
  • 3D Immersion: Building extrusion and spatial visualization
  • Accessibility: High contrast and clear visual hierarchy

πŸ” Security Features

  • CORS configuration for frontend-backend communication
  • Environment variable management for sensitive data
  • Input validation with Pydantic schemas
  • SQL injection prevention with SQLAlchemy ORM
  • Auto-generated SECRET_KEY for JWT tokens
  • Health check endpoint for monitoring

πŸ“Š Mock Data

The system generates realistic mock data for Connaught Place, Delhi:

  • 80 Safety Nodes with safety scores, lighting levels, and crowd density
  • 15 Crime Hotspots with severity levels and radius
  • 50 User Reports with various types and timestamps
  • 50 Detour Nodes for alternative routing

🎯 Demo Instructions

Quick Demo Mode (30-Second Judge Demo)

  1. Click "Quick Demo Mode" button in the sidebar
  2. Watch AI calculate optimal safe route
  3. View safety score comparison (safest vs fastest)
  4. See AI explainability panel with risk factors

Demo Scenarios

  • High Risk Area: Shows AI avoiding crime hotspots
  • Safe Corridor: Demonstrates optimal safe routing
  • Quick Demo: Instant AI value demonstration

See HACKATHON_PRESENTATION.md for complete demo script and talking points.

🐳 Docker Deployment

Using Docker Compose (Recommended)

# Build and start all services
docker-compose up --build

# Services will be available at:
# - Frontend: http://localhost:3000
# - Backend: http://localhost:8000
# - API Docs: http://localhost:8000/docs

Individual Docker Builds

# Backend
cd backend
docker build -t saferoute-backend .
docker run -p 8000:8000 saferoute-backend

# Frontend
cd frontend
docker build -t saferoute-frontend .
docker run -p 3000:3000 saferoute-frontend

See DEPLOYMENT.md for detailed deployment instructions.

πŸ“š Documentation

  • API Documentation: See API_DOCUMENTATION.md for complete API reference
  • Deployment Guide: See DEPLOYMENT.md for production deployment
  • Hackathon Guide: See HACKATHON_PRESENTATION.md for demo instructions
  • Interactive API Docs: Available at http://localhost:8000/docs when backend is running

🚧 Future Enhancements

  • Real-time GPS tracking
  • User authentication and profiles
  • Historical route analysis
  • Integration with real emergency services APIs
  • Mobile application (React Native)
  • Multi-city support
  • Real-time crowd-sourced safety reports
  • Advanced ML model training with real data

πŸ› Troubleshooting

Common Issues

Mapbox Token Error

  • Ensure NEXT_PUBLIC_MAPBOX_TOKEN is set in frontend/.env.local
  • Get a free token at mapbox.com

Backend Connection Error

  • Verify backend is running on http://localhost:8000
  • Check CORS configuration in backend/app/main.py
  • Ensure database is initialized with mock data

Port Conflicts

  • Frontend auto-selects available ports (3000-3006)
  • Backend runs on port 8000 by default
  • Modify ports in respective configuration files if needed

πŸ“ License\n\nThis project is licensed under the Apache License 2.0 - see the LICENSE file for details.

πŸ‘₯ Team

SafeRoute AI Development Team

πŸ“ž Support

For support and inquiries, contact the development team.


Built with ❀️ for safer navigation

About

AI-powered safe navigation with ML safety scoring, custom A* routing, crime heatmaps & SOS - FastAPI + Next.js + scikit-learn

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages