# chaoshour/ssh-audits architecture

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

- Interactive diagram: https://gitdiagram.com/chaoshour/ssh-audits
- Repository: https://github.com/chaoshour/ssh-audits

## Overview

##### Main Components
- Command-Line Interface (CLI) / Entry Point: The project uses a main Go file (cmd/ssh-audits/main.go) which initializes the application and parses command-line arguments.
- SSH Engine/Connector: Core functionality for connecting to remote hosts using SSH is handled by packages under “pkg/sshutil” and “pkg/sshkey”. These modules are responsible for managing SSH sessions, executing commands, and handling keys.
- SFTP Module: The “pkg/sftp” directory contains functionality related to SFTP file transfers. This component uploads files to remote hosts, adjusts permissions, and can trigger execution.
- Inventory Management: The “inventory/hosts” file (and supporting shell scripts) provides the list of target hosts. This represents the configuration or “data” component that drives which systems are contacted.
- Auxiliary Scripts: Additional scripts like “my-thing.sh” and “list.sh” are used for demonstration or extra functionality, interacting with the core modules.

##### And Map the Component Interactions
- The CLI module (cmd/ssh-audits) accepts parameters such as inventory file, host(s), command chains, and an SFTP flag.
- Once invoked, the application reads the inventory file and selects the target hosts.
- For each host:
– The SSH connector (using sshkey and sshutil packages) establishes a connection.
– If the “-c” (command) flag is provided, it sends commands for execution.
– If the “-sftp” flag is used, the SFTP module takes over: the file is transferred, appropriate permissions are set, and optionally executed by issuing a command.
- There is data flow from the user’s CLI input through the main process to the individual modules and then to the remote hosts.

##### Architectural Patterns and Design Principles
- Modular Design: The division between command parsing (cmd/ directory) and business logic (pkg/) is an example of separation of concerns.
- Reusability: Packages such as sshkey and sshutil encapsulate specific SSH functionalities making the overall system extensible.
- Clear Dependency Flow: The main application directs flow to the specific helper packages. Illustrate this layered dependency clearly.

## Diagram (Mermaid)

```mermaid
flowchart TD
    U("User/CLI Input"):::cli
    A("ssh-audits Application (main.go)"):::app
    U --> A

    subgraph "Application Components"
        CP("Command Parsing / CLI Handler"):::internal
        INV("Inventory Reader"):::internal
        subgraph "SSH Connector"
            SK("SSH Key"):::internal
            SU("SSH Util"):::internal
        end
        SP("SFTP Handler"):::internal
    end

    A --> CP
    A --> INV
    A --> SP

    CP -->|"triggersSSH"| SK
    CP -->|"triggersSSH"| SU
    CP -->|"initiatesSFTP"| SP
    INV -->|"suppliesHosts"| CP

    R1("Remote Host (SSH)"):::external
    R2("Remote Host (SFTP)"):::external

    SK -->|"SSHConnect"| R1
    SU -->|"SSHConnect"| R1
    SP -->|"SFTPTransfer"| R2

    subgraph "Auxiliary Scripts"
        LS("list.sh"):::external
        MT("my-thing.sh"):::external
    end

    LS ---|"auxiliary"| CP
    MT ---|"auxiliary"| CP

    click A "https://github.com/chaoshour/ssh-audits/blob/main/cmd/ssh-audits/main.go"
    click SK "https://github.com/chaoshour/ssh-audits/blob/main/pkg/sshkey/sshkey.go"
    click SU "https://github.com/chaoshour/ssh-audits/blob/main/pkg/sshutil/sshutil.go"
    click SP "https://github.com/chaoshour/ssh-audits/blob/main/pkg/sftp/sftp.go"
    click INV "https://github.com/chaoshour/ssh-audits/tree/main/inventory/hosts"
    click LS "https://github.com/chaoshour/ssh-audits/blob/main/list.sh"
    click MT "https://github.com/chaoshour/ssh-audits/blob/main/my-thing.sh"

    classDef cli fill:#fceabb,stroke:#e08b42,stroke-width:2px
    classDef app fill:#d3f8e2,stroke:#34c759,stroke-width:2px
    classDef internal fill:#bbdefb,stroke:#0d47a1,stroke-width:2px
    classDef external fill:#ffe0b2,stroke:#f57c00,stroke-width:2px
```
