Skip to content

Latest commit

Β 

History

67 Commits

Folders and files

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

Repository files navigation

SAFORA β€” Community Safety & Safe Walk App

React Native TypeScript Node.js Express PostgreSQL PostGIS

Academic Context: Minor Project-I submitted in partial fulfilment of the requirements for the degree of Bachelor of Technology in Computer Science & Engineering Institution: Dev Bhoomi Uttarakhand University (DBUU), Dehradun Batch: 2026 – 2027 Supervisor: Mr. Mukesh Rajput (Assistant Professor, Department of CSE, SoEC, DBUU) Project Team: Arushi Saxena (24BTCSE0241), Anurag Suyal (24BTCSE0264), Aman Singh Kunwar (24BTCSE0321), Shubham Kumar (24BTCSE0333)


🌟 Executive Summary

SAFORA is a community-powered personal safety navigation and emergency response application designed for campus and urban environments. While standard navigation systems focus solely on distance and speed, SAFORA empowers walkersβ€”especially women and students traveling at night or in unfamiliar areasβ€”to evaluate safety risks in real time.

Users crowdsource hazard reports (poor lighting, road hazards, waterlogging, isolated areas, harassment hotspots), view an algorithmic safety score, share their journey during Safe Walk mode, and trigger an instant One-Tap SOS to trusted contacts.

flowchart TD
    User(["πŸ‘€ Mobile User (Student / Citizen)"])
    Admin(["πŸ›‘οΈ Operations Lead (Web Admin Only)"])

    subgraph MobileApp ["Mobile Safety App (React Native + TypeScript)"]
        Radar["Safety Radar & Geospatial Canvas"]
        SafeWalk["Safe Walk Engine (150m Corridor)"]
        SOS["One-Tap SOS Emergency Trigger"]
    end

    subgraph WebAdmin ["Web Operations Command (React + Vite - Web Only)"]
        CommandMap["Live Operations Map"]
        IncidentQueue["Real-time SOS Dispatch Queue"]
        Moderation["Hazard Moderation & Verification Hub"]
        UserMgmt["User Directory"]
    end

    subgraph BackendGateway ["Backend API & Real-Time Gateway (Node.js + Express)"]
        Auth["JWT Auth & Role Guards"]
        ScoreEngine["Decay-Weighted Safety Score Engine"]
        IncidentMgr["Incident & Socket.IO Dispatcher"]
    end

    subgraph SpatialDB ["Spatial Data Store (PostgreSQL + PostGIS)"]
        PostGIS[("PostGIS Engine<br/>geography(Point, 4326) + GiST Indexes")]
    end

    subgraph ExternalServices ["External Services & Notifications"]
        FCM["Firebase Cloud Messaging (FCM)"]
        Cloudinary["Cloudinary Evidence Storage"]
        Contacts["πŸ‘₯ Trusted Contacts (SMS & Push)"]
    end

    User <--> MobileApp
    Admin <--> WebAdmin
    MobileApp <==>|"HTTPS (REST) & WSS (Socket.IO)"| BackendGateway
    WebAdmin <==>|"HTTPS (REST) & WSS (Socket.IO)"| BackendGateway
    BackendGateway <-->|"ST_DWithin & GiST Spatial Query"| SpatialDB
    BackendGateway -->|"Emergency Push"| FCM
    BackendGateway -->|"Media Storage"| Cloudinary
    FCM --> Contacts
Loading

The diagram above shows the target architecture the project is built toward. Live location streaming to guardians and automatic server-side deviation alerts are active development work β€” see Development Status below for what's built today versus in progress.


πŸ“Š Development Status

This project follows a staged plan (docs/v1/ β†’ docs/v2/ β†’ docs/v3/) rather than a single big-bang build. V1 is the version being built for this submission and targets the six modules below; not everything in this README is live yet.

Area Status
Auth, hazard reporting, offline queue, safety-score calculation βœ… Working
Live location streaming to guardians during Safe Walk πŸ”§ In progress β€” see docs/v1/tasks.md (task 5–6)
Automatic server-side deviation escalation (beyond the phone-side 60s prompt) πŸ”§ In progress β€” docs/v1/tasks.md (task 7)
Safety-score heatmap on the map screen πŸ”§ In progress β€” docs/v1/tasks.md (task 8)
Background tracking with screen locked, lock-screen SOS audio, ETA notification πŸ”§ In progress β€” docs/v1/tasks.md (tasks 13–15)
Admin dashboard β€” hazard moderation, SOS queue βœ… Working
Admin "live" Safe Walk radar πŸ”§ Sample-data fallback being removed β€” docs/v1/tasks.md (task 3)
One-tap SOS (GPS + battery + audio, FCM push, manual SMS/dialer fallback) βœ… Working

