# michielvha/edgectl architecture

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

- Interactive diagram: https://gitdiagram.com/michielvha/edgectl
- Repository: https://github.com/michielvha/edgectl

## Overview

##### Project type and purpose
- This is an open-source, Go-based CLI tool (“edge-cli”) built with Cobra/Viper.
- Its primary role is to automate the lifecycle of “edge cloud” Kubernetes clusters (powered by RKE2), manage secrets via HashiCorp Vault, and bootstrap additional tools (e.g. ArgoCD/Helm).

##### Key architectural components
a. CLI layer (entry point)
- main.go + cmd/ → Cobra commands and subcommands (rke2.{agent,server,lb,system}, vault, version)
- Flags & config via Viper (global flags, env vars, config file)
b. Core libraries (pkg/)
- pkg/common: shared helpers, embedded resources, shell-script wrappers (rke2-bash.sh, rke2-purge.sh, etc.)
- pkg/logger: zerolog wrapper for logging levels
- pkg/lb: load-balancer specific logic
- pkg/rke2: installation and orchestration logic for agent/server
- pkg/vault: abstraction over Vault API (generic, kubeconfig, load-balancer, server, token)
c. External scripts & manifests
- manifests/*.yml: Kubernetes manifests for debugging
- pkg/common/scripts/*.sh: low-level install/status/purge scripts
d. External systems & services
- RKE2 Kubernetes clusters (agent nodes, server nodes, load-balancer)
- HashiCorp Vault (secret storage/management)
- Helm/ArgoCD for GitOps bootstrapping
- GitVersion & Goreleaser for CI/CD (see .github/workflows, gitversion.yml, goreleaser.yml)

##### Interactions & data flow
- User runs `edgectl <command>` → Cobra parses command → delegates to a pkg/* handler
- Handler may:
- Invoke pkg/common/scripts/*.sh to install RKE2 binaries and systemd units on remote hosts
- Call pkg/rke2 code to configure and start RKE2 nodes (agent/server)
- Use pkg/vault to store or fetch cluster tokens and kubeconfig in Vault
- Fetch generated kubeconfig and merge it into local kubeconfig context
- Optionally commit or push Helm charts for ArgoCD integration
- CI/CD pipelines detect code changes → run tests (future), build binaries via Goreleaser, tag releases via GitVersion → publish artifacts

##### Architectural patterns & design principles
- Layered architecture: cmd/ (presentation) → pkg/ (domain logic) → external dependencies (Vault, RKE2 CLI, shell scripts)
- Adapter pattern for secret management (pkg/vault implements a Vault interface; future “bring your own” backends)
- Modular command structure via Cobra for easy extensibility
- Single responsibility: each pkg/* focuses on one integration or concern

- edgectl → pkg/rke2 (install/configure cluster)
- edgectl → pkg/vault (store/fetch secrets)
- pkg/rke2 → pkg/common/scripts (invoke shell scripts)
- pkg/vault ↔ Vault service (HTTPS API calls)
- edgectl → Kubernetes cluster (via kubeconfig, kubectl)
- edgectl → Git repository (Helm chart commits, ArgoCD bootstrap)
- CI/CD pipeline → edgectl repo (on push/tag) → builds → releases

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer" 
        direction TB
        CLI["edgectl (main.go)"]:::internal
        Root["cmd/root.go"]:::internal
        RKE2Cmd["cmd/rke2.go"]:::internal
        VaultCmd["cmd/vault.go"]:::internal
        VersionCmd["cmd/version.go"]:::internal
        subgraph "rke2 Commands"
            direction TB
            AgentCmd["cmd/rke2/agent/commands.go"]:::internal
            ServerCmd["cmd/rke2/server/commands.go"]:::internal
            LBCmd["cmd/rke2/lb/commands.go"]:::internal
            SystemCmd["cmd/rke2/system/commands.go"]:::internal
        end
    end

    %% Core Libraries
    subgraph "Core Libraries (pkg)" 
        direction TB
        Common["pkg/common"]:::internal
        Logger["pkg/logger"]:::internal
        LB["pkg/lb"]:::internal
        RKE2["pkg/rke2"]:::internal
        Vault["pkg/vault"]:::internal
    end

    %% Scripts and Manifests
    subgraph "Scripts & Manifests"
        direction TB
        ScriptsShell["pkg/common/scripts/*.sh"]:::script
        DebugYML["manifests/debug.yml"]:::script
    end

    %% External Services
    subgraph "External Systems"
        direction TB
        Cluster["RKE2 Kubernetes Cluster"]:::external
        VaultSvc["HashiCorp Vault"]:::external
        GitRepo["Git Repo (Helm/ArgoCD)"]:::external
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        direction TB
        Actions[".github/workflows"]:::cicd
        Goreleaser["goreleaser.yml"]:::cicd
        GitVersion["gitversion.yml"]:::cicd
    end

    %% Relationships
    CLI -->|"delegates to"| Root
    Root --> RKE2Cmd
    Root --> VaultCmd
    Root --> VersionCmd
    RKE2Cmd --> AgentCmd
    RKE2Cmd --> ServerCmd
    RKE2Cmd --> LBCmd
    RKE2Cmd --> SystemCmd

    CLI -->|"uses"| RKE2
    CLI -->|"uses"| Vault
    RKE2 -->|"invokes"| ScriptsShell
    Vault -->|"HTTPS Vault API"| VaultSvc
    CLI -->|"kubectl apply"| Cluster
    CLI -->|"git push"| GitRepo

    Actions -->|"on push/tag build"| CLI

    %% Click Events
    click CLI "https://github.com/michielvha/edgectl/blob/main/main.go"
    click Root "https://github.com/michielvha/edgectl/blob/main/cmd/root.go"
    click RKE2Cmd "https://github.com/michielvha/edgectl/blob/main/cmd/rke2.go"
    click VaultCmd "https://github.com/michielvha/edgectl/blob/main/cmd/vault.go"
    click VersionCmd "https://github.com/michielvha/edgectl/blob/main/cmd/version.go"
    click AgentCmd "https://github.com/michielvha/edgectl/blob/main/cmd/rke2/agent/commands.go"
    click ServerCmd "https://github.com/michielvha/edgectl/blob/main/cmd/rke2/server/commands.go"
    click LBCmd "https://github.com/michielvha/edgectl/blob/main/cmd/rke2/lb/commands.go"
    click SystemCmd "https://github.com/michielvha/edgectl/blob/main/cmd/rke2/system/commands.go"

    click Common "https://github.com/michielvha/edgectl/blob/main/pkg/common/embedded.go"
    click Common "https://github.com/michielvha/edgectl/blob/main/pkg/common/helpers.go"
    click ScriptsShell "https://github.com/michielvha/edgectl/blob/main/pkg/common/scripts/rke2.sh"
    click ScriptsShell "https://github.com/michielvha/edgectl/blob/main/pkg/common/scripts/rke2-bash.sh"
    click ScriptsShell "https://github.com/michielvha/edgectl/blob/main/pkg/common/scripts/rke2-status.sh"
    click ScriptsShell "https://github.com/michielvha/edgectl/blob/main/pkg/common/scripts/rke2-purge.sh"

    click Logger "https://github.com/michielvha/edgectl/blob/main/pkg/logger/log.go"
    click LB "https://github.com/michielvha/edgectl/blob/main/pkg/lb/handler.go"
    click RKE2 "https://github.com/michielvha/edgectl/blob/main/pkg/rke2/agent/install.go"
    click RKE2 "https://github.com/michielvha/edgectl/blob/main/pkg/rke2/server/install.go"
    click Vault "https://github.com/michielvha/edgectl/blob/main/pkg/vault/generic.go"
    click Vault "https://github.com/michielvha/edgectl/blob/main/pkg/vault/rke2_token.go"
    click Vault "https://github.com/michielvha/edgectl/blob/main/pkg/vault/rke2_kubeconfig.go"
    click Vault "https://github.com/michielvha/edgectl/blob/main/pkg/vault/rke2_loadbalancer.go"
    click Vault "https://github.com/michielvha/edgectl/blob/main/pkg/vault/rke2_server.go"

    click DebugYML "https://github.com/michielvha/edgectl/blob/main/manifests/debug.yml"

    click Actions "https://github.com/michielvha/edgectl/blob/main/.github/workflows/binary-release.yaml"
    click Actions "https://github.com/michielvha/edgectl/blob/main/.github/workflows/test.yaml.todo"
    click Goreleaser "https://github.com/michielvha/edgectl/blob/main/goreleaser.yml"
    click GitVersion "https://github.com/michielvha/edgectl/blob/main/gitversion.yml"

    %% Styles
    classDef internal fill:#bbdefb,stroke:#1e88e5,color:#0d47a1;
    classDef script fill:#ffe0b2,stroke:#fb8c00,color:#e65100;
    classDef external fill:#c8e6c9,stroke:#43a047,color:#1b5e20;
    classDef cicd fill:#e1bee7,stroke:#8e24aa,color:#4a148c;
```
