Skip to content
mohamad-shafeezPublic

About

AI-powered travel safety platform that combines real-time weather, AQI, traffic, and Gemini AI to deliver personalized risk analysis, safer routes, and smart travel planning.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

46 Commits

Folders and files

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

Repository files navigation

SafeNav Logo

SafeNav

AI-Powered Travel Safety Engine with Real-Time Environmental Intelligence

Features β€’ Tech Stack β€’ Architecture β€’ Getting Started β€’ API Reference β€’ Demo

Python Flask Gemini Firebase PWA License


πŸ“‹ Overview

SafeNav is a full-stack, health-aware travel safety platform that synthesizes live environmental data (weather, air quality, traffic incidents) with Google Gemini AI to deliver personalized safety directives, optimized routing, and AI-generated itineraries β€” all tailored to individual user health profiles.

Deterministic Output Layer: SafeNav transforms unstructured environmental data into deterministic, machine-readable safety signals using a hybrid of rule-based mathematical heuristics and LLM-assisted generation. This ensures stable and predictable safety scoring despite noisy, real-world inputs.


πŸŽ₯ Demo

Resource Link
Video Walkthrough Google Drive
GitHub Repository github.com/mohamad-shafeez/SafeNav

✨ Features

πŸ›‘οΈ Dynamic Risk Prediction Engine

  • Composite Safety Score (0–150) computed from cumulative environmental stress and user-specific health vulnerabilities
  • Exposure Multiplier β€” risk scales non-linearly with travel duration (30 min = 1.0Γ—, 60 min = 1.5Γ—, 120+ min = 2.0Γ—)
  • Adaptive Thresholds β€” heat limits dynamically adjust based on medical profile (31Β°C for cardiac/elderly vs. 38Β°C for standard)
  • Physical Exertion Penalty β€” walking in extreme conditions triggers a heart-strain penalty proportional to duration
  • AQI Sensitivity β€” respiratory health alerts fire at 55 AQI for asthma profiles vs. 100 AQI for standard users

πŸ—ΊοΈ Intelligent Route Engine

  • TomTom-powered routing with real-time traffic delay analysis from trafficDelayInSeconds
  • Live Incident Intelligence β€” BBox scanning fetches accidents, fog, lane closures (capped at 50 items) via TomTom's incidentDetails API
  • Dual-Engine Scoring β€” SafeNav route (green, health-optimized) vs. Fastest route (orange/red, speed-optimized)
  • Comprehensive Analytics β€” fuel consumption, COβ‚‚ emissions, toll costs, safety score, road type breakdown
  • Haversine Distance β€” server-side geodesic calculations for precise coordinate math

πŸ€– Gemini AI Integration

  • Safety Directives β€” gemini-1.5-flash generates 1-sentence personalized safety advice in raw text
  • Itinerary Generator β€” gemini-1.5-flash produces structured JSON travel plans respecting budget, vibe, health constraints
  • Smart Chat β€” conversational AI travel assistant
  • Image Analysis (OCR) β€” extract and translate text from images using Gemini Vision
  • Document Translation β€” translate PDF/TXT documents across 19 languages
  • Retry Shield β€” exponential backoff (wait = attempt Γ— 20s) with API key rotation for 429/503 resilience

🏨 Stay Safety Analysis

  • Real-time Weather Risk Scoring β€” thunderstorm and flood risk penalties from OpenWeatherMap
  • Regional Heuristics β€” latitude-based risk adjustments for seasonal hazard zones
  • Tiered Classification β€” Low / Medium / High risk with TTS-ready alert messages

πŸ“„ Secure Document Vault

  • Multi-Tier Encryption β€” Standard (AES-256), Military-Grade (AES + HMAC), Biometric, and Quantum-Resistant tiers
  • AI Document Analysis β€” Gemini Vision extracts and validates data from Passports, Visas, IDs, Medical Reports
  • File Integrity β€” SHA-256 checksums and entropy validation before storage
  • 22 Document Types β€” Passport, Aadhar, PAN, Visa, Travel Insurance, Medical Reports, Forex Receipts, and more
  • Secure Lifecycle β€” upload β†’ AI analysis β†’ encryption β†’ storage β†’ decryption β†’ secure wipe

