# byawitz/ggh architecture

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

- Interactive diagram: https://gitdiagram.com/byawitz/ggh
- Repository: https://github.com/byawitz/ggh

## Overview

##### Project Type & Purpose
- It’s a CLI tool written in Go that acts as a lightweight and fast wrapper around SSH. Its core functionality is to “recall your SSH sessions” by fetching session details from local SSH configuration and history, presenting them either interactively or as a list, and then launching SSH with the chosen session.
- The README clearly shows that GGH is used as a helper to simplify and remind users of their SSH session records without replacing SSH itself.

##### File Structure Analysis
- Top-level directories:
- cmd – Contains the main runnable entrypoint (cmd/ggh.go) that starts the application.
- internal – Contains most of the application’s business logic, split into several subdirectories:
o internal/command – Manages command-line flags and validation.
o internal/config – Reads and parses configuration files (likely your ~/.ssh/config).
o internal/history – Fetches, saves, and manages the history of SSH sessions.
o internal/interactive – Handles the interactive display for choosing sessions.
o internal/ssh – Wraps around SSH calls, ensuring SSH is available and executing the proper command.
o internal/theme – Manages presentation logic (styles and table display for interactive mode).
- Additional directories and files (assets, install, scripts, and CI/CD config in .github) show that the project is well-organized for development, releases, and testing.

- Main Entry Point (cmd/ggh.go/Main.go):
- Acts as the orchestrator; processes command-line arguments and routes execution.

- Command Module (internal/command):
- Parses user inputs/flags and validates them.
- Feeds relevant control flow to either interactive or non-interactive modes.

- Configuration Module (internal/config):
- Reads user SSH config files to gather possible session definitions.
- Provides parsed config data to the command or interactive module.

- History Module (internal/history):
- Tracks past SSH sessions.
- Retrieves and persists session information used in the interactive “recall” mode.

- Interactive Module (internal/interactive):
- Generates user-driven, interactive lists (like searchable/filterable session choices).
- Uses the Theme Module for styling the displayed results.

- SSH Module (internal/ssh):
- Validates the availability of SSH.
- Constructs and runs the SSH command with the appropriate parameters.

- Theme Module (internal/theme):
- Applies visual styles and builds tables for displaying data in the interactive mode.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Each internal module has a focused responsibility (e.g., config parsing, history management, interactive display) which results in a highly modular design.
- Layered Architecture: The main entry point delegates processing to different internal services which can be considered as layers (from input processing to session management and finally invoking SSH).
- Extensibility: Each module (especially the command and configuration parts) is decoupled, allowing future extensions (for example, adding new interactive visualizations or supporting other protocols).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    U["User Input/CLI"]:::external

    %% Core Application Modules
    subgraph "Core Application"
        M["Main Entrypoint (cmd/ggh.go)"]:::core
        C["Command Module (internal/command)"]:::core
        CFG["Configuration Module (internal/config)"]:::core
        H["History Module (internal/history)"]:::core
    end

    %% Interactive Layer
    subgraph "Interactive Layer"
        I["Interactive Module (internal/interactive)"]:::ui
        T["Theme Module (internal/theme)"]:::ui
    end

    %% Execution Layer
    subgraph "Execution Layer"
        S["SSH Module (internal/ssh)"]:::core
        SSHClient["SSH_Client"]:::external
    end

    %% DevOps & CI/CD Support
    subgraph "DevOps Support"
        D["CI/CD Workflows & Release Scripts"]:::devops
    end

    %% Data Flow Connections
    U -->|"initiates"| M
    M -->|"parsesflags"| C
    C -->|"validates"| CFG
    C -->|"validates"| H
    CFG -->|"providesconfig"| I
    H -->|"provideshistory"| I
    C -- "non-interactive" --> S
    I -->|"selection"| S
    I -->|"styledby"| T
    S -->|"executes"| SSHClient

    %% Supporting DevOps flow (not in runtime, but support for development)
    D -.-> M
    D -.-> C
    D -.-> CFG
    D -.-> H
    D -.-> I
    D -.-> S

    %% Click Events
    click M "https://github.com/byawitz/ggh/blob/master/cmd/ggh.go"
    click C "https://github.com/byawitz/ggh/tree/master/internal/command"
    click CFG "https://github.com/byawitz/ggh/tree/master/internal/config"
    click H "https://github.com/byawitz/ggh/tree/master/internal/history"
    click I "https://github.com/byawitz/ggh/tree/master/internal/interactive"
    click S "https://github.com/byawitz/ggh/blob/master/internal/ssh/ssh.go"
    click T "https://github.com/byawitz/ggh/tree/master/internal/theme"

    %% Styles
    classDef core fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef ui fill:#ABEBC6,stroke:#333,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef devops fill:#D2B4DE,stroke:#333,stroke-width:2px;
```
