Skip to content

Latest commit

Β 

History

133 Commits

Folders and files

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

Repository files navigation

πŸ›‘οΈ Safe Passage

AI-Powered Traveler Safety Companion for Low-Connectivity Environments

React Native Flask TypeScript Python License

Features β€’ Architecture β€’ Quick Start β€’ Documentation


πŸ“– Overview

Safe Passage is an AI-powered traveler safety solution designed to proactively assess risk, monitor traveler well-being, and respond intelligently in low-connectivity environments. Built for solo travelers venturing into remote or high-risk areas, the system provides a comprehensive safety net through intelligent risk prevention, real-time monitoring, and automated emergency response.

The Problem

Travelers in remote areas face unique challenges:

  • Unpredictable connectivity in rural or mountainous regions
  • Delayed emergency response when communication is lost
  • Lack of proactive risk assessment before entering dangerous areas
  • Limited local safety knowledge about destinations

Key Features

Intelligent Risk Assessment

  • AI-Powered Itinerary Analysis: Upload travel plans (PDF/DOCX) and receive category-specific risk assessments
  • GPT-5.2 & GPT-4.1-nano Integration: Multi-agent architecture for comprehensive risk evaluation
  • Actionable Insights: Detailed mitigation strategies for crime, infrastructure, health, political, and environmental risks
  • Travel Risk Scoring: Overall risk quantification with confidence intervals

Predictive Connectivity Monitoring

  • Deterministic Connectivity Model: Regional cellular coverage prediction using real-world signal metrics
  • Expected Offline Duration: Calculate anticipated connectivity loss based on destination coordinates
  • Smart Threshold Management: Dynamic offline detection based on location risk profiles

Heartbeat-Based Safety System

  • Background Health Signals: Periodic location, battery, and timestamp transmission
  • Offline Anomaly Detection: Automated escalation when travelers exceed expected offline thresholds
  • Historical Pattern Analysis: User-specific baseline establishment for accurate anomaly detection
  • Privacy-Conscious Design: Minimal data transmission with encrypted storage

Multi-Channel Emergency Response

  • SMS Notifications: Twilio-powered emergency contact alerts with last-known location
  • Telegram Bot Integration: Real-time emergency contact activation and notifications
  • Automated Escalation: Triggered alerts to local authorities with structured safety data
  • Manual SOS Trigger: User-initiated emergency broadcast with contextual information

Offline-First Mobile Experience

  • React Native + Expo: Cross-platform mobile app (iOS/Android)
  • SQLite Local Storage: Complete offline data persistence
  • Background Task Execution: Heartbeat transmission even when app is closed
  • Progressive Enhancement: Full functionality offline with sync when connected

Architecture

Safe Passage follows a multi-agent AI architecture with clear separation of concerns:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         Mobile App (React Native)                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Itinerary   β”‚  β”‚  Heartbeat   β”‚  β”‚  Emergency           β”‚  β”‚
β”‚  β”‚  Upload      β”‚  β”‚  Monitor     β”‚  β”‚  Dashboard           β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                    SQLite (Offline-First)                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚ HTTPS / REST API
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Backend (Flask + Python)                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Risk Engine         β”‚  β”‚  Connectivity Predictor        β”‚  β”‚
β”‚  β”‚  (GPT-5.2/4.1-nano)  β”‚  β”‚  (Regional Signal Data)        β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Heartbeat Monitor   β”‚  β”‚  Emergency Dispatcher          β”‚  β”‚
β”‚  β”‚  (APScheduler)       β”‚  β”‚  (Twilio + Telegram)           β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚ PostgreSQL (Supabase)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           Database Layer                         β”‚
β”‚  Users β€’ Trips β€’ Itineraries β€’ Risk Reports β€’ Heartbeats         β”‚
β”‚  Alerts β€’ Incidents β€’ Emergency Contacts β€’ Traveler Status       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Technology Stack

