# adembc/lazyssh architecture

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

- Interactive diagram: https://gitdiagram.com/adembc/lazyssh
- Repository: https://github.com/adembc/lazyssh

## Overview

##### Project type and purpose
- This is a single‐binary, terminal-based TUI (text UI) application called “lazyssh.”
It’s not a full-stack web app but a CLI/TUI tool for managing SSH servers.
- Purpose: read and write your `~/.ssh/config`, present an interactive dashboard of servers, allow edits, pinning, searching, and invoke real SSH sessions via the native `ssh` binary.

##### File structure
- cmd/main.go: application entrypoint and dependency wiring.
- internal/adapters/ui: TUI layer using tview/tcell, rendering screens, capturing key events, mapping them to handlers.
- internal/adapters/data/ssh_config_file: reads/writes the SSH config file, manages backups, preserves formatting.
- internal/core: “Clean architecture” style
· domain: core data models (e.g., Server)
· ports: interfaces/abstractions for repos and services
· services: business logic (e.g., server CRUD, invocation of ssh binary)
- internal/logger: centralized logging.
- docs, CI/CD workflows, makefile, config files: ancillary.

##### README for additional insights
- Relies on tview/tcell for UI.
- Writes atomically to SSH config, keeps rolling backups.
- Invokes the system ssh binary for actual connections.
- No database; persistence is the flat `~/.ssh/config` file.

