# bug1857/waybill-complete architecture

> Architecture diagram of the GitHub repository bug1857/waybill-complete, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bug1857/waybill-complete
- Repository: https://github.com/bug1857/waybill-complete

## Overview

Waybill is a courier-route optimization system whose Python engine is canonical; the preserved Google UI is explicitly a reference, not a deployed solver. The main workflow accepts stops and a distance/time matrix, builds an instance, solves and independently checks routes, then returns typed reports and map-ready data through the local API and static workbench. The graph preserves the documented TSP exact and heuristic methods, CVRPTW construction, road/place integrations, and evidence/reporting capabilities. Edges are limited to README and indexed source relationships; unsampled UI wiring is not inferred.

Main entry points: [`api/server.py`](https://github.com/bug1857/waybill-complete/blob/main/api/server.py) (Local solve API), [`core/construct/nearest_neighbor.py`](https://github.com/bug1857/waybill-complete/blob/main/core/construct/nearest_neighbor.py) (Nearest neighbour), [`core/model/instance.py`](https://github.com/bug1857/waybill-complete/blob/main/core/model/instance.py) (Routing instance), [`core/solver.py`](https://github.com/bug1857/waybill-complete/blob/main/core/solver.py) (Solver contract and budget)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Inputs and routing"]
  node_places["Places and stops<br/>[places.py]"]
  node_road["Road distance adapters<br/>[osrm.py]"]
  node_offline["Offline distance adapter<br/>[haversine.py]"]
end

subgraph group_model["Problem model"]
  node_matrix[("Cost matrix<br/>[matrix.py]")]
  node_instance["Routing instance<br/>[instance.py]"]
  node_geometry["Coordinates<br/>[geometry.py]"]
  node_stop["Stops and constraints<br/>[stop.py]"]
  node_vehicles["Vehicles<br/>[vehicle.py]"]
  node_solution["Route solution<br/>[solution.py]"]
end

subgraph group_solvers["Route solving"]
  node_solver_api["Solver contract and budget<br/>[solver.py]"]
  node_greedy["Nearest neighbour"]
  node_savings["Clarke-Wright construction<br/>[savings.py]"]
  node_exact["Exact TSP solvers"]
  node_heldkarp["Held-Karp cross-check<br/>[held_karp.py]"]
  node_local["Local search and annealing"]
end

subgraph group_results["Validation and results"]
  node_objective["Objective scoring<br/>[objective.py]"]
  node_feasibility["Independent feasibility<br/>[feasibility.py]"]
  node_report["Typed solve report<br/>[report.py]"]
  node_status["Claim and stop status<br/>[status.py]"]
end

subgraph group_interface["API and workbench"]
  node_api["Local solve API<br/>[server.py]"]
  node_web["Static workbench and map<br/>[app.js]"]
  node_evidence["Evidence viewer<br/>[evidence.js]"]
  node_live["Live route replay<br/>[live.js]"]
end

node_operator(("Courier/operator"))

node_operator -->|"submits solve"| node_api
node_api -->|"queries places"| node_places
node_api -->|"requests road matrix"| node_road
node_api -->|"requests estimate"| node_offline
node_road -->|"builds matrix"| node_matrix
node_offline -->|"builds matrix"| node_matrix
node_api -->|"creates instance"| node_instance
node_instance -->|"uses costs"| node_matrix
node_instance -->|"contains stops"| node_stop
node_instance -->|"contains vehicles"| node_vehicles
node_stop -->|"uses coordinates"| node_geometry
node_api -->|"dispatches solve"| node_solver_api
node_solver_api -->|"defines solver interface"| node_greedy
node_solver_api -->|"defines solver interface"| node_exact
node_solver_api -->|"defines solver interface"| node_heldkarp
node_api -->|"dispatches fleet construction"| node_savings
node_exact -->|"seeds incumbent"| node_greedy
node_greedy -->|"checks candidate"| node_feasibility
node_greedy -->|"scores candidate"| node_objective
node_savings -->|"checks plan"| node_feasibility
node_savings -->|"scores plan"| node_objective
node_local -->|"checks moves"| node_feasibility
node_local -->|"scores moves"| node_objective
node_api -->|"independently validates"| node_feasibility
node_api -->|"computes result cost"| node_objective
node_greedy -->|"creates route"| node_solution
node_exact -->|"returns incumbent"| node_solution
node_api -->|"returns report"| node_report
node_report -->|"enforces claims"| node_status
node_api -->|"serves workbench"| node_web
node_web -->|"posts solve request"| node_api
node_web -->|"shows generated evidence"| node_evidence
node_web -->|"offers route replay"| node_live
node_api -->|"includes schedules and hashes"| node_report

click node_places "https://github.com/bug1857/waybill-complete/blob/main/adapters/places.py"
click node_road "https://github.com/bug1857/waybill-complete/blob/main/adapters/distance/osrm.py"
click node_offline "https://github.com/bug1857/waybill-complete/blob/main/adapters/distance/haversine.py"
click node_matrix "https://github.com/bug1857/waybill-complete/blob/main/core/distance/matrix.py"
click node_instance "https://github.com/bug1857/waybill-complete/blob/main/core/model/instance.py"
click node_geometry "https://github.com/bug1857/waybill-complete/blob/main/core/model/geometry.py"
click node_stop "https://github.com/bug1857/waybill-complete/blob/main/core/model/stop.py"
click node_vehicles "https://github.com/bug1857/waybill-complete/blob/main/core/model/vehicle.py"
click node_solution "https://github.com/bug1857/waybill-complete/blob/main/core/model/solution.py"
click node_solver_api "https://github.com/bug1857/waybill-complete/blob/main/core/solver.py"
click node_greedy "https://github.com/bug1857/waybill-complete/blob/main/core/construct/nearest_neighbor.py"
click node_savings "https://github.com/bug1857/waybill-complete/blob/main/core/construct/savings.py"
click node_exact "https://github.com/bug1857/waybill-complete/blob/main/core/exact/branch_and_bound.py"
click node_heldkarp "https://github.com/bug1857/waybill-complete/blob/main/core/exact/held_karp.py"
click node_local "https://github.com/bug1857/waybill-complete/tree/main/core/local"
click node_objective "https://github.com/bug1857/waybill-complete/blob/main/core/eval/objective.py"
click node_feasibility "https://github.com/bug1857/waybill-complete/blob/main/core/eval/feasibility.py"
click node_report "https://github.com/bug1857/waybill-complete/blob/main/core/reporting/report.py"
click node_status "https://github.com/bug1857/waybill-complete/blob/main/core/reporting/status.py"
click node_api "https://github.com/bug1857/waybill-complete/blob/main/api/server.py"
click node_web "https://github.com/bug1857/waybill-complete/blob/main/web/app.js"
click node_evidence "https://github.com/bug1857/waybill-complete/blob/main/web/evidence.js"
click node_live "https://github.com/bug1857/waybill-complete/blob/main/web/live.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_places,node_road,node_offline toneBlue
class node_matrix,node_instance,node_geometry,node_stop,node_vehicles,node_solution toneAmber
class node_solver_api,node_greedy,node_savings,node_exact,node_heldkarp,node_local toneMint
class node_objective,node_feasibility,node_report,node_status toneRose
class node_api,node_web,node_evidence,node_live,node_operator toneIndigo
```

## Components

### Inputs and routing

- [Places and stops](https://github.com/bug1857/waybill-complete/blob/main/adapters/places.py): `adapters/places.py`
- [Road distance adapters](https://github.com/bug1857/waybill-complete/blob/main/adapters/distance/osrm.py): `adapters/distance/osrm.py`
- [Offline distance adapter](https://github.com/bug1857/waybill-complete/blob/main/adapters/distance/haversine.py): `adapters/distance/haversine.py`

### Problem model

- [Cost matrix](https://github.com/bug1857/waybill-complete/blob/main/core/distance/matrix.py): `core/distance/matrix.py`
- [Routing instance](https://github.com/bug1857/waybill-complete/blob/main/core/model/instance.py): `core/model/instance.py`
- [Coordinates](https://github.com/bug1857/waybill-complete/blob/main/core/model/geometry.py): `core/model/geometry.py`
- [Stops and constraints](https://github.com/bug1857/waybill-complete/blob/main/core/model/stop.py): `core/model/stop.py`
- [Vehicles](https://github.com/bug1857/waybill-complete/blob/main/core/model/vehicle.py): `core/model/vehicle.py`
- [Route solution](https://github.com/bug1857/waybill-complete/blob/main/core/model/solution.py): `core/model/solution.py`

### Route solving

- [Solver contract and budget](https://github.com/bug1857/waybill-complete/blob/main/core/solver.py): `core/solver.py`
- [Nearest neighbour](https://github.com/bug1857/waybill-complete/blob/main/core/construct/nearest_neighbor.py): `core/construct/nearest_neighbor.py`
- [Clarke-Wright construction](https://github.com/bug1857/waybill-complete/blob/main/core/construct/savings.py): `core/construct/savings.py`
- [Exact TSP solvers](https://github.com/bug1857/waybill-complete/blob/main/core/exact/branch_and_bound.py): `core/exact/branch_and_bound.py`
- [Held-Karp cross-check](https://github.com/bug1857/waybill-complete/blob/main/core/exact/held_karp.py): `core/exact/held_karp.py`
- [Local search and annealing](https://github.com/bug1857/waybill-complete/tree/main/core/local): `core/local`

### Validation and results

- [Objective scoring](https://github.com/bug1857/waybill-complete/blob/main/core/eval/objective.py): `core/eval/objective.py`
- [Independent feasibility](https://github.com/bug1857/waybill-complete/blob/main/core/eval/feasibility.py): `core/eval/feasibility.py`
- [Typed solve report](https://github.com/bug1857/waybill-complete/blob/main/core/reporting/report.py): `core/reporting/report.py`
- [Claim and stop status](https://github.com/bug1857/waybill-complete/blob/main/core/reporting/status.py): `core/reporting/status.py`

### API and workbench

- [Local solve API](https://github.com/bug1857/waybill-complete/blob/main/api/server.py): `api/server.py`
- [Static workbench and map](https://github.com/bug1857/waybill-complete/blob/main/web/app.js): `web/app.js`
- [Evidence viewer](https://github.com/bug1857/waybill-complete/blob/main/web/evidence.js): `web/evidence.js`
- [Live route replay](https://github.com/bug1857/waybill-complete/blob/main/web/live.js): `web/live.js`

### Other components

- **Courier/operator**

## Connections

- Courier/operator → Local solve API: submits solve
- Local solve API → Places and stops: queries places (evidence: `api/server.py`)
- Local solve API → Road distance adapters: requests road matrix (evidence: `api/server.py`)
- Local solve API → Offline distance adapter: requests estimate (evidence: `api/server.py`)
- Road distance adapters → Cost matrix: builds matrix (evidence: `adapters/distance/osrm.py`)
- Offline distance adapter → Cost matrix: builds matrix (evidence: `adapters/distance/haversine.py`)
- Local solve API → Routing instance: creates instance (evidence: `api/server.py`)
- Routing instance → Cost matrix: uses costs (evidence: `core/model/instance.py`)
- Routing instance → Stops and constraints: contains stops (evidence: `core/model/instance.py`)
- Routing instance → Vehicles: contains vehicles (evidence: `core/model/instance.py`)
- Stops and constraints → Coordinates: uses coordinates (evidence: `core/model/stop.py`)
- Local solve API → Solver contract and budget: dispatches solve (evidence: `api/server.py`)
- Solver contract and budget → Nearest neighbour: defines solver interface (evidence: `core/solver.py`)
- Solver contract and budget → Exact TSP solvers: defines solver interface (evidence: `core/solver.py`)
- Solver contract and budget → Held-Karp cross-check: defines solver interface (evidence: `core/solver.py`)
- Local solve API → Clarke-Wright construction: dispatches fleet construction (evidence: `api/server.py`)
- Exact TSP solvers → Nearest neighbour: seeds incumbent (evidence: `core/exact/branch_and_bound.py`)
- Nearest neighbour → Independent feasibility: checks candidate (evidence: `core/construct/nearest_neighbor.py`)
- Nearest neighbour → Objective scoring: scores candidate (evidence: `core/construct/nearest_neighbor.py`)
- Clarke-Wright construction → Independent feasibility: checks plan (evidence: `core/construct/savings.py`)
- Clarke-Wright construction → Objective scoring: scores plan (evidence: `core/construct/savings.py`)
- Local search and annealing → Independent feasibility: checks moves (evidence: `core/local/improve.py`)
- Local search and annealing → Objective scoring: scores moves (evidence: `core/local/improve.py`)
- Local solve API → Independent feasibility: independently validates (evidence: `api/server.py`)
- Local solve API → Objective scoring: computes result cost (evidence: `api/server.py`)
- Nearest neighbour → Route solution: creates route (evidence: `core/construct/nearest_neighbor.py`)
- Exact TSP solvers → Route solution: returns incumbent (evidence: `core/exact/branch_and_bound.py`)
- Local solve API → Typed solve report: returns report (evidence: `api/server.py`)
- Typed solve report → Claim and stop status: enforces claims (evidence: `core/reporting/report.py`)
- Local solve API → Static workbench and map: serves workbench
- Static workbench and map → Local solve API: posts solve request
- Static workbench and map → Evidence viewer: shows generated evidence
- Static workbench and map → Live route replay: offers route replay
- Local solve API → Typed solve report: includes schedules and hashes
