# thinkinaixyz/deepchat architecture

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

- Interactive diagram: https://gitdiagram.com/thinkinaixyz/deepchat
- Repository: https://github.com/thinkinaixyz/deepchat

## Overview

##### Main components
- Main Process: This is the backend of the Electron app. It includes modules such as the eventbus, contextMenuHelper, several presenter folders (for file operations, devices, MCP, LLM providers, etc.), and support libraries (e.g., file adapters, configuration presenters).
- Renderer Process (Frontend/UI): This part is built using Vue components (as seen in many .vue component files), along with specific stores (state management), composables, routing, and internationalization (i18n). It presents the UI and handles user interactions.
- Preload Scripts: The preload folder provides typed integration between the main and renderer processes (exposing APIs in a secure manner).
- Build and Deployment Components: The build scripts, Dockerfile, and Electron Builder configuration files indicate platform-specific packaging and deployment procedures.
- External Integrations: There is explicit support for multiple model providers (e.g., DeepSeek, OpenAI, Ollama, Silicon Flow, etc.) and local model management. This module is handled mainly via the presenter modules (such as llmProviderPresenter, llamaCppPresenter, and devicePresenter).
- Internationalization: Multiple language directories under the renderer (i18n for en-US, zh-CN, etc.) indicate the project supports multiple locales.

##### Relationships and interactions
- The Main Process is responsible for managing system-level events, configurations, file operations, and acts as the orchestrator. It uses “presenter” modules to abstract the business logic (from file handling to model provider interactions).
- The Renderer process (built with Vue) communicates with the Main process via the Preload API. User interactions (e.g., chat input, selections, file uploads) trigger events that route to the appropriate presenter services via API calls.
- Between the Renderer and Main, an eventbus mechanism (and IPC in Electron) passes information like chat messages, model requests, and configuration changes.
- The build system (scripts, Dockerfile, and electron-builder configuration) packages the app for different platforms, with specific nuances for Windows, macOS, and Linux.
- Integration with multiple external LLM services is handled by a common API compatibility layer (structured via llmProviderPresenter with multiple “provider” implementations).

##### Architectural patterns and design principles
- Separation of Concerns: There is a clear split between business logic (presenters in the main process) and UI (renderer). The use of “presenter” modules suggests an MVP/MVC-inspired pattern.
- Modular Design: Each provider, file adapter, or presenter is organized into its own subfolder (for example, separate directories for filePresenter, mcpPresenter, etc.), making the system extensible.
- Multi-platform Support: Electron’s architecture (with distinct main and renderer processes) is leveraged, along with platform-specific build scripts.
- Internationalization: The localized i18n directories reflect a commitment to internationalize the UI.
- Use of modern frontend patterns: The user interface is built with Vue components, Vue Router for navigation, and state management via Pinia – all suggesting modern best practices.

