# litmuschaos/litmusctl architecture

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

- Interactive diagram: https://gitdiagram.com/litmuschaos/litmusctl
- Repository: https://github.com/litmuschaos/litmusctl

## Overview

##### Project type and purpose
- Project type: a Go-based command-line “open-source tool” (CLI) for managing LitmusChaos agents and Chaos Center resources.
- Purpose: expose subcommands (connect, create, get, delete, etc.) to end-users, interact with Kubernetes (via kubeconfig + kubectl under the hood), and call remote Chaos Center APIs to orchestrate chaos experiments, environments, probes, etc.

##### File structure
Top-level directories:
- pkg/cmd – Cobra-based command definitions & dispatch (“frontend” of the CLI).
- pkg/apis – HTTP API clients for Chaos Center (auth, project, experiment, probe, infra, upgrade).
- pkg/k8s – wrappers around kubectl or client-go to apply/manipulate manifests.
- pkg/config – logic to store/load CLI config (accounts, contexts).
- pkg/infra_ops – logic to provision infrastructure (delegates) on cloud/K8s.
- pkg/types – shared data structures (API request/response, config types).
- pkg/utils – common helpers (constants, readers, compatibility checks).
Other files: main.go (root of CLI), go.mod/sum, Makefile, CI workflows, DEVELOPMENT.md.

##### README for additional insights
- Emphasizes that litmusctl uses kubeconfig + kubectl under the hood.
- Enumerates high-level operations (connect/disconnect delegates, create projects/environments/experiments).
- Lists external requirements: kubeconfig, kubectl, target Chaos Center endpoint.

##### Detail
– Capture each sublayer (Config Manager vs. Command Parser vs. HTTP client vs. K8s client).
– Show local file I/O (reading kubeconfig and litmusctl config files).
– Illustrate error/response flows (e.g., APIClient receives JSON → maps to types in pkg/types → passed back to CLI for output).

[User Shell]
↓
[CLI Binary: pkg/cmd (root + subcommands)]
→ reads/writes [Config Manager: pkg/config]
→ invokes [API Client Layer: pkg/apis/*] → → [Chaos Center REST API]
→ invokes [K8s Client: pkg/k8s (kubectl)] → → [K8s API Server]
→ invokes [Infra Ops: pkg/infra_ops] → → [Cloud Provider APIs or K8s]
Shared Libraries: pkg/types, pkg/utils

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers and Components
    subgraph "User Interaction" 
        Shell["User Shell"]:::external
    end

    subgraph "CLI Layer" 
        CLI["CLI Binary\n(pkg/cmd)"]:::frontend
        Config["Config Manager\n(pkg/config)"]:::service
    end

    subgraph "Service Layer"
        APIClient["API Client Layer\n(pkg/apis)"]:::service
        K8sClient["K8s Client Layer\n(pkg/k8s)"]:::service
        InfraOps["Infra Operator Layer\n(pkg/infra_ops)"]:::infra
    end

    subgraph "Shared Libraries"
        Types["Domain Types\n(pkg/types)"]:::shared
        Utils["Utilities\n(pkg/utils)"]:::shared
    end

    subgraph "External Systems"
        ChaosCenter["Chaos Center REST API"]:::external
        K8sServer["Kubernetes API Server"]:::external
        CloudAPI["Cloud Provider APIs"]:::external
    end

    %% Data Flows
    Shell -->|"invokes"| CLI
    CLI -->|"reads/writes"| Config
    CLI -->|"uses"| APIClient
    CLI -->|"uses"| K8sClient
    CLI -->|"uses"| InfraOps

    Config -->|"uses"| Types
    APIClient -->|"uses"| Types
    K8sClient -->|"uses"| Types
    InfraOps -->|"uses"| Types

    Config -->|"uses"| Utils
    APIClient -->|"uses"| Utils
    K8sClient -->|"uses"| Utils
    InfraOps -->|"uses"| Utils

    APIClient -->|"HTTPS calls"| ChaosCenter
    K8sClient -->|"kubectl / client-go"| K8sServer
    InfraOps -->|"API calls"| CloudAPI
    InfraOps -->|"deploys via"| K8sClient

    %% Click Events
    click Shell "https://github.com/litmuschaos/litmusctl/blob/master/main.go"
    click CLI "https://github.com/litmuschaos/litmusctl/tree/master/pkg/cmd"
    click Config "https://github.com/litmuschaos/litmusctl/blob/master/pkg/config/ops.go"
    click APIClient "https://github.com/litmuschaos/litmusctl/blob/master/pkg/apis/auth.go"
    click K8sClient "https://github.com/litmuschaos/litmusctl/blob/master/pkg/k8s/client.go"
    click InfraOps "https://github.com/litmuschaos/litmusctl/blob/master/pkg/infra_ops/ops.go"
    click Types "https://github.com/litmuschaos/litmusctl/blob/master/pkg/types/api_types.go"
    click Utils "https://github.com/litmuschaos/litmusctl/blob/master/pkg/utils/common.go"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef service fill:#E6FFED,stroke:#28A745,color:#22863A;
    classDef infra fill:#FFF5DB,stroke:#D73A49,color:#CB2431;
    classDef shared fill:#F0F0F0,stroke:#6A737D,color:#24292E;
    classDef external fill:#F5F5F5,stroke:#959DA5,color:#586069;
```
