# shopify/cli architecture

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

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

## Overview

##### Project type and purpose
- This is a monorepo for a Node-based CLI tool (Shopify CLI 3.0) implemented with oclif, Nx (pnpm-workspace), TypeScript, and Vite.
- Its purpose is to provide a single “shopify” executable that can initialize, build, develop, test, deploy, and manage Shopify apps, extensions, themes, functions, and custom storefronts.

##### File structure
- Top-level tooling:
- nx.json, pnpm-workspace.yaml – orchestrate multi-package workflow
- tsconfig.json, vite.config.ts – shared TypeScript + bundler configuration
- Key packages under /packages:
- cli (the oclif launcher & command loader)
- cli-kit (shared UI, API-client, GraphQL codegen utilities)
- app, theme, create-app, plugin-cloudflare, plugin-did-you-mean, features, ui-extensions-* (command plugins & UIs)
- Each package has its own src/cli/commands, services, utilities, tests, project.json (Nx), and tsconfig files.
- bin/ contains top-level build & release scripts. .github/workflows drive CI/CD.

##### README for additional insights
- Confirms CLI commands (init, build, dev, deploy) for apps, themes, Hydrogen.
- Mentions extensibility (plugins).
- Points to oclif as the underlying framework.

##### Be detailed but avoid over-compartmentalizing
- Cover the monorepo structure, CLI core, plugin ecosystem, shared libs, API flows, dev server, external endpoints.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Monorepo Workspace
    subgraph "Monorepo Workspace" 
        direction TB
        NX["nx.json<br/>pnpm-workspace.yaml"]:::monorepo
        click NX "https://github.com/shopify/cli/blob/main//nx.json"
        click NX "https://github.com/shopify/cli/blob/main//pnpm-workspace.yaml"
        TS["tsconfig.json<br/>vite.config.ts"]:::monorepo
        click TS "https://github.com/shopify/cli/blob/main//tsconfig.json"
        click TS "https://github.com/shopify/cli/blob/main//vite.config.ts"
    end

    %% CLI Executable
    CLI["packages/cli<br/>Oclif Core"]:::core
    click CLI "https://github.com/shopify/cli/blob/main/packages/cli/src/cli/index.ts"
    click CLI "https://github.com/shopify/cli/blob/main/packages/cli/oclif.manifest.json"

    %% Shared Libraries
    Shared["packages/cli-kit<br/>Shared Utilities"]:::shared
    click Shared "https://github.com/shopify/cli/tree/main/packages/cli-kit/src"

    %% Command Plugins
    subgraph "Command Plugins" 
        direction TB
        App["App Plugin"]:::plugin
        click App "https://github.com/shopify/cli/tree/main/packages/app/src/cli/commands/app"
        click App "https://github.com/shopify/cli/tree/main/packages/app/src/cli/api/graphql"
        Theme["Theme Plugin"]:::plugin
        click Theme "https://github.com/shopify/cli/tree/main/packages/theme/src/cli/commands/theme"
        click Theme "https://github.com/shopify/cli/tree/main/packages/theme/src/cli/services"
        CreateApp["Create-App Plugin"]:::plugin
        click CreateApp "https://github.com/shopify/cli/blob/main/packages/create-app/src/index.ts"
        Cloudflare["Cloudflare Plugin"]:::plugin
        click Cloudflare "https://github.com/shopify/cli/tree/main/packages/plugin-cloudflare/src"
        DidYouMean["Did-You-Mean Plugin"]:::plugin
        click DidYouMean "https://github.com/shopify/cli/tree/main/packages/plugin-did-you-mean/src"
        UIExtDev["UI Extensions Dev Console"]:::ui
        click UIExtDev "https://github.com/shopify/cli/tree/main/packages/ui-extensions-dev-console/src"
        UIExtServer["UI Extensions Server Kit"]:::ui
        click UIExtServer "https://github.com/shopify/cli/tree/main/packages/ui-extensions-server-kit/src"
    end

    %% Runtime Services
    subgraph "Dev-mode Runtime Services"
        direction TB
        DevFlow["Vite Dev Server<br/>WebSocket"]:::runtime
        click DevFlow "https://github.com/shopify/cli/tree/main/packages/app/src/cli/services/dev"
        GraphiQL["GraphiQL Server"]:::runtime
        click GraphiQL "https://github.com/shopify/cli/tree/main/packages/app/src/cli/services/dev/graphiql"
        Proxy["Local Reverse Proxy"]:::runtime
        click Proxy "https://github.com/shopify/cli/blob/main/packages/app/src/cli/utilities/app/http-reverse-proxy.ts"
    end

    %% External Services
    subgraph "External Services"
        direction TB
        ShopifyAPI["Shopify Admin GraphQL APIs"]:::external
        PartnersAPI["Partners & Business-Platform APIs"]:::external
        Registries["Homebrew/NPM Registries"]:::external
    end

    %% Relationships
    NX --> CLI
    TS --> CLI
    CLI --> Shared
    CLI --> App
    CLI --> Theme
    CLI --> CreateApp
    CLI --> Cloudflare
    CLI --> DidYouMean
    CLI --> UIExtDev
    CLI --> UIExtServer

    App --> Shared
    Theme --> Shared
    CreateApp --> Shared
    Cloudflare --> Shared
    DidYouMean --> Shared
    UIExtDev --> Shared
    UIExtServer --> Shared

    App --> ShopifyAPI
    Theme --> ShopifyAPI
    Shared --> ShopifyAPI
    Shared --> PartnersAPI

    App --> DevFlow
    DevFlow --> GraphiQL
    DevFlow --> Proxy
    Proxy --> App

    CLI --> Registries

    %% Styles
    classDef monorepo fill:#D6E9F8,stroke:#6EA8DC,color:#034EA2
    classDef core fill:#DFF0D8,stroke:#3C763D,color:#2B542C
    classDef shared fill:#F7F7D9,stroke:#E2D216,color:#8A6D3B
    classDef plugin fill:#D9EDF7,stroke:#31708F,color:#245269
    classDef runtime fill:#FCF8E3,stroke:#8A6D3B,color:#66512C
    classDef external fill:#FCF2F2,stroke:#B94A48,color:#A94442
    classDef ui fill:#F5E6FF,stroke:#A569BD,color:#5E2D79
```
