How harshsaple/let-the-ambulance-pass works
Project type and purpose
• This is a full-stack, web-based “Smart Ambulance Routing System” built with Flask (Python), HTML/CSS/JavaScript, and integrations with external routing APIs (Google Geocoding and INRIX).
• Purpose: Allow dispatchers or users to input an origin and destination, compute the fastest ambulance path, and actively manage traffic along that path in real time.
File structure
• Top-level files
• app.py / template.py – main Flask application entry points
• models.py – domain logic, data classes for routes/locations
• call_api.py, geocoding.py, search_places.py, set_api_key.py, accessToken.py – modules for handling API calls, key management, and geocoding
• api_key.txt, encrypted_api_key.bin – API key storage/encryption
• sample.html, script.js – standalone examples or prototypes
• requirements.txt – Python dependencies
• Directories
• static/ – client-side assets (styles.css, script.js)
• templates/ – Jinja2 HTML templates (home.html, index.html)
• venv/ and __pycache__/ – environment and caches
README for additional insights
• Describes core components (Geocoding API, INRIX GetRoute/FindRoute APIs, front-end interface).
• Highlights the system’s real-time rerouting, scalability, and future expansion (traffic signal integration, notifications, ML).
• Demonstrates user flow via the Flask demo.
a. Main components
• Client Browser (UI)
– HTML/CSS/JS served from Flask
– Allows user to enter addresses, displays map and route
• Web Server (Flask Application)
– app.py / template.py handle HTTP routes
– Renders templates, serves static assets
• Service Layer (Python modules)
– geocoding.py → converts addresses to lat/long via Google Geocoding API
– call_api.py / search_places.py → queries INRIX APIs for routes and traffic data
– models.py → encapsulates route objects, distance/time calculations
– set_api_key.py, accessToken.py → manage and decrypt API credentials
• External Services
– Google Geocoding API
– INRIX GetRoute and FindRoute APIs
• (Planned) Traffic Infrastructure / Notification Service
– Smart traffic signals, user notification push
b. Relationships and interactions
1. User enters origin/destination in browser → HTTP POST to Flask
2. Flask controller validates input → calls geocoding.py
3. geocoding.py calls Google Geocoding → returns coordinates
4. Flask then invokes call_api.py/search_places.py → fetches optimal route segments and real-time traffic data from INRIX
5. Response combined into model objects → passed to Jinja2 templates
6. Browser renders map and route; client-side script.js may poll or receive WebSocket updates (future) for dynamic rerouting
7. (Future) Web server pushes reroute notifications back to external traffic signal controllers or mobile clients
c. Architectural patterns and design principles
• MVC-style separation:
• Model: models.py, geocoding.py data structures
• View: Jinja2 templates + static assets
• Controller: app.py / template.py routes
• Service abstraction for external API calls
• Secure key management (encrypted_api_key.bin, accessToken.py)
• Scalability considerations: stateless Flask endpoints, modular service layer for easy horizontal scaling
d. Key technologies, frameworks, and libraries
• Flask (web framework)
• Python requests (HTTP client)
• Google Geocoding API
• INRIX Routing APIs (GetRoute, FindRoute)
• HTML5/CSS3/JavaScript for UI
• Jinja2 (templating engine)
• Encryption library for API key handling
Detail without over-complication
• Every Python module or group related modules under “Service Layer”
• Distinguish between synchronous requests (HTTP calls) and asynchronous events (future real-time reroute pushes)
• How encrypted_api_key.bin is decrypted at startup by accessToken.py