# moul/sshportal architecture

> Architecture diagram of the GitHub repository moul/sshportal, 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/sshportal
- Repository: https://github.com/moul/sshportal

## Overview

##### Main Components

a) Core Components:
- SSH Server Interface (Port 2222)
- Built-in Shell/CLI
- Authentication System
- Session Manager
- Access Control Layer (ACL)
- Database Layer (SQLite/MySQL)

b) External Interfaces:
- Client SSH Connections
- Target SSH Hosts
- Telnet Hosts (for non-SSH proxy support)

**[Client Layer]**

**[Frontend Layer]**

**[Core Services Layer]**

**[Data Layer]**

##### Component Relationships

a) Client Flow:
- SSH Client → SSH Server Interface
- SSH Server Interface → Authentication System
- Authentication System → ACL Manager
- ACL Manager → Session Manager
- Session Manager → Target Hosts

b) Management Flow:
- Admin CLI → Built-in Shell
- Built-in Shell → Core Services
- Core Services → Database Layer

##### Specific Implementation Details

a) Package Organization (from /pkg directory):
- Bastion: Core SSH handling
- Crypto: Security operations
- DBModels: Data structures
- Utils: Helper functions

b) Key Features:
- User Management System
- Host Key Management
- Session Recording
- Health Checking
- Audit Logging

##### Scaling Components

Specific notations for:
- Load balancer (when using MySQL backend)
- Multiple SSHportal instances
- Shared database configuration

- Security boundaries
- Data flow directions
- Scaling points
- Integration interfaces

Use standardized symbols:
- Rectangles for services
- Hexagons for security components
- Clouds for external systems

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Clients
        SSHClient[SSH Client]
        AdminClient[Admin Client]
    end

    %% Frontend Layer
    subgraph Frontend
        SSHServer["SSH Server Interface (2222)"]:::security
        Shell["Built-in Shell/CLI"]:::management
    end

    %% Core Services Layer
    subgraph CoreServices
        Auth["Authentication System"]:::security
        ACL["Access Control Layer"]:::security
        SessionMgr["Session Manager"]:::core
        HealthCheck["Health Checker"]:::monitoring
        LogTunnel["Session Logger"]:::monitoring
    end

    %% Data Layer
    subgraph DataLayer
        DB[(Database Layer)]
        Models["Data Models"]
        Validator["Data Validator"]
    end

    %% External Systems
    subgraph TargetSystems
        SSHHosts[("SSH Hosts")]:::external
        TelnetHosts[("Telnet Hosts")]:::external
    end

    %% Deployment Components
    subgraph Deployment
        K8s{"Kubernetes"}:::deployment
        MySQL{"MySQL Cluster"}:::database
    end

    %% Connections
    SSHClient --> SSHServer
    AdminClient --> Shell
    SSHServer --> Auth
    Auth --> ACL
    ACL --> SessionMgr
    SessionMgr --> SSHHosts
    SessionMgr --> TelnetHosts
    SessionMgr --> LogTunnel
    LogTunnel --> DB
    Shell --> Auth
    Auth --> DB
    DB --> Models
    Models --> Validator
    HealthCheck --> SSHHosts
    HealthCheck --> TelnetHosts
    K8s --> SSHServer
    DB --> MySQL

    %% Styles
    classDef core fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef security fill:#ff9999,stroke:#333,stroke-width:2px
    classDef management fill:#ffeb99,stroke:#333,stroke-width:2px
    classDef monitoring fill:#c2f0c2,stroke:#333,stroke-width:2px
    classDef database fill:#d1c4e9,stroke:#333,stroke-width:2px
    classDef external fill:#e0e0e0,stroke:#333,stroke-width:2px
    classDef deployment fill:#b2dfdb,stroke:#333,stroke-width:2px

    %% Click Events
    click SSHServer "https://github.com/moul/sshportal/blob/master/pkg/bastion/ssh.go"
    click Shell "https://github.com/moul/sshportal/blob/master/pkg/bastion/shell.go"
    click Auth "https://github.com/moul/sshportal/blob/master/pkg/crypto/crypto.go"
    click SessionMgr "https://github.com/moul/sshportal/blob/master/pkg/bastion/session.go"
    click ACL "https://github.com/moul/sshportal/blob/master/pkg/bastion/acl.go"
    click DB "https://github.com/moul/sshportal/blob/master/pkg/dbmodels/dbmodels.go"
    click TelnetHosts "https://github.com/moul/sshportal/blob/master/pkg/bastion/telnet.go"
    click HealthCheck "https://github.com/moul/sshportal/blob/master/healthcheck.go"
    click LogTunnel "https://github.com/moul/sshportal/blob/master/pkg/bastion/logtunnel.go"
    click Models "https://github.com/moul/sshportal/blob/master/pkg/dbmodels/dbmodels.go"
    click Validator "https://github.com/moul/sshportal/blob/master/pkg/dbmodels/validator.go"
    click K8s "https://github.com/moul/sshportal/blob/master/helm/sshportal/templates/deployment.yaml"
    click MySQL "https://github.com/moul/sshportal/blob/master/examples/mysql/docker-compose.yml"
```
