# thxrhmn/hmpssh architecture

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

- Interactive diagram: https://gitdiagram.com/thxrhmn/hmpssh
- Repository: https://github.com/thxrhmn/hmpssh

## Overview

##### Main Components
- User Interface (CLI): Since the tool is terminal-based, the CLI is the primary presentation layer. It handles user inputs (like selecting add, connect, delete, backup, etc.) and displays connection lists.
- Application Logic: The core logic implemented in main.go, which coordinates the different features such as adding connections, connecting to servers, managing SSH keys, and handling backups.
- Configuration Management: A component responsible for reading from and writing to the config file (located at ~/.ssh/connections.conf) and managing SSH keys and file permissions.
- External Integrations:
– SSH Operations: Invoking system tools such as ssh, ssh-keygen, ssh-copy-id for actual SSH connections and key management.
– Backup/Restore Operations: Using tools like tar for configuration backup and extraction.
- File System & Persistence: This element represents interactions with the file system for saving configuration, SSH keys, and backup archives (stored in ~/ssh_backup).

##### Relationships and Interactions
- The CLI accepts user commands and relays them to the Application Logic.
- Application Logic processes the commands and, depending on the operation, interacts with the Configuration Management component (to persist or read connection settings).
- When an operation requires SSH actions or backups, the Application Logic hands off to External Integration components using system calls, which then interact with the underlying system's SSH tools or file system.
- In the backup/restore flow, the backup component uses tar to create or extract configuration archives.

##### Architectural Patterns and Design Principles
- Minimalist and Modular: Even though the project is simple, segmenting the CLI, application logic, configuration management, and integrations helps keep the architecture clean.
- Single Responsibility Principle: Each component (CLI, logic, configuration, integration) has a distinct role.
- Layered Interaction: Data flows from user input (CLI) through business logic to external system calls, showing a clear separation of concerns.

##### Relevant Technologies and Libraries
- Programming Language: Go (main.go, go.mod, go.sum).
- External Tools: ssh, ssh-keygen, ssh-copy-id, tar.
- OS/Filesystem: Interaction with directories such as ~/.ssh and ~/ssh_backup.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface Layer"
        A["CLI Interface"]:::cli
    end

    subgraph "Application Layer"
        B["Application Logic"]:::logic
        C["Configuration Management"]:::config
        D["SSH Operations & External Integrations"]:::external
        E["Backup Module"]:::backup
    end

    subgraph "Persistence Layer"
        F["Config File: ~/.ssh/connections.conf"]:::datastore
        G["Backup Storage: ~/ssh_backup"]:::datastore
    end

    A -->|"CLI_to_Logic"| B
    B -->|"Config_IO"| C
    B -->|"SSH_Exec"| D
    B -->|"Backup_Operation"| E
    C -->|"Persist_Config"| F
    E -->|"Store_Backup"| G

    click A "https://github.com/thxrhmn/hmpssh/blob/main/main.go"
    click B "https://github.com/thxrhmn/hmpssh/blob/main/main.go"
    click C "https://github.com/thxrhmn/hmpssh/blob/main/main.go"
    click D "https://github.com/thxrhmn/hmpssh/blob/main/main.go"
    click E "https://github.com/thxrhmn/hmpssh/blob/main/main.go"

    classDef cli fill:#a3d9ff,stroke:#333,stroke-width:2px;
    classDef logic fill:#c3f9c7,stroke:#333,stroke-width:2px;
    classDef config fill:#ffe0a3,stroke:#333,stroke-width:2px;
    classDef external fill:#ffb3b3,stroke:#333,stroke-width:2px;
    classDef backup fill:#d1c0ff,stroke:#333,stroke-width:2px;
    classDef datastore fill:#f4f4f4,stroke:#333,stroke-dasharray:3 3;
```
