Skip to content
Rittick DattaFULL STACK DEVELOPER

Route Planner API

A Google Maps-inspired route planning system exploring graph algorithms, shortest-path optimization, traffic-aware navigation, and practical backend engineering.

A Google Maps-inspired route planning backend

Route Planner API

A Google Maps-inspired route planning backend built with Node.js, Express, and TypeScript.

How do navigation applications find the best route through a road network? And what happens when traffic increases or a road becomes unavailable?

I built Route Planner API to explore these questions through graph data structures, shortest-path algorithms, and a REST API.

The system models intersections as vertices and roads as weighted edges. It supports different routing objectives, simulated traffic conditions, one-way roads, and road closures.

Interactive Demo

Explore the routing engine below. Change the optimization strategy, adjust traffic, or close a road to see how the selected path changes.

Interactive Route Planner

Explore routing algorithms and changing road conditions.

Browser simulation
Route optimization
R1R2R3R4R5R6ABCDE
🟦 Start🟩 Destination🟢 Selected route🔴 Closed road

Road conditions

Traffic affects travel time, not distance. Closed roads cannot be used by either algorithm.

Route result

A → B → C

2

Roads

5.0

km

10.0

Minutes

Optimized for: fastest estimated travel time

This interactive example runs locally in your browser. It demonstrates the backend algorithms but does not send requests to the Express API.

This is a client-side simulation of the routing logic. The actual Express API is maintained separately.

The Problem

A route planner must answer more than one question:

  • Which path uses the fewest roads?
  • Which path covers the shortest distance?
  • Which path takes the least estimated travel time?
  • How should the result change when traffic increases or roads close?

These questions require different optimization strategies.

A route with fewer road segments may cover more distance. A shorter route may take longer because of traffic.

Modeling Roads as a Graph

I used a weighted adjacency-list graph.

Each intersection is a vertex, and each road is an edge containing information such as distance, estimated travel time, direction, traffic multiplier, and closure status.

Adjacency lists are well suited to sparse road networks because they allow efficient traversal of neighboring intersections without allocating a dense adjacency matrix.

Routing Algorithms

Breadth-First Search

BFS finds a route with the fewest road segments.

It uses a queue, a visited Set, and parent tracking to reconstruct the path.

Time complexity: O(V + E)

Auxiliary space: O(V)

BFS does not account for distance or travel time, making it suitable for unweighted routing objectives.

Dijkstra's Algorithm

Dijkstra finds the minimum-cost path when edge weights are nonnegative.

I implemented a binary min-heap to efficiently select the next intersection with the lowest tentative cost.

The same algorithm supports two different edge-weight calculations:

  • Shortest route: Road distance in kilometers.
  • Fastest route: Base travel time multiplied by the traffic multiplier.

Time complexity: O((V + E) log(V + E)) with the lazy-deletion heap implementation.

This approach avoids the need to implement a decrease-key operation.

Dynamic Traffic and Road Closures

The routing engine supports changing road conditions without rewriting the graph algorithms.

Traffic updates change the effective travel-time weights. Road closures remove unavailable roads from traversal.

For example, the default fastest route from A to C is:

A → B → C — 10 minutes

When traffic on road R2 increases to three times its normal travel time, the fastest route changes to:

A → B → E → C — 14 minutes

The original route remains shorter by distance, but it is no longer the fastest.

This illustrates why real navigation systems need weighted routing rather than simple shortest-hop searches.

REST API Design

The Express API provides endpoints for managing intersections and roads, retrieving graph information, calculating routes, updating traffic, and changing road availability.

Example requests:

GET /api/routes/bfs?from=A&to=C
GET /api/routes/optimal?from=A&to=C&metric=distance
GET /api/routes/optimal?from=A&to=C&metric=time

Traffic and closure updates use PATCH requests:

PATCH /api/roads/R2/traffic
PATCH /api/roads/R2/closure

Request validation and centralized error handling help protect graph integrity and provide consistent responses.

Testing and Reliability

The project includes automated tests for graph operations, BFS, Dijkstra, road closures, traffic updates, invalid requests, and edge cases.

The application factory supports dependency injection, allowing tests to create independent in-memory graph instances.

I also prepared Postman collection tests and Newman CLI execution for repeatable API scenarios.

Performance Benchmarking

I benchmarked BFS and Dijkstra using deterministic grid-based road networks of increasing sizes.

The benchmark separates graph construction from routing execution and reports median execution times after warm-up iterations.

BFS and Dijkstra solve different optimization problems, so their timings represent computational cost rather than interchangeable route quality.

For the complete benchmark methodology and measured results, see the repository documentation.

Engineering Tradeoffs

In-memory graph storage: Simple and fast for an algorithm-focused project, but state is not persisted across restarts.

Adjacency lists: Efficient for sparse networks, although road updates require maintaining consistent graph references.

Binary min-heap: Improves Dijkstra's priority selection compared with repeatedly scanning every vertex.

Simulated traffic: Makes route recalculation testable without external traffic services.

Separate browser demo: Allows portfolio visitors to explore the algorithms without depending on backend deployment or network availability.

What I Learned

This project reinforced the importance of choosing data structures based on the problem being solved.

BFS is appropriate when every road segment has equal cost. Dijkstra is necessary when distances and travel times differ.

I also learned how traffic and closure updates affect graph traversal, how to separate algorithm logic from HTTP handling, and how to evaluate performance with reproducible benchmarks.

Source Code

View the Route Planner API on GitHub

The repository includes the Express API, routing algorithms, tests, Postman collection, benchmark scripts, and technical documentation.