πŸ”Š Voice & Accessibility Engine

  • Real-Time Voice Alerts β€” TTS-powered spoken warnings for extreme heat, poor air quality along the active route
  • Hydration Reminders β€” periodic alerts for walking users based on live heat-strain parameters
  • Multi-Language TTS β€” supports 19 languages including Hindi, Tamil, Telugu, Japanese, Korean, and more
  • Speech-to-Text Analysis β€” audio file transcription via Google Cloud Speech API

🌐 AI Travel Toolkit

  • Smart Chat β€” context-aware conversational travel assistant
  • Universal Translator β€” text, image (OCR), and document translation across 19 languages
  • Itinerary Planner β€” budget-aware, health-conscious AI trip planning with structured JSON output
  • Image Proxy β€” secure Unsplash integration for destination imagery

πŸ›‘οΈ Admin Command Center

  • JWT-Verified Admin Dashboard β€” Firebase token authentication with hardcoded admin whitelist
  • User Management β€” ban, unban, delete users, and modify roles via Firebase Auth + Firestore
  • Kill Switch β€” system-wide threat level control (L0–L3) with immutable audit logging
  • API Quota Monitoring β€” real-time tracking of OpenWeatherMap, WAQI, Gemini, and Nominatim usage
  • Vault Purge β€” admin-level document force-deletion with audit trail
  • Health Profile Analytics β€” aggregated user health condition statistics

⚑ Progressive Web App (PWA)

  • Stale-While-Revalidate caching strategy β€” app shell loads instantly while assets refresh in background
  • Offline Fallback β€” graceful 404 page when navigation fails offline
  • Smart Cache Exclusions β€” API calls, Firebase, external map tiles, and weather radar are never cached
  • Installable β€” standalone display with maskable icons (192px, 512px)

πŸ› οΈ Tech Stack

Layer Technologies
Frontend HTML5, CSS3 (Custom Glassmorphism UI), Vanilla JavaScript (ES6+), MapLibre GL JS, Leaflet.js, Capacitor
Backend Python 3.12, Flask 3.1.2, Flask-CORS, Gunicorn 25.1.0
AI / ML Google Gemini 1.5 Flash (google-generativeai 0.8.6, google-genai 1.64.0)
Navigation TomTom Routing API, TomTom Incidents API, Polyline Encoding
Environmental OpenWeatherMap (Weather), WAQI (Air Quality Index), RainViewer (Radar)
Image Unsplash API (Destination Imagery), Pillow (Image Processing)
Document PyPDF2 (PDF Parsing), Gemini Vision (OCR & Validation)
Security Firebase Admin SDK, JWT Verification, Fernet Encryption (AES-256-CBC), PBKDF2-HMAC-SHA256, SHA-256 Checksums
PWA Service Workers (Stale-While-Revalidate), Web App Manifest, Capacitor (Native Bridge)
Hosting Render (Backend API), Firebase Hosting (Frontend), Vercel (Serverless Fallback)

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         CLIENT (Frontend)                          β”‚
β”‚  HTML5 + CSS3 (Glassmorphism) + Vanilla JS + MapLibre + Leaflet   β”‚
β”‚  Firebase Auth (JWT) β”‚ Service Worker (PWA) β”‚ Capacitor (Mobile)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚ HTTPS / REST API
                               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        GATEWAY (Flask API)                         β”‚
β”‚          CORS Enforcement β”‚ Blueprint Router β”‚ JWT Validation       β”‚
β”‚                                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  Route   β”‚ β”‚Predictionβ”‚ β”‚ Planner  β”‚ β”‚  Vault   β”‚ β”‚  Admin   β”‚ β”‚
β”‚  β”‚ Blueprintβ”‚ β”‚ Blueprintβ”‚ β”‚ Blueprintβ”‚ β”‚ Blueprintβ”‚ β”‚ Blueprintβ”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β–Ό            β–Ό            β–Ό            β–Ό            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      LOGIC ENGINE (Services)                       β”‚
β”‚                                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Route Engine    β”‚  β”‚Prediction Engine β”‚  β”‚ Documents Engine  β”‚  β”‚
β”‚  β”‚  (TomTom API)    β”‚  β”‚(Weather+AQI+AI)  β”‚  β”‚ (Encrypt+AI+OCR) β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Stay Engine    β”‚  β”‚ Planner Engine   β”‚  β”‚ Security Manager  β”‚  β”‚
β”‚  β”‚(Weather+Heuristic) β”‚(Gemini Itinerary)β”‚  β”‚(Fernet+AES+HMAC) β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                     β”‚                      β”‚
        β–Ό                     β–Ό                      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ External APIs β”‚  β”‚  Firebase / GCP  β”‚  β”‚   Local Storage    β”‚
