# mykso/myks architecture

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

- Interactive diagram: https://gitdiagram.com/mykso/myks
- Repository: https://github.com/mykso/myks

## Overview

##### Main Components
- CLI Interface: Represented by the commands defined under the “cmd” directory (e.g., all.go, sync.go, render.go, init.go, etc.). This is the entry point where users issue commands.
- Core Engine/Controller: The core “myks” logic that resides mostly in the “internal/myks” directory. Key subcomponents here include:
- Application & Configuration Manager (e.g., application.go, config_helm.go, environment.go).
- Pipeline Modules: Separate modules handling different stages like sync (downloading using vendir integration), render (combining ytt templates, helm charts, overlays), and smart mode detection (smart_mode.go).
- Plugin Integration: Components like plugin_argocd.go, plugin_static_files.go add extensibility to the core operation.
- External Dependencies & Tools:
- vendir and ytt (both integrated in myks) for downloading and rendering configurations.
- Helm charts are processed when needed.
- Optional integration with ArgoCD and other Kubernetes tools.
- Caching & Environment Handling: Modules that manage downloaded configurations and maintain a unified source of truth for multiple clusters.
- Examples/Tests: Though these are for user guidance and quality assurance, they indicate the multiple deployment patterns (from simple, default to integration tests).

##### Data Flow and Interactions
- User Command Input: The application is started with a command (e.g., “myks all”, “myks sync”, or “myks render”).
- Command Parser & Dispatcher: The CLI (from the cmd/ package) parses the input and routes it to the relevant stage (sync or render).
- Sync Stage:
- The tool checks the configuration (projects, environments, applications) via configuration files and directory structures.
- Render Stage:
- After the sync, the render module (with ytt templates and helm integrations) consolidates inputs and applies environment-specific overlays.
- The rendered output (Kubernetes manifests) is staged in a “rendered” directory that may be used by deployment tools like ArgoCD.
- Plugins and Smart Mode:
- A separate block for plugins shows additional customization during sync or render.

##### Architectural Patterns and Design Principles
- Modularity: The separation between the CLI (cmd/*) and the logic in internal/myks emphasizes layered architecture.
- Pipeline/Stages: Clearly show two sequential phases (sync then render) and optionally include the “all” command as a composite pipeline.
- Extensibility: A separate module for plugins and clear configuration management that supports different sources and templates.
- Reusability and Centralized Configuration: The tool enables a single source of truth for multi-cluster configurations, which should be clearly noted.

##### Relevant Technologies and Frameworks
- Go (the application is built in Go, as seen in the go.mod, go.sum, and internal packages).
- vendir and ytt are integrated (and optionally helm for additional configurations).
- CI/CD integrations: Indicate the role of ArgoCD, GitHub workflows (in the .github directory), and containerization via Dockerfile.

##### Detailed Step-by-Step for the Engineer
- Input/Invocation Layer (CLI).
- Processing Layer (sync stage and render stage). Represent each stage as its own sub-component within the processing layer.
- Output/Integration Layer (rendered manifests, integration with ArgoCD or external deployment pipelines).
b. Next, break down the Processing Layer into:
- A “Sync Manager” module that interacts with external sources (vendir, Git/GitHub releases, helm repositories).
- A “Render Engine” module that uses ytt templates, applies overlays, and generates the final manifests.
- A “Configuration & Plugin Handler” module that centrally manages configuration data and plugins.
- For example, “CLI Command → Core Engine” then “Core Engine (Sync) → External Sources (vendir, Git, etc.)”, followed by “Core Engine (Render) → Final Manifests”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    User("User Command"):::user

    %% CLI Layer
    subgraph "CLI Interface"
        CLI("CLI Entry Point"):::cli
    end

    %% Core Engine Layer
    subgraph "Core Engine/Controller"
        AppConfig("App Config Manager"):::core
        Sync("Sync Manager"):::core
        Render("Render Engine"):::core
        Smart("Smart Mode Detection"):::core
        Plugins("Plugin Integration"):::core
        Cache("Caching & Environment Handling"):::cache
    end

    %% External Tools
    subgraph "External Tools Integration"
        Vendir("Vendir Integration"):::external
        Ytt("ytt Integration"):::external
    end

    %% Output/Deployment Layer
    Final("Final Manifests"):::output
    Deploy("Deployment Tools (ArgoCD)"):::external

    %% Connections from User to CLI
    User --> CLI

    %% CLI dispatches commands to Core Engine modules
    CLI -->|"sync_command"| Sync
    CLI -->|"render_command"| Render
    CLI -->|"smart_mode_command"| Smart
    CLI -->|"plugin_command"| Plugins

    %% App Config providing config to both Sync and Render modules
    AppConfig -->|"provide_config"| Sync
    AppConfig -->|"provide_config"| Render

    %% Sync Module interactions
    Sync -->|"download_&_cache"| Vendir
    Sync -->|"store_entries"| Cache

    %% Render Module interactions
    Render -->|"template_rendering"| Ytt
    Render -->|"generate_manifests"| Final
    Render -->|"retrieve_cache"| Cache

    %% Smart Mode triggers selective render
    Smart -->|"trigger_render"| Render

    %% Plugin Integration extends both stages
    Plugins -->|"extend_sync"| Sync
    Plugins -->|"extend_render"| Render

    %% Final manifests consumed by deployment tools
    Final -->|"deploy_manifests"| Deploy

    %% Styling classes
    classDef cli fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef core fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef external fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef cache fill:#cccccc,stroke:#333,stroke-width:2px;
    classDef output fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef user fill:#f9d3b4,stroke:#333,stroke-width:2px;

    %% Click Events
    click CLI "https://github.com/mykso/myks/tree/main/cmd/"
    click AppConfig "https://github.com/mykso/myks/blob/main/internal/myks/application.go"
    click Sync "https://github.com/mykso/myks/blob/main/internal/myks/sync.go"
    click Render "https://github.com/mykso/myks/blob/main/internal/myks/render.go"
    click Smart "https://github.com/mykso/myks/blob/main/internal/myks/smart_mode.go"
    click Plugins "https://github.com/mykso/myks/blob/main/internal/myks/plugins.go"
    click Vendir "https://github.com/mykso/myks/blob/main/cmd/embedded/vendir.go"
    click Ytt "https://github.com/mykso/myks/blob/main/cmd/embedded/ytt.go"
    click Cache "https://github.com/mykso/myks/blob/main/internal/myks/cache.go"
```
