# lenohard/cherry-studio architecture

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

- Interactive diagram: https://gitdiagram.com/lenohard/cherry-studio
- Repository: https://github.com/lenohard/cherry-studio

## Overview

##### Main Components Identification

The system architecture should be divided into these key components:

a. Electron Application Layer
- Main Process (src/main)
- Renderer Process (src/renderer)
- Preload Scripts (src/preload)

b. Core Services Layer
- Provider Services (src/renderer/providers)
- Application Services (src/renderer/services)
- Database Services (packages/database)

c. UI Layer
- Pages (src/renderer/pages)
- Components (src/renderer/components)
- Assets (src/renderer/assets)

**┌─────────────────────────────────────────────┐**
- Electron App                  │
- ┬─────────────┬───────────────┤
- Main Process  │  Preload    │   Renderer    │
- ┴─────────────┴───────────────┘

**┌─────────────────────────────────────────────┐**
- Service Layer                   │
- ┬────────────┬───────────────────┤
- AI       │  File      │     Knowledge     │
- Providers │  Storage   │     Management    │
- ┴────────────┴───────────────────┘

**┌─────────────────────────────────────────────┐**
- External Services               │
- ┬────────────┬───────────────────┤
- OpenAI   │  Gemini    │     Anthropic     │
- API      │   API      │        API        │
- ┴────────────┴───────────────────┘

##### Integration Points

Integration with:
- LLM Providers (OpenAI, Gemini, Anthropic)
- WebDAV Services
- Local File System
- Database Systems

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Electron["Electron Application"]
        MainProcess["Main Process"]:::main
        PreloadScripts["Preload Scripts"]:::preload
        RendererProcess["Renderer Process"]:::renderer
    end

    subgraph CoreServices["Core Services Layer"]
        direction TB
        WindowMgmt["Window Management"]:::service
        FileSystem["File System Operations"]:::service
        AppUpdates["Application Updates"]:::service
        ConfigMgmt["Configuration Management"]:::service
        KnowledgeMgmt["Knowledge Management"]:::service
        WebDAV["WebDAV Service"]:::service
        Security["Security Layer"]:::service
    end

    subgraph UI["UI Layer"]
        direction TB
        Pages["Pages"]:::ui
        Components["Components"]:::ui
        Assets["Assets"]:::ui
        I18n["Internationalization"]:::ui
    end

    subgraph State["Application State"]
        Store["Store Management"]:::state
    end

    subgraph Providers["Provider Services"]
        direction TB
        OpenAI["OpenAI Provider"]:::provider
        Gemini["Gemini Provider"]:::provider
        Anthropic["Anthropic Provider"]:::provider
    end

    subgraph Services["Service Layer"]
        direction TB
        ApiService["API Service"]:::service
        AssistantService["Assistant Service"]:::service
        ModelService["Model Service"]:::service
    end

    subgraph Database["Database Layer"]
        DB["Database Services"]:::database
    end

    MainProcess --> CoreServices
    PreloadScripts --> MainProcess
    RendererProcess --> PreloadScripts
    RendererProcess --> UI
    RendererProcess --> State
    RendererProcess --> Services
    Services --> Providers
    Services --> DB
    CoreServices --> DB

    %% Click events for component mapping
    click MainProcess "https://github.com/lenohard/cherry-studio/tree/main/src/main/"
    click RendererProcess "https://github.com/lenohard/cherry-studio/tree/main/src/renderer/"
    click PreloadScripts "https://github.com/lenohard/cherry-studio/tree/main/src/preload/"
    click OpenAI "https://github.com/lenohard/cherry-studio/blob/main/src/renderer/src/providers/OpenAIProvider.ts"
    click Gemini "https://github.com/lenohard/cherry-studio/blob/main/src/renderer/src/providers/GeminiProvider.ts"
    click Anthropic "https://github.com/lenohard/cherry-studio/blob/main/src/renderer/src/providers/AnthropicProvider.ts"
    click WindowMgmt "https://github.com/lenohard/cherry-studio/blob/main/src/main/services/WindowService.ts"
    click FileSystem "https://github.com/lenohard/cherry-studio/blob/main/src/main/services/FileStorage.ts"
    click AppUpdates "https://github.com/lenohard/cherry-studio/blob/main/src/main/services/AppUpdater.ts"
    click ConfigMgmt "https://github.com/lenohard/cherry-studio/blob/main/src/main/services/ConfigManager.ts"
    click KnowledgeMgmt "https://github.com/lenohard/cherry-studio/blob/main/src/main/services/KnowledgeService.ts"
    click WebDAV "https://github.com/lenohard/cherry-studio/blob/main/src/main/services/WebDav.ts"
    click DB "https://github.com/lenohard/cherry-studio/tree/main/packages/database/"
    click Pages "https://github.com/lenohard/cherry-studio/tree/main/src/renderer/src/pages/"
    click Components "https://github.com/lenohard/cherry-studio/tree/main/src/renderer/src/components/"
    click Assets "https://github.com/lenohard/cherry-studio/tree/main/src/renderer/src/assets/"
    click Store "https://github.com/lenohard/cherry-studio/tree/main/src/renderer/src/store/"
    click ApiService "https://github.com/lenohard/cherry-studio/blob/main/src/renderer/src/services/ApiService.ts"
    click AssistantService "https://github.com/lenohard/cherry-studio/blob/main/src/renderer/src/services/AssistantService.ts"
    click ModelService "https://github.com/lenohard/cherry-studio/blob/main/src/renderer/src/services/ModelService.ts"
    click Security "https://github.com/lenohard/cherry-studio/blob/main/src/main/utils/aes.ts"
    click I18n "https://github.com/lenohard/cherry-studio/tree/main/src/renderer/src/i18n/"

    %% Styling
    classDef main fill:#2196F3,stroke:#1565C0,color:white
    classDef preload fill:#4CAF50,stroke:#2E7D32,color:white
    classDef renderer fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef service fill:#FF9800,stroke:#EF6C00,color:white
    classDef ui fill:#E91E63,stroke:#C2185B,color:white
    classDef state fill:#607D8B,stroke:#455A64,color:white
    classDef provider fill:#00BCD4,stroke:#0097A7,color:white
    classDef database fill:#795548,stroke:#5D4037,color:white

    %% Legend
    subgraph Legend
        L1["Main Process"]:::main
        L2["Preload"]:::preload
        L3["Renderer"]:::renderer
        L4["Services"]:::service
        L5["UI Components"]:::ui
        L6["State Management"]:::state
        L7["Providers"]:::provider
        L8["Database"]:::database
    end
```
