Inspiration

Modern cities suffer from unpredictable congestion, but the tools we use to solve it are fundamentally flawed. Live-traffic APIs (like Google Maps or TomTom) are incredibly expensive and entirely reactive—they tell you where traffic is right now, not where it will be in two hours. We realized that urban traffic is just a mathematical rhythm. If we could decouple the temporal rhythm of traffic from the spatial geography of the city, we could build a predictive engine that forecasts congestion proactively, without relying on massive, hyper-local, ten-year historical datasets for every single street.

What it does

CityFlow is a proactive, AI-driven urban traffic forecasting engine. Instead of polling live APIs, it uses a deep learning model to predict future traffic volumes based on time and historical rhythms. Users can select a specific route in the city (e.g., Madhya Marg) and a future time of day. CityFlow's engine calculates the predicted congestion level and visually updates the city map in real-time, acting as a "command center" for city planners and commuters to see bottlenecks before they actually happen.

How we built it

We architected CityFlow using a decoupled Spatio-Temporal approach, split into three main layers:

  • The Brain (Machine Learning): We trained a custom Hybrid Neural Network using PyTorch. By combining an LSTM (Long Short-Term Memory) to capture daily/weekly macro-patterns and a GRU (Gated Recurrent Unit) to capture immediate, short-term volatility, the model learns the pure temporal flow of traffic over 24-timestep (6-hour) lookback windows.
  • Feature Engineering: To help the neural network understand that time is a continuous circle, we used cyclical temporal encoding for our input features: $$T_{sin} = \sin\left(\frac{2\pi \cdot h}{24}\right), \quad T_{cos} = \cos\left(\frac{2\pi \cdot h}{24}\right)$$
  • The Nervous System (Backend): We built a lightning-fast FastAPI backend in Python. It takes the pure temporal prediction $M(t)$ from the PyTorch model and maps it to specific spatial bottlenecks using a heuristic capacity weight $W_{spatial}$: $$P_{final} = M(t) \times W_{spatial}$$
  • The Face (Frontend): We built a highly responsive React frontend using Tailwind CSS and react-leaflet. We utilized the CartoDB Dark Matter tile layer to make our spatial GeoJSON data visually pop.

Challenges we ran into

  • Dependency Hell: We initially struggled to get PyTorch running on local environments due to strict versioning conflicts with newer Python installations. We had to dynamically unpin dependencies and utilize CPU-specific wheels to get the backend compiling rapidly for the hackathon.
  • React-Leaflet State Management: We hit a major roadblock where our interactive map refused to re-render new route lines when the user selected a different spatial bottleneck. We had to hack the React DOM lifecycle by passing dynamic key props to the <GeoJSON /> component to force Leaflet to destroy and redraw the data layer on every state change.
  • The Spatio-Temporal Gap: Training a model purely on time meant we couldn't easily visualize it on a map. Building the mathematical heuristic layer in our API to translate an abstract LSTM output into a physical, color-coded street on an OpenStreetMap layer was a major architectural hurdle.

Accomplishments that we're proud of

  • Successfully building and integrating a custom Deep Learning model from scratch during a hackathon, rather than just wrapping a pre-built API.
  • The UI/UX. The dark-mode interactive map perfectly visualizes the ML output in a way that feels like a polished, enterprise-grade SaaS product.
  • Architecting the system to be infinitely scalable. Because the temporal model is detached from the spatial map, CityFlow can theoretically be deployed to any city in the world tomorrow.

What we learned

  • Advanced techniques in Time-Series forecasting, specifically the advantages of parallelizing LSTM and GRU layers for complex sequence data.
  • How to handle and style complex GeoJSON data mapping inside React components.
  • The immense value of clean, organized architecture—specifically, separating our experimental ML training scripts from the live FastAPI production engine.

What's next for CityFlow

This prototype proves the concept. The next steps for a V2 production launch include:

  1. Graph Neural Networks (T-GCN): Upgrading the architecture to understand the spatial "ripple effect" of traffic across connected nodes (e.g., if Route A is blocked, Route B will congest in 15 minutes).
  2. External Context Vectors: Expanding the PyTorch input tensor to include live Weather API data and local event calendars to handle anomaly prediction.
  3. Continuous MLOps: Building an automated pipeline that ingests actual local traffic data daily and re-trains the model weights every Sunday night to ensure it gets smarter over time.

Built With

Share this project:

Updates

Submission history