# harness/smp-installer architecture

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

- Interactive diagram: https://gitdiagram.com/harness/smp-installer
- Repository: https://github.com/harness/smp-installer

## Overview

##### Major Architectural Layers and Components
- CLI / Entrypoint: Represent the main binary found in cmd/main.go and the various resource commands (e.g., harness.go, kubernetes.go, loadbalancer.go, etc.) in cmd/resources. This layer is in charge of parsing the configuration and dispatching resource creation tasks.
- Resource Commands: These implement the Resource interface and simply serve as orchestration controllers to invoke the client logic.
- Client Layer: In pkg/client, each resource has its own client (for example, pkg/client/dns.go, pkg/client/kubernetes.go, etc.) that abstracts the resource-specific logic, implementing methods like PreExec, Exec, and PostExec.
- Tofu Modules: Under pkg/tofu, the project contains modules for AWS resource provisioning (e.g., aws/dns, aws/kubernetes, aws/loadbalancer, etc.). These modules use templated or direct Terraform/OpenTofu files (*.tf, tf.vars) to generate the actual IaC output.
- Profiles & Configuration Overrides: The pkg/profiles and the profiles/ directory provide configuration overrides for different deployment profiles (e.g., “small” and “pov”). They represent parameters that tailor the installation to different scale or resource requirements.
- Rendering & Store: The pkg/render (template logic) and pkg/store (in-memory or persistent state storage) components handle dynamic configuration generation and storing the intermediate outputs produced by resource clients.

##### Break Down Relationships and Interactions
- The CLI (cmd/main.go) is the starting point that reads the configuration (example.yaml) and invokes relevant resource commands.
- Each resource command (inside cmd/resources) calls its respective client from pkg/client.
- The client layer executes a series of steps (PreExec, Exec, PostExec) and interacts with the tofu modules (in pkg/tofu) to generate the infrastructure files.
- The rendered templates (via pkg/render/template.go) and the state storage (via pkg/store) are updated through these interactions.
- The configuration profiles (from pkg/profiles or profiles/ folder) feed custom parameters into the templating and execution steps.
- Finally, all outputs (resources created such as EKS clusters, ALBs, VPCs, etc.) are consolidated and stored, with outputs potentially influencing further stages (e.g., monitoring and helm chart installation).

##### Architectural Patterns and Design Principles
- Modular Design: Notice how each functional area is broken down (resource commands, clients, tofu modules) to provide separation of concerns.
- Template-driven Code Generation: The use of templating (pkg/render) with built-in objects (.Config, .Output, .Self) is a key architectural principle.
- Inversion of Control: The orchestration follows the command pattern where specific resource commands trigger client actions.
- Extensibility: The structure clearly shows extension points (for adding new resources) following consistent patterns – a new file in cmd/resources, client in pkg/client, and tofu module under pkg/tofu.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Input
    subgraph "User Input"
        Config["Configuration File (example.yaml)"]:::config
        Profiles["Configuration Profiles"]:::profiles
    end

    %% CLI Layer
    subgraph "CLI Layer"
        CLI["CLI / Entrypoint (cmd/main.go)"]:::cli
    end

    %% Commands Layer
    subgraph "Commands Layer"
        ResourceCommands["Resource Commands (cmd/resources)"]:::commands
    end

    %% Client & Processing Layer
    subgraph "Client & Processing Layer"
        Clients["Client Layer (pkg/client)"]:::clients
        Rendering["Render Templates (pkg/render/template.go)"]:::rendering
        Store["State Storage (pkg/store)"]:::store
    end

    %% Infrastructure Provisioning
    subgraph "Infrastructure Provisioning"
        TofuModules["Tofu Modules (pkg/tofu/aws)"]:::tofu
        AWS["AWS Services"]:::external
    end

    %% Relationships
    Config -->|"reads"| CLI
    CLI -->|"dispatches"| ResourceCommands
    ResourceCommands -->|"invokes"| Clients
    Profiles -->|"overrides"| Clients
    Clients -->|"calls"| TofuModules
    Clients -->|"generates"| Rendering
    Clients -->|"updates"| Store
    TofuModules -->|"provisions"| AWS

    %% Click Events
    click CLI "https://github.com/harness/smp-installer/blob/main/cmd/main.go"
    click ResourceCommands "https://github.com/harness/smp-installer/tree/main/cmd/resources"
    click Clients "https://github.com/harness/smp-installer/tree/main/pkg/client"
    click TofuModules "https://github.com/harness/smp-installer/tree/main/pkg/tofu/aws"
    click Profiles "https://github.com/harness/smp-installer/tree/main/pkg/profiles"
    click Rendering "https://github.com/harness/smp-installer/blob/main/pkg/render/template.go"
    click Store "https://github.com/harness/smp-installer/tree/main/pkg/store"
    click Config "https://github.com/harness/smp-installer/blob/main/example.yaml"

    %% Styles
    classDef cli fill:#bbdefb,stroke:#333,stroke-width:2px;
    classDef config fill:#d7ccc8,stroke:#333,stroke-width:2px;
    classDef profiles fill:#d1c4e9,stroke:#333,stroke-width:2px;
    classDef commands fill:#c8e6c9,stroke:#333,stroke-width:2px;
    classDef clients fill:#fff9c4,stroke:#333,stroke-width:2px;
    classDef rendering fill:#e1bee7,stroke:#333,stroke-width:2px;
    classDef store fill:#b2ebf2,stroke:#333,stroke-width:2px;
    classDef tofu fill:#ffe0b2,stroke:#333,stroke-width:2px;
    classDef external fill:#ffcdd2,stroke:#333,stroke-width:2px;
```