Full live status, file-level tasks, and acceptance tests are tracked in docs/v1/tasks.md β€” that file, not this README, is the source of truth while V1 is in progress.


πŸ“š Project Documentation Hub

Documentation is organised into three stages, plus an archive of earlier drafts:

Folder Contents
πŸš€ docs/v1/ This submission. Architecture, API, database schema, safety algorithms, mobile features, admin panel, setup, task list, and testing/submission checklist for the current build.
πŸ—ΊοΈ docs/v2/ Product roadmap beyond the submission: accounts hardening, real per-mode routing & voice guidance, no-unlock SOS triggers, staged chat, Hindi/Uttarakhand localisation, weather & earthquake data, security/privacy/DPDP compliance.
πŸ”­ docs/v3/ Research notes on the synopsis's future-scope items (AI safe-route scoring, offline mesh SOS messaging, AI hazard image detection) β€” honestly scoped, not scheduled.
πŸ—„οΈ docs/archive/ Earlier documentation drafts, kept for reference during the transition to the v1/v2/v3 structure.
πŸ“„ Academic Synopsis PDF Approved project synopsis submitted to Dev Bhoomi Uttarakhand University.

Start here: docs/README.md (folder index) β†’ docs/v1/README.md (this submission's scope) β†’ docs/v1/tasks.md (what's being worked on right now).


πŸš€ Key Features & The 6 Core Modules

Based on Section 4.2 of the Project Synopsis. Items marked πŸ”§ are in active development for this submission β€” see Development Status.

  1. Module 1: User Authentication, Onboarding & Session Management
    • Secure stateless authentication using JSON Web Tokens (JWT) and bcrypt password hashing.
    • 4-Slide First-Install Onboarding Flow (OnboardingScreen.tsx) introducing the Safety Score, Safe Walk, Instant SOS, and Community Reporting, with "Skip" and "Get Started" triggers.
    • Rehydration splash loader preventing login screen flicker on app resume; guest mode examiner bypass.
  2. Module 2: Community Hazard Reporting & Offline Queue
    • Crowdsourced hazard pinning with category selection (lighting, construction, waterlogging, isolated trail, traffic) and severity ratings (1 to 5).
    • Anti-abuse mechanisms: rate limiting (20 report submissions per 15-minute window per user) and strict schema input validation.
    • In-memory server-side caching for nearby-hazard and safety-score queries, invalidated on new report submission.
    • Offline Incident Queue: stores unsubmitted hazard reports in AsyncStorage when internet drops, automatically syncing once connection is restored.
  3. Module 3: Safety Score & Calibrated Multi-Modal Routing
    • Real-time score computation (0–100) combining hazard severity, distance falloff, recency exponential decay ($t_{\text{half}} = 24\text{h}$), and community confirmations. See docs/v1/safety-algorithms.md for the exact formula.
    • Spatial analysis endpoint via PostGIS ST_ClusterDBSCAN (GET /api/reports/clusters), grouping hazards within ~330m for density analytics. πŸ”§ Rendering this as a heatmap on the map/home screens is in progress.
    • Calibrated Multi-Modal Travel Time estimates (Walk / 2-Wheeler / Car), based on fixed speed constants over the routed distance:
      • Walk: $1.60\text{ m/s}$ ($5.8\text{ km/h}$) β†’ ~10.4 mins per 1 km.
      • 2-Wheeler: $8.88\text{ m/s}$ ($32\text{ km/h}$) + 20s buffer β†’ ~2.2 mins per 1 km.
      • Car: $7.22\text{ m/s}$ ($26\text{ km/h}$) + 45s buffer β†’ ~3.0 mins per 1 km.
    • Known limitation: all three modes currently route over the same street geometry (a single routing call); real per-mode route differentiation is planned for docs/v2/.
    • Proximity-biased local search powered by the Photon OpenStreetMap engine, with a MapTiler fallback.
  4. Module 4: Safe Walk Mode & Geospatial Canvas
    • Server-side route-compliance monitoring along a configured 150-meter corridor.
    • Dual-Strategy Geolocation: high-accuracy GPS with automatic fallback to cellular triangulation.
    • Layered basemap switcher: dark and light themes over OpenStreetMap tiles, plus Esri World Imagery for satellite view.
    • Note on offline tile caching: an earlier bulk offline-tile-prefetch approach is being reworked (docs/v2/) to comply with OpenStreetMap's tile usage policy and to add proper attribution.
    • Hierarchical Android hardware back navigation: step-back through search dropdowns β†’ hazard cards β†’ tab history β†’ double-tap exit on Home.
    • Confirm-before-escalate: on a route deviation, the walker gets a 60-second on-phone prompt before contacts are notified. πŸ”§ A server-side backstop (so an escalation still fires if the app is killed or the phone loses signal) and live location streaming to guardians are in progress for this submission β€” see docs/v1/architecture.md Β§3–§4.
  5. Module 5: Guardian SOS, Safety Alerts Center & Audio Evidence
    • Hybrid dispatch:
      • Online: captures GPS coordinates, battery level, and up to 30 seconds of recorded audio; looks up guardians by email and dispatches Firebase push notifications.
      • Offline fallback: manual SMS composer pre-filled with a live Google Maps location link, and one-tap dialer fallback to trusted contacts or 112, requiring no internet connection.
    • Guardian email verification: shows whether an added contact is a Safora member (in-app push + audio playback) or SMS-only.
    • Safety Alerts Center (NotificationScreen.tsx): unread-count badge, GPS map links, and an embedded audio evidence player.
    • Test SOS drills: lets a walker rehearse the SOS flow without alerting real contacts.
    • One-tap native dialer fallback (tel:112, tel:108, tel:1090).
  6. Module 6: Administrative Moderation & Diagnostics
    • Moderation workflow to mark hazard reports as active, resolved, duplicate, or fake.
    • Live system health checks and database latency diagnostics (/api/diagnostics).
    • πŸ”§ The Safe Walk radar's fallback to illustrative sample data (when no walk is active) is being replaced with a proper empty state β€” see docs/v1/tasks.md (task 3).

