Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ihfaz297/MND/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The RouteLeg model represents a single segment of a route. A complete route consists of one or more legs in sequence.

Type Definition

interface RouteLeg {
  mode: 'bus' | 'local' | 'walk';
  submode?: 'driving' | 'walking';
  route_id?: string;
  trip_id?: string;
  from: string;
  to: string;
  departure?: string;
  arrival?: string;
  durationMin?: number;
  distanceMeters?: number;
  cost?: number;
  source?: 'graph' | 'distance_matrix';
}
Source: /home/daytona/workspace/source/MND-backend/src/core/types.ts:71-84

Fields

mode
string
required
Primary transport mode for this leg.
submode
string
Specific mode within local transport (only when mode: 'local').
route_id
string
Bus route identifier (only when mode: 'bus').Examples: bus1, bus2, bus3, etc.
trip_id
string
Specific bus trip identifier (only when mode: 'bus').Format: {route_id}_{departure_time}Examples: bus1_0825, bus3_1710
from
string
required
Origin node ID for this leg.Example: TILAGOR, CAMPUS, SUBIDBAZAR
to
string
required
Destination node ID for this leg.Example: CAMPUS, AMBARKHANA, MEDICAL
departure
string
Departure time in HH:MM format (only for bus legs).Example: 08:30, 17:15
arrival
string
Arrival time in HH:MM format (only for bus legs).Example: 09:20, 17:45
durationMin
number
Duration of this leg in minutes.
  • For buses: Time between departure and arrival
  • For local transport: Estimated travel time
  • For walking: Estimated walking time
distanceMeters
number
Distance traveled in meters.Only available when Distance Matrix API is used. May be omitted for graph-based calculations.
cost
number
Cost in local currency (Bangladeshi Taka).
  • Bus: 0 (free university service)
  • Local transport: 15-50 BDT
  • Walking: 0
source
string
Data source for this leg’s calculations.

Leg Types

Bus Leg

Represents a bus ride between stops.
{
  "mode": "bus",
  "route_id": "bus1",
  "trip_id": "bus1_0930",
  "from": "TILAGOR",
  "to": "CAMPUS",
  "departure": "09:30",
  "arrival": "10:20",
  "durationMin": 50,
  "cost": 0,
  "source": "graph"
}
Required Fields:
  • mode: 'bus'
  • route_id
  • trip_id
  • from
  • to
  • departure
  • arrival
  • durationMin
  • cost: 0

Local Transport Leg

Represents travel by CNG, rickshaw, or taxi.
{
  "mode": "local",
  "submode": "driving",
  "from": "AMBARKHANA",
  "to": "CHOWHATTA",
  "durationMin": 6,
  "distanceMeters": 1200,
  "cost": 25,
  "source": "graph"
}
Required Fields:
  • mode: 'local'
  • from
  • to
  • durationMin
  • cost
Optional Fields:
  • submode: Usually 'driving'
  • distanceMeters: If available from Distance Matrix

Walking Leg

Represents pedestrian walking.
{
  "mode": "walk",
  "from": "RIKABI_BAZAR",
  "to": "CHOWHATTA",
  "durationMin": 6,
  "cost": 0,
  "source": "graph"
}
Required Fields:
  • mode: 'walk'
  • from
  • to
  • durationMin
  • cost: 0

Field Relationships

Mode-Specific Fields

Fieldbuslocalwalk
route_idRequired--
trip_idRequired--
departureRequired--
arrivalRequired--
submode-Optional-
durationMinRequiredRequiredRequired
distanceMeters-OptionalOptional
cost0>00

Source Field

graph: Data from pre-computed graph edges
{
  "mode": "local",
  "from": "SUBIDBAZAR",
  "to": "RIKABI_BAZAR",
  "durationMin": 5,
  "cost": 20,
  "source": "graph"
}
distance_matrix: Real-time data from Google API
{
  "mode": "local",
  "submode": "driving",
  "from": "TILAGOR",
  "to": "MEDICAL",
  "durationMin": 15,
  "distanceMeters": 3500,
  "cost": 40,
  "source": "distance_matrix"
}

Examples

Single Bus Leg

Simplest route: one bus from start to end.
{
  "legs": [
    {
      "mode": "bus",
      "route_id": "bus1",
      "trip_id": "bus1_0825",
      "from": "TILAGOR",
      "to": "CAMPUS",
      "departure": "08:25",
      "arrival": "09:15",
      "durationMin": 50,
      "cost": 0,
      "source": "graph"
    }
  ]
}

Bus + Local Transport