##### Relevant technologies, frameworks, or libraries
- Electron – for building the desktop application.
- Vue (with .vue components) – for the renderer process UI.
- Pinia – for state management.
- Various model provider integrations via API layers (e.g., OpenAI, DeepSeek, Ollama).
- Electron Builder and related build configuration tools for packaging.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Renderer Process
    subgraph "Renderer Process"
        rendererHTML("Renderer HTML"):::renderer
        rendererMain("Renderer Main"):::renderer
        vueComponents("Vue Components"):::renderer
        uiComponents("UI Components"):::renderer
        artifactsComponents("Artifacts Components"):::renderer
        vueRouter("Vue Router"):::renderer
        piniaStores("Pinia Stores"):::renderer
        assetsStyles("Assets & Styles"):::renderer
        i18n("i18n"):::renderer
    end

    %% Preload Scripts
    subgraph "Preload Scripts"
        preloadAPI("Preload API"):::preload
        preloadTypes("Preload Types"):::preload
    end

    %% Main Process
    subgraph "Main Process"
        mpIndex("Main Index"):::main
        mpEventBus("Event Bus"):::main
        mpEvents("Events"):::main
        contextMenu("ContextMenuHelper"):::main
        filePresenter("File Presenter"):::main
        configPresenter("Config Presenter"):::main
        devicePresenter("Device Presenter"):::main
        llmPresenter("LLM Provider Presenter"):::main
        mcpPresenter("MCP Presenter"):::main
    end

    %% External Integrations
    subgraph "External Integrations"
        localModel("Local Model Integration"):::external
    end

    %% Build and Deployment
    subgraph "Build and Deployment"
        buildScripts("Build Scripts"):::build
        dockerfile("Dockerfile"):::build
        electronBuilder("Electron Builder"):::build
        builderMac("Builder Mac Config"):::build
        scripts("Scripts"):::build
        electronVite("Electron Vite Config"):::build
    end

    %% Assets and Resources
    subgraph "Assets and Resources"
        staticResources("Static Resources"):::assets
    end

    %% Data Flow Connections
    %% User Interaction: Renderer to Preload
    rendererHTML -- "UserAction" --> preloadAPI
    rendererMain -- "UserAction" --> preloadAPI
    vueComponents -- "UserAction" --> preloadAPI

    %% Preload Bridges: Preload to Main Process
    preloadAPI -- "IPCRequest" --> mpIndex
    mpIndex -- "Response" --> preloadAPI
    preloadAPI -- "DataDelivery" --> rendererMain

    %% Main Process internal interactions
    mpIndex -- "initializes" --> mpEventBus
    mpEventBus -- "triggers" --> filePresenter
    mpEventBus -- "triggers" --> configPresenter
    mpEventBus -- "triggers" --> devicePresenter
    mpEventBus -- "triggers" --> llmPresenter
    mpEventBus -- "triggers" --> mcpPresenter
    contextMenu -- "assists" --> mpIndex

    %% Main Process to External Integrations
    llmPresenter -- "API_call" --> localModel
    localModel -- "Response" --> llmPresenter

    %% Main Process sends updates to Renderer
    mpIndex -- "updates" --> rendererMain

    %% Renderer loads external assets
    rendererMain -- "loads" --> staticResources

    %% Styles
    classDef main fill:#fff7cc,stroke:#d4a017,stroke-width:2px;
    classDef renderer fill:#cfe2f3,stroke:#4a90e2,stroke-width:2px;
    classDef preload fill:#e2eafc,stroke:#7a7aff,stroke-width:2px;
    classDef build fill:#d1e7dd,stroke:#0f5132,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#a71d2a,stroke-width:2px;
    classDef assets fill:#fff3cd,stroke:#f0ad4e,stroke-width:2px;

    %% Click Events for Main Process Components
    click mpIndex "https://github.com/thinkinaixyz/deepchat/blob/main/src/main/index.ts"
    click mpEventBus "https://github.com/thinkinaixyz/deepchat/blob/main/src/main/eventbus.ts"
    click mpEvents "https://github.com/thinkinaixyz/deepchat/blob/main/src/main/events.ts"
    click contextMenu "https://github.com/thinkinaixyz/deepchat/blob/main/src/main/contextMenuHelper.ts"
    click filePresenter "https://github.com/thinkinaixyz/deepchat/tree/main/src/main/presenter/filePresenter/"
    click configPresenter "https://github.com/thinkinaixyz/deepchat/tree/main/src/main/presenter/configPresenter/"
    click devicePresenter "https://github.com/thinkinaixyz/deepchat/blob/main/src/main/presenter/devicePresenter/index.ts"
    click llmPresenter "https://github.com/thinkinaixyz/deepchat/tree/main/src/main/presenter/llmProviderPresenter/"
    click mcpPresenter "https://github.com/thinkinaixyz/deepchat/tree/main/src/main/presenter/mcpPresenter/"

    %% Click Events for Renderer Process Components
    click rendererHTML "https://github.com/thinkinaixyz/deepchat/blob/main/src/renderer/index.html"
    click rendererMain "https://github.com/thinkinaixyz/deepchat/blob/main/src/renderer/src/main.ts"
    click vueComponents "https://github.com/thinkinaixyz/deepchat/tree/main/src/renderer/src/components/"
    click uiComponents "https://github.com/thinkinaixyz/deepchat/tree/main/src/renderer/src/components/ui/"
    click artifactsComponents "https://github.com/thinkinaixyz/deepchat/tree/main/src/renderer/src/components/artifacts/"
    click vueRouter "https://github.com/thinkinaixyz/deepchat/blob/main/src/renderer/src/router/index.ts"
    click piniaStores "https://github.com/thinkinaixyz/deepchat/tree/main/src/renderer/src/stores/"
    click assetsStyles "https://github.com/thinkinaixyz/deepchat/tree/main/src/renderer/src/assets/"
    click i18n "https://github.com/thinkinaixyz/deepchat/tree/main/src/renderer/src/i18n/"

    %% Click Events for Preload Scripts
    click preloadAPI "https://github.com/thinkinaixyz/deepchat/blob/main/src/preload/index.ts"
    click preloadTypes "https://github.com/thinkinaixyz/deepchat/blob/main/src/preload/index.d.ts"

    %% Click Events for Build and Deployment Components
    click buildScripts "https://github.com/thinkinaixyz/deepchat/tree/main/build/"
    click dockerfile "https://github.com/thinkinaixyz/deepchat/blob/main/Dockerfile.build.linux"
    click electronBuilder "https://github.com/thinkinaixyz/deepchat/blob/main/electron-builder.yml"
    click builderMac "https://github.com/thinkinaixyz/deepchat/blob/main/electron-builder-macx64.yml"
    click scripts "https://github.com/thinkinaixyz/deepchat/tree/main/scripts/"
    click electronVite "https://github.com/thinkinaixyz/deepchat/blob/main/electron.vite.config.ts"

    %% Click Event for External Integration
    click localModel "https://github.com/thinkinaixyz/deepchat/tree/main/src/main/presenter/llamaCppPresenter/"

    %% Click Event for Assets and Resources
    click staticResources "https://github.com/thinkinaixyz/deepchat/tree/main/resources/"
```
