Skip to content
Partha-ShankarPublic

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

RoadSoS

React TypeScript FastAPI Leaflet OpenStreetMap

A mobile-first emergency response web application for road accidents. RoadSoS uses the device's location to find nearby hospitals, police stations, ambulance stations, and vehicle rescue services, and presents them with one-tap calling and navigation.

Notice: RoadSoS is a prototype. In an emergency, call your local emergency number directly (112 in India). When live data is unavailable, the application shows sample entries marked "(Demo)", which are not real services.

Overview

RoadSoS is designed for use under stress, with a single prominent SOS button, large touch targets, and a high-contrast interface. A FastAPI backend queries OpenStreetMap through the Overpass API and ranks results by distance, so the application needs no paid map or places API key.

Key Features

  • SOS button: a single tap requests the device location and loads nearby services
  • Ranked service lists: hospitals, police, ambulance, and vehicle rescue, sorted by straight-line distance
  • Tap to call and navigate: direct tel: links and Google Maps directions for every result
  • Interactive map: Leaflet map with OpenStreetMap tiles and custom markers, with a list and map toggle on mobile
  • Accident report sharing: generates a report containing the location, time, description, and a map link, ready to share through WhatsApp
  • Bilingual interface: one-tap switching between English and Hindi
  • Emergency helplines: national and regional helpline directory, with a built-in copy if the API is unreachable
  • Cached results: the last successful search is stored in localStorage and shown with its age when the device is offline
  • Fallback behavior: uses Bengaluru coordinates in a labeled demo mode when location access is unavailable, and sample entries when the Overpass API fails or returns nothing

Technology Stack

Layer Technology
Frontend React 19, TypeScript, Vite
Styling Tailwind CSS 4, Lucide icons
Maps Leaflet, OpenStreetMap tiles
Localization i18next, react-i18next
Backend FastAPI, Uvicorn, Pydantic, Requests
Data source OpenStreetMap Overpass API

Architecture and Workflow

flowchart LR
    A[SOS button] --> B[Browser geolocation]
    B --> C[POST /api/nearby]
    C --> D[FastAPI backend]
    D --> E[Overpass API]
    E --> D
    D --> F[Categorized results sorted by distance]
    F --> G[Lists, map, and localStorage cache]
Loading

Project Structure

RoadSoS/
├── backend/
│   ├── main.py              API routes, Overpass query, and distance logic
│   └── requirements.txt
├── frontend/
│   ├── src/
│   │   ├── App.tsx          Application interface and state
│   │   ├── i18n.ts          English and Hindi translations
│   │   ├── index.css
│   │   └── main.tsx
│   └── package.json
└── README.md

Installation and Setup

Prerequisites

  • Node.js 18 or later
  • Python 3.9 or later

Backend

cd backend
pip install -r requirements.txt
python main.py

The API runs at http://127.0.0.1:8000.

Frontend

cd frontend
npm install
npm run dev

The application runs at http://localhost:5173.

Configuration

No API keys are required. The frontend reads one optional variable:

Variable Default Purpose
VITE_API_URL http://127.0.0.1:8000 Backend base URL

Usage

  1. Open the application and select the SOS button.
  2. Allow location access when prompted.
  3. Choose a service category, then call or navigate to a listed service.
  4. Optionally complete the accident report form and share the summary through WhatsApp.

API Reference

Method Path Purpose
POST /api/nearby Returns categorized services for a lat and lng
GET /api/emergency-numbers Returns national and regional helplines

Technical Implementation

Service Discovery

The backend sends one Overpass QL query covering hospitals, police, and ambulance stations within 10 km, and car repair and towing services within 15 km. Each result is categorized from its OpenStreetMap tags, and its distance from the user is calculated with the Haversine formula.

Contact and Address Handling

Addresses are assembled from OpenStreetMap address tags. When a result has no phone number, the backend substitutes the relevant national helpline: 108 for medical services, 100 for police, and 1073 for vehicle rescue.

Offline Behavior

The browser's online status is monitored, and an offline banner shows the age of the cached results. The helpline directory is built into the frontend, so it remains available if the backend cannot be reached.

Future Scope

  • Full offline support through a service worker
  • Additional languages
  • Live traffic-aware routing

Releases

Packages

Contributors

Languages