SafePath AI is an enterprise-grade GeoAI pedestrian routing and safety infrastructure decision-support platform. It evaluates multi-modal municipal telemetry (smart LED lighting, CCTV nodes, 24/7 emergency callboxes, open commercial active edges, and historical incident report context) to generate transparent, deterministic safety evidence scores for walking routes.
SafePath AI bridges municipal spatial data, real-time routing engines, and grounded generative AI reasoning to help pedestrians select safer walking routes while providing city authorities with infrastructure gap analytics.
- Deterministic 6-Factor Safety Scoring Engine: Transparent, weighted safety scoring based strictly on physical evidence.
- Missing Telemetry Awareness: Never invents missing data; flags unmeasured parameters and downgrades confidence levels dynamically.
- 7-Tool Agentic Pipeline: Autonomous tool calling pipeline for candidate route extraction, lighting calculation, CCTV density analysis, emergency hub proximity lookup, incident context aggregation, and RAG grounding.
- Grounded RAG Knowledge Base: Uses vector similarity retrieval over CPTED (Crime Prevention Through Environmental Design) guidelines and municipal lighting standards with explicit citations.
- Interactive GeoAI Map: Custom Leaflet visualization with interactive route polylines, infrastructure nodes, hazard clusters, and gap corridors.
- Governance & Infrastructure Analytics: Heatmap dashboards for municipal urban planners to prioritize lighting and CCTV investments.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FRONTEND (React + Vite) β
β ββββββββββββββββββββββ βββββββββββββββββββββββ βββββββββββββββββββββββββββββ β
β β Route Search Form β β Interactive Map β β Route Recommendation Card β β
β βββββββββββ¬βββββββββββ ββββββββββββ¬βββββββββββ βββββββββββββββ¬ββββββββββββββ β
β β β β β
β βββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββββββββββΌββββββββββββββ β
β β State Management & API Client β β
β ββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββ
β HTTP / REST (/api/analyze, /api/rag, /api/agent)
βββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββ
β BACKEND (Express + Node.js) β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Gemini Agent Orchestrator β β
β β (Tool calling with Gemini 2.5 Flash / Deterministic Fallback) β β
β ββββββββ¬βββββββββββββ¬ββββββββββββββ¬ββββββββββββββ¬βββββββββββββ¬ββββββββββββββββ β
β β β β β β β
β ββββββββΌββββββ ββββββΌββββββββ βββββΌβββββββ ββββββΌββββββββ ββββΌβββββββββββββ β
β β Routing β β Lighting β β CCTV β β Callbox β β Incident β β
β β Tool β β Telemetry β β Node Toolβ β Hub Tool β β Context Toolβ β
β ββββββββ¬ββββββ ββββββ¬ββββββββ βββββ¬βββββββ ββββββ¬ββββββββ ββββ¬βββββββββββββ β
β ββββββββββββββΌββββββββββββββΌββββββββββββββΌβββββββββββββ β
β βΌ βΌ βΌ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Scoring Engine & Math Evaluator β β
β β Score = β (factor_value Γ factor_weight) Γ Data_Availability β β
β ββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββ β
β β β
β ββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββ β
β β Vector Store & RAG Engine β β
β β In-Memory Cosine Similarity + Grounded Citation Verification β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Node.js 18+ or Node.js 20+
- npm 9+
-
Clone the repository:
git clone https://github.com/your-org/safepath-ai.git cd safepath-ai -
Install dependencies:
npm install
-
Configure environment variables:
cp .env.example .env # Add your GEMINI_API_KEY to .env if available (optional, deterministic engine works without it) -
Run development server:
npm run dev
Open
http://localhost:3000in your browser. -
Run test suite:
npm run test -
Build for production:
npm run build npm start
| Variable Name | Required? | Default / Example | Description |
|---|---|---|---|
GEMINI_API_KEY |
Optional | AIzaSy... |
Gemini API key for natural language agent reasoning. If missing, the app seamlessly runs on the deterministic 7-tool orchestrator. |
APP_URL |
Optional | http://localhost:3000 |
Host URL for self-referential endpoints and production deployment routing. |
NODE_ENV |
Optional | development |
Environment mode (development or production). |
Security Note: Never commit actual API keys to git. Define keys in
.envor inject via host secret management.
Executes complete SafePath AI route analysis for a origin and destination.
Request Body:
{
"origin": "Downtown Central Station",
"destination": "Innovation Tech Campus",
"timeOfDay": "Night (10:15 PM)",
"travelMode": "Standard Pace"
}Response:
{
"success": true,
"data_availability_status": "Complete",
"recommended_route": {
"route_id": "route-b",
"route_name": "Route B (Commercial Corridor)",
"safety_score": 89,
"travel_time": "24 min",
"distance": "1.8 km",
"recommendation_statement": "This route is recommended based on available safety evidence."
},
"candidate_routes_evaluated": [...],
"tool_execution_logs": [...]
}Performs vector retrieval over CPTED guidelines and municipal lighting documentation.
Request Body:
{
"query": "What are CPTED standards for pedestrian pathway lighting?",
"top_k": 3
}The Retrieval-Augmented Generation (RAG) module grounds all safety explanations in official CPTED (Crime Prevention Through Environmental Design) municipal manuals and IESNA lighting standards.
- In-Memory Vector Search: Uses TF-IDF cosine similarity embeddings over curated municipal policy documents.
- Strict Citation Requirements: Every RAG passage returned includes
document_title,section,citation_code, andrelevance_score. - Zero Hallucination Guard: If no relevant passages match the query threshold (
score > 0.05), the engine explicitly returnsresults_found: falseand"Relevant verified information was not found."
SafePath AI evaluates geographical segment attributes across spatial buffer zones (50m - 100m corridor width):
- Lighting Coverage Density: Calculates smart LED streetlamp frequency and average foot-candle illuminance along polyline segments.
- CCTV Node Proximity: Measures density of active municipal CCTV cameras within 50m of sidewalk paths.
- Emergency Callbox Buffer: Distance-decay calculation from 24/7 blue-light emergency help points and police sub-stations.
- Commercial Active Edge: Foot traffic density and open storefront ratio during late-night hours (21:00 - 05:00).
- Incident Context Density: Inverse historical report density along pathway segments (100 = minimal incident history).
The Gemini agent and fallback orchestrator execute a deterministic 7-tool sequence:
get_candidate_routes: Fetches physical paths between origin and destination.get_lighting_telemetry: Measures streetlamp illuminance and density along segments.get_cctv_telemetry: Retrieves active CCTV camera coverage percentages.get_emergency_accessibility: Calculates distance to nearest 24/7 help callboxes.get_incident_context: Evaluates historical report density context.get_public_activity_index: Assesses commercial open-storefront density.search_rag_knowledge_base: Retrieves grounded CPTED design standards.
Where:
-
$V_i$ = Raw factor value ($0 - 100$ ) -
$W_i$ = Factor weight
-
Lighting Coverage:
$25%$ ($W = 0.25$ ) -
Safety Infrastructure (CCTV):
$20%$ ($W = 0.20$ ) -
Emergency Accessibility:
$15%$ ($W = 0.15$ ) -
Historical Incident Context:
$15%$ ($W = 0.15$ ) -
Public Activity / Foot Traffic:
$15%$ ($W = 0.15$ ) -
Route Connectivity / Sidewalk Quality:
$10%$ ($W = 0.10$ )
If any factor null or undefined, its weighted contribution is set to
- Non-Predictive / Non-Profilative: SafePath AI does NOT perform predictive policing, individual crime forecasting, or demographic profiling.
- Telemetry Transparency: All scores are accompanied by an itemized factor breakdown explaining exact score origins.
-
Missing Telemetry Warning: When sensor coverage is low (
$< 50%$ ), confidence is automatically downgraded fromHightoMediumorLow, alerting pedestrians to walk with standard caution.
- Select Downtown Central Station as Start and Innovation Tech Campus as Destination.
- Click Analyze Walking Routes.
- Inspect the recommended Route B (Commercial Corridor) with a Safety Score of 89/100.
- Click Inspect Formula & Data Evidence to review factor weightings and telemetry breakdown.
- Toggle map layers (Green Recommended, Amber Gaps, Blue Infrastructure, Red Hotspots) to inspect spatial distribution.
- Navigate to the Governance Dashboard tab to view municipal lighting gap analytics.
- Simulated Municipal Feed: In the demonstration environment, municipal sensor telemetry is drawn from calibrated synthetic geo-datasets. Real-world deployment requires integration with city OpenData APIs or PostGIS databases.
- Static Weather Inputs: Current safety scoring assumes standard clear weather conditions. Heavy snow or flooding effects require real-time weather API overlays.
safepath-ai/
βββ .env.example # Environment variable documentation & template
βββ metadata.json # Application metadata and platform capabilities
βββ package.json # Project dependencies and npm scripts
βββ README.md # Complete production & technical documentation
βββ server.ts # Express production server & API route proxies
βββ vite.config.ts # Vite bundle configuration
βββ src/
β βββ main.tsx # Client entry point
β βββ App.tsx # Main application layout & state orchestrator
β βββ types.ts # TypeScript interfaces and global data models
β βββ scoringEngine.ts # Deterministic 6-factor safety scoring engine
β βββ apiClient.ts # Client API wrapper
β βββ mockData.ts # Calibrated municipal spatial datasets
β βββ __tests__/ # Automated Vitest unit test suite
β β βββ safepath.test.ts # 15 tests covering all 14 edge cases
β βββ agent/ # Agent tool definitions & execution engine
β β βββ agentCore.ts # Agent orchestrator & fallback pipeline
β β βββ tools.ts # 7 deterministic safety tools
β βββ rag/ # Vector retrieval engine
β β βββ vectorStore.ts # In-memory TF-IDF vector store & CPTED knowledge base
β βββ components/ # Modular React UI components
β βββ Header.tsx # Navigation header & tab switcher
β βββ RouteSearchForm.tsx # Mobile-optimized start/destination search
β βββ InteractiveMap.tsx # Leaflet map visualization
β βββ SafetyLegend.tsx # Map layer toggle legend
β βββ RouteCard.tsx # Route option display card
β βββ RouteRecommendationPanel.tsx # Detailed score breakdown panel
β βββ ExplainableAIPanel.tsx # XAI decision transparency modal
β βββ GovernanceDashboard.tsx # Municipal planner analytics tab
β βββ AgentOrchestratorView.tsx # Agent tool execution inspector
β βββ RAGKnowledgeView.tsx # CPTED knowledge search tab
β βββ DisclaimerBanner.tsx # Safety disclaimer footer
β βββ AboutView.tsx # Methodology documentation tab
β βββ PrivacyView.tsx # Responsible AI & privacy policy tab