# helm/chart-testing architecture

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

- Interactive diagram: https://gitdiagram.com/helm/chart-testing
- Repository: https://github.com/helm/chart-testing

## Overview

##### Project type and purpose
- This is a Go-based, open-source, command-line tool named “ct” (Chart Testing) for linting and testing Helm charts in CI/CD workflows.
- It detects which charts have changed (via Git), lints them (using Yamllint/Yamale), installs them (via Helm), and optionally runs tests against a Kubernetes cluster (via Kubectl).

##### File structure
- Top‐level binaries and scripts:
- Dockerfile, build.sh, setup.sh – build and packaging
- ct/main.go + ct/cmd/*.go – the CLI entrypoint and subcommands (cobra)
- Core packages under pkg/:
- pkg/chart – chart detection and representation
- pkg/config – config file / environment / CLI flag handling (Viper)
- pkg/exec – unified command execution engine
- pkg/ignore – chart ignore logic
- pkg/tool – wrappers for external tools (helm, kubectl, git, linters)
- pkg/util – miscellaneous helpers
- Examples/ and etc/ – sample charts, CI config, lint rules, config schemas
- doc/ – user documentation per command

##### README for additional insights
- Confirms use of external tools: Helm, Git, Yamllint, Yamale, Kubectl
- Describes configuration hierarchy (flags > env vars > config file)
- Provides usage patterns: local repo vs remote repo vs Docker image

##### Main components of the system
a. CLI Frontend
– “ct” binary built from ct/main.go + ct/cmd
– Parses user input (CLI flags, env vars, config file via pkg/config)
b. Core Engines
– Chart Detector (pkg/chart + Git wrapper in pkg/tool)
– Linter Engine (pkg/tool → Yamllint, Yamale)
– Installer Engine (pkg/tool → Helm, optionally Kubectl for tests)
– Executor (pkg/exec) to unify calls to external tools
– Ignore Filter (pkg/ignore) to exclude directories/charts
c. External Services/Systems
– Source Control (Git repo)
– Helm Repositories / OCI Registries
– Kubernetes Cluster (for install & tests via Kubectl)
d. Configuration Store
– Config file(s) on host or in /etc/ct, ~/.ct (parsed by pkg/config)
– Environment variables (CT_*)
– CLI flags

##### Relationships and interactions
1. User → CLI Frontend (ct)
2. CLI Frontend → Config Loader (pkg/config)
3. CLI Frontend → Chart Detector
– Chart Detector calls Git wrapper to list changed files
– Filters through Ignore Filter
4. For each chart:
a. Linter Engine → spawns Yamllint/Yamale
b. Installer Engine → invokes Helm to install charts into cluster
c. (Optional) Test Runner → invokes Kubectl to verify resources
5. Executor provides a unified interface for all external calls
6. Results → CLI Frontend → console output / CI exit codes

##### Architectural patterns and design principles
- Modular, layered design: separation of concerns between CLI handling, configuration, business logic (chart detection, linting, installing), and external tool execution
- Use of adapters/wrappers (pkg/tool) to isolate direct calls to external binaries
- Dependency injection via pkg/exec so all command calls are testable
- Configuration precedence follows Viper best practices
- Single‐binary distribution; Docker container wraps the binary plus dependencies

##### Relevant technologies/frameworks/libraries
- Go modules (go.mod)
- Cobra for CLI (ct/cmd)
- Viper for configuration (pkg/config)
- External binaries: helm, git, kubectl, yamllint, yamale
- Goreleaser (build.sh + .goreleaser.yml) for release automation
- Docker for packaging

1. Sketch the user interaction at the top (User invokes `ct ...`).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User and Inputs
    User["User"]:::user
    subgraph "Inputs" 
        Flags["CLI Flags"]:::input
        Env["Env Variables"]:::input
        ConfigFile["Config Files\n(/etc/ct, ~/.ct)"]:::input
    end

    %% Core Layers
    subgraph "CLI Layer"
        CLI["CLI Frontend"]:::internal
    end

    subgraph "Configuration"
        ConfigLoader["Config Loader"]:::internal
    end

    subgraph "Processing Pipeline"
        ChartDetect["Chart Detector"]:::internal
        IgnoreFilter["Ignore Filter"]:::internal
        LinterEngine["Linter Engine"]:::internal
        InstallerEngine["Installer Engine"]:::internal
        TestRunner["Test Runner"]:::internal
    end

    subgraph "Execution"
        Executor["Executor"]:::internal
    end

    subgraph "Tool Wrappers"
        GitWrapper["Git Wrapper"]:::wrapper
        HelmWrapper["Helm Wrapper"]:::wrapper
        KubectlWrapper["Kubectl Wrapper"]:::wrapper
        LinterWrapper["Linter Wrapper"]:::wrapper
        CmdAdapter["Cmd Executor Adapter"]:::wrapper
    end

    subgraph "External Systems"
        GitRepo["Git Repository"]:::external
        HelmRepo["Helm/OCI Registry"]:::external
        K8sCluster["Kubernetes Cluster"]:::external
    end

    %% Connections
    User --> CLI
    Flags --> CLI
    Env --> CLI
    ConfigFile --> CLI

    CLI --> ConfigLoader
    CLI --> ChartDetect

    ChartDetect --> IgnoreFilter
    IgnoreFilter --> LinterEngine
    IgnoreFilter --> InstallerEngine
    IgnoreFilter --> TestRunner

    LinterEngine --> Executor
    InstallerEngine --> Executor
    TestRunner --> Executor
    ChartDetect --> Executor

    Executor --> GitWrapper
    Executor --> HelmWrapper
    Executor --> KubectlWrapper
    Executor --> LinterWrapper
    Executor --> CmdAdapter

    GitWrapper --> GitRepo
    HelmWrapper --> HelmRepo
    KubectlWrapper --> K8sCluster
    LinterWrapper --> K8sCluster

    %% Click Events
    click CLI "https://github.com/helm/chart-testing/blob/main/ct/main.go"
    click ConfigLoader "https://github.com/helm/chart-testing/blob/main/pkg/config/config.go"
    click ChartDetect "https://github.com/helm/chart-testing/blob/main/pkg/chart/chart.go"
    click IgnoreFilter "https://github.com/helm/chart-testing/blob/main/pkg/ignore/ignore.go"
    click Executor "https://github.com/helm/chart-testing/blob/main/pkg/exec/exec.go"
    click GitWrapper "https://github.com/helm/chart-testing/blob/main/pkg/tool/git.go"
    click HelmWrapper "https://github.com/helm/chart-testing/blob/main/pkg/tool/helm.go"
    click KubectlWrapper "https://github.com/helm/chart-testing/blob/main/pkg/tool/kubectl.go"
    click LinterWrapper "https://github.com/helm/chart-testing/blob/main/pkg/tool/linter.go"
    click CmdAdapter "https://github.com/helm/chart-testing/blob/main/pkg/tool/cmdexecutor.go"

    %% Styles
    classDef internal fill:#c2f0c2,stroke:#2d7f2d,color:#000;
    classDef wrapper fill:#c2e0ff,stroke:#0050a0,color:#000;
    classDef external fill:#e0ccff,stroke:#602080,color:#000;
    classDef input fill:#ffe0b3,stroke:#b36b00,color:#000;
    classDef user fill:#ffd1dc,stroke:#b3003b,color:#000;
```
