# prabanjanraja/lazygit architecture

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

- Interactive diagram: https://gitdiagram.com/prabanjanraja/lazygit
- Repository: https://github.com/prabanjanraja/lazygit

## Overview

##### Main Components
- Command-line Entry & Application Bootstrapping – Represented by files like main.go (at the root) and the “cmd” directory (which provides entry points for different modes, including integration tests).
- Core Application Logic – Found in pkg/app (with subdirectories for daemon processes, error handling, and type definitions) that orchestrates the overall application flow.
- Command Abstraction & Git Interactions – Located in pkg/commands (and its subdirectories like git_commands, git_config, patch, etc.). This component encapsulates the execution of git commands (with OS wrappers in pkg/commands/oscommands) and processes the data models (in pkg/commands/models) for working with branches, commits, remotes, tags, etc.
- Terminal UI / GUI Layer – Found in pkg/gui (with a rich structure containing controllers, various contexts, views, keybindings, and window/panel management) which forms the TUI interface (likely leveraging a library like gocui). This layer both receives user input and displays interactive elements (lists, file trees, patch views, diff viewers).
- Configuration and Internationalization – Under pkg/config (handling user-specific and default configurations) along with pkg/i18n which manages language translations.
- Additional Functionality – Components like pkg/cheatsheet, pkg/tasks, pkg/utils, pkg/theme handle supplementary tasks like helper routines, asynchronous tasks, and styling.
- Testing and Integration – Integration tests and demo scripts are provided under pkg/integration and test directories; these show how core modules communicate with one another and with a live git repository.

##### Relationships and Interactions
- The application launches via the main.go entry point. It initializes the configuration and sets up the proper environment (loading user config and language settings).
- The TUI layer (pkg/gui) captures user interactions, then forwards commands to the controllers. Controllers then invoke the command abstraction layer (in pkg/commands) to invoke git operations (like staging lines, interactive rebasing, cherry-picking, etc.).
- Business logic in pkg/app ties together these layers by handling core flows, error conditions, and communication between the UI, the command wrappers, and configuration.
- The testing and integration modules simulate end-to-end scenarios to verify that these components correctly interact with an actual git repository.
- External services include the actual git tool (invoked through OS commands) and possibly external dependencies (like Docker or CI pipelines as configured through .github and Dockerfiles).

##### Architectural Patterns & Design Principles
- Modular Design: The project is broken down into clear modules like cmd, pkg/app, pkg/commands, and pkg/gui. Each module encapsulates a specific responsibility.
- MVC-like Separation in the UI: The pkg/gui directory is organized with separate controllers, context definitions, views/presentations, and helper utilities.
- Abstraction of OS-specific behavior: Modules in pkg/commands/oscommands clearly abstract the differences in how git commands run on different platforms.
- Testability: Clear integration and unit test directories promote testing each component’s functionality separately.

##### Relevant Technologies and Frameworks
- Go Language (with its standard module system; see go.mod and go.sum)
- Git (as an external dependency, since lazygit wraps git functionality)
- CI/CD configurations are in .github/workflows and other Docker/devcontainer files, which can be noted as part of the deployment and development toolchain.
- TUI Libraries: Implicit usage of libraries like gocui (referenced by pkg/theme/gocui.go) for rendering the terminal interface.

##### Detail and Clarity
- Don’t be shy about breaking down the system into as many components as practically possible if it improves clarity.
- Annotations for key interactions, design choices (like the MVC-like structure in the TUI), and external dependencies (e.g., git and system environment).

– The multiple layers (UI, commands, app logic, configuration)
– The interplay between these layers via directional flows
– How user actions in lazygit’s terminal interface trigger git operations and update the UI

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Bootstrapping Layer
    subgraph "Bootstrapping"
        MAIN("main.go"):::bootstrap
        CMD_DIR("cmd/"):::bootstrap
    end

    %% Core Layer
    subgraph "Core Layer"
        APP("Core Application Logic"):::app
        CONFIG("Configuration"):::config
        I18N("Internationalization"):::config
    end

    %% Command Abstraction Layer
    subgraph "Command Layer"
        CMD_ABS("Command Abstraction & Git Interactions"):::commands
    end

    %% UI Layer
    subgraph "UI Layer"
        GUI("Terminal UI / GUI Layer"):::ui
    end

    %% Additional Functionality
    subgraph "Additional Functionality"
        CHEATSHEET("Cheatsheet"):::additional
        ASYNC("Async Tasks"):::additional
        UTILS("Utility Routines"):::additional
        THEME("Theme & Styling"):::additional
    end

    %% Testing & Integration
    subgraph "Testing & Integration"
        INTEGRATION("Integration Tests"):::test
        TEST_DIR("Test Suite"):::test
    end

    %% Relationships
    MAIN -->|"initializes"| APP
    CMD_DIR -->|"bootstraps"| APP

    CONFIG -->|"feeds config"| APP
    I18N -->|"feeds language"| APP

    GUI -->|"userInput"| CMD_ABS
    CMD_ABS -->|"executes commands"| APP
    APP -->|"updates"| GUI

    APP -->|"invokes"| CHEATSHEET
    APP -->|"invokes"| ASYNC
    APP -->|"invokes"| UTILS
    APP -->|"invokes"| THEME

    INTEGRATION -->|"tests"| APP
    TEST_DIR -->|"tests"| APP

    %% Styles
    classDef bootstrap fill:#fce4ec,stroke:#ad1457,stroke-width:2px;
    classDef app fill:#e3f2fd,stroke:#1565c0,stroke-width:2px;
    classDef commands fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px;
    classDef ui fill:#fff3e0,stroke:#ef6c00,stroke-width:2px;
    classDef config fill:#fffde7,stroke:#f9a825,stroke-width:2px;
    classDef additional fill:#e1f5fe,stroke:#0277bd,stroke-width:2px;
    classDef test fill:#fbe9e7,stroke:#d84315,stroke-width:2px;

    %% Click Events (Paths for click events)
    click MAIN "https://github.com/prabanjanraja/lazygit/blob/master/main.go"
    click CMD_DIR "https://github.com/prabanjanraja/lazygit/tree/master/cmd/"
    click APP "https://github.com/prabanjanraja/lazygit/tree/master/pkg/app/"
    click CMD_ABS "https://github.com/prabanjanraja/lazygit/tree/master/pkg/commands/"
    click GUI "https://github.com/prabanjanraja/lazygit/tree/master/pkg/gui/"
    click CONFIG "https://github.com/prabanjanraja/lazygit/tree/master/pkg/config/"
    click I18N "https://github.com/prabanjanraja/lazygit/tree/master/pkg/i18n/"
    click CHEATSHEET "https://github.com/prabanjanraja/lazygit/tree/master/pkg/cheatsheet/"
    click ASYNC "https://github.com/prabanjanraja/lazygit/tree/master/pkg/tasks/"
    click UTILS "https://github.com/prabanjanraja/lazygit/tree/master/pkg/utils/"
    click THEME "https://github.com/prabanjanraja/lazygit/tree/master/pkg/theme/"
    click INTEGRATION "https://github.com/prabanjanraja/lazygit/tree/master/pkg/integration/"
    click TEST_DIR "https://github.com/prabanjanraja/lazygit/tree/master/test/"
```