β”‚ TomTom        β”‚  β”‚  Firestore       β”‚  β”‚  vault_storage/    β”‚
β”‚ OpenWeatherMapβ”‚  β”‚  Auth             β”‚  β”‚  encrypted_files/  β”‚
β”‚ WAQI          β”‚  β”‚  Analytics        β”‚  β”‚  keys/             β”‚
β”‚ Unsplash      β”‚  β”‚  Audit Logs       β”‚  β”‚  metadata.json     β”‚
β”‚ Nominatim     β”‚  β”‚                    β”‚  β”‚                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‚ Project Structure

safenav/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app.py                        # Flask application factory & entry point
β”‚   β”œβ”€β”€ config.py                     # Vault storage paths & file validation
β”‚   β”œβ”€β”€ vercel.json                   # Vercel serverless deployment config
β”‚   β”œβ”€β”€ requirements.txt              # Python dependencies (pinned versions)
β”‚   β”‚
β”‚   β”œβ”€β”€ routes/                       # Flask Blueprints (API layer)
β”‚   β”‚   β”œβ”€β”€ auth.py                   # Authentication endpoint stub
β”‚   β”‚   β”œβ”€β”€ route.py                  # Routing, analytics, cost, weather, optimization
β”‚   β”‚   β”œβ”€β”€ prediction.py             # Environmental risk prediction endpoint
β”‚   β”‚   β”œβ”€β”€ planner.py                # AI trip planner endpoint
β”‚   β”‚   β”œβ”€β”€ stays.py                  # Stay safety analysis endpoint
β”‚   β”‚   β”œβ”€β”€ tools.py                  # Chat, translate, OCR, itinerary, image proxy
β”‚   β”‚   β”œβ”€β”€ voice.py                  # TTS synthesis & speech-to-text
β”‚   β”‚   β”œβ”€β”€ documents.py              # Document data models & enums
β”‚   β”‚   β”œβ”€β”€ documents_routes.py       # Vault CRUD API (upload/download/delete)
β”‚   β”‚   └── dashboard.py              # Admin command center & analytics API
β”‚   β”‚
β”‚   β”œβ”€β”€ services/                     # Core business logic
β”‚   β”‚   β”œβ”€β”€ route_engine.py           # TomTom routing, incidents, fuel & COβ‚‚ math
β”‚   β”‚   β”œβ”€β”€ prediction_engine.py      # Weather + AQI + Gemini risk calculator
β”‚   β”‚   β”œβ”€β”€ planner_engine.py         # Gemini itinerary generator with retry shield
β”‚   β”‚   β”œβ”€β”€ stay_engine.py            # Weather-aware stay risk scoring
β”‚   β”‚   β”œβ”€β”€ documents_engine.py       # Full vault lifecycle (AI + encryption + storage)
β”‚   β”‚   └── image_service.py          # Unsplash destination image fetcher
β”‚   β”‚
β”‚   β”œβ”€β”€ utils/                        # Shared utilities
β”‚   β”‚   β”œβ”€β”€ security_utils.py         # SecurityManager (Fernet, AES-256, checksums)
β”‚   β”‚   β”œβ”€β”€ data_manager.py           # JSON metadata CRUD, audit logging, statistics
β”‚   β”‚   β”œβ”€β”€ firebase_admin.py         # Firebase Admin SDK initialization helper
β”‚   β”‚   β”œβ”€β”€ firebase_auth.py          # Firebase authentication utilities
β”‚   β”‚   β”œβ”€β”€ jwt_helper.py             # JWT token utilities
β”‚   β”‚   └── risk_logic.py             # Basic speed/distance risk heuristics
β”‚   β”‚
β”‚   └── models/                       # Data models
β”‚       β”œβ”€β”€ user.py                   # User model
β”‚       └── stay.py                   # Stay model
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ index.html                    # Main application gateway
β”‚   β”œβ”€β”€ route.html                    # Route planning & navigation interface
β”‚   β”œβ”€β”€ prediction.html               # Environmental risk prediction dashboard
β”‚   β”œβ”€β”€ planner.html                  # AI trip planner interface
β”‚   β”œβ”€β”€ stays.html                    # Stay safety analysis interface
β”‚   β”œβ”€β”€ documents.html                # Secure document vault interface
β”‚   β”œβ”€β”€ tools.html                    # AI toolkit (chat, translate, OCR)
β”‚   β”œβ”€β”€ dashboard.html                # User dashboard
β”‚   β”œβ”€β”€ admin.html                    # Admin command center
β”‚   β”œβ”€β”€ package.html                  # Travel package explorer
β”‚   β”œβ”€β”€ login.html                    # Authentication - login
β”‚   β”œβ”€β”€ signup.html                   # Authentication - registration
β”‚   β”œβ”€β”€ navbar.html                   # Shared navigation component
β”‚   β”œβ”€β”€ 404.html                      # Offline fallback page
β”‚   β”œβ”€β”€ sw.js                         # Service Worker (Stale-While-Revalidate)
β”‚   β”œβ”€β”€ service-worker.js             # Service Worker (alternate registration)
β”‚   β”œβ”€β”€ manifest.json                 # PWA manifest (icons, theme, display)
β”‚   β”œβ”€β”€ capacitor.config.json         # Capacitor native mobile bridge config
β”‚   β”œβ”€β”€ config.example.js             # Frontend config template (API keys)
β”‚   β”‚
β”‚   β”œβ”€β”€ js/                           # Frontend logic modules
β”‚   β”‚   β”œβ”€β”€ route-core.js             # Core routing logic & map rendering
β”‚   β”‚   β”œβ”€β”€ route-premium.js          # Premium route features
β”‚   β”‚   β”œβ”€β”€ prediction.js             # Risk prediction UI logic
β”‚   β”‚   β”œβ”€β”€ planner.js                # AI planner UI logic
β”‚   β”‚   β”œβ”€β”€ stays.js                  # Stay analysis UI logic
β”‚   β”‚   β”œβ”€β”€ vault.js                  # Document vault UI logic
β”‚   β”‚   β”œβ”€β”€ tools.js                  # AI toolkit UI logic
β”‚   β”‚   β”œβ”€β”€ dashboard.js              # Dashboard UI logic
β”‚   β”‚   β”œβ”€β”€ admin-dashboard.js        # Admin command center UI
β”‚   β”‚   β”œβ”€β”€ package.js                # Travel packages UI
β”‚   β”‚   β”œβ”€β”€ auth.js                   # Firebase authentication logic
β”‚   β”‚   β”œβ”€β”€ firebase.js               # Firebase SDK initialization
β”‚   β”‚   β”œβ”€β”€ navbar.js                 # Navigation component logic
β”‚   β”‚   β”œβ”€β”€ bg-canvas.js              # Background canvas animations
β”‚   β”‚   β”œβ”€β”€ translation.js            # Translation module
β”‚   β”‚   β”œβ”€β”€ voice-alerts.js           # Voice alert & TTS controller
β”‚   β”‚   └── service-worker.js         # Service worker registration
β”‚   β”‚
β”‚   β”œβ”€β”€ css/                          # Stylesheets
β”‚   β”‚   β”œβ”€β”€ style.css                 # Global design tokens
β”‚   β”‚   β”œβ”€β”€ auth.css                  # Authentication pages
β”‚   β”‚   β”œβ”€β”€ dashboard.css             # Dashboard styles
β”‚   β”‚   β”œβ”€β”€ route.css                 # Route planner styles
β”‚   β”‚   β”œβ”€β”€ prediction.css            # Prediction dashboard styles
β”‚   β”‚   β”œβ”€β”€ planner.css               # AI planner styles
β”‚   β”‚   β”œβ”€β”€ stays.css                 # Stay analysis styles
β”‚   β”‚   β”œβ”€β”€ vault.css                 # Document vault styles
β”‚   β”‚   β”œβ”€β”€ tools.css                 # AI toolkit styles
β”‚   β”‚   β”œβ”€β”€ package.css               # Travel package styles
β”‚   β”‚   β”œβ”€β”€ navbar.css                # Navigation styles
β”‚   β”‚   └── admin-analytics.css       # Admin dashboard styles
β”‚   β”‚
β”‚   └── assets/                       # Static media assets
β”‚       └── icon-192.png              # PWA icon (192Γ—192)
β”‚
β”œβ”€β”€ firebase.json                     # Firebase Hosting configuration
β”œβ”€β”€ .firebaserc                       # Firebase project alias
β”œβ”€β”€ requirements.txt                  # Root-level Python dependencies
└── .gitignore                        # Git exclusion rules

πŸš€ Getting Started

Prerequisites

  • Python 3.10+
  • Node.js 16+ (optional, for Capacitor builds)
  • Git

1. Clone the Repository

git clone https://github.com/mohamad-shafeez/SafeNav.git
cd SafeNav

2. Set Up the Backend

# Create and activate a virtual environment
python -m venv backend/venv
source backend/venv/bin/activate        # macOS/Linux
backend\venv\Scripts\activate           # Windows

# Install dependencies
pip install -r requirements.txt

3. Configure Environment Variables

Create a .env file in the backend/ directory:

# --- AI Engine ---
GOOGLE_API_KEY=your_gemini_api_key
GEMINI_API_KEY=your_gemini_api_key_backup
PLANNER_API_KEY=your_planner_gemini_key

# --- Navigation ---
TOMTOM_API_KEY=your_tomtom_api_key

# --- Environmental Data ---
OPENWEATHER_API_KEY=your_openweathermap_key
AQI_TOKEN=your_waqi_token

# --- Image Service ---
UNSPLASH_ACCESS_KEY=your_unsplash_key

# --- Firebase ---
FIREBASE_PROJECT_ID=your_firebase_project_id

# --- App ---
SECRET_KEY=your_flask_secret_key

4. Configure Firebase (Optional)