##### Detail
- Every port interface (e.g., `ServerRepository`, `ServerService`).
- Two backup flows: initial original backup (one-time) and rolling timestamped backups.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Launcher
    AppLauncher["Application Launcher<br/>(cmd/main.go)"] 
    click AppLauncher "https://github.com/adembc/lazyssh/blob/main/cmd/main.go"

    %% UI Adapter Layer
    subgraph "UI Adapter Layer"
        direction TB
        UI_TUI["TUI Entry Point<br/>(tui.go)"] 
        UI_Handlers["Event Handlers<br/>(handlers.go)"]
        UI_ServerList["Server List View<br/>(server_list.go)"]
        UI_ServerForm["Server Form View<br/>(server_form.go)"]
        UI_SearchBar["Search Bar Component<br/>(search_bar.go)"]
        UI_StatusBar["Status Bar<br/>(status_bar.go)"]
        UI_Header["Header Component<br/>(header.go)"]
        UI_FieldHelp["Field Help<br/>(field_help.go)"]
        UI_Utils["UI Utilities<br/>(utils.go)"]
        UI_Validation["Validation Utils<br/>(validation.go)"]

        click UI_TUI "https://github.com/adembc/lazyssh/blob/main/internal/adapters/ui/tui.go"
        click UI_Handlers "https://github.com/adembc/lazyssh/blob/main/internal/adapters/ui/handlers.go"
        click UI_ServerList "https://github.com/adembc/lazyssh/blob/main/internal/adapters/ui/server_list.go"
        click UI_ServerForm "https://github.com/adembc/lazyssh/blob/main/internal/adapters/ui/server_form.go"
        click UI_SearchBar "https://github.com/adembc/lazyssh/blob/main/internal/adapters/ui/search_bar.go"
        click UI_StatusBar "https://github.com/adembc/lazyssh/blob/main/internal/adapters/ui/status_bar.go"
        click UI_Header "https://github.com/adembc/lazyssh/blob/main/internal/adapters/ui/header.go"
        click UI_FieldHelp "https://github.com/adembc/lazyssh/blob/main/internal/adapters/ui/field_help.go"
        click UI_Utils "https://github.com/adembc/lazyssh/blob/main/internal/adapters/ui/utils.go"
        click UI_Validation "https://github.com/adembc/lazyssh/blob/main/internal/adapters/ui/validation.go"
    end

    %% Core Layer
    subgraph "Core Layer"
        direction TB
        DomainModel["Domain Model<br/>(server.go)"]
        Ports["Ports Interfaces<br/>(repositories.go<br/>services.go)"]
        Services["Core Services<br/>(server_service.go)"]
        SysUnix["SysProcAttr Unix<br/>(sysprocattr_unix.go)"]
        SysWin["SysProcAttr Windows<br/>(sysprocattr_windows.go)"]

        click DomainModel "https://github.com/adembc/lazyssh/blob/main/internal/core/domain/server.go"
        click Ports "https://github.com/adembc/lazyssh/blob/main/internal/core/ports/repositories.go"
        click Ports "https://github.com/adembc/lazyssh/blob/main/internal/core/ports/services.go"
        click Services "https://github.com/adembc/lazyssh/blob/main/internal/core/services/server_service.go"
        click SysUnix "https://github.com/adembc/lazyssh/blob/main/internal/core/services/sysprocattr_unix.go"
        click SysWin "https://github.com/adembc/lazyssh/blob/main/internal/core/services/sysprocattr_windows.go"
    end

    %% Data Adapter Layer
    subgraph "Data Adapter Layer"
        direction TB
        DataRepo["SSH Config Repo<br/>(ssh_config_file_repo.go)"]
        DataCRUD["CRUD Operations<br/>(crud.go)"]
        DataBackup["Backup Manager<br/>(backup.go)"]
        DataMeta["Metadata Manager<br/>(metadata_manager.go)"]
        DataFS["File System I/O<br/>(file_system.go)"]
        DataConfigIO["Config I/O<br/>(config_io.go)"]
        DataMapper["Mapper<br/>(mapper.go)"]

        click DataRepo "https://github.com/adembc/lazyssh/blob/main/internal/adapters/data/ssh_config_file/ssh_config_file_repo.go"
        click DataCRUD "https://github.com/adembc/lazyssh/blob/main/internal/adapters/data/ssh_config_file/crud.go"
        click DataBackup "https://github.com/adembc/lazyssh/blob/main/internal/adapters/data/ssh_config_file/backup.go"
        click DataMeta "https://github.com/adembc/lazyssh/blob/main/internal/adapters/data/ssh_config_file/metadata_manager.go"
        click DataFS "https://github.com/adembc/lazyssh/blob/main/internal/adapters/data/ssh_config_file/file_system.go"
        click DataConfigIO "https://github.com/adembc/lazyssh/blob/main/internal/adapters/data/ssh_config_file/config_io.go"
        click DataMapper "https://github.com/adembc/lazyssh/blob/main/internal/adapters/data/ssh_config_file/mapper.go"
    end

    %% Logger
    Logger["Centralized Logger<br/>(logger.go)"]
    click Logger "https://github.com/adembc/lazyssh/blob/main/internal/logger/logger.go"

    %% External Systems
    FS["File System<br/>(~/.ssh/config)"]
    SSHBin["Native SSH Binary"]

    %% Connections
    AppLauncher --> UI_TUI
    AppLauncher --> Ports
    AppLauncher --> DataRepo
    AppLauncher --> Logger

    UI_Handlers --> Ports
    UI_Handlers --> Logger

    Ports --> Services
    Services --> DataRepo
    Services --> Logger
    Services --> SysUnix
    Services --> SysWin
    Services --> SSHBin

    DataRepo --> DataCRUD
    DataCRUD --> DataBackup
    DataBackup --> DataMeta
    DataMeta --> DataFS
    DataFS --> DataConfigIO
    DataConfigIO --> DataMapper
    DataMapper --> FS
    DataRepo --> Logger

    FS -->|reads/writes| DataRepo
    SSHBin -->|executes| Services

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#000,color:#000;
    classDef core fill:#DFFFE0,stroke:#000,color:#000;
    classDef data fill:#FFE0B2,stroke:#000,color:#000;
    classDef logger fill:#DDDDDD,stroke:#000,color:#000;
    classDef external fill:#F0F0F0,stroke:#000,color:#000;

    class UI_TUI,UI_Handlers,UI_ServerList,UI_ServerForm,UI_SearchBar,UI_StatusBar,UI_Header,UI_FieldHelp,UI_Utils,UI_Validation ui;
    class DomainModel,Ports,Services,SysUnix,SysWin core;
    class DataRepo,DataCRUD,DataBackup,DataMeta,DataFS,DataConfigIO,DataMapper data;
    class Logger logger;
    class FS,SSHBin external;
```
