# benc-uk/k6-reporter architecture

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

- Interactive diagram: https://gitdiagram.com/benc-uk/k6-reporter
- Repository: https://github.com/benc-uk/k6-reporter

## Overview

##### Main Components
- K6 Test Integration – This is where the test code calls out to the htmlReport function via the handleSummary callback. Show how the user’s K6 script imports the module from dist/bundle.js.
- HTML Report Generator Module – Represent the module’s core logic found in the “src” folder (e.g., html-report.js and template.ejs) that processes the summary data and uses a templating engine (EJS) to generate HTML output.
- Bundler & Build Process – Include a component for the Webpack build process (webpack.config.js, package.json) that converts the source code from “src” into the bundled file in “dist”.
- Testing and Validation – Mark the “tests” folder that contains test cases and protocol files (e.g., hello.proto, grpc.js, simple.js, etc.), which ensure proper functionality.
- Legacy Code Component – Although not active in the current module version, note that there is an “archive” folder with the previous Golang implementation. This can be shown as a deprecated or alternate path for historical context.

##### Component Relationships and Data Flow
- Data Flow: Start with the K6 test execution where summary data is produced during/after the test run. This data is passed into the handleSummary callback, which then sends the JSON summary data into the htmlReport function.
- Output: The final HTML content is written to the filesystem (as specified via the key in the returned object of handleSummary).
- Optional Multi-output Handling: Represent how the design also accommodates combining HTML report output with other summary formats (like textSummary) for extended usage.

##### Architectural Patterns & Design Principles
- Modular Design: Emphasize the separation between the report generator logic (conversion and templating) and the bundling/distribution mechanism.
- Template Engine Pattern: Highlight the use of EJS (or similar templating) to dynamically create HTML reports from JSON data.
- Extensibility: The design allows users to extend functionality by combining multiple output generators, as illustrated in the README’s “Multiple outputs” section.
- Legacy Code Segregation: Note that the older Golang implementation is archived and isolated from the current JavaScript-based solution.

##### Technologies Involved
- JavaScript ES6 modules, Node.js (for running the build/test processes), and NPM (package.json and package-lock.json).
- Webpack for bundling.
- ESLint for code quality (see .eslintrc.json).
- EJS for templating.
- K6 for load testing integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% K6 Integration Layer
    A["K6 Test Execution (handleSummary Callback)"]:::k6

    %% Report Generation Layer
    B["HTML Report Generator (src/html-report.js)"]:::report
    C["Template Engine (src/template.ejs)"]:::template
    D["Report Output File (HTML)"]:::report

    %% Build Process Layer
    E["Webpack Build Process (webpack.config.js, package.json)"]:::build
    F["Bundled Module (dist/bundle.js)"]:::bundle

    %% Testing and Legacy Layer
    G["Tests (tests)"]:::test
    H["Legacy Implementation (archive)"]:::legacy

    %% Data Flow
    A -->|"calls"| B
    B -->|"uses"| C
    C -->|"generates"| D

    %% Build Process Flow
    B -->|"bundledBy"| E
    E -->|"outputs"| F
    F -->|"importedBy"| A

    %% Testing and Legacy
    G -->|"validates"| B
    H -.->|"deprecated"| B

    %% Click Events
    click F "https://github.com/benc-uk/k6-reporter/blob/main/dist/bundle.js"
    click B "https://github.com/benc-uk/k6-reporter/blob/main/src/html-report.js"
    click C "https://github.com/benc-uk/k6-reporter/blob/main/src/template.ejs"
    click E "https://github.com/benc-uk/k6-reporter/blob/main/webpack.config.js"
    click G "https://github.com/benc-uk/k6-reporter/tree/main/tests/"
    click H "https://github.com/benc-uk/k6-reporter/tree/main/archive/"

    %% Styles
    classDef k6 fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef report fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef template fill:#ffeeba,stroke:#856404,stroke-width:2px;
    classDef build fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef bundle fill:#d6d8d9,stroke:#1b1e21,stroke-width:2px;
    classDef test fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef legacy fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
