# linuxsuren/api-testing architecture

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

- Interactive diagram: https://gitdiagram.com/linuxsuren/api-testing
- Repository: https://github.com/linuxsuren/api-testing

## Overview

##### Main Components
- CLI/Command-Line Interface – represented by the “cmd” directory. This includes subcommands such as “run”, “server”, “sample”, etc.
– apispec: handling API specifications, Swagger, JSON schema, etc.
– generator: converting test cases to various formats (JMeter, Curl, robot, etc).
– runner: the execution engine that runs tests over protocols like HTTP, gRPC, and handles test result reporting (Markdown, HTML, PDF, Stdout).
– server: providing the HTTP and gRPC endpoints when running in server mode.
– mock: supporting the mock server functionality.
– extension, oauth, secret, logging and others: supporting additional functionalities and integrations.
- Console/UI – in the “console” directory, which includes a desktop version and a web-based UI (atest-ui). They interact with the backend server APIs.
- Deployment & Integration Artifacts – Dockerfile, Kubernetes manifests (in “docs/manifests”, “helm”), and integration components (Prometheus monitoring, etc.).
- Testing & Documentation – folders like “e2e” and “docs” provide end-to-end tests and extensive documentation, respectively.

##### Relationships and Interactions
- The CLI and Server Modules: The user can invoke commands through the CLI (cmd/), which internally utilizes the shared “pkg” business logic. Running in “server” mode exposes HTTP and gRPC endpoints that are consumed by external tools and possibly the UI.
- The API Runner: This component (inside pkg/runner) is responsible for executing the test suites. It coordinates with components of pkg/mock (for simulating services), pkg/compare (to check the responses), and pkg/runner’s reporting components.
- Code Generators and Converters: Modules under pkg/generator convert test scenarios into various formats (e.g., JMeter files, code snippets in Java, Python, Go, etc.).
- UI/Console Communication: The “console” module (particularly the atest-ui) consumes the server’s APIs. It likely handles visual test management and report display.
- External integrations: The system integrates with monitoring (Prometheus, SkyWalking), authentication (OAuth interceptors) and multiple storage backends. These should be shown as external services that interact with the core server or runners.

##### Architectural Patterns and Design Principles
- Layered Architecture: Clearly map out the separation between the user interface (CLI and UI/console), business logic (pkg submodules like runner, generator, server) and external integrations (storage backends, authentication, and deployment manifests).
- Extensibility: Show how “extensions” (and hooks for pre- or post-processing) allow customization. This is important given the templating (using Sprig functions) feature mentioned in the README.
- Testability: Although you may not need to detail every testing file, note that there are dedicated tests (inside directories like “cmd”, “pkg”, “e2e”) ensuring each component is verifiable.

##### Final Details
- Notes about the technology stack when appropriate: Go as the implementation language for core components; Vue.js (or similar) for the atest-ui in the console; Helm/Kubernetes for deployment; Docker integration.
- Mention that the system supports multi-protocol test execution (HTTP, gRPC, tRPC) and diverse report formats, which requires highlighting the conversion/generation and reporting modules.
- Testing strategies by indicating that there are directories dedicated to tests (both unit and e2e) that ensure the reliability of each module.

This approach not only outlines the key areas of functionality but also reflects the modular design and multiple deployment/use-case strategies as described in the project documentation.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Actor
    user["Tester/Developer"]:::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        console["Console/UI Module"]:::frontend
    end

    %% Middleware/Server Layer
    subgraph "Middleware/Server Layer"
        cli["CLI/Command-Line Interface"]:::middleware
        srv["HTTP/gRPC Server"]:::middleware
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        apispec["API Specification Handler"]:::business
        generator["Code Generator"]:::business
        runner["Test Runner & Reporting Engine"]:::business
        mock["Mock Server Functionality"]:::business
        extension["Extensions"]:::business
        oauth["OAuth Interceptors"]:::business
        secret["Secret Handling"]:::business
        logging["Logging"]:::business
    end

    %% Integration/Deployment Layer
    subgraph "Integration/Deployment Layer"
        docker["Deployment Artifacts: Dockerfile"]:::integration
        k8s["Deployment Artifacts: K8s Manifests"]:::integration
        helm["Deployment Artifacts: Helm Charts"]:::integration
        testing["Testing & E2E"]:::integration
        docs["Documentation"]:::integration
    end

    %% Relationships between external actor and interface layers
    user --> cli
    user --> console

    %% Communication between Frontend and Middleware
    console -->|"consumes APIs"| srv

    %% Middleware invoking Business Logic
    cli -->|"triggers tests"| runner
    srv -->|"invokes testing"| runner

    %% Business Logic internal flows
    apispec -->|"supplies specs"| runner
    generator -->|"converts cases"| runner
    runner -->|"calls mock"| mock
    runner -->|"hooks extensions"| extension
    runner -->|"auth via"| oauth
    runner -->|"retrieves secrets from"| secret
    runner -->|"logs via"| logging

    %% Middleware linked to Deployment Artifacts
    srv -->|"packaged as"| docker
    srv -->|"orchestrated with"| k8s
    srv -->|"deployed via"| helm

    %% Business Logic output linked to Testing & Docs
    runner -->|"outputs tests"| testing
    runner -->|"generates docs"| docs

    %% Click Events
    click cli "https://github.com/linuxsuren/api-testing/tree/master/cmd/"
    click apispec "https://github.com/linuxsuren/api-testing/tree/master/pkg/apispec/"
    click generator "https://github.com/linuxsuren/api-testing/tree/master/pkg/generator/"
    click runner "https://github.com/linuxsuren/api-testing/tree/master/pkg/runner/"
    click srv "https://github.com/linuxsuren/api-testing/tree/master/pkg/server/"
    click mock "https://github.com/linuxsuren/api-testing/tree/master/pkg/mock/"
    click extension "https://github.com/linuxsuren/api-testing/tree/master/pkg/extension/"
    click oauth "https://github.com/linuxsuren/api-testing/tree/master/pkg/oauth/"
    click secret "https://github.com/linuxsuren/api-testing/tree/master/pkg/secret/"
    click logging "https://github.com/linuxsuren/api-testing/tree/master/pkg/logging/"
    click console "https://github.com/linuxsuren/api-testing/tree/master/console/"
    click docker "https://github.com/linuxsuren/api-testing/tree/master/Dockerfile"
    click k8s "https://github.com/linuxsuren/api-testing/tree/master/docs/manifests/"
    click helm "https://github.com/linuxsuren/api-testing/tree/master/helm/"
    click testing "https://github.com/linuxsuren/api-testing/tree/master/e2e/"
    click docs "https://github.com/linuxsuren/api-testing/tree/master/docs/"

    %% Styles
    classDef frontend fill:#fde2e2,stroke:#d40000,stroke-width:2px;
    classDef middleware fill:#e2f7fd,stroke:#007acc,stroke-width:2px;
    classDef business fill:#e2fde2,stroke:#2ecc40,stroke-width:2px;
    classDef integration fill:#fff2cc,stroke:#f1c232,stroke-width:2px;
    classDef external fill:#fff,stroke:#555,stroke-width:2px,stroke-dasharray: 5 5;
```
