# roovetgit/roo-code architecture

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

- Interactive diagram: https://gitdiagram.com/roovetgit/roo-code
- Repository: https://github.com/roovetgit/roo-code

## Overview

##### Project type and purpose
- Roo Code is an open-source VS Code extension paired with a React-based webview UI.
- It acts as an “autonomous coding agent,” orchestrating workspace file I/O, terminal commands, browser automation, and AI‐powered code assistance via pluggable model providers (OpenAI, Anthropic, Bedrock, etc.).
- The repo also contains an “evals” monorepo (CLI + Next.js web app) for benchmarking tasks, plus end-to-end and unit tests.

##### File structure
- Top‐level “src/” holds the extension’s TypeScript code (activate, api, core, services, integrations, tools).
- “webview-ui/” is a standalone Vite/React app delivering the in-editor chat interface.
- “evals/” is a separate workspace for CLI and Web evaluation apps.
- “e2e/” contains integration tests that spin up VS Code and drive the extension+webview.
- Configuration manifests include tsconfig.json, package.json, .github/workflows, changesets, pnpm/turbo configs.

##### README for additional insights
- Describes key features (modes, tools, MCP).
- Mentions extension host vs webview separation and external API/provider integrations.

##### Main components
a. VS Code Host & Extension Host Process
- “extension.ts” loads on activation.
- Core controllers (activate/handleTask, registerCommands, webviewMessageHandler).
- Service modules: file I/O, terminal (Execa), browser automation, tree-sitter, MCP server manager, telemetry (PostHog).
- API providers layer: fetchers + provider adapters for OpenAI, Anthropic, etc.
- Task persistence & checkpoint services.
b. Webview UI (React + Vite)
- Host: webview tab inside VS Code.
- UI components (chat view, settings, history).
- Context providers (React-Query, theme, translation).
- Messaging bridge (vs code postMessage ↔ extension).
c. External Dependencies
- AI provider endpoints (OpenAI, Anthropic, Vertex, custom OpenRouter).
- Optional MCP servers/agents (Model Context Protocol).
- Telemetry backend (PostHog).
d. Test Harnesses
- E2E: launches VS Code with extension + webview, drives commands via Webdriver.
- Unit tests: Jest/Vitest for core modules, providers, integrations.

##### Component interactions & data flow
- User interacts with the Chat UI → React dispatches a “sendPrompt” message → VS Code webviewMessageHandler receives it.
- Extension’s core logic assembles a tool-enabled prompt, picks a provider adapter → calls external AI API over HTTPS → receives streamed response.
- Response is transformed by the api/transform layer → sent back to Webview via postMessage → rendered in the chat UI.
- If file read/write or terminal commands are needed, core modules (services/fs, services/terminal, core/tools) execute them in the workspace.
- TelemetryService logs events to PostHog.
- CheckpointService persists intermediate states on disk.
- Custom Modes & MCP server modules allow plugging in additional capabilities via IPC or HTTP.

