# ymtdzzz/lazypkg architecture

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

- Interactive diagram: https://gitdiagram.com/ymtdzzz/lazypkg
- Repository: https://github.com/ymtdzzz/lazypkg

## Overview

##### Project type and purpose
- Project Type: A terminal-based TUI (Text User Interface) application.
- Purpose: It manages packages across different package managers (apt, gem, homebrew, npm, and optionally docker) by providing an interactive interface where users can check for updates and perform package updates.
- Key Features: Handling UI interactions, confirming actions, performing package updates through various executors, and managing configuration details (such as enabling optional features and handling administrator privileges).

##### File structure
- Top-Level Files and Directories:
- main.go: The entry point of the application.
- components: Contains the core UI and configuration files (app.go, confirm.go, dialog.go, list.go, etc.) along with their tests and test data.
- executors: Holds the implementations for interacting with specific package managers (apt, docker, gem, homebrew, npm, etc.) including tests.
- docs: Contains documentation and images used by the README.
- GitHub workflows and release configuration files: They indicate a CI/CD pipeline setup.
- Makefile and configuration files (.goreleaser.yaml, .gitignore): For build, release management, and local development environment configuration.

##### Key Components
a. Application Entry & Core Flow:
- Main Application (main.go): The starting point that initializes the application.
- Configuration Manager (components/config.go): Loads and manages configuration and feature flags (like “--enable-feature”).

b. TUI/Component Layer:
- UI Controller (components/app.go): Coordinates the overall UI and integrates with lower-level UI elements.
- UI Components:
- Sidebar for Package Managers (“components/*” such as confirm.go, dialog.go, list.go, password.go, etc.).
- Dialogs/Confirmations: Provide safety warnings before executing updates.
- Help and Logging components: (for handling keymaps and scrolling logs as per README).

c. Executor Layer (Interaction with Package Managers):
- Each package manager has a dedicated executor in the executors folder (apt, gem, homebrew, npm, docker).
- These executors abstract the system/CLI commands needed to check for updates or install packages.
- They act as services where the UI layer passes the selected commands and receives feedback on execution.

##### Relationships and Interactions
- The entry point in main.go initializes the configuration and UI.
- The TUI controllers invoke various UI components to render the interface and capture user input (keymaps, selections, confirmations).
- Upon user decisions (e.g., update command), the UI components interact with the proper executor which handles the operations for the selected package manager.
- Directional data flow: user input → TUI component → business logic to determine package manager → executor → feedback return → UI update.
- Error handling and confirmation dialogs (like password prompts for apt) are managed within the components layer before calling the executors.

##### Architectural Patterns or Design Principles
- Separation of Concerns: Clear division between UI (components) and business logic (executors).
- Modularization: Executors are implemented in a modular way so that additional package managers (like docker) can be integrated via feature flags.
- Testability: Presence of test files and golden files in components/testdata and executors, indicating a design where components can be tested individually.
- Extensibility: Simple means to add new executors and UI components since the code is organized in separate directories.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Initialization
    subgraph "Core Initialization"
        M("main.go"):::entry
        C("Configuration Manager"):::config
        U("UI Controller"):::tui
    end

    %% UI Components Layer
    subgraph "UI Components"
        CONF("Confirmation Component"):::tui
        DIALOG("Dialog/Prompt Component"):::tui
        LIST("Package Listing Component"):::tui
        PASS("Password Prompt Component"):::tui
    end

    %% Integration/Executors Layer
    subgraph "Executors"
        APT("Apt Executor"):::executor
        GEM("Gem Executor"):::executor
        BREW("Homebrew Executor"):::executor
        NPM("Npm Executor"):::executor
        DOCKER("Docker Executor"):::executor
    end

    %% Relationships: Core Initialization
    M --> C
    M --> U

    %% Relationships: UI Components
    U --> CONF
    U --> DIALOG
    U --> LIST
    U --> PASS

    %% Relationships: Integration via UI actions
    U -->|"updateCommand"| APT
    U -->|"updateCommand"| GEM
    U -->|"updateCommand"| BREW
    U -->|"updateCommand"| NPM
    U -->|"updateCommand"| DOCKER

    %% Click events
    click M "https://github.com/ymtdzzz/lazypkg/blob/main/main.go"
    click C "https://github.com/ymtdzzz/lazypkg/blob/main/components/config.go"
    click U "https://github.com/ymtdzzz/lazypkg/blob/main/components/app.go"
    click CONF "https://github.com/ymtdzzz/lazypkg/blob/main/components/confirm.go"
    click DIALOG "https://github.com/ymtdzzz/lazypkg/blob/main/components/dialog.go"
    click LIST "https://github.com/ymtdzzz/lazypkg/blob/main/components/list.go"
    click PASS "https://github.com/ymtdzzz/lazypkg/blob/main/components/password.go"
    click APT "https://github.com/ymtdzzz/lazypkg/blob/main/executors/apt.go"
    click GEM "https://github.com/ymtdzzz/lazypkg/blob/main/executors/gem.go"
    click BREW "https://github.com/ymtdzzz/lazypkg/blob/main/executors/homebrew.go"
    click NPM "https://github.com/ymtdzzz/lazypkg/blob/main/executors/npm.go"
    click DOCKER "https://github.com/ymtdzzz/lazypkg/blob/main/executors/docker.go"

    %% Styles
    classDef entry fill:#ffcccb,stroke:#333,stroke-width:2px;
    classDef config fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef tui fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef executor fill:#f4a460,stroke:#333,stroke-width:2px;
```
