AI-Powered Traveler Safety Companion for Low-Connectivity Environments
Features β’ Architecture β’ Quick Start β’ Documentation
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.
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
- 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
- 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
- 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
- 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
- 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
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 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- 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
- 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
- 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
- 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)
git clone https://github.com/yourusername/safe-passage.git
cd safe-passage# Copy environment template
Copy-Item backend/.env.example backend/.env
# Edit backend/.env with your credentials
# Then start the backend
docker compose up --build backendBackend will be available at http://localhost:5000
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=5000cd frontend
# Install dependencies
npm install
# Configure environment
cp .env.example .env
# Edit .env with backend URL
# Start Expo development server
npm startScan QR code with Expo Go app (iOS/Android) or press:
afor Android emulatorifor iOS simulatorwfor web browser
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- Heartbeat System Guide: Backend integration and monitoring controls
- Heartbeat Frontend Integration: Mobile runtime and implementation
- Offline Storage Architecture: SQLite schema and synchronization
- Backend API Documentation: Complete API reference and smoke tests
- Telegram Bot Setup: Emergency contact activation guide
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 and seed data are available in contracts/db/:
schema_outline.sql: Complete PostgreSQL schemaseed_stage1_bootstrap_missing_status_*.sql: Bootstrap dataseed_stage1_watchdog_*.sql: Heartbeat monitoring configuration
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.pyThe 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 --helpWhat 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
cd frontend
npm run typecheck# Run smoke test for complete user flow
cd backend
python tools/smoke_user_flow.pyThe 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)
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# 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 downsafe-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