# perliedman/leaflet-routing-machine architecture

> Architecture diagram of the GitHub repository perliedman/leaflet-routing-machine, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/perliedman/leaflet-routing-machine
- Repository: https://github.com/perliedman/leaflet-routing-machine

## Overview

Leaflet Routing Machine is a Leaflet plugin for entering waypoints, requesting routes, and displaying route lines, alternatives, and turn-by-turn instructions. The main workflow runs from the map control through waypoint planning and a configurable routing backend, then presents the returned route on the map and in an itinerary. Geocoding and localization support waypoint entry and readable instructions. The excerpts show key component calls, but some routing and rendering details are incomplete; unverified links are omitted or marked dashed.

Main entry points: [`src/control.js`](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/control.js) (Routing Control), [`src/geocoder-element.js`](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/geocoder-element.js) (Geocoder Element), [`src/index.js`](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/index.js) (Plugin API), [`src/plan.js`](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/plan.js) (Waypoint Plan)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Control and Planning"]
  node_control["Routing Control<br/>[control.js]"]
  node_plan["Waypoint Plan<br/>[plan.js]"]
  node_plugin_api["Plugin API<br/>[index.js]"]
end

subgraph group_geocoding["Waypoint Entry"]
  node_geocoder["Geocoder Element"]
  node_autocomplete["Autocomplete<br/>[autocomplete.js]"]
end

subgraph group_routing["Routing Backends"]
  node_osrm["OSRM v5 Router<br/>[osrm-v1.js]"]
  node_mapbox["Mapbox Router<br/>[mapbox.js]"]
end

subgraph group_presentation["Route Presentation"]
  node_line["Route Line<br/>[line.js]"]
  node_itinerary["Itinerary Control<br/>[itinerary.js]"]
  node_formatter["Instruction Formatter<br/>[formatter.js]"]
  node_builder["Itinerary Builder"]
  node_error_control["Error Control<br/>[error-control.js]"]
end

subgraph group_shared["Shared Models"]
  node_waypoint["Waypoint<br/>[waypoint.js]"]
  node_localization["Localization<br/>[localization.js]"]
end

node_user(("Map User"))
node_geocoder_service["Configured Geocoder"]
node_osrm_service["OSRM Service"]
node_mapbox_service["Mapbox Directions"]

node_user -->|"uses"| node_control
node_control -->|"creates"| node_plan
node_plan -->|"normalizes"| node_waypoint
node_plan -->|"creates"| node_geocoder
node_geocoder -->|"creates"| node_autocomplete
node_geocoder -->|"localizes fields"| node_localization
node_geocoder -.->|"requests geocoding"| node_geocoder_service
node_control -->|"defaults to"| node_osrm
node_osrm -->|"requests routes"| node_osrm_service
node_mapbox -->|"requests directions"| node_mapbox_service
node_control -->|"creates route lines"| node_line
node_control -->|"initializes"| node_itinerary
node_itinerary -->|"formats instructions"| node_formatter
node_itinerary -->|"builds rows"| node_builder
node_formatter -->|"gets translations"| node_localization
node_plugin_api -->|"exports"| node_control
node_plugin_api -->|"exports"| node_mapbox
node_plugin_api -->|"exports"| node_error_control

