# openagentplatform/dive architecture

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

- Interactive diagram: https://gitdiagram.com/openagentplatform/dive
- Repository: https://github.com/openagentplatform/dive

## Overview

##### Project Type & Purpose
- Project Type: Electron desktop application with a React/TypeScript renderer and a Node/TypeScript main process.
- Purpose: Host and orchestrate “Model Context Protocol” (MCP) LLM agents via a Python-based DiveHost, provide UI for chats, settings, updates, and multi-language support.

##### File Structure
- Top-Level Modules:
– electron/… → main-process code (IPC channels, tray, menu, auto-update, service).
– electron/preload/… → sandboxed bridge exposing safe IPC methods to the renderer.
– src/… → React renderer: views, components, hooks, atoms (state), styles.
– scripts/… & docker/… → build, packaging, host binaries, MCP host downloads.
– prebuilt/… → precompiled DiveHost Python package for stdio/SSE modes.
- Config & Tooling: vite.config.*.ts, electron-builder.json, tsconfig.*, Dockerfiles, BUILD.md.

##### Pull Insights from README
- Cross-platform support (Windows, macOS, Linux).
- Universal LLM support via function-calling.
- Auto-update mechanism.
- Python DiveHost rewritten v0.8.0 extracted to separate repo; here prebuilt host used.
- Configurable MCP servers (fetch, filesystem, yt-dl) via stdio or SSE transport.

##### Main Components & Interactions
a. Components
1. Renderer Process (React UI)
– Chat UI, settings panels, localizations, state mgmt (Jotai atoms), Vite dev server in dev mode.
2. Preload Script
– Exposes a typed IPC API (`ipcRenderer.invoke` / `on`) for environment, system, menu, LLM commands.
3. Main Process
– Bootstraps BrowserWindow, handles tray/menu, IPC handlers, spawns DiveHost subprocess, orchestrates update checks, reads/writes store.
4. DiveHost Subprocess (Python)
– Launch command (`uvx` or Python), supports stdio / SSE for MCP tool invocations, communicates JSON-RPC with main.
5. Persistent Store & File System
– Electron-store or similar (state.json), chat history, MCP server configs, localization JSON.
6. External Services / APIs
– LLM providers (OpenAI, Anthropic, Gemini, Mistral) via HTTP/HTTPS.
– External MCP SSE servers.
– Auto-update server (GitHub Releases).
b. Interactions
– UI → Preload → IPC → Main
– Main ↔ DiveHost (stdio pipes or SSE)
– Main → Local FS (read/write config & history)
– Main → GitHub Releases (auto‐update)
– DiveHost → External MCP tools (spawn local tools or HTTP calls)
– Main → LLMs (via DiveHost or direct HTTP if implemented)

##### Architectural Patterns & Principles
- Multi‐process separation (renderer vs. main vs. subprocess).
- IPC event/command pattern for security and separation of concerns.
- React + Jotai for unidirectional data flow in the renderer.
- Plugin‐style MCP server configuration (extensible tool integrations).
- Auto-update leveraging electron-builder and GitHub Releases.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Renderer Layer
    subgraph "Renderer (React UI)" 
        direction TB
        ReactRenderer["React Renderer Process"]:::frontend
        Components["UI Components"]:::frontend
        click Components "https://github.com/openagentplatform/dive/tree/main/src/components/"
        Views["Views"]:::frontend
        click Views "https://github.com/openagentplatform/dive/tree/main/src/views/"
        Hooks["Hooks & Utilities"]:::frontend
        click Hooks "https://github.com/openagentplatform/dive/tree/main/src/hooks/"
        Atoms["UI State Management (Jotai)"]:::frontend
        click Atoms "https://github.com/openagentplatform/dive/tree/main/src/atoms/"
        Styles["Styling"]:::frontend
        click Styles "https://github.com/openagentplatform/dive/tree/main/src/styles/"
        I18n["Internationalization Setup"]:::frontend
        click I18n "https://github.com/openagentplatform/dive/blob/main/src/i18n.ts"
    end

    %% Preload Layer
    subgraph "Preload Script" 
        direction TB
        Preload["Preload IPC Bridge"]:::core
        click Preload "https://github.com/openagentplatform/dive/blob/main/electron/preload/index.ts"
    end

    %% Main Process Layer
    subgraph "Main Process (Electron Orchestration)" 
        direction TB
        MainEntry["Electron Main Process"]:::core
        click MainEntry "https://github.com/openagentplatform/dive/blob/main/electron/main/index.ts"
        Config["Configuration"]:::core
        click Config "https://github.com/openagentplatform/dive/blob/main/electron/config/index.ts"
        click ConfigKey "https://github.com/openagentplatform/dive/blob/main/electron/config/keymap.ts"
        IPCHandlers["IPC Handlers"]:::core
        click IPCHandlers "https://github.com/openagentplatform/dive/tree/main/electron/main/ipc/"
        Tray["Tray"]:::core
        click Tray "https://github.com/openagentplatform/dive/blob/main/electron/main/tray.ts"
        Menu["Menu IPC"]:::core
        click Menu "https://github.com/openagentplatform/dive/blob/main/electron/main/ipc/menu.ts"
        UpdateModule["Auto-update Module"]:::infra
        click UpdateModule "https://github.com/openagentplatform/dive/blob/main/electron/main/update.ts"
        Service["Service"]:::infra
        click Service "https://github.com/openagentplatform/dive/blob/main/electron/main/service.ts"
        StateStore["State & Store"]:::infra
        click StateStore "https://github.com/openagentplatform/dive/blob/main/electron/main/store.ts"
        click AppState "https://github.com/openagentplatform/dive/blob/main/electron/main/state.ts"
    end

    %% DiveHost Subprocess Layer
    subgraph "DiveHost Subprocess (Python)" 
        direction TB
        PythonHost["Prebuilt DiveHost Bundle"]:::external
        click PythonHost "https://github.com/openagentplatform/dive/tree/main/prebuilt/"
        DownloadScripts["Host Download/Build Scripts"]:::external
        click DL1 "https://github.com/openagentplatform/dive/blob/main/scripts/download-host-deps.ts"
        click DL2 "https://github.com/openagentplatform/dive/blob/main/scripts/download-python.ts"
        click DL3 "https://github.com/openagentplatform/dive/blob/main/scripts/download-uv.ts"
    end

    %% Persistent Storage & Files
    subgraph "Persistent Storage & Files" 
        direction TB
        StoreWrapper["Electron Store Wrapper"]:::infra
        click StoreWrapper "https://github.com/openagentplatform/dive/blob/main/electron/main/store.ts"
        AppStateModel["Application State Model"]:::infra
        click AppStateModel "https://github.com/openagentplatform/dive/blob/main/electron/main/state.ts"
        Localization["Localization Files"]:::infra
        click Localization "https://github.com/openagentplatform/dive/tree/main/public/locales/"
        Assets["Static Assets & Icons"]:::infra
        click Assets "https://github.com/openagentplatform/dive/tree/main/public/image/"
        click Resources "https://github.com/openagentplatform/dive/tree/main/resources/mac/"
    end

    %% External Services
    subgraph "External Services & APIs" 
        direction TB
        LLMAPIs["LLM Providers (OpenAI, Anthropic, etc.)"]:::external
        SSE["MCP SSE Servers"]:::external
        UpdateServer["Auto-update Server (GitHub Releases)"]:::infra
    end

    %% Build & Packaging
    subgraph "Build & Packaging" 
        direction TB
        Vite["Vite Configs"]:::infra
        click Vite "https://github.com/openagentplatform/dive/blob/main/vite.config.ts"
        click ViteE "https://github.com/openagentplatform/dive/blob/main/vite.config.electron.ts"
        ElectronBuilder["Electron Builder Config"]:::infra
        click ElectronBuilder "https://github.com/openagentplatform/dive/blob/main/electron-builder.json"
        Docker["Docker Build Scripts"]:::infra
        click DockFile "https://github.com/openagentplatform/dive/tree/main/docker/win-build/Dockerfile"
        click DockScript "https://github.com/openagentplatform/dive/blob/main/scripts/docker/build-win.sh"
    end

    %% Connections
    ReactRenderer -->|"uses"| Components
    ReactRenderer --> Views
    ReactRenderer --> Hooks
    ReactRenderer --> Atoms
    ReactRenderer --> Styles
    ReactRenderer --> I18n

    ReactRenderer -->|"IPC"| Preload
    Preload -->|"IPC"| MainEntry

    MainEntry -->|"spawn stdio/SSE"| PythonHost
    MainEntry -->|"read/write"| StoreWrapper
    MainEntry --> StateStore
    MainEntry --> UpdateServer
    MainEntry -->|"calls"| LLMAPIs

    PythonHost -->|"SSE/Tool spawn"| SSE
    PythonHost -->|"HTTP RPC"| LLMAPIs

    StoreWrapper --> AppStateModel
    StoreWrapper --> Localization
    StoreWrapper --> Assets

    MainEntry --> Config
    MainEntry --> IPCHandlers
    MainEntry --> Tray
    MainEntry --> Menu
    MainEntry --> UpdateModule
    MainEntry --> Service

    Vite --> ReactRenderer
    ElectronBuilder --> MainEntry
    Docker --> ElectronBuilder

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef core fill:#D0F8D0,stroke:#333,stroke-width:1px
    classDef external fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef infra fill:#E0E0E0,stroke:#333,stroke-width:1px
```
