Skip to content
Jai Tiwari edited this page Jun 4, 2025 · 1 revision

Safe Route: Intelligent Route Safety Navigation System for India

Project Overview

Safe Route is a full-stack web application designed to address the critical issue of road safety in India. By leveraging crowdsourced data, real-time routing algorithms, and modern web technologies, the application enables users to find routes that prioritize both safety and efficiency. This project represents a novel approach to navigation that goes beyond traditional metrics like distance and time, incorporating the human element of road safety perception.

Problem Statement

India faces significant challenges with road safety, recording over 150,000 road fatalities annually. Traditional navigation systems focus primarily on finding the shortest or fastest routes without considering safety factors. Safe Route addresses this gap by creating a platform where:

  1. Users can share knowledge about road conditions and safety
  2. Algorithms can calculate routes that balance safety with travel time
  3. Travelers can make informed decisions based on comprehensive route information

Core Features

Intelligent Route Calculation

  • Safety-Prioritized Algorithm: Custom weighted algorithm that balances safety (70%) with travel time (30%)
  • Multiple Routing Services: Integration with OpenRouteService, GraphHopper, and OSRM for robust route generation
  • Fallback Mechanisms: Graceful degradation when external services are unavailable

Crowdsourced Road Ratings

  • Segment-Based Rating System: Roads divided into ~2km segments for precise ratings
  • Binary Rating Options: Simple "Good" or "Bad" ratings for ease of use
  • Aggregated Safety Scores: Ratings combined to generate 0-100 safety scores for routes

Interactive Map Interface

  • Leaflet Integration: High-performance map rendering with React-Leaflet
  • Visual Safety Indicators: Color-coded route segments based on safety ratings
  • Interactive Elements: Clickable segments for rating submission

Location Services

  • Geolocation Integration: Automatic detection of user's current location
  • Search with Autocomplete: Location search powered by Nominatim API
  • India-Specific Boundaries: Optimized for Indian geographical context

Technology Stack

Frontend

  • React: Component-based UI architecture with hooks for state management
  • Leaflet: Interactive maps with custom overlays and controls
  • Tailwind CSS: Utility-first CSS framework for responsive design
  • Axios: Promise-based HTTP client for API requests
  • Firebase Authentication: User authentication and account management

Backend

  • Node.js/Express: RESTful API server with middleware support
  • Firebase Firestore: NoSQL database for storing ratings and user data
  • Firebase Functions: Serverless functions for API endpoints
  • Firebase Hosting: Production deployment platform

External APIs and Services

  • OpenRouteService: Primary routing service for real road network data
  • GraphHopper: Alternative routing service for redundancy
  • OSRM (Open Source Routing Machine): Lightweight routing service
  • Nominatim: Geocoding service for location search
  • Firebase: Authentication, database, and hosting platform

Implementation Details

Route Calculation Methodology

The route calculation process follows these steps:

  1. Multiple Route Generation: Request several alternative routes from routing services
  2. Segmentation: Divide routes into ~2km segments for granular safety analysis
  3. Safety Score Application: Apply known safety ratings to each segment
  4. Score Calculation: Calculate a weighted score using:
    finalScore = (safetyScore * 0.7) + (speedScore * 0.3)
    
  5. Route Selection: Select the route with the highest combined score

Road Rating System

The rating system implements:

  1. Segment Identification: Unique IDs for each road segment based on coordinates
  2. Majority Voting: Aggregation of multiple user ratings for each segment
  3. Temporal Relevance: More recent ratings given higher weight
  4. Persistence: Ratings stored in Firebase Firestore with fallback to local storage

Data Flow Architecture

The application follows a client-server architecture with these data flows:

  1. Location Input: User inputs start and destination locations
  2. Route Request: Client requests route options from server
  3. External API Calls: Server communicates with routing services
  4. Safety Enhancement: Server applies safety data to routes
  5. Response Delivery: Enhanced routes returned to client
  6. Visualization: Client renders routes with safety indicators
  7. User Feedback: Ratings submitted back to server for storage

Challenges and Solutions

Challenge 1: Routing Service Reliability

Problem: External routing APIs occasionally fail or have rate limits. Solution: Implemented a multi-tiered fallback system:

  1. Primary: OpenRouteService with API key
  2. Secondary: GraphHopper with alternative API key
  3. Tertiary: OSRM public API
  4. Final Fallback: Client-side direct route calculation with safety overlays

Challenge 2: Data Sparsity

Problem: Limited initial road safety data for meaningful route calculations. Solution:

  1. Implemented a mock data generation system for initial testing
  2. Created a bootstrap dataset for major Indian cities
  3. Designed algorithms that function with partial data coverage
  4. Added weighted confidence scores based on data density

Challenge 3: Performance Optimization

Problem: Route calculation and rendering caused performance issues on mobile devices. Solution:

  1. Implemented request debouncing and throttling
  2. Added route caching for frequently accessed paths
  3. Optimized Leaflet rendering with clustering and simplified geometries
  4. Used React.memo and useMemo for component optimization

Challenge 4: Firebase Integration

Problem: Authentication and database integration issues in production. Solution:

  1. Created robust error handling with graceful degradation
  2. Implemented client-side fallbacks when Firebase services are unavailable
  3. Added comprehensive logging for debugging
  4. Developed a hybrid storage approach using both Firestore and local storage

Deployment Architecture

The application is deployed using a modern cloud-native approach:

  1. Firebase Hosting: Static assets and client-side application
  2. Firebase Functions: Serverless backend API endpoints
  3. Firebase Firestore: NoSQL database for ratings and user data
  4. Firebase Authentication: User identity management

This architecture provides:

  • Scalability to handle varying load
  • High availability across geographical regions
  • Cost-effectiveness with pay-as-you-go pricing
  • Simplified DevOps with automated deployment pipelines

Research Implications

This project has several implications for research in transportation safety:

  1. Crowdsourced Safety Data: Demonstrates the viability of user-generated safety ratings
  2. Multi-factor Route Optimization: Extends beyond traditional time/distance optimization
  3. Human-Computer Interaction: Novel interface design for safety-focused navigation
  4. Data Visualization: Effective communication of safety information in map context

Future Directions

Planned enhancements include:

  1. Machine Learning Integration: Predictive safety models based on historical data
  2. Detailed Rating Categories: Expanded rating options for specific hazards
  3. Temporal Analysis: Time-based safety patterns (day/night, seasonal)
  4. Mobile Applications: Native iOS and Android versions
  5. Offline Functionality: Enhanced capabilities without internet connection
  6. Integration with Vehicle Systems: API for in-vehicle navigation systems

Getting Started

Prerequisites

  • Node.js (v14 or higher)
  • Firebase account and project
  • API keys for routing services

Installation

  1. Clone the repository
git clone <repository-url>
cd safe-route
  1. Install server dependencies
cd server
npm install
  1. Install client dependencies
cd ../client
npm install
  1. Configure Firebase
firebase login
firebase use <your-project-id>

Running the Application

  1. Start the server
cd server
npm run dev
  1. Start the client
cd ../client
npm start
  1. Open your browser and navigate to http://localhost:3000

Usage

  1. Allow location access when prompted
  2. Search for a destination using the sidebar
  3. The app will calculate and display the safest route
  4. You can rate road segments by clicking on them
  5. Traffic conditions are displayed with color-coded overlays

Acknowledgments

  • OpenStreetMap for map data
  • Leaflet for map visualization
  • OpenRouteService for routing API
  • Firebase for backend services
  • The research community for guidance on safety metrics