Frontend

  • Framework: React Native 0.81.5 with Expo 54
  • Navigation: Expo Router 6.0
  • Styling: NativeWind (Tailwind CSS for React Native)
  • State Management: AsyncStorage + SQLite
  • Network Detection: NetInfo for connectivity awareness
  • Background Tasks: Expo Background Fetch & Task Manager

Backend

  • Framework: Flask 3.1.0 (Python 3.11+)
  • Database: Supabase (PostgreSQL) with SQLAlchemy ORM
  • AI Models: OpenAI GPT-5.2 (analysis) + GPT-4.1-nano (filtering)
  • Task Scheduling: APScheduler 3.10.4
  • Validation: Pydantic 2.11+
  • Notifications: Twilio (SMS) + Telegram Bot API

Infrastructure

  • Containerization: Docker + Docker Compose
  • WSGI Server: Gunicorn 23.0.0
  • Email Validation: email-validator 2.2.0
  • Document Parsing: pdfplumber 0.10.3 + python-docx 1.1.2

Quick Start

Prerequisites

  • Node.js 18+ and npm
  • Python 3.11+
  • Docker (optional, for containerized backend)
  • Expo CLI (install via npm install -g expo-cli)
  • Supabase Account (for database)
  • OpenAI API Key (for AI features)

1. Clone the Repository

git clone https://github.com/yourusername/safe-passage.git
cd safe-passage

2. Backend Setup

Option A: Docker (Recommended)

# Copy environment template
Copy-Item backend/.env.example backend/.env

# Edit backend/.env with your credentials
# Then start the backend
docker compose up --build backend

Backend will be available at http://localhost:5000

Option B: Local Python Environment

cd backend

# Create virtual environment
py -3 -m venv .venv
.\.venv\Scripts\Activate.ps1

# Install dependencies
python -m pip install --upgrade pip
python -m pip install -r requirements.txt

# Configure environment
Copy-Item .env.example .env
# Edit .env with your credentials

# Run Flask development server
flask run --host=0.0.0.0 --port=5000

3. Frontend Setup

cd frontend

# Install dependencies
npm install

# Configure environment
cp .env.example .env
# Edit .env with backend URL

# Start Expo development server
npm start

Scan QR code with Expo Go app (iOS/Android) or press:

  • a for Android emulator
  • i for iOS simulator
  • w for web browser

4. Telegram Bot Setup (Optional)

cd telegram-bot

# Create virtual environment
py -m venv .venv
.\.venv\Scripts\Activate.ps1

# Install dependencies
python -m pip install -r requirements.txt

# Configure bot
Copy-Item .env.example .env
# Add TELEGRAM_BOT_TOKEN and database URI

# Run bot
python bot.py

Documentation

Core Systems

API Contracts

Comprehensive API contracts are documented in the contracts/ directory:

  • Prevention: Itinerary upload and risk analysis endpoints
  • Cure: Heartbeat ingestion and monitoring APIs
  • Mitigation: Emergency alert and incident management
  • Shared: Authentication, user management, and common schemas

Database Schema

Database schema and seed data are available in contracts/db/:

  • schema_outline.sql: Complete PostgreSQL schema
  • seed_stage1_bootstrap_missing_status_*.sql: Bootstrap data
  • seed_stage1_watchdog_*.sql: Heartbeat monitoring configuration

Testing

Backend Tests

cd backend
pytest tests/

# Run specific test suites
pytest tests/test_itinerary_analysis.py
pytest tests/test_connectivity_model.py
pytest tests/test_heartbeat_monitor.py

Performance Tests

The backend includes a comprehensive performance test suite for heartbeat monitoring and emergency escalation systems:

cd backend

# Run all performance tests
python run_performance_tests.py --all

# Run specific test categories
python run_performance_tests.py --load          # Heartbeat ingestion
python run_performance_tests.py --watchdog      # Watchdog scalability
python run_performance_tests.py --escalation    # Emergency escalation
python run_performance_tests.py --alerts        # Alert delivery

# View help and all options
python run_performance_tests.py --help

What these tests measure:

  • βœ“ Code correctness and algorithm logic
  • βœ“ Memory usage patterns
  • βœ“ Error handling robustness
  • βœ“ Concurrent execution behavior