Place your serviceAccountKey.json in the backend/ directory for Firebase Admin SDK initialization. Without it, the app falls back to project ID–based initialization.

5. Configure the Frontend

# Copy the config template
cp frontend/config.example.js frontend/config.js

# Edit config.js with your API keys

6. Start the Development Server

python backend/app.py

The API server will start at http://127.0.0.1:5000.

7. Open the Frontend

Open frontend/index.html in your browser, or deploy via Firebase Hosting:

firebase deploy --only hosting

🌐 Environment Variables

Variable Service Required Description
GOOGLE_API_KEY Gemini AI βœ… Primary Gemini API key for prediction & directives
GEMINI_API_KEY Gemini AI ⚑ Backup key for retry shield rotation
PLANNER_API_KEY Gemini AI ⚑ Dedicated key for itinerary generation
TOMTOM_API_KEY TomTom βœ… Routing, traffic, and incident data
OPENWEATHER_API_KEY OpenWeatherMap βœ… Real-time weather data
AQI_TOKEN WAQI βœ… Air Quality Index data
UNSPLASH_ACCESS_KEY Unsplash ⚑ Destination imagery
FIREBASE_PROJECT_ID Firebase ⚑ Fallback if serviceAccountKey.json is missing
SECRET_KEY Flask ⚑ Flask session secret key

βœ… = Required for core functionality Β Β  ⚑ = Optional / Fallback


πŸ“‘ API Reference

Health Check

GET  /api/health

Prediction Engine

POST /api/prediction/predict
Field Type Default Description
lat float β€” Latitude (required)
lng float β€” Longitude (required)
time string "day" Time of day (day / night)
travel_mode string "walking" Mode of travel
user_profile string "standard" Health profile
duration_mins int 30 Exposure duration in minutes

Route Engine

POST /api/route/calculate
POST /api/route/multiple-routes
POST /api/route/route-analytics
POST /api/route/route-safety
POST /api/route/route-cost
POST /api/route/route-weather
POST /api/route/real-time-update
POST /api/route/optimize-route
POST /api/route/analyze
GET  /api/route/health

