# moul/assh architecture

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

- Interactive diagram: https://gitdiagram.com/moul/assh
- Repository: https://github.com/moul/assh

## Overview

##### Project Type and Purpose
This is an open-source SSH configuration management tool that acts as a transparent wrapper around SSH, providing advanced features like regex support, aliases, gateways, and dynamic hostnames.

##### Main Components

Core Components:
**A. Command Layer**
- Main CLI interface
- Command handlers (build, info, config, sockets, ping)

**B. Configuration Management**
- YAML Parser
- Config Builder
- Template Engine
- Host Resolution

**C. SSH Integration**
- ProxyCommand Handler
- Control Socket Manager
- Gateway Manager

**D. Hook System**
- Event Handlers
- Notification System
- Command Execution

**1. Layout Structure:**
- Top -> Bottom architecture with the following layers:

- User Interface   |

- Command Handlers   |

- Core Processing      |

- Integration Layer   |

**2. Component Relationships:**
- Rectangles: Main components
- Rounded rectangles: Services
- Hexagons: External integrations

- Blue: Core components
- Green: External integrations
- Orange: Configuration elements
- Gray: Support services

##### Detailed Component Breakdown

**A. User Interface Layer:**
- CLI Commands (assh config, ping, info, etc.)
- Configuration File Interface (~/.ssh/assh.yml)

**B. Command Handler Layer:**
- Config Builder
- Socket Manager
- Host Resolution
- Gateway Manager

**C. Core Processing Layer:**
- Template Engine
- Pattern Matcher
- Host Resolver
- Hook System

**D. Integration Layer:**
- SSH Config Generator
- ProxyCommand Handler
- Control Socket Manager
- External Tool Integration

##### Data Flow Indicators

**1. Configuration Flow:**
- assh.yml -> Parser -> Config Builder -> ssh_config

**2. Command Flow:**
- CLI -> Command Handler -> Core Processing -> SSH Integration

**3. Hook System Flow:**
- Events -> Hook Manager -> Drivers (Exec/Notify/Write)

##### External Integration Points

**Show connections to:**
- OpenSSH
- System SSH Config
- Control Sockets
- Notification Systems
- External Commands (nc, socat)

##### Important Notes

**Include:**
**2. Version information**
**3. Main data flow paths**
**4. Configuration file locations**
**5. Integration points with SSH**

- The transparent wrapper nature of the tool
- The configuration transformation process
- The gateway and proxy command handling
- The hook system's event flow
- The integration with the SSH ecosystem

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI
        CLI["CLI Interface"]:::ui
        ConfigFile["~/.ssh/assh.yml"]:::config
    end

    subgraph CommandLayer
        CmdHandler["Command Handler"]:::command
        BuildCmd["Build Command"]:::command
        ConfigCmd["Config Command"]:::command
        ProxyCmd["Proxy Command"]:::command
        InfoCmd["Info Command"]:::command
    end

    subgraph CoreProcessing
        ConfigMgr["Configuration Manager"]:::core
        HostMgr["Host Manager"]:::core
        TemplateEngine["Template Engine"]:::core
        Logger["Logger"]:::core
        RateLimit["Rate Limiter"]:::core
        GraphViz["Pattern Visualizer"]:::core
    end

    subgraph HookSystem
        HookMgr["Hook Manager"]:::hook
        ExecDriver["Execution Driver"]:::hook
        NotifyDriver["Notification Driver"]:::hook
        WriteDriver["Write Driver"]:::hook
    end

    subgraph Integration
        SocketMgr["Control Socket Manager"]:::integration
        ProxyHandler["ProxyCommand Handler"]:::integration
        EnvIntegration["Environment Integration"]:::integration
        VersionMgr["Version Manager"]:::integration
    end

    subgraph External
        OpenSSH["OpenSSH"]:::external
        SysConfig["System SSH Config"]:::external
        ControlSockets["Control Sockets"]:::external
    end

    %% Relationships
    CLI --> CmdHandler
    ConfigFile --> ConfigMgr
    
    CmdHandler --> BuildCmd & ConfigCmd & ProxyCmd & InfoCmd
    
    BuildCmd & ConfigCmd & ProxyCmd & InfoCmd --> ConfigMgr
    ConfigMgr --> HostMgr
    HostMgr --> TemplateEngine
    
    ConfigMgr --> HookMgr
    HookMgr --> ExecDriver & NotifyDriver & WriteDriver
    
    ProxyCmd --> ProxyHandler
    ProxyHandler --> SocketMgr
    SocketMgr --> ControlSockets
    
    ConfigMgr --> OpenSSH
    ConfigMgr --> SysConfig

    %% Click Events
    click CmdHandler "https://github.com/moul/assh/blob/master/pkg/commands/commands.go"
    click BuildCmd "https://github.com/moul/assh/blob/master/pkg/commands/build.go"
    click ConfigCmd "https://github.com/moul/assh/blob/master/pkg/commands/config.go"
    click ProxyCmd "https://github.com/moul/assh/blob/master/pkg/commands/proxy.go"
    click InfoCmd "https://github.com/moul/assh/blob/master/pkg/commands/info.go"
    click ConfigMgr "https://github.com/moul/assh/blob/master/pkg/config/config.go"
    click HostMgr "https://github.com/moul/assh/blob/master/pkg/config/host.go"
    click TemplateEngine "https://github.com/moul/assh/blob/master/pkg/templates/templates.go"
    click SocketMgr "https://github.com/moul/assh/blob/master/pkg/controlsockets/control-sockets.go"
    click HookMgr "https://github.com/moul/assh/blob/master/pkg/hooks/hooks.go"
    click ExecDriver "https://github.com/moul/assh/blob/master/pkg/hooks/driver_exec.go"
    click NotifyDriver "https://github.com/moul/assh/blob/master/pkg/hooks/driver_notification.go"
    click WriteDriver "https://github.com/moul/assh/blob/master/pkg/hooks/driver_write.go"
    click GraphViz "https://github.com/moul/assh/blob/master/pkg/config/graphviz/graphviz.go"
    click RateLimit "https://github.com/moul/assh/blob/master/pkg/ratelimit/ratelimit.go"
    click Logger "https://github.com/moul/assh/blob/master/pkg/logger/logger.go"
    click EnvIntegration "https://github.com/moul/assh/blob/master/pkg/utils/env.go"
    click VersionMgr "https://github.com/moul/assh/blob/master/pkg/version/version.go"

    %% Styles
    classDef ui fill:#B8D4FF,stroke:#2E75B6
    classDef command fill:#FFD966,stroke:#BF9000
    classDef core fill:#A8D08D,stroke:#548235
    classDef hook fill:#FFB366,stroke:#C65911
    classDef integration fill:#C3B4E0,stroke:#7030A0
    classDef external fill:#F2F2F2,stroke:#7F7F7F
    classDef config fill:#FFE699,stroke:#BF8F00
```
