# phisgr/gatling-grpc architecture

> Architecture diagram of the GitHub repository phisgr/gatling-grpc, 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/phisgr/gatling-grpc
- Repository: https://github.com/phisgr/gatling-grpc

## Overview

##### Project Type and Purpose
- This is a load testing plugin for Gatling that focuses on gRPC. The core functionality lets users express gRPC calls (requests, streams, dynamic payloads, etc.) as part of Gatling simulations.
- It is designed to work with code generation (from Protocol Buffers) and provides support for both ScalaPB (for Scala) and Java Protobuf classes.

##### Main Components
a. Core Plugin Library:
– The heart of the project is the gRPC DSL implementation (found mainly in the src/main/scala/com/github/phisgr/gatling/grpc directory).
– This includes the various action builders (e.g. GrpcCallActionBuilder and others) and supporting utilities (protocol marshallers, check support, stream handling).
b. Language-specific Bindings:
– The “gatling-grpc-kt” module contains bindings written in Kotlin to support both Java and Kotlin users.
– The “macro” module might contain Scala macros meant to provide syntactic sugar or compile‐time code generation.
c. Code Generation & Protobuf Integration:
– The project handles gRPC’s need for code generation from protobuf files. Directories like src/test/protobuf and bench/src/main/protobuf highlight this aspect.
– There is also integration with ScalaPB, which is set up via build.sbt and the companion instructions in the README.
d. Benchmarking & Testing:
– The “bench” module is dedicated to performance benchmarking and might include JMH tests (as evident from the “bench/src/main/scala/…” and the jmh directories in “gatling-grpc-kt/src/jmh”).
– The “src/test” directory contains functional tests and example simulations.
e. External Dependencies:
– Integration with the Gatling load testing engine itself, which provides the simulation and session management.
– Dependencies on language-specific tooling and build systems (SBT for Scala, Gradle for the Kotlin binding module).

##### Relationships and Data Flow
- Within the plugin, differentiate between the DSL that users write (simulation scripts) and the underlying gRPC call builders that actually generate the requests.
- Integration point where Protocol Buffers get converted into runtime objects using ScalaPB (or Java PB), and then used by DSL actions.
- How benchmarking (bench module) and JMH tests interact with or measure the performance of the core gRPC calls.

##### Architectural Patterns and Design Principles
- A layered/microservice-like separation is evident: simulation scripts (user-facing API) → DSL-to-gRPC request construction → gRPC transport interaction.
- There’s separation by language modules (Scala core component, Kotlin and Java bindings) that extend the overall architecture.
- Use of extension methods and dynamic payload generation (using ScalaPB lenses) to enable dynamic test scenarios.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Component
    EL["Gatling Load Engine (External)"]:::external

    %% Plugin Core Layer
    subgraph "Gatling-gRPC Plugin Core"
        PL["gRPC DSL & Action Builders"]:::core
        MAC["Scala Macros (DSL Enhancements)"]:::macros
    end

    %% Language Bindings Module
    LB["Language Bindings (Kotlin/Java API)"]:::bindings

    %% Code Generation & Protobuf Integration
    subgraph "Code Generation & Protobuf Integration"
        Proto1["Test Protobuf Definitions"]:::proto
        Proto2["Bench Protobuf Definitions"]:::proto
        Proto3["Kotlin Test Protobuf Definitions"]:::proto
    end

    %% Benchmarking & Testing Module
    subgraph "Benchmarking & Testing Module"
        Bench["Performance Benchmarking (bench)"]:::bench
        JMH["JMH Tests"]:::bench
        Tests["Functional Tests & Simulations"]:::bench
    end

    %% Relationships
    EL -->|"triggers"| PL
    PL -->|"uses"| MAC
    LB -->|"calls"| PL
    PL -->|"translates-to"| Proto1
    PL -->|"translates-to"| Proto2
    PL -->|"translates-to"| Proto3
    PL -->|"benchmarks"| Bench
    PL -->|"measures"| JMH
    PL -->|"validates"| Tests

    %% Click Events
    click PL "https://github.com/phisgr/gatling-grpc/tree/master/src/main/scala/com/github/phisgr/gatling/grpc"
    click LB "https://github.com/phisgr/gatling-grpc/tree/master/gatling-grpc-kt/src/main/kotlin/com/github/phisgr/gatling/kt/grpc"
    click MAC "https://github.com/phisgr/gatling-grpc/tree/master/macro/src/main/scala/com/github/phisgr/gatling"
    click Proto1 "https://github.com/phisgr/gatling-grpc/tree/master/src/test/protobuf"
    click Proto2 "https://github.com/phisgr/gatling-grpc/tree/master/bench/src/main/protobuf"
    click Proto3 "https://github.com/phisgr/gatling-grpc/tree/master/gatling-grpc-kt/scala-tests/src/main/proto"
    click Bench "https://github.com/phisgr/gatling-grpc/tree/master/bench/src/main/scala"
    click JMH "https://github.com/phisgr/gatling-grpc/tree/master/gatling-grpc-kt/src/jmh"
    click Tests "https://github.com/phisgr/gatling-grpc/tree/master/src/test"

    %% Styles
    classDef external fill:#ffcccc,stroke:#d30000,stroke-width:2px;
    classDef core fill:#cce5ff,stroke:#1a8cff,stroke-width:2px;
    classDef macros fill:#ffdb99,stroke:#ff9900,stroke-width:2px;
    classDef bindings fill:#ccffcc,stroke:#33cc33,stroke-width:2px;
    classDef proto fill:#e5ccff,stroke:#a64dff,stroke-width:2px;
    classDef bench fill:#ffffcc,stroke:#cccc00,stroke-width:2px;
```