Important: These tests use mocked I/O (in-memory database, intercepted network calls) to validate code quality.

Test output:

  • JSON results: backend/test_results/performance_YYYYMMDD_HHMMSS.json
  • HTML dashboard: backend/test_results/performance_report.html

Frontend Type Checking

cd frontend
npm run typecheck

Integration Tests

# Run smoke test for complete user flow
cd backend
python tools/smoke_user_flow.py

Development Workflow

Connectivity Predictor (Standalone Component)

The deterministic connectivity model can be used independently:

from app.services.connectivity_predictor import predict_connectivity_for_latlon

result = predict_connectivity_for_latlon(25.6009, 85.1452)  # Bihar, India
print(f"Score: {result['connectivity_score']}")
print(f"Group: {result['connectivity_group']}")
print(f"Expected offline: {result['expected_offline_minutes']} minutes")

Connectivity Bands:

  • Poor: 0-24 (High risk)
  • Average: 25-49 (Moderate risk)
  • Good: 50-74 (Low risk)
  • Excellent: 75-100 (Minimal risk)

Environment Configuration

Required environment variables for backend:

# Database
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_KEY=your-service-key

# AI Models
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...  # Optional

# Notifications
TWILIO_ACCOUNT_SID=AC...
TWILIO_AUTH_TOKEN=...
TWILIO_FROM_NUMBER=+1...
TELEGRAM_BOT_TOKEN=...

# Configuration
APP_CONFIG=development  # or production
ENABLE_HEARTBEAT_SCHEDULER=1
HEARTBEAT_WATCHDOG_INTERVAL_MINUTES=5

Docker Management Scripts

# Start services
./scripts/backend-docker.ps1 -Action up

# Check status
./scripts/backend-docker.ps1 -Action status

# View logs
./scripts/backend-docker.ps1 -Action logs

# Stop services
./scripts/backend-docker.ps1 -Action down

πŸ“Š Project Structure

safe-passage/
β”œβ”€β”€ backend/                    # Flask API server
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ models/            # Database models (SQLAlchemy)
β”‚   β”‚   β”œβ”€β”€ routes/            # API endpoints
β”‚   β”‚   β”œβ”€β”€ schemas/           # Pydantic validation schemas
β”‚   β”‚   β”œβ”€β”€ services/          # Business logic
β”‚   β”‚   β”‚   β”œβ”€β”€ connectivity_predictor.py
β”‚   β”‚   β”‚   β”œβ”€β”€ risk_engine.py
β”‚   β”‚   β”‚   └── data/          # Signal metrics dataset
β”‚   β”‚   β”œβ”€β”€ tasks/             # Background jobs
β”‚   β”‚   └── utils/             # Shared utilities
β”‚   β”œβ”€β”€ tests/                 # Unit and integration tests
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── Dockerfile
β”‚
β”œβ”€β”€ frontend/                   # React Native mobile app
β”‚   β”œβ”€β”€ app/                   # Expo Router pages
β”‚   β”‚   β”œβ”€β”€ dashboard.tsx
β”‚   β”‚   β”œβ”€β”€ heartbeat.tsx
β”‚   β”‚   β”œβ”€β”€ trips/
β”‚   β”‚   └── emergency/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ features/          # Feature modules
β”‚   β”‚   β”œβ”€β”€ lib/               # API clients
β”‚   β”‚   └── shared/            # Shared components
β”‚   └── package.json
β”‚
β”œβ”€β”€ telegram-bot/              # Emergency contact bot
β”‚   β”œβ”€β”€ bot.py
β”‚   └── requirements.txt
β”‚
β”œβ”€β”€ contracts/                 # API & DB contracts
β”‚   β”œβ”€β”€ api/                   # OpenAPI specifications
β”‚   └── db/                    # Database schemas
β”‚
β”œβ”€β”€ scripts/                   # Automation scripts
β”‚   └── backend-docker.ps1
β”‚
└── docker-compose.yml         # Container orchestration

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages