# zhdh2008/ui-tars-desktop architecture

> Architecture diagram of the GitHub repository zhdh2008/ui-tars-desktop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zhdh2008/ui-tars-desktop
- Repository: https://github.com/zhdh2008/ui-tars-desktop

## Overview

##### Main components
- Desktop Applications: There are two main “apps” (apps/agent-tars and apps/ui-tars). Agent TARS acts as a multimodal AI agent that integrates web page visual recognition, command line, and filesystem operations, whereas UI-TARS provides a GUI layer for natural language control.
- Electron Main Process: Both apps include an Electron “main” process that handles activities like creating windows, inter-process communications (IPC) via ipcRoutes, system-level operations (menus, file permissions, logging) and integrating with shared modules.
- Renderer/UI Process: The “renderer” directories under both apps contain the UI code (React with TSX), layout components, hooks, state management, and styling, forming the client-facing interface.
- Shared Libraries/Packages: The packages folder shows multiple libraries (agent-infra, common, ui-tars, etc.) that are used throughout the project. They include modules for logging, browser automation, agent actions, search functionalities, and more. They represent common infrastructure and utilities that both apps depend on.
- LLM Providers and Custom Tools: Notice the “llmProvider” and “customTools” directories in agent-tars. These define extensible interfaces and providers (like Anthropic, Azure OpenAI, Gemini, etc.) for interacting with large language models.
- IPC and Service Modules: Both the main and renderer sides have dedicated IPC route files (e.g., ipcRoutes) and service modules to facilitate communication between application parts, the operating system, and even external services.
- Deployment and Build Configurations: The presence of configuration files, build scripts (e.g., electron-builder.yml, vite configurations, forge configs), and GitHub workflows (in .github/workflows) indicate a well‐structured CI/CD and build process.

##### Relationships and interactions
- At the bottom, denote shared backend modules and external integrations such as:
▸ LLM providers (improving the AI capabilities) with their factory-pattern module (ProviderFactory.ts).
▸ File system operations, custom tools, and menu management.
▸ Shared libraries in the packages directory that support browser automation, logging, search functionalities, etc.
- From UI events triggered in the renderer to the main process via IPC (e.g., file permission requests, agent actions).
- From the main process to external services (like LLM providers or browser sessions) when invoking custom tools or fetching web information.
- From shared modules back to both main and renderer layers.

##### Architectural patterns and components
- Modular separation: Distinct modules for UI, system integration, agent logic (LLM and custom tool execution), and shared libraries.
- Plugin/Provider model: Emphasize the pluggable LLM providers and custom tool mechanisms that support various AI integrations.
- Use of micro-frontends: Show that within the renderer process, different feature components (like ChatUI, CanvasPanel, and Sidebar) are organized modularly—enhancing maintainability.

##### Following technical details
- Technologies and frameworks: Electron, Node.js, React (TypeScript/TSX), Vite, and build tools like Electron Builder.
- Agent TARS (with its customTools, ipcRoutes, llmProvider, mcp, and preload modules).
- UI-TARS Desktop (with components for ChatUI, window management, renderer processes, and preload scripts).
- Shared packages (agent-infra, logger, search, common utilities).
- External integrations (LLM providers: OpenAI, Anthropic, etc.)
- Renderer → IPC → Main Process.
- Main Process → LLM Providers / File System Services.
- Modules communicating via shared libraries.

##### Be as detailed as possible
- Avoid oversimplification—focus on representing the critical interoperability between renderer, main process, and shared libraries.
- Note sections for any CI/CD or build configurations if relevant for understanding the system lifecycle.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Desktop Applications Layer
    subgraph "Desktop Applications"
        AgentApp["Agent TARS App"]:::deploy
        UITarsApp["UI-TARS Desktop App"]:::deploy
    end

    %% UI Layer
    subgraph "UI Layer"
        AR["Renderer Process (Agent TARS)"]:::ui
        UR["Renderer Process (UI-TARS)"]:::ui
    end

    %% Backend (Electron Main Process)
    subgraph "Backend (Electron Main Process)"
        subgraph "Agent TARS Backend"
            AM["Electron Main Process (Agent TARS)"]:::main
            AIPC["IPC Routes (Agent TARS)"]:::main
            ALLM["LLM Providers (Agent TARS)"]:::backend
            ACT["Custom Tools (Agent TARS)"]:::backend
        end
        subgraph "UI-TARS Backend"
            UM["Electron Main Process (UI-TARS)"]:::main
            UIPC["IPC Routes (UI-TARS)"]:::main
        end
    end

    %% Shared Modules & Integrations
    subgraph "Shared Modules & Integrations"
        SPI["Electron IPC (Shared Integration)"]:::shared
        SL["Shared Libraries/Packages"]:::shared
    end

    %% Deployment & Build Configurations
    DBC["Deployment & Build Configurations"]:::deploy

    %% Connections between Desktop Applications and UI Layer
    AgentApp --> AR
    UITarsApp --> UR

    %% UI to Backend communication (IPC channel)
    AR -->|"IPC"| AM
    UR -->|"IPC"| UM

    %% Agent TARS Backend internal flows
    AM -->|"routes"| AIPC
    AM -->|"LLM calls"| ALLM
    AM -->|"tool commands"| ACT

    %% Backend integration with Shared Modules
    AM -->|"shares IPC"| SPI
    UM -->|"shares IPC"| SPI
    SPI -->|"integrates"| SL

    %% Deployment influence on backend processes
    DBC ---|"build config"| AM
    DBC ---|"build config"| UM

    %% Click Events
    click AgentApp "https://github.com/zhdh2008/ui-tars-desktop/tree/main/apps/agent-tars"
    click UITarsApp "https://github.com/zhdh2008/ui-tars-desktop/tree/main/apps/ui-tars"
    click AR "https://github.com/zhdh2008/ui-tars-desktop/tree/main/apps/agent-tars/src/renderer"
    click UR "https://github.com/zhdh2008/ui-tars-desktop/tree/main/apps/ui-tars/src/renderer"
    click AM "https://github.com/zhdh2008/ui-tars-desktop/tree/main/apps/agent-tars/src/main"
    click UM "https://github.com/zhdh2008/ui-tars-desktop/tree/main/apps/ui-tars/src/main"
    click AIPC "https://github.com/zhdh2008/ui-tars-desktop/tree/main/apps/agent-tars/src/main/ipcRoutes"
    click UIPC "https://github.com/zhdh2008/ui-tars-desktop/tree/main/apps/ui-tars/src/main/ipcRoutes"
    click ALLM "https://github.com/zhdh2008/ui-tars-desktop/tree/main/apps/agent-tars/src/main/llmProvider"
    click ACT "https://github.com/zhdh2008/ui-tars-desktop/tree/main/apps/agent-tars/src/main/customTools"
    click SL "https://github.com/zhdh2008/ui-tars-desktop/tree/main/packages"
    click SPI "https://github.com/zhdh2008/ui-tars-desktop/tree/main/packages/ui-tars/electron-ipc"
    click DBC "https://github.com/zhdh2008/ui-tars-desktop/blob/main/apps/agent-tars/electron-builder.yml"

    %% Styles
    classDef ui fill:#a2d2ff,stroke:#000,stroke-width:1px;
    classDef main fill:#ffc6ff,stroke:#000,stroke-width:1px;
    classDef backend fill:#ffadad,stroke:#000,stroke-width:1px;
    classDef shared fill:#caffbf,stroke:#000,stroke-width:1px;
    classDef deploy fill:#fdffb6,stroke:#000,stroke-width:1px;
```
