- Poway Auto: Full-Stack Smart Routing Platform
Poway Auto: Full-Stack Smart Routing Platform
Project Goal: Improve routing in Poway, CA using real-time data, AI optimization, and public input.
📐 Technical Architecture
System Components
1. User Frontend
- Built with HTML, JavaScript, TailwindCSS, and Leaflet for interactive maps.
- Features:
- Route planning and visualization.
- Daily routine scheduling.
- Favorite location management.
- Hazard reporting interface.
- Communicates with backend via REST API (JSON).
2. Backend API (Flask)
- Implements RESTful endpoints to serve frontend requests.
- Responsibilities:
- Handling user authentication and session management.
- Managing CRUD operations for user data, hazards, routines, and favorites.
- Interfacing with Google Maps APIs for routing, geocoding, and traffic info.
- Invoking ML models for congestion prediction and route optimization.
- Returning JSON responses with data and status.
3. Database (SQLAlchemy ORM)
- Stores persistent data including:
- User profiles and preferences.
- Hazard reports and location data.
- Daily routines and favorite places.
- Enables quick retrieval and update of records.
- Ensures data consistency and integrity.
4. External APIs
- Google Maps API:
- Directions API for route calculations.
- Geocoding API to convert addresses and coordinates.
- Traffic API for real-time traffic data and incident reports.
- Poway Open Data Portal:
- Local traffic datasets.
- Road closures and hazard data.
- Transit schedules.
5. Machine Learning Model
- Built using Python libraries (e.g., scikit-learn).
- Inputs:
- Historical traffic data.
- Real-time traffic and user route requests.
- Outputs:
- Predicted congestion levels.
- Suggested alternative routes for optimal travel times.
- Integrated with backend for dynamic decision making.
Data Flow & Process
- User Interaction
- User opens frontend, inputs travel details, reports hazards, or manages routines.
- Frontend sends REST API requests to backend.
- Backend Processing
- Validates and authenticates user requests.
- Updates or queries the database accordingly.
- Calls external APIs to fetch route and traffic data.
- Invokes ML model to analyze congestion and optimize routes.
- Aggregates data into a coherent JSON response.
- Response Delivery
- Backend sends processed data back to frontend.
- Frontend updates map visuals and UI elements dynamically.
- Continuous Learning
- ML model retrains periodically with new traffic data.
- System adapts to changing traffic patterns and improves recommendations.
API Endpoints (Examples)
Endpoint | Method | Description |
---|---|---|
/api/login |
POST | User login with credentials |
/api/logout |
POST | Ends user session |
/api/routes |
GET | Get route information based on user input |
/api/routines |
GET/POST/DELETE | Manage daily routines |
/api/favorites |
GET/POST/DELETE | Manage favorite locations |
/api/hazards |
GET/POST/DELETE | Report and retrieve hazard information |
/api/traffic/predict |
POST | Returns congestion predictions from ML model |
Technical Requirements
- Frontend:
- Modern browsers support.
- Responsive design using TailwindCSS.
- Leaflet for interactive maps.
- Backend:
- Python 3.10+
- Flask framework.
- SQLAlchemy ORM with PostgreSQL/MySQL.
- Integration with Google Maps APIs.
- ML model integration via Python modules.
- Deployment:
- Docker containers for backend and frontend.
- CI/CD pipelines for automated testing and deployment.
- Hosted on cloud infrastructure supporting scalability.
- Security:
- Secure authentication (JWT or OAuth).
- Input validation and sanitization.
- HTTPS enforced for all communications.
🔗 Components
Layer | Technology | Description |
---|---|---|
Frontend | HTML, TailwindCSS, JavaScript, Leaflet.js | User interface for route input, hazard reports, daily routine planner |
Backend | Python, Flask, SQLAlchemy, SQLite/PostgreSQL | API for routing logic, daily routines, and hazard logs |
External | Google Maps API, Poway Open Data Portal | Route and live traffic data, local transit schedules |
ML Models | scikit-learn, pandas, joblib | Predict congestion, forecast ETA, dynamic routing suggestions |
Deployment | Docker, GitHub Actions | Local and cloud containerized deployment, CI/CD |
Data Flow | RESTful API, JSON, HTTP | Communication between frontend, backend, and ML services |
💡 Features Overview
🛣️ Dynamic Routing
- User selects start and end locations
- Routes visualized on a map using Google Maps Directions API
- Incorporates real-time traffic
📆 Daily Routine Planner
- Schedule recurring trips (e.g., commute to school)
- Auto-fill address/time
- Adjusts based on predicted congestion
🗺️ Favorite Locations
- Saved destinations for quick access
- Linked to user session or localStorage
- Shortcut buttons auto-fill route forms
⚠️ Hazard Reporting
- Users report hazards (accidents, construction)
- Stored in backend DB and displayed on map
- Public map layer via Leaflet.js for transparency
🔌 Flask API Reference
GET /api/route
Description: Get Google Maps route with traffic
Query Parameters:
- origin (str): starting point
- destination (str): end point
Response Example: { “duration”: “18 mins”, “distance”: “5.3 miles”, “steps”: […], “polyline”: “encodedPolyline” }
POST /api/hazard
Description: Submit a traffic hazard
Request Body Example: { “location”: “Espola Rd & Titan Way”, “type”: “accident”, “timestamp”: “2025-06-01T14:30:00” }
Response: { “message”: “Hazard saved.” }
GET /api/hazards
Description: Get all reported hazards
Response Example: [ {“location”: “Twin Peaks Rd & Midland”, “type”: “construction”, “timestamp”: “2025-06-01T09:10:00”}, {“location”: “Community Rd & Poway Rd”, “type”: “accident”, “timestamp”: “2025-06-01T11:20:00”} ]
POST /api/routine
Description: Add a daily routine entry
Request Body Example: { “user”: “john123”, “origin”: “12345 Poway Rd”, “destination”: “Del Norte High”, “time”: “07:30” }
Response: { “message”: “Routine added.” }
GET /api/routines?user=Ahaanv19
Description: Get user’s daily routines
Response Example: [ { “origin”: “12345 Poway Rd”, “destination”: “Del Norte High”, “time”: “07:30” } ]
GET /api/favorites?user=Ahaanv19
Description: Get user’s favorite locations
Response Example: [ {“name”: “Home”, “address”: “12345 Poway Rd”}, {“name”: “School”, “address”: “Del Norte High”} ]
POST /api/favorite
Description: Save a favorite location
Request Body Example: { “user”: “john123”, “name”: “Work”, “address”: “13500 Kirkham Way” }
Response: { “message”: “Favorite saved.” }
🧠 Machine Learning Model
Purpose
- Predict congestion likelihood for next 30 minutes
- Adjust routing recommendations in real time
Input Features
- Hour of day
- Day of week
- Historical traffic patterns
- Public hazard reports
- Weather conditions (future release)
Model Pipeline (Python)
from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score import pandas as pd
data = pd.read_csv(“poway_congestion.csv”) X = data.drop(“congested”, axis=1) y = data[“congested”]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) model = RandomForestClassifier() model.fit(X_train, y_train) print(“Accuracy:”, accuracy_score(y_test, model.predict(X_test)))
- Trained on historical congestion data from Poway
- Saved via joblib and served via Flask route
🌐 Google Maps API
Services Used
- Directions API
- Geocoding API
- Distance Matrix API (for ETA)
Usage
- Backend sends route requests with origin/destination
- Frontend visualizes route polylines and step instructions
- Live traffic overlay enabled for realtime updates
🚀 Deployment & CI/CD
- Docker: Containerize Flask backend and ML services
- GitHub Actions: Automate testing, linting, and deployment
- Hosting: Cloud server (AWS/GCP/DigitalOcean) for API and model hosting
- Frontend: Hosted on GitHub Pages or static site hosting with environment variables for API endpoints
🗂️ Data Storage
- User Data: Stored securely in PostgreSQL with SQLAlchemy ORM
- Hazard Reports: Timestamped and geotagged in DB
- User Preferences: Favorite locations and routines stored per user
- ML Data: Historical traffic logs for model training and updates
🔮 Future Enhancements
- Integrate weather data to predict impact on congestion
- Support multi-modal routing (bike, walk, public transit)
- Real-time alerts pushed to users about hazards on route
- User authentication & profile management
- Mobile app with offline caching and push notifications