Bus to intermediate point, then CNG to final destination.
{
  "legs": [
    {
      "mode": "bus",
      "route_id": "bus1",
      "trip_id": "bus1_1710",
      "from": "SUBIDBAZAR",
      "to": "AMBARKHANA",
      "departure": "17:15",
      "arrival": "17:20",
      "durationMin": 5,
      "cost": 0,
      "source": "graph"
    },
    {
      "mode": "local",
      "submode": "driving",
      "from": "AMBARKHANA",
      "to": "CHOWHATTA",
      "durationMin": 6,
      "distanceMeters": 1200,
      "cost": 25,
      "source": "graph"
    }
  ]
}

Local + Walking

CNG to nearby point, then walk to final destination.
{
  "legs": [
    {
      "mode": "local",
      "from": "SUBIDBAZAR",
      "to": "RIKABI_BAZAR",
      "durationMin": 5,
      "cost": 20,
      "source": "graph"
    },
    {
      "mode": "walk",
      "from": "RIKABI_BAZAR",
      "to": "CHOWHATTA",
      "durationMin": 6,
      "cost": 0,
      "source": "graph"
    }
  ]
}

Bus Transfer

Two buses with a transfer point.
{
  "legs": [
    {
      "mode": "bus",
      "route_id": "bus1",
      "trip_id": "bus1_0825",
      "from": "TILAGOR",
      "to": "SUBIDBAZAR",
      "departure": "08:25",
      "arrival": "08:50",
      "durationMin": 25,
      "cost": 0,
      "source": "graph"
    },
    {
      "mode": "bus",
      "route_id": "bus3",
      "trip_id": "bus3_0925",
      "from": "SUBIDBAZAR",
      "to": "CAMPUS",
      "departure": "09:25",
      "arrival": "09:50",
      "durationMin": 25,
      "cost": 0,
      "source": "graph"
    }
  ]
}
Note the 35-minute gap between legs (08:50 to 09:25) for the transfer.

Calculating Leg Duration

Bus Legs

durationMin = arrival - departure

// Example:
// departure: "08:30" (510 minutes from midnight)
// arrival: "09:20" (560 minutes from midnight)
// duration: 560 - 510 = 50 minutes

Local Transport Legs

From graph data:
// Pre-configured in edges.json
{
  "from": "SUBIDBAZAR",
  "to": "RIKABI_BAZAR",
  "mode": "local",
  "time_min": 5,
  "cost": 20
}
From Distance Matrix API:
// Real-time calculation
const response = await distanceMatrixAPI.getDistance(
  fromAddress,
  toAddress,
  'driving'
);

durationMin = Math.ceil(response.durationSeconds / 60);
distanceMeters = response.distanceMeters;

Walking Legs

Estimated at 5 km/h (83 meters/minute):
durationMin = Math.ceil(distanceMeters / 83);

// Example:
// 500 meters ÷ 83 = 6 minutes

Cost Structure

Bus Rides

All bus rides are free (university service):
{
  "mode": "bus",
  "cost": 0
}

Local Transport

Costs vary by distance (pre-configured in graph):
DistanceCost (BDT)
< 1 km15-20
1-2 km20-25
2-4 km25-35
> 4 km35-50
{
  "mode": "local",
  "distanceMeters": 1200,
  "cost": 25
}

Walking

Always free:
{
  "mode": "walk",
  "cost": 0
}

Validation Rules

Required Field Validation

function validateLeg(leg: RouteLeg): boolean {
  // All legs must have these
  if (!leg.mode || !leg.from || !leg.to) {
    return false;
  }
  
  // Bus legs must have route info and timing
  if (leg.mode === 'bus') {
    if (!leg.route_id || !leg.trip_id || 
        !leg.departure || !leg.arrival || 
        leg.cost !== 0) {
      return false;
    }
  }
  
  // Cost must be non-negative
  if (leg.cost && leg.cost < 0) {
    return false;
  }
  
  return true;
}

Logical Consistency

// Duration should match departure/arrival for buses
if (leg.mode === 'bus') {
  const expectedDuration = 
    timeToMinutes(leg.arrival) - timeToMinutes(leg.departure);
  assert(leg.durationMin === expectedDuration);
}

// Walking and buses should be free
if (leg.mode === 'walk' || leg.mode === 'bus') {
  assert(leg.cost === 0);
}

// Local transport should have positive cost
if (leg.mode === 'local') {
  assert(leg.cost > 0);
}

Integration with RouteOption

Legs are always returned within a RouteOption:
{
  "label": "Fastest Route",
  "totalTimeMin": 56,
  "totalCost": 25,
  "legs": [
    { /* Bus leg */ },
    { /* Local leg */ }
  ]
}
The totals should match sum of legs:
const totalTime = legs.reduce((sum, leg) => sum + leg.durationMin, 0);
const totalCost = legs.reduce((sum, leg) => sum + leg.cost, 0);

RouteOption

Complete route containing multiple legs

Node

From/to location information

Bus Schedule

Trip timing for bus legs

Route Planning

API endpoint that returns legs

Build docs developers (and LLMs) love