# kangfenmao/cherry-studio architecture

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

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

## Overview

##### Main Components

a. Frontend Layer (Renderer Process):
- User Interface Components (/src/renderer)
- Pages and Views
- State Management (Store)
- Service Layers
- Providers for different LLM services

b. Backend Layer (Main Process):
- Core Services
- File System Operations
- IPC Communication
- System Services (Updates, Backups, etc.)

c. External Services:
- LLM Providers (OpenAI, Gemini, Anthropic, etc.)
- WebDAV Storage
- Local Ollama Integration

**[User Interface Layer]**
- ↑↓
**[Electron Main Process]**
- ↑↓
**[External Services/Storage]**

##### Component Details

Frontend (Renderer):
- State management store (/src/renderer/src/store)
- Service layers (/src/renderer/src/services)
- Providers integration (/src/renderer/src/providers)

Main Process:
- Core services (/src/main/services)
- File system operations
- IPC bridge
- Configuration management

External Integration:
- LLM Provider connections
- File storage systems
- Knowledge base integration
- WebDAV connectivity

##### Key Elements to Highlight

- Multi-provider support architecture
- File processing pipeline
- Knowledge base integration
- State management flow
- IPC communication patterns

##### Specific Implementation Notes

- Electron's main and renderer process separation
- How different LLM providers are abstracted (/src/renderer/src/providers)
- Service layer architecture (/src/renderer/src/services)
- Data flow between components
- Integration points with external services

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef frontend fill:#a7c7e7,stroke:#666
    classDef backend fill:#c6ecc6,stroke:#666
    classDef external fill:#ffb366,stroke:#666
    classDef storage fill:#e6b3e6,stroke:#666
    classDef communication fill:#ffcccc,stroke:#666

    %% Frontend Layer
    subgraph Frontend
        UI[UI Components]:::frontend
        Pages[Pages/Views]:::frontend
        Store[State Management]:::frontend
        FServices[Frontend Services]:::frontend
        Providers[LLM Providers Layer]:::frontend
        Hooks[Frontend Hooks]:::frontend
        Layout[Application Layout]:::frontend
        Messages[Message Components]:::frontend
        Settings[Settings Interface]:::frontend
    end

    %% Backend Layer
    subgraph Backend
        CoreServices[Core Services]:::backend
        IPC[IPC Communication]:::communication
        FSOperations[File System Operations]:::backend
        WebDAV[WebDAV Integration]:::backend
        Updates[System Updates]:::backend
        KnowledgeBase[Knowledge Base]:::backend
        WindowMgmt[Window Management]:::backend
        Config[Configuration Management]:::backend
        Backup[Backup System]:::backend
    end

    %% External Services
    subgraph External
        OpenAI[OpenAI]:::external
        Gemini[Gemini]:::external
        Anthropic[Anthropic]:::external
        Ollama[Local Ollama]:::external
        Storage[WebDAV Storage]:::storage
    end

    %% Relationships
    Frontend --> |IPC| Backend
    Backend --> |IPC| Frontend
    Backend --> External
    Providers --> External

    %% Click events
    click UI "https://github.com/kangfenmao/cherry-studio/tree/main/src/renderer/src/components"
    click Pages "https://github.com/kangfenmao/cherry-studio/tree/main/src/renderer/src/pages"
    click Store "https://github.com/kangfenmao/cherry-studio/tree/main/src/renderer/src/store"
    click FServices "https://github.com/kangfenmao/cherry-studio/tree/main/src/renderer/src/services"
    click Providers "https://github.com/kangfenmao/cherry-studio/tree/main/src/renderer/src/providers"
    click CoreServices "https://github.com/kangfenmao/cherry-studio/tree/main/src/main/services"
    click IPC "https://github.com/kangfenmao/cherry-studio/blob/main/src/main/ipc.ts"
    click FSOperations "https://github.com/kangfenmao/cherry-studio/blob/main/src/main/services/FileStorage.ts"
    click WebDAV "https://github.com/kangfenmao/cherry-studio/blob/main/src/main/services/WebDav.ts"
    click Updates "https://github.com/kangfenmao/cherry-studio/blob/main/src/main/services/AppUpdater.ts"
    click KnowledgeBase "https://github.com/kangfenmao/cherry-studio/blob/main/src/main/services/KnowledgeService.ts"
    click WindowMgmt "https://github.com/kangfenmao/cherry-studio/blob/main/src/main/services/WindowService.ts"
    click Config "https://github.com/kangfenmao/cherry-studio/blob/main/src/main/services/ConfigManager.ts"
    click Backup "https://github.com/kangfenmao/cherry-studio/blob/main/src/main/services/BackupManager.ts"
    click Hooks "https://github.com/kangfenmao/cherry-studio/tree/main/src/renderer/src/hooks"
    click Layout "https://github.com/kangfenmao/cherry-studio/tree/main/src/renderer/src/components/Layout"
    click Messages "https://github.com/kangfenmao/cherry-studio/tree/main/src/renderer/src/pages/home/Messages"
    click Settings "https://github.com/kangfenmao/cherry-studio/tree/main/src/renderer/src/pages/settings"

    %% Legend
    subgraph Legend
        Frontend_L[Frontend Components]:::frontend
        Backend_L[Backend Services]:::backend
        External_L[External Services]:::external
        Storage_L[Storage Systems]:::storage
        Comm_L[Communication Layer]:::communication
    end
```