click node_control "https://github.com/perliedman/leaflet-routing-machine/blob/master/src/control.js"
click node_plan "https://github.com/perliedman/leaflet-routing-machine/blob/master/src/plan.js"
click node_waypoint "https://github.com/perliedman/leaflet-routing-machine/blob/master/src/waypoint.js"
click node_geocoder "https://github.com/perliedman/leaflet-routing-machine/blob/master/src/geocoder-element.js"
click node_autocomplete "https://github.com/perliedman/leaflet-routing-machine/blob/master/src/autocomplete.js"
click node_osrm "https://github.com/perliedman/leaflet-routing-machine/blob/master/src/osrm-v1.js"
click node_mapbox "https://github.com/perliedman/leaflet-routing-machine/blob/master/src/mapbox.js"
click node_line "https://github.com/perliedman/leaflet-routing-machine/blob/master/src/line.js"
click node_itinerary "https://github.com/perliedman/leaflet-routing-machine/blob/master/src/itinerary.js"
click node_formatter "https://github.com/perliedman/leaflet-routing-machine/blob/master/src/formatter.js"
click node_builder "https://github.com/perliedman/leaflet-routing-machine/blob/master/src/itinerary-builder.js"
click node_localization "https://github.com/perliedman/leaflet-routing-machine/blob/master/src/localization.js"
click node_error_control "https://github.com/perliedman/leaflet-routing-machine/blob/master/src/error-control.js"
click node_plugin_api "https://github.com/perliedman/leaflet-routing-machine/blob/master/src/index.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_control,node_plan,node_plugin_api,node_user toneBlue
class node_geocoder,node_autocomplete toneAmber
class node_osrm,node_mapbox toneMint
class node_line,node_itinerary,node_formatter,node_builder,node_error_control toneRose
class node_waypoint,node_localization,node_geocoder_service,node_osrm_service,node_mapbox_service toneIndigo
```

## Components

### Control and Planning

- [Routing Control](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/control.js): `src/control.js`
- [Waypoint Plan](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/plan.js): `src/plan.js`
- [Plugin API](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/index.js): `src/index.js`

### Waypoint Entry

- [Geocoder Element](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/geocoder-element.js): `src/geocoder-element.js`
- [Autocomplete](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/autocomplete.js): `src/autocomplete.js`

### Routing Backends

- [OSRM v5 Router](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/osrm-v1.js): `src/osrm-v1.js`
- [Mapbox Router](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/mapbox.js): `src/mapbox.js`

### Route Presentation

- [Route Line](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/line.js): `src/line.js`
- [Itinerary Control](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/itinerary.js): `src/itinerary.js`
- [Instruction Formatter](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/formatter.js): `src/formatter.js`
- [Itinerary Builder](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/itinerary-builder.js): `src/itinerary-builder.js`
- [Error Control](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/error-control.js): `src/error-control.js`

### Shared Models

- [Waypoint](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/waypoint.js): `src/waypoint.js`
- [Localization](https://github.com/perliedman/leaflet-routing-machine/blob/master/src/localization.js): `src/localization.js`

### Other components

- **Map User**
- **Configured Geocoder**
- **OSRM Service**
- **Mapbox Directions**

## Connections

- Map User → Routing Control: uses (evidence: `README.md`)
- Routing Control → Waypoint Plan: creates (evidence: `src/control.js`)
- Waypoint Plan → Waypoint: normalizes (evidence: `src/plan.js`)
- Waypoint Plan → Geocoder Element: creates (evidence: `src/plan.js`)
- Geocoder Element → Autocomplete: creates (evidence: `src/geocoder-element.js`)
- Geocoder Element → Localization: localizes fields (evidence: `src/geocoder-element.js`)
- Geocoder Element → Configured Geocoder: requests geocoding
- Routing Control → OSRM v5 Router: defaults to (evidence: `src/control.js`)
- OSRM v5 Router → OSRM Service: requests routes (evidence: `README.md`)
- Mapbox Router → Mapbox Directions: requests directions (evidence: `README.md`)
- Routing Control → Route Line: creates route lines (evidence: `src/control.js`)
- Routing Control → Itinerary Control: initializes (evidence: `src/control.js`)
- Itinerary Control → Instruction Formatter: formats instructions (evidence: `src/itinerary.js`)
- Itinerary Control → Itinerary Builder: builds rows (evidence: `src/itinerary.js`)
- Instruction Formatter → Localization: gets translations (evidence: `src/formatter.js`)
- Plugin API → Routing Control: exports (evidence: `src/index.js`)
- Plugin API → Mapbox Router: exports (evidence: `src/index.js`)
- Plugin API → Error Control: exports (evidence: `src/index.js`)