πŸ› οΈ Architecture & Technology Stack

Layer Technology Engineering Rationale
Mobile App React Native 0.87.1 + TypeScript Native mobile performance with Hermes bytecode engine and Fabric (New Architecture) enabled.
Spatial Canvas OpenMapView.tsx (Leaflet in a WebView) Hardware-accelerated WebView map with a layered basemap switcher (dark/light OpenStreetMap tiles, Esri satellite imagery).
Routing Engine OSRM + calibrated multi-modal speed constants Real street-network route geometry with distance-based travel-time estimates per mode (see Module 3's known limitation above).
State & Navigation Zustand + Native Stack Navigator Fast, decoupled state management with native transitions, session hydration, and persistent AsyncStorage.
Backend API Node.js + Express + TypeScript Asynchronous REST API with in-memory caching for hot spatial queries and a Socket.IO WebSocket gateway.
Database PostgreSQL 15+ with PostGIS Uses geography(Point, 4326) for true ellipsoidal distance accuracy across the earth's curved surface.
Spatial Indexing GiST (reports_location_gist_idx) Efficient bounding-box search for hazard proximity lookups (ST_DWithin) and clustering.
Notifications Firebase Cloud Messaging (FCM) Push alerts for SOS dispatch; deviation-escalation push is part of this submission's in-progress work.

Full technology deltas against the original synopsis (e.g. Leaflet vs. the synopsis's originally-named mapping library) are documented in docs/v1/tech-stack.md.


πŸ“‚ Repository Structure

The project is configured as an npm workspace monorepo:

safora/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ backend/                # Express.js + TypeScript API server (Port 5000)
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ config/         # Database pool, diagnostics, environment
β”‚   β”‚   β”‚   β”œβ”€β”€ controllers/    # Route controllers (auth, reports)
β”‚   β”‚   β”‚   β”œβ”€β”€ middleware/     # Auth guards, validation, rate limiting
β”‚   β”‚   β”‚   β”œβ”€β”€ routes/         # Express routers (/api/auth, /api/reports)
β”‚   β”‚   β”‚   └── app.ts          # Server bootstrap & Socket.IO initialization
β”‚   β”‚   β”œβ”€β”€ .env
β”‚   β”‚   └── package.json
β”‚   β”‚
β”‚   β”œβ”€β”€ frontend/               # Vite + React + Tailwind Admin Console (Port 5173)
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ components/     # Command map, dispatch console, diagnostics
β”‚   β”‚   β”‚   β”œβ”€β”€ pages/          # Admin dashboard, incident moderation
β”‚   β”‚   β”‚   └── services/       # Socket.IO client & API integration
β”‚   β”‚   β”œβ”€β”€ .env
β”‚   β”‚   └── package.json
β”‚   β”‚
β”‚   └── mobile/                 # React Native mobile application
β”‚       β”œβ”€β”€ android/            # Android Gradle project (New Arch, arm64-v8a ABI)
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   β”œβ”€β”€ screens/        # UI screens (Home, Map, SafeWalk, Profile, Auth)
β”‚       β”‚   β”œβ”€β”€ navigation/     # RootNavigator (Native Stack)
β”‚       β”‚   β”œβ”€β”€ services/       # Location engine, API client (Axios)
β”‚       β”‚   β”œβ”€β”€ store/          # Zustand global state
β”‚       β”‚   └── theme/          # Typography, colors, styles
β”‚       β”œβ”€β”€ metro.config.js     # Monorepo resolution with extraNodeModules
β”‚       └── package.json
β”‚
β”œβ”€β”€ packages/
β”‚   └── shared-types/           # Shared TypeScript interfaces (User, HazardReport, etc.)
β”‚       β”œβ”€β”€ src/
β”‚       └── package.json
β”‚
β”œβ”€β”€ docs/                        # Technical documentation & Academic Synopsis
β”‚   β”œβ”€β”€ v1/                      # This submission β€” architecture, API, DB, tasks, testing
β”‚   β”œβ”€β”€ v2/                      # Post-submission product roadmap
β”‚   β”œβ”€β”€ v3/                      # Research notes on synopsis future-scope items
β”‚   β”œβ”€β”€ archive/                 # Earlier documentation drafts
β”‚   β”œβ”€β”€ setup.md                 # Developer setup & run guide
β”‚   β”œβ”€β”€ SAFORA_Synopsis_Formatted.pdf
β”‚   └── README.md                # Docs folder index
β”‚
└── README.md                    # Root repository documentation (this file)

⚑ Quick Start & Run Commands

1. Prerequisites

  • Node.js: v20.x or v22.x & npm
  • PostgreSQL: 15+ with the postgis extension enabled (e.g. via Neon)
  • Android SDK: Platform 34/35, NDK 27.1.12297006, OpenJDK 17

2. Dependency Installation

From the root repository:

npm install

3. Database setup

On a fresh database, initDatabase() creates the schema automatically on first backend start. On an existing database, apply the V1 migration once before starting the new backend build β€” see docs/v1/database.md Β§7 for the exact script.

4. Start the Backend API

cd apps/backend
npm run dev
  • API Base URL: http://localhost:5000/api
  • Health Check: http://localhost:5000/api/health
  • Live Diagnostics: http://localhost:5000/api/diagnostics

Set INTERNAL_TICK_SECRET in apps/backend/.env before running β€” it protects the internal watchdog endpoint. See docs/v1/setup.md for the full list of new V1 environment variables.

5. Run the Mobile App

In a second terminal:

cd apps/mobile
npm start -- --reset-cache

In a third terminal:

cd apps/mobile
npm run android

6. Build Standalone Debug APK

To package the standalone APK for physical testing without a local dev server:

cd apps/mobile/android
.\gradlew assembleDebug

Compiled APK path: apps/mobile/android/app/build/outputs/apk/debug/app-debug.apk (size will change as V1's background-service work lands; last verified build was ~59 MB, optimised for arm64-v8a)


🎯 Project Scope Boundaries

To maintain high quality within the academic timeline, strict boundaries are enforced:

  • Included in Minor Project-I Scope (see docs/v1/ for the exact task list):
    • Fully functional React Native mobile application, Android.
    • Node.js/Express backend with Socket.IO real-time location streaming to guardians.
    • PostgreSQL + PostGIS spatial querying (ST_DWithin) and DBSCAN hazard clustering, rendered as a heatmap.
    • Safe Walk corridor compliance with both phone-side and server-side deviation escalation.
    • One-tap SOS emergency alert dispatch, with background tracking that survives a locked screen.
    • Administrative moderation and system diagnostics.
  • Planned for the post-submission product roadmap (see docs/v2/):
    • Account/session hardening, email verification, real per-mode routing with voice guidance, no-unlock SOS triggers, staged chat, Hindi/Uttarakhand localisation, weather & earthquake-aware safety scoring.
  • Explicitly Out of Scope for now (see docs/v3/ for the research notes):
    • AI-based safe-route recommendation (lighting/crowd predictive models).
    • Offline Bluetooth / Wi-Fi Direct mesh communication.
    • AI image hazard detection from camera photos.
    • Hardware wearable SOS device integration.

πŸ“„ License & Academic Attribution

This project is developed as an academic Minor Project-I under the School of Engineering and Computing (SoEC), Dev Bhoomi Uttarakhand University (DBUU), Dehradun. All rights reserved by the project authors and institution.

About

Community safety platform for women and students: crowdsourced hazard map with a decay-weighted safety score, Safe Walk route monitoring with auto-escalation, one-tap SOS with guardian alerts and audio evidence, and a live admin command center. React Native, Node.js, PostGIS.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages