# jiqinga/kube-prompt architecture

> Architecture diagram of the GitHub repository jiqinga/kube-prompt, 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/jiqinga/kube-prompt
- Repository: https://github.com/jiqinga/kube-prompt

## Overview

Based on our analysis of the provided file tree and README, this project is an interactive command-line Kubernetes client (Kube-Prompt) written in Go that aims to offer auto-completion, rich resource management, and command-line smart suggestions while wrapping around familiar Kubernetes commands (thus not requiring the “kubectl” prefix). It essentially provides a full-featured CLI interface that closely integrates with Kubernetes clusters via existing kubeconfig files.

##### Main Components
- Command Parser & Dispatcher – The core logic responsible for interpreting commands (e.g., get, describe, create, delete, ...). This module dispatches commands to appropriate handlers.
- Option Generation Modules – Located in the “kube” directory, these files (e.g., option_get.gen.go, option_create.gen.go, etc.) implement auto-completion and command-specific option parsing.
- Internal Utilities – Modules found under “internal” (for debugging, logging, etc.) that support cross-cutting concerns like logging (internal/debug/log.go) and possibly more.
- Auxiliary & Code Generation Tools – The “_tools” directory contains additional code generators and helper scripts (e.g., option-gen, ai tools) that help to automate the creation of parts of the CLI’s option handling or even debugging.

##### Relationships & Interactions
- The frontend communicates with the Command Parser/Dispatcher component that interprets typed commands.
- A link between the core command handling and the Kubernetes API integration layer. Emphasize that the tool uses the kubeconfig for authorization and connectivity.
- Optionally, show the flow that demonstrates how release and CI/CD configurations (e.g., GitHub workflows, goreleaser) support the project’s lifecycle but keep these distinct from the runtime architecture.

##### Architectural Patterns & Design Principles
- Modular Design – The clear separation between the interactive CLI, command parsing, option generation, and debugging/logging illustrates a layered architecture.
- Code Generation – Files in the “_tools” directory (such as option-gen and related tools) indicate a design pattern where parts of the code are auto-generated based on certain inputs. Emphasize this as it reduces redundancy.

– User Input flows to the CLI.
– A connection from the Command Parser to the Kubernetes API Integration (using kubeconfig for authentication).
– Frontend components (e.g., CLI),
– Core processing (command parsing, option generation),
– External integrations (Kubernetes API, kubecolor, and code generation tools),
– Infrastructure and pipeline elements (CI/CD config files from the .github directory can be grouped separately if desired).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface"
        UI["CLI Frontend"]:::frontend
    end

    %% Command Processing Layer
    subgraph "Command Processing"
        AP["Arguments Parser"]:::core
        CE["Command Executor"]:::core
        OG1["Option Generation (get)"]:::option
        OG2["Option Generation (create)"]:::option
        API["Kubernetes API Integration"]:::integration
    end

    %% Support Utilities Layer
    subgraph "Support Utilities"
        UTIL["Logging & Debugging"]:::util
    end

    %% Auxiliary & Code Generation Tools Layer
    subgraph "Auxiliary Tools"
        OGTool["Option-Gen Tool"]:::aux
        CodeScript["Codegen Script"]:::aux
    end

    %% Data Flow Connections
    UI -->|"inputs"| AP
    AP -->|"dispatches"| CE
    CE -->|"calls"| API
    CE -->|"triggers"| OG1
    CE -->|"triggers"| OG2

    OGTool -->|"generates"| OG1
    OGTool -->|"generates"| OG2
    CodeScript -->|"generates"| OG1
    CodeScript -->|"generates"| OG2

    UI -->|"logs"| UTIL
    AP -->|"logs"| UTIL
    CE -->|"logs"| UTIL
    OG1 -->|"logs"| UTIL
    OG2 -->|"logs"| UTIL
    API -->|"logs"| UTIL

    %% Click Events
    click UI "https://github.com/jiqinga/kube-prompt/blob/main/main.go"
    click AP "https://github.com/jiqinga/kube-prompt/blob/main/kube/arguments.go"
    click CE "https://github.com/jiqinga/kube-prompt/blob/main/kube/executor.go"
    click OG1 "https://github.com/jiqinga/kube-prompt/blob/main/kube/option_get.gen.go"
    click OG2 "https://github.com/jiqinga/kube-prompt/blob/main/kube/option_create.gen.go"
    click UTIL "https://github.com/jiqinga/kube-prompt/blob/main/internal/debug/log.go"
    click OGTool "https://github.com/jiqinga/kube-prompt/tree/main/_tools/option-gen"
    click CodeScript "https://github.com/jiqinga/kube-prompt/blob/main/_tools/codegen.sh"
    click API "https://github.com/jiqinga/kube-prompt/blob/main/kube/resource.go"

    %% Styles
    classDef frontend fill:#a2d9ff,stroke:#1b4f72,stroke-width:2px;
    classDef core fill:#b9f6ca,stroke:#00695c,stroke-width:2px;
    classDef option fill:#fff59d,stroke:#f9a825,stroke-width:2px;
    classDef integration fill:#ffab91,stroke:#d84315,stroke-width:2px;
    classDef util fill:#e0e0e0,stroke:#616161,stroke-width:2px;
    classDef aux fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
```
