# dopplerhq/cli architecture

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

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

## Overview

##### Main Components

a. Core Components:
- CLI Interface Layer (pkg/cmd)
- Controllers Layer (pkg/controllers)
- HTTP Client Layer (pkg/http)
- Configuration Management (pkg/configuration)
- Models Layer (pkg/models)
- Terminal UI Component (pkg/tui)
- Utility Services (pkg/utils)
- Crypto Services (pkg/crypto)

b. External Systems:
- Doppler API Service
- Local File System
- System Keyring
- Package Managers (brew, winget, etc.)

**User Interaction Layer**

**Command Layer (CLI Commands)**

**Business Logic Layer (Controllers)**

**Service Layer (HTTP, Crypto, Config)**

**External Systems**

##### Key Elements to Highlight

a. Command Flow:
- How user commands flow through the system
- Relationship between commands (pkg/cmd) and their corresponding controllers
- Demonstrate how authentication and configuration are handled

b. Data Flow:
- How secrets and configurations are retrieved from the Doppler API
- How local configuration is stored and accessed
- Encryption/decryption flows for sensitive data

##### Specific Implementation Details

a. Authentication Flow:
- Login command flow
- Token management
- Scope handling (root vs directory-specific)

b. Configuration Management:
- Project setup flow
- Config selection and storage
- Local configuration persistence

c. Secret Management:
- Secret retrieval and caching
- Encryption/decryption processes
- Environment variable injection

##### Component Relationships

Clear connections between:
- Commands (pkg/cmd) → Controllers (pkg/controllers)
- Controllers → HTTP Client (pkg/http)
- HTTP Client → Doppler API
- Configuration (pkg/configuration) → Local Storage
- TUI (pkg/tui) → Controllers

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph User["User Interaction Layer"]
        CLI(["CLI Command Line"]):::ui
        TUI(["Terminal UI"]):::ui
    end

    subgraph Commands["Command Layer"]
        Auth["Authentication Commands"]:::cmd
        SecretsCMD["Secrets Commands"]:::cmd
        ConfigCMD["Config Commands"]:::cmd
    end

    subgraph Controllers["Business Logic Layer"]
        SecretsCTRL["Secrets Controller"]:::controller
        ProjectsCTRL["Projects Controller"]:::controller
        AnalyticsCTRL["Analytics Controller"]:::controller
    end

    subgraph Services["Service Layer"]
        subgraph HTTP["HTTP Services"]
            APIClient["API Client"]:::service
            AnalyticsClient["Analytics Client"]:::service
        end

        subgraph Config["Configuration Services"]
            CoreConfig["Core Config"]:::service
            KeyringIntegration["Keyring Integration"]:::service
        end

        subgraph Crypto["Crypto Services"]
            AES["AES Implementation"]:::security
            CryptoUtils["Crypto Utils"]:::security
        end

        subgraph Utils["Utility Services"]
            EnvUtils["Environment Utils"]:::util
            IOOps["IO Operations"]:::util
            Logging["Logging"]:::util
        end
    end

    subgraph Models["Models Layer"]
        APIModels["API Models"]:::model
        ConfigModels["Config Models"]:::model
        SecretsModels["Secrets Models"]:::model
    end

    subgraph External["External Systems"]
        DopplerAPI["Doppler API"]:::external
        LocalFS["Local File System"]:::external
        SysKeyring["System Keyring"]:::external
        PackageManagers["Package Managers"]:::external
    end

    %% Relationships
    CLI --> Auth & SecretsCMD & ConfigCMD
    TUI --> SecretsCTRL & ProjectsCTRL
    Auth --> SecretsCTRL
    SecretsCMD --> SecretsCTRL
    ConfigCMD --> ProjectsCTRL
    SecretsCTRL --> APIClient
    ProjectsCTRL --> APIClient
    AnalyticsCTRL --> AnalyticsClient
    APIClient --> DopplerAPI
    CoreConfig --> LocalFS
    KeyringIntegration --> SysKeyring
    SecretsCTRL --> AES
    AES --> CryptoUtils

    %% Click Events
    click Auth "https://github.com/DopplerHQ/cli/blob/master/pkg/cmd/login.go"
    click SecretsCMD "https://github.com/DopplerHQ/cli/blob/master/pkg/cmd/secrets.go"
    click ConfigCMD "https://github.com/DopplerHQ/cli/blob/master/pkg/cmd/configs.go"
    click SecretsCTRL "https://github.com/DopplerHQ/cli/blob/master/pkg/controllers/secrets.go"
    click ProjectsCTRL "https://github.com/DopplerHQ/cli/blob/master/pkg/controllers/projects.go"
    click AnalyticsCTRL "https://github.com/DopplerHQ/cli/blob/master/pkg/controllers/analytics.go"
    click APIClient "https://github.com/DopplerHQ/cli/blob/master/pkg/http/api.go"
    click AnalyticsClient "https://github.com/DopplerHQ/cli/blob/master/pkg/http/analytics.go"
    click CoreConfig "https://github.com/DopplerHQ/cli/blob/master/pkg/configuration/config.go"
    click KeyringIntegration "https://github.com/DopplerHQ/cli/blob/master/pkg/configuration/keyring.go"
    click APIModels "https://github.com/DopplerHQ/cli/blob/master/pkg/models/api.go"
    click ConfigModels "https://github.com/DopplerHQ/cli/blob/master/pkg/models/config.go"
    click SecretsModels "https://github.com/DopplerHQ/cli/blob/master/pkg/models/secrets_format.go"
    click TUI "https://github.com/DopplerHQ/cli/blob/master/pkg/tui/gui/gui.go"
    click EnvUtils "https://github.com/DopplerHQ/cli/blob/master/pkg/utils/env.go"
    click IOOps "https://github.com/DopplerHQ/cli/blob/master/pkg/utils/io.go"
    click Logging "https://github.com/DopplerHQ/cli/blob/master/pkg/utils/log.go"
    click AES "https://github.com/DopplerHQ/cli/blob/master/pkg/crypto/aes.go"
    click CryptoUtils "https://github.com/DopplerHQ/cli/blob/master/pkg/crypto/util.go"

    %% Styling
    classDef ui fill:#9370DB,stroke:#333,stroke-width:2px
    classDef cmd fill:#4169E1,stroke:#333,stroke-width:2px
    classDef controller fill:#1E90FF,stroke:#333,stroke-width:2px
    classDef service fill:#20B2AA,stroke:#333,stroke-width:2px
    classDef security fill:#FFD700,stroke:#333,stroke-width:2px
    classDef util fill:#A9A9A9,stroke:#333,stroke-width:2px
    classDef model fill:#98FB98,stroke:#333,stroke-width:2px
    classDef external fill:#F08080,stroke:#333,stroke-width:2px
```
