# platformsh/cli architecture

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

## Overview

##### Main Components

a. Core CLI Application
- Command Layer (under /commands)
- Internal Services Layer (under /internal)
- Package Layer (under /pkg)

b. Legacy System
- PHP Embedded Runtime (under /internal/legacy)
- PHP Archives and Configurations

c. External Integration Points
- Platform.sh API Integration
- Authentication System
- Package Distribution Systems (Homebrew, Scoop, etc.)

**┌─ Distribution Layer ─────────────────────┐**
- Homebrew │ Scoop │ APT │ YUM │ Installer │
- ┘
- ↓
**┌─ CLI Core Layer ──────────────────────────────┐**
- ┌─ Command Interface ─┐                       │
- Root Command     │                       │
- List Command     │      Configuration    │
- Version Command  │←──── Management       │
- Help Command     │      (/internal/config)│
- ┬─┘                       │
- ↓                         │
- ┌─ Internal Services ─────────────────────┐   │
- State Management │ Update Service      │   │
- MD Processing    │ Mock API (for dev)  │   │
- ┘   │
- ┘
- ↓
**┌─ Legacy Support Layer ────────────────────────┐**
- ┌─ PHP Runtime ─────┐ ┌─ Platform Support ─┐  │
- Windows Support   │ │ Darwin AMD64       │  │
- Linux Support     │ │ Darwin ARM64       │  │
- Unix Common       │ │ Linux AMD64/ARM    │  │
- ┬─┘ └──────────────────┬┘  │
- ┘
- ↓                    ↓
**┌─ External Services Layer ──────────────────────┐**
- Platform.sh API │ Authentication Service    │
- ┘

##### Important Elements to Highlight

a. Cross-Platform Support
- Different runtime paths for Windows/Linux/Darwin
- Architecture-specific components (AMD64/ARM)

b. Legacy Integration
- PHP embedding mechanism
- Configuration templates and archives

c. Command Structure
- Hierarchical command organization
- Relationship to internal services

##### Technical Details

- Go modules and package structure
- Configuration file locations and formats
- Build artifact generation paths
- Extension system integration points

##### The configuration management system

This structure reflects both the modern Go-based CLI tool and its ability to maintain backwards compatibility with PHP-based functionality, which is a key feature of this project.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Distribution
        HB[Homebrew]
        SC[Scoop]
        APT[APT]
        YUM[YUM]
        INS[Installer]:::installer
    end

    subgraph CLI
        subgraph Commands
            RC[Root Command]:::command
            LC[List Command]:::command
            VC[Version Command]:::command
            HC[Help Command]:::command
        end

        subgraph Internal
            CFG[Configuration Management]:::config
            SM[State Management]:::internal
            MD[MD Processing]:::internal
            US[Update Service]:::internal
            MOCK[Mock API]:::mock
        end
    end

    subgraph Legacy
        subgraph "PHP Runtime"
            WIN[Windows Support]:::legacy
            LIN[Linux Support]:::legacy
            UNIX[Unix Common]:::legacy
        end

        subgraph "Platform Support"
            DAMD[Darwin AMD64]:::legacy
            DARM[Darwin ARM64]:::legacy
            LAMD[Linux AMD64/ARM]:::legacy
        end

        PHPC[PHP Config Templates]:::legacy
    end

    subgraph External
        API[Platform.sh API]:::external
        AUTH[Authentication Service]:::external
    end

    %% Relationships
    HB & SC & APT & YUM & INS --> RC
    RC --> LC & VC & HC
    RC --> CFG
    CFG --> SM
    SM --> MD
    US --> MOCK
    MOCK --> API

    WIN & LIN & UNIX --> PHPC
    DAMD & DARM & LAMD --> API
    API --> AUTH

    %% Click Events
    click RC "https://github.com/platformsh/cli/blob/main/commands/root.go"
    click LC "https://github.com/platformsh/cli/blob/main/commands/list.go"
    click VC "https://github.com/platformsh/cli/blob/main/commands/version.go"
    click HC "https://github.com/platformsh/cli/blob/main/commands/help.go"
    click CFG "https://github.com/platformsh/cli/tree/main/internal/config"
    click SM "https://github.com/platformsh/cli/blob/main/internal/state/state.go"
    click MD "https://github.com/platformsh/cli/blob/main/internal/md/builder.go"
    click US "https://github.com/platformsh/cli/blob/main/internal/update.go"
    click MOCK "https://github.com/platformsh/cli/tree/main/pkg/mockapi"
    click WIN "https://github.com/platformsh/cli/blob/main/internal/legacy/php_windows.go"
    click LIN "https://github.com/platformsh/cli/blob/main/internal/legacy/php_linux_amd64.go"
    click UNIX "https://github.com/platformsh/cli/blob/main/internal/legacy/php_unix.go"
    click DAMD "https://github.com/platformsh/cli/blob/main/internal/legacy/php_darwin_amd64.go"
    click DARM "https://github.com/platformsh/cli/blob/main/internal/legacy/php_darwin_arm64.go"
    click PHPC "https://github.com/platformsh/cli/blob/main/internal/legacy/archives/windows_php.ini.tpl"
    click INS "https://github.com/platformsh/cli/blob/main/installer.sh"

    %% Styles
    classDef command fill:#2374ab
    classDef config fill:#2374ab,stroke:#333
    classDef internal fill:#2374ab,stroke-dasharray: 5 5
    classDef legacy fill:#ff7f50
    classDef external fill:#48a14d
    classDef mock fill:#2374ab,stroke-width:3px
    classDef installer fill:#gray

    %% Legend
    subgraph Legend
        L1[CLI Components]:::command
        L2[Legacy Components]:::legacy
        L3[External Services]:::external
    end
```
