# passbolt/go-passbolt-cli architecture

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

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

## Overview

##### Main Components

a. CLI Interface Layer:
- Main entry point (main.go)
- To the command structure (cmd/* files)
- Core commands (create, delete, get, list, move, share, update)

b. Domain Logic Layer:
- Four main entity handlers:
- Resource (passwords)
- Folder
- User
- Group
- Each entity should show its standard operations (create, delete, get, list, update)

c. Utility Layer:
- Util package components:
- HTTP client
- Context management
- CEL (Common Expression Language) handling

d. External Integration:
- Passbolt Server connection
- Configuration management
- Authentication/MFA handling

**[CLI Layer (Top)]**
- ↓
**[Command Router]**
- ↓
**[Domain Logic Layer]**
- ↓
**[Utility Layer]**
- ↓
**[External Systems (Bottom)]**

##### Key Relationships

a. Command Flow:
- User input → CLI commands → Entity handlers
- Entity handlers → Utility layer → External API

b. Cross-cutting Concerns:
- Configuration management affecting all layers
- Authentication/MFA verification flow
- Server verification process

##### Important Details

a. Security Features:
- MFA handling (TOTP modes)
- Server verification
- Private key management

b. Data Flows:
- JSON output capability for scripting
- Resource sharing permissions (1, 7, 15, -1)

##### Specific Implementation Notes

- How the cmd package orchestrates operations
- How entity packages (resource, folder, user, group) interact
- Demonstrate utility package's supporting role
- Configuration flow (configure command)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph CLI
        Main["Main Entry Point"]:::cli
        CmdRouter["Command Router"]:::cli
        
        subgraph Commands
            Create["Create Command"]:::command
            Delete["Delete Command"]:::command
            Get["Get Command"]:::command
            List["List Command"]:::command
            Move["Move Command"]:::command
            Share["Share Command"]:::command
            Update["Update Command"]:::command
            Configure["Configure Command"]:::command
            Verify["Server Verify"]:::command
            Export["Export Command"]:::command
        end
    end

    subgraph Domain
        subgraph ResourceHandler["Resource Handler"]
            R_Create["Create"]:::domain
            R_Delete["Delete"]:::domain
            R_Get["Get"]:::domain
            R_List["List"]:::domain
            R_Update["Update"]:::domain
            R_Move["Move"]:::domain
            R_Share["Share"]:::domain
        end

        subgraph FolderHandler["Folder Handler"]
            F_Create["Create"]:::domain
            F_Delete["Delete"]:::domain
            F_Get["Get"]:::domain
            F_List["List"]:::domain
            F_Update["Update"]:::domain
            F_Move["Move"]:::domain
            F_Share["Share"]:::domain
        end

        subgraph UserHandler["User Handler"]
            U_Create["Create"]:::domain
            U_Delete["Delete"]:::domain
            U_Get["Get"]:::domain
            U_List["List"]:::domain
            U_Update["Update"]:::domain
        end

        subgraph GroupHandler["Group Handler"]
            G_Create["Create"]:::domain
            G_Delete["Delete"]:::domain
            G_Get["Get"]:::domain
            G_List["List"]:::domain
            G_Update["Update"]:::domain
        end
    end

    subgraph Utilities
        HttpClient["HTTP Client"]:::util
        ContextMgmt["Context Management"]:::util
        CEL["Common Expression Language"]:::util
        KeePass["KeePass Integration"]:::util
    end

    subgraph External
        PassboltServer["Passbolt Server"]:::external
        MFA["MFA/TOTP"]:::security
        Auth["Authentication"]:::security
    end

    Main --> CmdRouter
    CmdRouter --> Commands
    
    Create --> ResourceHandler & FolderHandler & UserHandler & GroupHandler
    Delete --> ResourceHandler & FolderHandler & UserHandler & GroupHandler
    Get --> ResourceHandler & FolderHandler & UserHandler & GroupHandler
    List --> ResourceHandler & FolderHandler & UserHandler & GroupHandler
    Move --> ResourceHandler & FolderHandler
    Share --> ResourceHandler & FolderHandler
    Update --> ResourceHandler & FolderHandler & UserHandler & GroupHandler
    
    ResourceHandler & FolderHandler & UserHandler & GroupHandler --> HttpClient
    HttpClient --> PassboltServer
    
    Configure --> Auth
    Verify --> PassboltServer
    Export --> KeePass
    
    Auth --> MFA
    MFA --> PassboltServer

    %% Click Events
    click Main "https://github.com/passbolt/go-passbolt-cli/blob/main/main.go"
    click CmdRouter "https://github.com/passbolt/go-passbolt-cli/blob/main/cmd/root.go"
    click Create "https://github.com/passbolt/go-passbolt-cli/blob/main/cmd/create.go"
    click Delete "https://github.com/passbolt/go-passbolt-cli/blob/main/cmd/delete.go"
    click Get "https://github.com/passbolt/go-passbolt-cli/blob/main/cmd/get.go"
    click List "https://github.com/passbolt/go-passbolt-cli/blob/main/cmd/list.go"
    click Move "https://github.com/passbolt/go-passbolt-cli/blob/main/cmd/move.go"
    click Share "https://github.com/passbolt/go-passbolt-cli/blob/main/cmd/share.go"
    click Update "https://github.com/passbolt/go-passbolt-cli/blob/main/cmd/update.go"
    click Configure "https://github.com/passbolt/go-passbolt-cli/blob/main/cmd/configure.go"
    click Verify "https://github.com/passbolt/go-passbolt-cli/blob/main/cmd/verify.go"
    click Export "https://github.com/passbolt/go-passbolt-cli/blob/main/cmd/export.go"
    click KeePass "https://github.com/passbolt/go-passbolt-cli/blob/main/keepass/export.go"
    click HttpClient "https://github.com/passbolt/go-passbolt-cli/blob/main/util/http.go"
    click ContextMgmt "https://github.com/passbolt/go-passbolt-cli/blob/main/util/context.go"
    click CEL "https://github.com/passbolt/go-passbolt-cli/blob/main/util/cel.go"

    %% Styles
    classDef cli fill:#2196F3,stroke:#1565C0,color:white
    classDef command fill:#42A5F5,stroke:#1565C0,color:white
    classDef domain fill:#4CAF50,stroke:#2E7D32,color:white
    classDef util fill:#FFC107,stroke:#FFA000,color:black
    classDef external fill:#9E9E9E,stroke:#616161,color:white
    classDef security fill:#F44336,stroke:#C62828,color:white

    %% Legend
    subgraph Legend
        CLI_L["CLI Component"]:::cli
        Command_L["Command"]:::command
        Domain_L["Domain Logic"]:::domain
        Util_L["Utility"]:::util
        External_L["External System"]:::external
        Security_L["Security Component"]:::security
    end
```
