# stevensu1977/obsidian-copilot architecture

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

- Interactive diagram: https://gitdiagram.com/stevensu1977/obsidian-copilot
- Repository: https://github.com/stevensu1977/obsidian-copilot

## Overview

##### External Integrations (Show as external systems)
- OpenAI API
- Anthropic API
- Azure OpenAI
- Google Gemini
- OpenRouter
- Local Models (LM Studio/Ollama)
- Obsidian API

##### Data Flow Patterns

- User Interface → Command Manager → LLM Integration Layer
- LLM Integration Layer → External APIs
- Vector Store → Search Components → LLM Integration Layer
- Settings Manager → All Components (configuration flow)

##### Key Architectural Patterns to Highlight

a. Plugin Architecture:
- Obsidian App
- Copilot Plugin
- UI Layer (React Components)
- Business Logic Layer
- Integration Layer

b. LLM Provider Architecture:
- Chain Manager
- Chat Model Manager
- Embedding Manager
- Memory Manager

##### Important Notes

- Plugin's ability to work completely offline
- Separation between local and cloud-based features
- Where encryption and rate limiting occur
- Components responsible for context management and retrieval

This architecture represents a modern AI-assisted note-taking tool with a strong emphasis on privacy and local-first functionality, which should be clearly reflected in the visual representation.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and Classes
    classDef core fill:#e1f5fe,stroke:#01579b
    classDef ui fill:#f3e5f5,stroke:#4a148c
    classDef llm fill:#e8f5e9,stroke:#1b5e20
    classDef vector fill:#fff3e0,stroke:#e65100
    classDef util fill:#f3e5f5,stroke:#4a148c
    classDef external fill:#fafafa,stroke:#424242,stroke-dasharray: 5 5
    classDef store cylinder

    %% Main Plugin Section
    subgraph Plugin["Core Plugin Components"]
        Main["Main Plugin Controller"]
        Settings["Settings Manager"]
        Commands["Command Manager"]
        UI["UI Components"]
        ChatUI["Chat Interface"]
        SettingsUI["Settings UI"]
        ChatState["Chat State Management"]
        Context["Context Management"]
    end

    %% LLM Integration Layer
    subgraph LLMLayer["LLM Integration Layer"]
        LLMManager["LLM Providers Manager"]
        Chain["Chain Manager"]
        ChatModel["Chat Model Manager"]
        Embedding["Embedding Manager"]
        Memory["Memory Manager"]
        Prompt["Prompt Manager"]
    end

    %% Vector Store Section
    subgraph VectorSection["Vector Store & Search"]
        VectorStore["Vector Store Manager"]
        HybridRetriever["Hybrid Retriever"]
        VectorDB["Vector DB Manager"]
    end

    %% Utility Services
    subgraph Utils["Utility Services"]
        Encryption["Encryption Service"]
        RateLimiter["Rate Limiter"]
        PromptProcessor["Custom Prompt Processor"]
    end

    %% External Services
    subgraph External["External Services"]
        OpenAI["OpenAI API"]
        Anthropic["Anthropic API"]
        Azure["Azure OpenAI"]
        Gemini["Google Gemini"]
        OpenRouter["OpenRouter"]
        LocalModels["Local Models"]
        ObsidianAPI["Obsidian API"]
    end

    %% Relationships
    Main --> Settings
    Main --> Commands
    Main --> UI
    UI --> ChatUI
    UI --> SettingsUI
    ChatUI --> ChatState
    ChatUI --> Context
    Commands --> LLMManager
    LLMManager --> Chain
    Chain --> ChatModel
    Chain --> Embedding
    Chain --> Memory
    Chain --> Prompt
    LLMManager --> External
    VectorStore --> HybridRetriever
    HybridRetriever --> VectorDB
    VectorDB --> Embedding
    Settings --> Utils
    Utils --> External

    %% Click Events
    click Main "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/main.ts"
    click Settings "https://github.com/stevensu1977/obsidian-copilot/tree/master/src/settings/"
    click Commands "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/commands.ts"
    click UI "https://github.com/stevensu1977/obsidian-copilot/tree/master/src/components/"
    click Chain "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/LLMProviders/chainManager.ts"
    click ChatModel "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/LLMProviders/chatModelManager.ts"
    click Embedding "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/LLMProviders/embeddingManager.ts"
    click Memory "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/LLMProviders/memoryManager.ts"
    click Prompt "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/LLMProviders/promptManager.ts"
    click VectorStore "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/VectorStoreManager.ts"
    click HybridRetriever "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/search/hybridRetriever.ts"
    click VectorDB "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/vectorDBManager.ts"
    click Encryption "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/encryptionService.ts"
    click RateLimiter "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/rateLimiter.ts"
    click PromptProcessor "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/customPromptProcessor.ts"
    click ChatUI "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/components/Chat.tsx"
    click SettingsUI "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/settings/components/SettingsMain.tsx"
    click ChatState "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/aiState.ts"
    click Context "https://github.com/stevensu1977/obsidian-copilot/blob/master/src/context.ts"

    %% Styling
    class Main,Settings,Commands,UI core
    class ChatUI,SettingsUI ui
    class LLMManager,Chain,ChatModel,Embedding,Memory,Prompt llm
    class VectorStore,HybridRetriever,VectorDB vector
    class Encryption,RateLimiter,PromptProcessor util
    class OpenAI,Anthropic,Azure,Gemini,OpenRouter,LocalModels,ObsidianAPI external
```
