# hopinc/cli architecture

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

- Interactive diagram: https://gitdiagram.com/hopinc/cli
- Repository: https://github.com/hopinc/cli

## Overview

##### Project type and purpose
- Hop CLI is a Rust-based command-line application that serves as a client for Hop’s backend services. It replaces the browser-based Console by exposing Hop functionality (auth, projects, deploy, etc.) via terminal commands.

##### File structure
- Top-level files: Cargo.toml/build.rs for Rust build, README.md, scripts/ (installation and CI scripts), build/ (packaging for Windows MSI), .github/ workflows for CI/CD.
- src/main.rs: CLI entry point. src/lib.rs: core logic.
- src/commands/: each subfolder represents a top-level command namespace (auth, channels, containers, deploy, ignite, projects, etc.). Within each, further modules implement individual actions.
- src/state/http/: HTTP client abstraction (types & client setup).
- src/store/: local state management (context, auth tokens, Hopfile parsing).
- src/utils/: shared utilities (serialization, browser launching, size formatting).

##### README for additional insights
- The README confirms its role as a CLI for Hop, describes installation and login flow, and highlights key operations (projects switch, deploy, link).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User and External Interfaces
    Terminal["User / Terminal"]:::interface
    Browser["Browser"]:::interface
    subgraph "External Services"
        HopBackend["Hop Backend (REST API)"]:::external
    end

    %% CLI Core and Configuration
    subgraph "CLI Core Layer"
        CLICore["CLI Core"]:::core
        Config["CLI Configuration"]:::core
    end

    %% Command Modules
    subgraph "Command Modules" 
        AuthMod["Auth Module"]:::module
        ChannelsMod["Channels Module"]:::module
        ContainersMod["Containers Module"]:::module
        DeployMod["Deploy Module"]:::module
        IgniteMod["Ignite Module"]:::module
        ProjectsMod["Projects Module"]:::module
        OtherMods["Other Command Namespaces"]:::module
    end

    %% Infrastructure Layers
    subgraph "Infrastructure Layer"
        HTTPLayer["HTTP Layer"]:::infra
        LocalStore["Local Store"]:::storage
        Utils["Utilities"]:::infra
    end

    %% Build and Packaging
    subgraph "Build & Installer"
        BuildScript["build.rs"]:::build
        WindowsPack["Windows MSI Packaging"]:::build
        Scripts["Installation & CI Scripts"]:::build
        CIWorkflows["CI/CD Workflows"]:::build
    end

    %% Project Metadata
    subgraph "Project Metadata"
        Cargo["Cargo.toml / Cargo.lock"]:::meta
        Readme["README.md"]:::meta
    end

    %% Relationships
    Terminal -->|invokes hop <command>| CLICore
    CLICore -->|loads config| Config
    CLICore -->|dispatches| AuthMod
    CLICore -->|dispatches| ChannelsMod
    CLICore -->|dispatches| ContainersMod
    CLICore -->|dispatches| DeployMod
    CLICore -->|dispatches| IgniteMod
    CLICore -->|dispatches| ProjectsMod
    CLICore -->|dispatches| OtherMods

    AuthMod -->|uses| HTTPLayer
    AuthMod -->|reads/writes| LocalStore
    AuthMod -->|invokes| Browser
    Browser -->|OAuth redirect| AuthMod

    ChannelsMod -->|uses| HTTPLayer
    ChannelsMod -->|reads/writes| LocalStore

    ContainersMod -->|uses| HTTPLayer
    ContainersMod -->|reads/writes| LocalStore

    DeployMod -->|uses| HTTPLayer
    DeployMod -->|reads/writes| LocalStore

    IgniteMod -->|uses| HTTPLayer
    IgniteMod -->|reads/writes| LocalStore

    ProjectsMod -->|uses| HTTPLayer
    ProjectsMod -->|reads/writes| LocalStore

    OtherMods -->|uses| HTTPLayer
    OtherMods -->|reads/writes| LocalStore

    HTTPLayer <-->|"JSON over HTTP"| HopBackend

    AuthMod -->|calls| Utils
    ChannelsMod -->|calls| Utils
    ContainersMod -->|calls| Utils
    DeployMod -->|calls| Utils
    IgniteMod -->|calls| Utils
    ProjectsMod -->|calls| Utils
    OtherMods -->|calls| Utils

    BuildScript -->|compiles| CLICore
    BuildScript -->|generates| WindowsPack
    Scripts -->|supports| BuildScript
    Scripts -->|supports| WindowsPack
    CIWorkflows -->|runs| Scripts

    Cargo -->|defines deps| BuildScript
    Cargo -->|defines deps| CLICore
    Readme -->|documents| CLICore

    %% Click Events
    click CLICore "https://github.com/hopinc/cli/blob/main/src/main.rs"
    click CLICore "https://github.com/hopinc/cli/blob/main/src/lib.rs"
    click AuthMod "https://github.com/hopinc/cli/blob/main/src/commands/auth/mod.rs"
    click AuthMod "https://github.com/hopinc/cli/blob/main/src/commands/auth/login/browser_auth.rs"
    click AuthMod "https://github.com/hopinc/cli/blob/main/src/commands/auth/logout.rs"
    click ChannelsMod "https://github.com/hopinc/cli/tree/main/src/commands/channels/"
    click ContainersMod "https://github.com/hopinc/cli/tree/main/src/commands/containers/"
    click DeployMod "https://github.com/hopinc/cli/blob/main/src/commands/deploy/mod.rs"
    click DeployMod "https://github.com/hopinc/cli/tree/main/src/commands/deploy/builder/"
    click DeployMod "https://github.com/hopinc/cli/tree/main/src/commands/deploy/local/"
    click IgniteMod "https://github.com/hopinc/cli/blob/main/src/commands/ignite/mod.rs"
    click ProjectsMod "https://github.com/hopinc/cli/blob/main/src/commands/projects/mod.rs"
    click OtherMods "https://github.com/hopinc/cli/tree/main/src/commands/"
    click HTTPLayer "https://github.com/hopinc/cli/blob/main/src/state/http/mod.rs"
    click HTTPLayer "https://github.com/hopinc/cli/blob/main/src/state/http/types.rs"
    click LocalStore "https://github.com/hopinc/cli/blob/main/src/store/mod.rs"
    click LocalStore "https://github.com/hopinc/cli/blob/main/src/store/auth.rs"
    click LocalStore "https://github.com/hopinc/cli/blob/main/src/store/context.rs"
    click LocalStore "https://github.com/hopinc/cli/blob/main/src/store/hopfile.rs"
    click LocalStore "https://github.com/hopinc/cli/blob/main/src/store/utils.rs"
    click Utils "https://github.com/hopinc/cli/blob/main/src/utils/mod.rs"
    click Utils "https://github.com/hopinc/cli/blob/main/src/utils/browser.rs"
    click Utils "https://github.com/hopinc/cli/blob/main/src/utils/deser.rs"
    click Utils "https://github.com/hopinc/cli/blob/main/src/utils/size.rs"
    click Utils "https://github.com/hopinc/cli/blob/main/src/utils/sudo.rs"
    click Utils "https://github.com/hopinc/cli/tree/main/src/utils/arisu/"
    click Config "https://github.com/hopinc/cli/blob/main/src/config.rs"
    click BuildScript "https://github.com/hopinc/cli/blob/main/build.rs"
    click WindowsPack "https://github.com/hopinc/cli/tree/main/build/windows/"
    click Scripts "https://github.com/hopinc/cli/blob/main/scripts/install.sh"
    click Scripts "https://github.com/hopinc/cli/blob/main/scripts/build.ps1"
    click Scripts "https://github.com/hopinc/cli/blob/main/scripts/bump.sh"
    click CIWorkflows "https://github.com/hopinc/cli/blob/main/.github/workflows/release.yml"
    click Cargo "https://github.com/hopinc/cli/blob/main/Cargo.toml"
    click Readme "https://github.com/hopinc/cli/blob/main/README.md"

    %% Styles
    classDef interface fill:#EEEEEE,stroke:#666,stroke-width:1px
    classDef core fill:#D6EAF8,stroke:#1B4F72,stroke-width:1px
    classDef module fill:#AED6F1,stroke:#1B4F72,stroke-width:1px
    classDef infra fill:#D5F5E3,stroke:#196F3D,stroke-width:1px
    classDef storage fill:#ABEBC6,stroke:#1D8348,stroke-width:1px
    classDef external fill:#FADBD8,stroke:#922B21,stroke-width:1px
    classDef build fill:#F9E79F,stroke:#7D6608,stroke-width:1px
    classDef meta fill:#E8DAEF,stroke:#6C3483,stroke-width:1px
```
