# hyperledger-caliper/caliper architecture

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

- Interactive diagram: https://gitdiagram.com/hyperledger-caliper/caliper
- Repository: https://github.com/hyperledger-caliper/caliper

## Overview

##### Main Components
- CLI Interface: Represented by packages/caliper-cli, this is the entry point for users. It is responsible for loading benchmark configurations and initiating tests.
- Core Engine: Found in packages/caliper-core, this forms the heart of the system. It manages the overall benchmark lifecycle, such as worker orchestration, configuration management, message handling, reporting, and interactions with the connectors.
- Connectors/Adapters: There are dedicated packages for each supported blockchain:
- packages/caliper-ethereum (for Ethereum)
- packages/caliper-fabric (for Hyperledger Fabric)
- (And potentially other connectors like for Hyperledger Besu through Ethereum adapters)
These connector components implement specific interfaces (e.g., connector-interface.js) that allow seamless communication with varying underlying blockchain technologies.
- Worker Modules & Rate Controllers: Located within caliper-core and caliper-core/worker, these modules handle the actual transaction submission, including various rate control implementations (such as fixedRate, linearRate, etc.) which simulate network load.
- Test Orchestrators, Monitors, & Reporting: The caliper-core package includes orchestrators (worker, round, monitor orchestrators), monitor modules for collecting metrics, and report generation modules (with chart builders and HTML templates).
- Supplementary Tools: Include modules like packages/caliper-publish (for Docker and npm publishing), packages/generator-caliper (for generating configuration templates), and various integration tests (under packages/caliper-tests-integration) used to validate functionality against real blockchain networks.

- A bidirectional communication between the Core Engine and the Worker Modules, mediated by message handlers and rate controllers.
- Core Engine interfacing with various Connectors, which abstract the underlying blockchain network protocols.
- Reporting/monitoring subsystem as receiving inputs from the Worker and Core Engine; then flowing these outputs into report generators (including chart builders).
- If desired, add connections from the integration testing and publishing tools to the respective components they target (for continuous integration and deployment).

##### Architectural Patterns and Design Principles
- Modular and Pluggable Structure: Emphasize the layered modular design where components like connectors, worker modules, and rate controllers can be independently maintained or extended.
- Separation of Concerns: The project cleanly separates the user interface (CLI), core benchmarking logic, blockchain-specific interactions, testing integrations, and deployment scripts.
- Communication via Messaging: Point out that there is an abstraction for messaging (using different messengers like MQTT or process-based) which decouples components.
- Extensible Plugin Architecture: Note how new blockchain solutions or workload generators can be added as new packages or generators.

##### Relevant Technologies and Libraries
- Node.js is the primary runtime (with many .js files visible).
- Use of YAML and JSON for configuration files.
- Docker is used for publishing and running the environment (as seen in Dockerfiles and compose files).
- Testing frameworks and possibly linting/build tools are indicated by ESLint configurations and GitHub workflow scripts.
- Documentation is provided via the docs directory (including mkdocs for generating static documentation sites).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Subgraph: User Interface
    subgraph "User Interface"
        CLI["Caliper CLI"]:::cli
    end

    %% Subgraph: Benchmark Core
    subgraph "Benchmarking Core"
        Engine["Benchmark Engine"]:::engine
        Workers["Transaction Worker Modules"]:::worker
        RateControllers["Rate Controllers"]:::worker
        Messengers["Messaging & Communication"]:::messenger
    end

    %% Subgraph: Blockchain Connectors
    subgraph "Blockchain Connectors"
        Ethereum["Ethereum Connector"]:::connector
        Fabric["Fabric Connector"]:::connector
    end

    %% Subgraph: Monitoring & Reporting
    subgraph "Monitoring & Reporting"
        Reporting["Test Orchestrators & Reporting"]:::reporting
    end

    %% Subgraph: Supplementary Tools
    subgraph "Supplementary Tools"
        Publish["Publishing Tools"]:::supplement
        ConfigGen["Configuration Generators"]:::supplement
        IntegrationTests["Integration Testing Tools"]:::supplement
    end

    %% Connections
    CLI -->|"initiates"| Engine
    Engine -->|"orchestrates and configures"| Workers
    Workers -->|"managed by"| RateControllers
    Engine -->|"communicates with"| Messengers
    Engine -->|"interfaces with"| Ethereum
    Engine -->|"interfaces with"| Fabric
    Workers -->|"reports metrics to"| Reporting
    Engine -->|"aggregates reports from"| Reporting

    %% Supplementary Tools interactions
    ConfigGen -->|"generates benchmark configs for"| CLI
    IntegrationTests -->|"validates"| Engine
    Publish -->|"publishes artifacts from"| Engine

    %% Class Definitions for Colors
    classDef cli fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef engine fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef worker fill:#f94144,stroke:#333,stroke-width:2px;
    classDef messenger fill:#277da1,stroke:#333,stroke-width:2px;
    classDef connector fill:#f3722c,stroke:#333,stroke-width:2px;
    classDef reporting fill:#43aa8b,stroke:#333,stroke-width:2px;
    classDef supplement fill:#577590,stroke:#333,stroke-width:2px;

    %% Click Events (Component Mapping)
    click CLI "https://github.com/hyperledger-caliper/caliper/tree/main/packages/caliper-cli"
    click Engine "https://github.com/hyperledger-caliper/caliper/tree/main/packages/caliper-core"
    click Ethereum "https://github.com/hyperledger-caliper/caliper/tree/main/packages/caliper-ethereum"
    click Fabric "https://github.com/hyperledger-caliper/caliper/tree/main/packages/caliper-fabric"
    click Workers "https://github.com/hyperledger-caliper/caliper/tree/main/packages/caliper-core/lib/worker"
    click RateControllers "https://github.com/hyperledger-caliper/caliper/tree/main/packages/caliper-core/lib/worker/rate-control"
    click Messengers "https://github.com/hyperledger-caliper/caliper/tree/main/packages/caliper-core/lib/common/messengers"
    click Reporting "https://github.com/hyperledger-caliper/caliper/tree/main/packages/caliper-core/lib/manager"
    click Publish "https://github.com/hyperledger-caliper/caliper/tree/main/packages/caliper-publish"
    click ConfigGen "https://github.com/hyperledger-caliper/caliper/tree/main/packages/generator-caliper"
    click IntegrationTests "https://github.com/hyperledger-caliper/caliper/tree/main/packages/caliper-tests-integration"
```