##### Architectural patterns & principles
- Layered & modular: Presentation (webview UI) ↔ Application core (extension host) ↔ Infrastructure (services, external APIs).
- Plugin architecture for AI providers (api/providers/) and tools (core/tools/).
- Event‐driven messaging between UI and extension host.
- Monorepo structure (pnpm workspaces + Turbo) for isolation of “evals” subproject and shared packages.

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Extension Host Layer
  subgraph "Extension Host" 
    direction TB
    EP["Extension Entry Point\nsrc/extension.ts"]:::extension
    AC["Activation & Commands\nindex.ts, registerCommands.ts, handleTask.ts"]:::extension
    WMH["Webview Message Handler\nwebviewMessageHandler.ts"]:::extension
    subgraph "Services & Integrations"
      direction TB
      FIO["File I/O Service\nopen-file.ts, fs.ts"]:::extension
      TERM["Terminal Integration\nExecaTerminal.ts, TerminalRegistry.ts"]:::extension
      BROWSER["Browser Automation\nBrowserSession.ts"]:::extension
      TSITTER["Tree-sitter Service\nindex.ts"]:::extension
      MCPM["MCP Server Manager\nMcpServerManager.ts"]:::extension
      TELE["Telemetry Service\nTelemetryService.ts"]:::extension
      CP["Checkpoint Services\nShadowCheckpointService.ts, RepoPerTaskCheckpointService.ts"]:::extension
    end
    subgraph "API Layer"
      direction TB
      PROVIDERS["AI Providers\nsrc/api/providers/"]:::extension
      TRANSFORM["API Transform\nsrc/api/transform/"]:::extension
    end
    subgraph "Core Tools"
      direction TB
      TOOLS["Prompt-enabled Tools\nsrc/core/tools/"]:::extension
    end
  end

  %% Webview UI Layer
  subgraph "Webview UI" 
    direction TB
    UI_APP["App.tsx"]:::webview
    subgraph "Chat Components"
      direction TB
      CHATVIEW["ChatView.tsx"]:::webview
      CHATROW["ChatRow.tsx"]:::webview
      CHATINPUT["ChatTextArea.tsx"]:::webview
    end
    subgraph "Panels"
      direction TB
      SETTINGS["SettingsView.tsx"]:::webview
      HISTORY["HistoryView.tsx"]:::webview
    end
    subgraph "Context Providers"
      direction TB
      RQ["react-query-provider.tsx"]:::webview
      THEME["theme-provider.tsx"]:::webview
      I18N["TranslationContext.tsx"]:::webview
    end
    UTIL["UI Messaging Utils\nvscode.ts"]:::webview
  end

  %% External Dependencies
  subgraph "External Services" 
    direction TB
    AI_OPENAI["OpenAI API"]:::external
    AI_ANTHROPIC["Anthropic API"]:::external
    AI_BEDROCK["Bedrock API"]:::external
    AI_VERTEX["Vertex API"]:::external
    AI_ROUTER["OpenRouter"]:::external
    MCP_SERVER["MCP Servers"]:::external
    POSTHOG["PostHog Telemetry"]:::external
  end

  %% Test Harnesses
  subgraph "Test & Evals" 
    direction TB
    E2E["E2E Tests\nrunTest.ts, suite/*.ts"]:::test
    UNIT["Unit Tests\n__tests__"]:::test
    EVALS["Evals Monorepo\napps/cli, apps/web"]:::test
  end

  %% Connections
  CHATVIEW -->|postMessage sendPrompt| WMH
  CHATINPUT -->|postMessage sendPrompt| WMH
  WMH -->|invoke| TOOLS
  WMH -->|uses| FIO
  WMH -->|uses| TERM
  WMH -->|uses| BROWSER
  WMH -->|uses| TSITTER
  WMH -->|uses| MCPM
  WMH -->|logs| TELE
  WMH -->|persists| CP
  WMH -->|calls| PROVIDERS
  PROVIDERS -->|fetches| TRANSFORM
  PROVIDERS -->|HTTPS| AI_OPENAI
  PROVIDERS -->|HTTPS| AI_ANTHROPIC
  PROVIDERS -->|HTTPS| AI_BEDROCK
  PROVIDERS -->|HTTPS| AI_VERTEX
  PROVIDERS -->|HTTPS| AI_ROUTER
  MCPM -->|IPC/HTTP| MCP_SERVER
  TELE -->|HTTP| POSTHOG
  WMH -->|postMessage response| CHATVIEW

  E2E -->|drives| EP
  E2E -->|drives| UI_APP
  UNIT -->|tests| EP
  UNIT -->|tests| PROVIDERS
  UNIT -->|tests| TOOLS
  EVALS -.->|separate context| EP

  %% Click Events
  click EP "https://github.com/roovetgit/roo-code/blob/main/src/extension.ts"
  click AC "https://github.com/roovetgit/roo-code/blob/main/src/activate/index.ts"
  click AC "https://github.com/roovetgit/roo-code/blob/main/src/activate/registerCommands.ts"
  click AC "https://github.com/roovetgit/roo-code/blob/main/src/activate/handleTask.ts"
  click WMH "https://github.com/roovetgit/roo-code/blob/main/src/core/webview/webviewMessageHandler.ts"
  click FIO "https://github.com/roovetgit/roo-code/blob/main/src/integrations/misc/open-file.ts"
  click FIO "https://github.com/roovetgit/roo-code/blob/main/src/utils/fs.ts"
  click TERM "https://github.com/roovetgit/roo-code/blob/main/src/integrations/terminal/ExecaTerminal.ts"
  click TERM "https://github.com/roovetgit/roo-code/blob/main/src/integrations/terminal/TerminalRegistry.ts"
  click BROWSER "https://github.com/roovetgit/roo-code/blob/main/src/services/browser/BrowserSession.ts"
  click TSITTER "https://github.com/roovetgit/roo-code/blob/main/src/services/tree-sitter/index.ts"
  click MCPM "https://github.com/roovetgit/roo-code/blob/main/src/services/mcp/McpServerManager.ts"
  click TELE "https://github.com/roovetgit/roo-code/blob/main/src/services/telemetry/TelemetryService.ts"
  click PROVIDERS "https://github.com/roovetgit/roo-code/tree/main/src/api/providers/"
  click TRANSFORM "https://github.com/roovetgit/roo-code/tree/main/src/api/transform/"
  click CP "https://github.com/roovetgit/roo-code/blob/main/src/services/checkpoints/ShadowCheckpointService.ts"
  click CP "https://github.com/roovetgit/roo-code/blob/main/src/services/checkpoints/RepoPerTaskCheckpointService.ts"
  click TOOLS "https://github.com/roovetgit/roo-code/tree/main/src/core/tools/"
  click UI_APP "https://github.com/roovetgit/roo-code/blob/main/webview-ui/src/App.tsx"
  click CHATVIEW "https://github.com/roovetgit/roo-code/blob/main/webview-ui/src/components/chat/ChatView.tsx"
  click CHATROW "https://github.com/roovetgit/roo-code/blob/main/webview-ui/src/components/chat/ChatRow.tsx"
  click CHATINPUT "https://github.com/roovetgit/roo-code/blob/main/webview-ui/src/components/chat/ChatTextArea.tsx"
  click SETTINGS "https://github.com/roovetgit/roo-code/blob/main/webview-ui/src/components/settings/SettingsView.tsx"
  click HISTORY "https://github.com/roovetgit/roo-code/blob/main/webview-ui/src/components/history/HistoryView.tsx"
  click RQ "https://github.com/roovetgit/roo-code/blob/main/webview-ui/src/components/providers/react-query-provider.tsx"
  click THEME "https://github.com/roovetgit/roo-code/blob/main/webview-ui/src/components/providers/theme-provider.tsx"
  click I18N "https://github.com/roovetgit/roo-code/blob/main/webview-ui/src/i18n/TranslationContext.tsx"
  click UTIL "https://github.com/roovetgit/roo-code/blob/main/webview-ui/src/utils/vscode.ts"
  click E2E "https://github.com/roovetgit/roo-code/blob/main/e2e/src/runTest.ts"
  click EVALS "https://github.com/roovetgit/roo-code/blob/main/evals/apps/cli/src/index.ts"
  click EVALS "https://github.com/roovetgit/roo-code/blob/main/evals/apps/web/src/app/page.tsx"

  %% Styles
  classDef extension fill:#e0f7e9,stroke:#2e7d32,stroke-width:2px
  classDef webview fill:#e3f2fd,stroke:#1565c0,stroke-width:2px
  classDef external fill:#fff3e0,stroke:#ef6c00,stroke-width:2px
  classDef test fill:#eceff1,stroke:#607d8b,stroke-width:2px
```