AI Trip Planner

POST /api/planner/generate

Stay Safety Analysis

POST /api/stays/analyze

AI Toolkit

POST /api/chat
POST /api/translate
POST /api/analyze-image
POST /api/generate-itinerary
POST /api/translate-doc
GET  /api/get-image?query={destination}

Voice Engine

POST /api/voice/speak
POST /api/voice/analyze-speech

Document Vault

POST   /api/documents/upload
GET    /api/documents/list
GET    /api/documents/download/{doc_id}
DELETE /api/documents/delete/{doc_id}
PATCH  /api/documents/update/{doc_id}
GET    /api/documents/statistics
GET    /api/documents/export/summary

Admin Command Center (JWT Required)

POST /api/admin/user-action
POST /api/admin/vault-purge
POST /api/admin/vault-update
POST /api/admin/kill-switch
POST /api/admin/track-event
GET  /api/admin/analytics/system-health
GET  /api/admin/analytics/audit-logs
GET  /api/admin/analytics/users
GET  /api/admin/analytics/health-profiles
GET  /api/admin/analytics/api-quota
GET  /api/admin/analytics/routes-today
GET  /api/admin/analytics/recent-activity

πŸš€ Deployment

Backend (Render)

The production backend is hosted on Render at safenav-18sk.onrender.com. The app is served via Gunicorn:

gunicorn backend.app:app --bind 0.0.0.0:$PORT

Backend (Vercel β€” Serverless Fallback)

Configured via backend/vercel.json using @vercel/python runtime. All requests are routed to app.py.

Frontend (Firebase Hosting)

firebase deploy --only hosting

The firebase.json serves the frontend/ directory as the public root.


⚠️ Failure Handling & Resilience

Strategy Implementation
API Retry Shield Exponential backoff with key rotation for Gemini 429/503 errors
Graceful Degradation Cached/fallback values when external APIs are unreachable
Score Clamping Safety scores capped at 150 to prevent extreme fluctuations
Firebase Fallback Project ID–based init when serviceAccountKey.json is absent
Offline PWA Service Worker serves cached app shell; 404 page for navigation failures
Database Recovery Automatic backup restoration when metadata.json is corrupted
Audit Trail All admin actions logged to Firestore with immutable timestamps

πŸ”’ Security

  • Encryption β€” Fernet (AES-256-CBC) with PBKDF2-HMAC-SHA256 key derivation
  • Key Management β€” Auto-generated keys with timestamped backup rotation
  • Data Integrity β€” SHA-256 checksums on all encrypted documents
  • Authentication β€” Firebase Auth with JWT token verification on all admin endpoints
  • Admin Whitelist β€” Hardcoded email allowlist for admin access (backend-enforced)
  • CORS β€” Configured per-blueprint with wildcard restriction on production
  • Secrets β€” All API keys, service account files, and encryption keys excluded via .gitignore

🧠 Technical Deep Dive

Risk Score Formula

Exposure Multiplier = min(2.0, max(1.0, duration_mins / 30))

Score += (50 Γ— multiplier)   if real_feel > adaptive_heat_limit
Score += (40 Γ— multiplier)   if AQI > profile_threshold
Score += (15 Γ— multiplier)   if walking in extreme conditions
Score += 10                  if nighttime

Fuel & Emissions Model

Fuel (L)  = Ξ£ (segment_km / 100) Γ— road_type_rate
COβ‚‚ (kg)  = Fuel Γ— 2.31 kg/L
Cost ($)  = Fuel Γ— price + Toll + Maintenance (0.05/km) + Depreciation (0.10/km)

Safety Score (Route)

Base = 85
  βˆ’5   if distance > 100 km
  βˆ’2n  for each complex maneuver (roundabouts, forks)
Clamped to [0, 100]

πŸ“„ License

This project was developed as a Final Year Project (FYP).


Built with ❀️ by Mohamad Shafeez

About

AI-powered travel safety platform that combines real-time weather, AQI, traffic, and Gemini AI to deliver personalized risk analysis, safer routes, and smart travel planning.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages