# htoooth/qwen-code architecture

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

- Interactive diagram: https://gitdiagram.com/htoooth/qwen-code
- Repository: https://github.com/htoooth/qwen-code

## Overview

##### Project type and purpose
- Qwen Code is a monorepo-style developer tool—a Node.js/TypeScript CLI application with an accompanying core library and VS Code extension.
- Purpose: Provide interactive AI-driven code understanding, editing, and workflow automation via Qwen3-Coder models and an enhanced parser.

##### File structure
Top-level folders and files:
- scripts/, Makefile, Dockerfile, .github/, .aoneci/, .gcp/ → build & CI/CD pipelines
- docs/ → architecture, CLI tutorials, troubleshooting
- integration-tests/ → end-to-end tests of CLI tools
- packages/
– cli/ → user-facing command-line interface (Ink/React in terminal, commands, config, sandbox utils)
– core/ → AI integration (model client), tool scheduler/registry, built-in tools (fs, shell, web-fetch, memory), services (file discovery, git, telemetry)
– vscode-ide-companion/ → VS Code extension host + IDE server bridging to core
- root config (tsconfig.json, esbuild.config.js, eslint.config.js)

##### Extract architecture insights from README & docs
- Layered CLI ↔ Core boundary: CLI package handles UI, input parsing, presentation; Core package handles business logic, tool orchestration, AI requests, telemetry.
- Tools are pluggable modules registered centrally and invoked by the Core tool scheduler.
- Sandbox isolation profiles for macOS to securely invoke host tools.
- CI/CD uses GitHub Actions, aoneci, and GCP build/release to produce Docker images and NPM packages.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        direction TB
        CLIEntry["CLI Entry Point"]:::ui
        CLIUI["CLI UI (Ink/React)"]:::ui
        CommandService["Command Service"]:::ui
        ConfigAuth["Config & Auth"]:::ui
        SandboxUtils["Sandbox Utilities"]:::tools
    end

    CLIEntry -->|"bootstraps"| CLIUI
    CLIUI -->|"invokes"| CommandService
    CommandService -->|"loads"| ConfigAuth
    CommandService -->|"uses"| SandboxUtils

    click CLIEntry "https://github.com/htoooth/qwen-code/blob/main/packages/cli/index.ts"
    click CLIEntry "https://github.com/htoooth/qwen-code/blob/main/packages/cli/src/nonInteractiveCli.ts"
    click CLIUI "https://github.com/htoooth/qwen-code/tree/main/packages/cli/src/ui"
    click CommandService "https://github.com/htoooth/qwen-code/blob/main/packages/cli/src/services/CommandService.ts"
    click ConfigAuth "https://github.com/htoooth/qwen-code/blob/main/packages/cli/src/config/config.ts"
    click ConfigAuth "https://github.com/htoooth/qwen-code/blob/main/packages/cli/src/config/auth.ts"
    click ConfigAuth "https://github.com/htoooth/qwen-code/blob/main/packages/cli/src/config/settings.ts"
    click ConfigAuth "https://github.com/htoooth/qwen-code/blob/main/packages/cli/src/config/extension.ts"
    click ConfigAuth "https://github.com/htoooth/qwen-code/blob/main/packages/cli/src/config/sandboxConfig.ts"
    click SandboxUtils "https://github.com/htoooth/qwen-code/blob/main/packages/cli/src/utils/sandbox.ts"
    click SandboxUtils "https://github.com/htoooth/qwen-code/blob/main/packages/cli/src/utils/sandbox-macos-*.sb"

    %% Core Library
    subgraph "Core Library" 
        direction TB
        CoreIndex["Core Library Index"]:::core
        AIClient["AI Client"]:::core
        ToolScheduler["Tool Scheduler & Registry"]:::core
        subgraph "Built-in Tools"
            direction TB
            ReadFile["read-file"]:::tools
            WriteFile["write-file"]:::tools
            ReadMany["read-many-files"]:::tools
            LS["ls"]:::tools
            Glob["glob"]:::tools
            Grep["grep"]:::tools
            ShellTool["shell"]:::tools
            WebFetch["web-fetch"]:::tools
            WebSearch["web-search"]:::tools
            MemoryTool["memory"]:::tools
        end
        subgraph "Core Services"
            direction TB
            FileDiscovery["fileDiscovery"]:::core
            GitService["gitService"]:::core
            LoopDetection["loopDetection"]:::core
        end
        TelemetryCore["Telemetry"]:::core
    end

    CommandService -->|"calls"| CoreIndex
    CoreIndex -->|"orchestrates"| ToolScheduler
    ToolScheduler -->|"registers/invokes"| ReadFile
    ToolScheduler --> WriteFile
    ToolScheduler --> ReadMany
    ToolScheduler --> LS
    ToolScheduler --> Glob
    ToolScheduler --> Grep
    ToolScheduler --> ShellTool
    ToolScheduler --> WebFetch
    ToolScheduler --> WebSearch
    ToolScheduler --> MemoryTool
    CoreIndex --> AIClient
    CoreIndex --> FileDiscovery
    CoreIndex --> GitService
    CoreIndex --> LoopDetection
    CoreIndex --> TelemetryCore

    click CoreIndex "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/index.ts"
    click AIClient "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/core/client.ts"
    click AIClient "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/core/geminiChat.ts"
    click AIClient "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/core/geminiRequest.ts"
    click AIClient "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/core/openaiContentGenerator.ts"
    click ToolScheduler "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/core/coreToolScheduler.ts"
    click ToolScheduler "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/tools/tool-registry.ts"
    click ReadFile "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/tools/read-file.ts"
    click WriteFile "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/tools/write-file.ts"
    click ReadMany "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/tools/read-many-files.ts"
    click LS "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/tools/ls.ts"
    click Glob "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/tools/glob.ts"
    click Grep "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/tools/grep.ts"
    click ShellTool "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/tools/shell.ts"
    click WebFetch "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/tools/web-fetch.ts"
    click WebSearch "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/tools/web-search.ts"
    click MemoryTool "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/tools/memoryTool.ts"
    click FileDiscovery "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/services/fileDiscoveryService.ts"
    click GitService "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/services/gitService.ts"
    click LoopDetection "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/services/loopDetectionService.ts"
    click TelemetryCore "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/telemetry/index.ts"
    click TelemetryCore "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts"
    click TelemetryCore "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/telemetry/loggers.ts"
    click TelemetryCore "https://github.com/htoooth/qwen-code/blob/main/packages/core/src/telemetry/metrics.ts"

    %% Sandbox & Local Environment
    subgraph "Sandbox Isolation" 
        direction TB
        Sandbox["macOS Sandbox"]:::tools
        subgraph "Local Environment"
            direction TB
            FileSystem["File System"]:::tools
            Shell["Shell"]:::tools
            Network["Network"]:::tools
        end
    end

    ToolScheduler --> Sandbox
    Sandbox --> FileSystem
    Sandbox --> Shell
    Sandbox --> Network

    %% VS Code Extension
    subgraph "VS Code Extension"
        direction TB
        ExtensionHost["Extension Host"]:::ui
        IDEServer["IDE Server (IPC/HTTP)"]:::ui
    end

    IDEServer -->|"IPC/HTTP"| CoreIndex
    click ExtensionHost "https://github.com/htoooth/qwen-code/blob/main/packages/vscode-ide-companion/src/extension.ts"
    click IDEServer "https://github.com/htoooth/qwen-code/blob/main/packages/vscode-ide-companion/src/ide-server.ts"

    %% External Services
    QwenAPI["Qwen API Endpoint"]:::external
    TelemetryEndpoint["Telemetry Endpoint (GCP)"]:::external

    AIClient -->|"HTTP"| QwenAPI
    TelemetryCore -->|"HTTP"| TelemetryEndpoint

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        direction TB
        GitHubActions["GitHub Actions"]:::pipeline
        AoneCI["AoneCI"]:::pipeline
        GCPBuild["GCP Build & Docker"]:::pipeline
    end

    GitHubActions --> GCPBuild
    AoneCI --> GCPBuild

    click GitHubActions "https://github.com/htoooth/qwen-code/blob/main/.github/workflows/ci.yml"
    click AoneCI "https://github.com/htoooth/qwen-code/blob/main/.aoneci/workflows/ci.yml"
    click GCPBuild "https://github.com/htoooth/qwen-code/blob/main/.gcp/Dockerfile.gemini-code-builder"
    click GCPBuild "https://github.com/htoooth/qwen-code/blob/main/.gcp/release-docker.yaml"

    %% Styles
    classDef ui fill:#ffcc80,stroke:#e65100
    classDef core fill:#c8e6c9,stroke:#2e7d32
    classDef tools fill:#e0e0e0,stroke:#424242
    classDef external fill:#90caf9,stroke:#1565c0
    classDef pipeline fill:#ce93d8,stroke:#6a1b9a
```
