# unit-mesh/autodev-vscode architecture

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

- Interactive diagram: https://gitdiagram.com/unit-mesh/autodev-vscode
- Repository: https://github.com/unit-mesh/autodev-vscode

## Overview

##### Project Type & Purpose
- This is a full-stack VSCode extension (“AutoDev for VSCode”) comprising:
- A Node/TypeScript extension backend running in the VSCode Extension Host
- A React-based webview UI (“gui-sidebar”) served by the extension
- Multiple core subsystems (code-search, code-context, prompt management, AI agent flows)
- Integration with external LLM and embedding services (OpenAI, Ollama, local ONNX)
- Persistence layers for indexing/search (SQLite, LanceDB, optionally ElasticSearch)
- Purpose: provide AI-powered coding assistance (chat mode, code completion, auto-doc, refactoring, RAG search, CI generation, test generation, etc.)

##### Key Architectural Layers & Modules
- VSCode Host Layer
- VSCode Editor UI & API
- Extension Host (Node.js)
- Webview UI Layer (“gui-sidebar”)
- React Components, Redux store, Webview messaging bridge
- Extension Core Layer (src/)
- Activation & command registration (extension.ts, commands/)
- Action subsystem (src/action): ActionCreators, ActionExecutors, code-action providers
- Agent subsystem (src/agent): built-in flows, catalyser, custom agent connectors
- Code-Context subsystem (src/code-context): Tree-Sitter parsing, relevant-code providers, structurer/test-gen providers
- Code-Search subsystem (src/code-search): chunking, indexing, embedding, retrieval, reranking, semantic/TfIdf search, scope graph
- Prompt Management (src/prompt-manage): template loading, overrides, custom/team prompts, execution tasks
- Toolchain Context (src/toolchain-context): detect languages, frameworks, build tools, dependency inspectors
- Configuration & Services (src/base/common): configurationService, instantiation, logging, lifecycle, webview helper
- Domain & Utility modules: query expansion, team terms, git parsing, markdown processing
- Persistence & External Services
- Local DB (SQLite via SqliteDb), LanceDB, optional ElasticSearch
- LLM & Embedding APIs (OpenAI, Ollama, Anthropic, local ONNX via onnxruntime-node)

##### Relationships & Data Flows
- User triggers UI command (keyboard shortcut, sidebar button)
- VSCode forwards to Extension Host → CommandService → ActionCreator
- ActionCreator builds TemplateContext via PromptManager and potentially ToolchainContext
- Extension invokes Code-Search and/or Code-Context services to gather code snippets/context
- PromptManager constructs prompt → passed to LLM provider (external API or local inferencing)
- LLM response returned → ActionExecutor applies edits/refactoring/generation via VSCode API
- For webview flows: React UI sends message → Extension Host handles via webviewViewProvider → processes similarly → sends back result → React renders

##### Architectural Patterns
- Modular “Service” & “Provider” pattern: each domain (code-search, code-context, toolchain) has manager/service + provider implementations
- Dependency Injection via instantiationService (in src/base/common/instantiation)
- Template Method & Strategy for search strategies (Hyde, TfIdf, semantic) and chunkers
- Adapter layers for LLM providers, embedding providers, and build tool providers

##### Detail & Clarity
- Optionally, annotate key interfaces (e.g., ICodeContextProvider, IEmbeddingsProvider)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    EditorUI["VSCode Editor UI"]:::ui
    WebviewSidebar["Webview Sidebar<br/>(React + Redux)"]:::ui

    %% Extension Host
    subgraph "VSCode Extension Host (Node.js/TS)"
        Activation["Commands & Activation"]:::core
        ActionSub["Action Subsystem"]:::core
        AgentSub["Agent Subsystem"]:::core
        CodeContextSub["Code-Context Subsystem"]:::core
        CodeSearchSub["Code-Search Subsystem"]:::core
        PromptManageSub["Prompt Management"]:::core
        ToolchainSub["Toolchain Context"]:::core
        CommonUtil["Common Utilities & ConfigService"]:::core
    end

    %% Persistence Layer
    Database[(SQLite / LanceDB / ElasticSearch)]:::persistence

    %% External Services
    subgraph "External LLM & Embedding Services"
        OpenAI["OpenAI API"]:::external
        Ollama["Ollama"]:::external
        Anthropic["Anthropic"]:::external
        ONNX["Local ONNX"]:::external
    end

    %% Connections
    EditorUI -->|keyboard shortcut<br/>or command| Activation
    Activation -->|"trigger action"| ActionSub
    ActionSub -->|"uses providers"| CodeSearchSub
    ActionSub -->|"uses providers"| CodeContextSub
    ActionSub -->|"invoke prompts"| PromptManageSub
    PromptManageSub -->|"HTTP/gRPC"| OpenAI
    PromptManageSub -->|"HTTP/gRPC"| Ollama
    PromptManageSub -->|"HTTP/gRPC"| Anthropic
    PromptManageSub -->|"Local inference"| ONNX
    CodeSearchSub -->|"SQL queries / LanceDB API"| Database
    CodeContextSub -->|"SQL queries / LanceDB API"| Database
    WebviewSidebar <-->|"postMessage"| CommonUtil
    CommonUtil -->|"VSCode Command API"| Activation
    OpenAI -->|"response payload"| ActionSub
    Ollama -->|"response payload"| ActionSub
    Anthropic -->|"response payload"| ActionSub
    ONNX -->|"response payload"| ActionSub

    %% Click Events
    click Activation "https://github.com/unit-mesh/autodev-vscode/blob/master/src/extension.ts"
    click ActionSub "https://github.com/unit-mesh/autodev-vscode/tree/master/src/action/_base"
    click AgentSub "https://github.com/unit-mesh/autodev-vscode/tree/master/src/agent/builtin"
    click CodeContextSub "https://github.com/unit-mesh/autodev-vscode/tree/master/src/code-context/_base"
    click CodeSearchSub "https://github.com/unit-mesh/autodev-vscode/tree/master/src/code-search/chunk"
    click PromptManageSub "https://github.com/unit-mesh/autodev-vscode/blob/master/src/prompt-manage/PromptManager.ts"
    click ToolchainSub "https://github.com/unit-mesh/autodev-vscode/blob/master/src/toolchain-context/ToolchainContextManager.ts"
    click CommonUtil "https://github.com/unit-mesh/autodev-vscode/tree/master/src/base/common/configuration"
    click Database "https://github.com/unit-mesh/autodev-vscode/blob/master/src/code-search/database/SqliteDb.ts"
    click OpenAI "https://github.com/unit-mesh/autodev-vscode/blob/master/src/base/common/language-models/providers/openaiProvider.ts"
    click Ollama "https://github.com/unit-mesh/autodev-vscode/blob/master/src/base/common/language-models/providers/ollamaProvider.ts"
    click Anthropic "https://github.com/unit-mesh/autodev-vscode/blob/master/src/base/common/language-models/providers/anthropicProvider.ts"
    click ONNX "https://github.com/unit-mesh/autodev-vscode/tree/master/vendors/onnxruntime-node"
    click WebviewSidebar "https://github.com/unit-mesh/autodev-vscode/tree/master/gui-sidebar/src"

    %% Styles
    classDef ui fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1
    classDef core fill:#C8E6C9,stroke:#1B5E20,color:#1B5E20
    classDef persistence fill:#FFE0B2,stroke:#E65100,color:#E65100
    classDef external fill:#E1BEE7,stroke:#4A148C,color:#4A148C
```
