# graphhopper/jsprit architecture

> Architecture diagram of the GitHub repository graphhopper/jsprit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/graphhopper/jsprit
- Repository: https://github.com/graphhopper/jsprit

## Overview

Based on our analysis of the project’s file tree and the README, jsprit is a Java-based open source toolkit dedicated to solving complex vehicle routing and traveling salesman type problems. It is built in a modular manner, providing both core algorithm functionalities (in jsprit-core) and additional analysis/visualization tools (in jsprit-analysis) to allow for rich problem setups (e.g., VRP with time windows, backhauls, pickups and deliveries, etc.). The project is set up in a way that allows custom problem definitions, use of meta-heuristics, and easy extension via modular design.

##### Key system components
- Core Algorithm Engine – Represented by the jsprit-core module which contains the central VRP/TSP algorithm implementations. This includes the algorithm’s different phases such as problem parsing, initial solution creation, iterative improvement, and termination criteria.
- Analysis and Visualization Tools – Found in the jsprit-analysis module; these are responsible for charting, recording algorithm events, and providing a graphical view of solution progress.
- Supporting Utilities and Common Libraries – These include common data structures (for example, classes for location, cost, vehicle types, and problem definitions) and utility functions for distance calculations and time/coordinate management found throughout the codebase.
- Testing and Validation Modules – The project integrates both unit and integration tests (organized under jsprit-core/src/test) to guarantee algorithm correctness and performance.
- Documentation and Configuration – The docs directory, Maven configuration files (pom.xml files) and continuous integration related configs (in .github/workflows) that support building, testing, and maintaining the library.

##### Relationships and interactions
- Inputs (problem instances) flow into the Core Algorithm Engine. This component is responsible for reading, validating, and parsing classical VRP/TSP instances from either files or programmatically defined instances.
- The Algorithm Engine then applies one or several meta-heuristic strategies. Here, various sub-components interact such as the insertion strategies, ruin and recreate methods, and state-update modules, each depicted as smaller functional blocks within the engine.
- The Analysis Tools listen to events from the core. They record algorithm events, compute statistics (using classes like AlgorithmEventsRecorder, XYLineChartBuilder, etc.), and supply visualization outputs.
- The testing suite interacts with both the core and the analysis modules to validate correctness of implementations and algorithm performance.

##### Important architectural patterns/design principles
- Modular Design – Clear separation between algorithmic core (jsprit-core) and auxiliary tools (jsprit-analysis) as well as tests. This separation reinforces extensibility and maintainability.
- Event-Driven and Listener Patterns – Within the core module, several listeners and event components (e.g., AlgorithmStartsListener, InsertionListener) are used to notify and intervene during different phases of the algorithm execution.
- Pluggability/Configurability – The design supports different constraint managers, cost calculators, and insertion strategies – each provided as separate classes which can be easily interchanged to tailor algorithm behavior.
- Dependency Injection – Though not explicitly flagged, the layered structure suggests that components (such as cost calculators or route validators) are provided as interchangeable modules or factories.

##### Following elements
- Business logic (core algorithm modules, strategy modules, utility classes)
- Integration/Interface components (data input, reporting tools)
- Infrastructure (Maven configuration, CI/CD files)
- If needed, display nested components within the core engine to indicate sub-systems such as:
- Input Parsing
- Initial Solution Generation
- Meta-heuristic Search Loop (with sub-components like acceptance and insertion strategies)
- Termination and State Management

## Diagram (Mermaid)

```mermaid
flowchart TD
    I1["Input / Problem Definition"]:::input

    subgraph "jsprit Core Engine"
        Core["Core Algorithm Engine"]:::core
        CP1["Input Parsing"]:::coreSub
        CP2["Initial Solution Factory"]:::coreSub
        CP3["Meta-Heuristic Manager"]:::coreSub
        CP4["Event Listener Framework"]:::coreSub
        CP5["Constraint Modules"]:::coreSub
    end

    A["Analysis & Visualization Tools"]:::analysis
    SU["Supporting Utilities"]:::utility
    Test["Test & Validation Modules"]:::test
    Doc["Documentation & Configuration"]:::docs

    I1 --> Core
    Core --> CP1
    CP1 --> CP2
    CP2 --> CP3
    CP3 --> CP4
    CP4 --> CP5
    CP3 --> A
    Core --> SU
    Test --> Core
    Test --> A
    Doc -.-> Core
    Doc -.-> Test

    click Core "https://github.com/graphhopper/jsprit/tree/master/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm"
    click A "https://github.com/graphhopper/jsprit/tree/master/jsprit-analysis/src/main/java/com/graphhopper/jsprit/analysis/toolbox"
    click SU "https://github.com/graphhopper/jsprit/tree/master/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util"
    click Test "https://github.com/graphhopper/jsprit/tree/master/jsprit-core/src/test"
    click Doc "https://github.com/graphhopper/jsprit/tree/master/docs"

    classDef input fill:#FFE4E1,stroke:#CD5C5C,stroke-width:2px;
    classDef core fill:#B0C4DE,stroke:#4682B4,stroke-width:2px;
    classDef coreSub fill:#ADD8E6,stroke:#1E90FF,stroke-width:2px;
    classDef analysis fill:#98FB98,stroke:#2E8B57,stroke-width:2px;
    classDef utility fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef test fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
    classDef docs fill:#D3D3D3,stroke:#A9A9A9,stroke-width:2px;
```
