# glowingjade/obsidian-smart-composer architecture

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

- Interactive diagram: https://gitdiagram.com/glowingjade/obsidian-smart-composer
- Repository: https://github.com/glowingjade/obsidian-smart-composer

## Overview

──────────────────────────────
##### Identifying the Project’s Components
──────────────────────────────
- Project Purpose:
- Smart Composer is designed as an Obsidian plugin that integrates AI-powered contextual chat and editing capabilities.
- It enables you to reference files from your vault during a chat session.
- It allows users to choose from various AI providers (e.g., OpenAI, Anthropic, and notably, Ollama for local models).

- Main Architectural Areas:
a. Frontend UI Components: Mainly implemented in TypeScript/React under the “src/components” folder (e.g., ChatView, ApplyView, settings modals, and various chat-input plugins).
b. Core AI/LLM Integration: In “src/core/llm”, where multiple provider connectors (including Ollama) and the central LLM manager are implemented.
c. Vault Context & Retrieval (RAG): Found in “src/core/rag”, which handles semantic search across your vault content.
d. Database & Settings: Managed in “src/database” and “src/settings”, including schema migrations and settings context, ensuring that things like your API keys and provider configurations are stored and updated.
e. Build & Migration Tools: The “drizzle” folder holds SQL migration scripts that maintain versioning for vector tables and templates, indicating underlying database support for advanced features.

──────────────────────────────
──────────────────────────────

- Frontend (Obsidian Plugin UI):
– ChatView and ApplyView components (interaction layer for user chats, image uploads, code blocks, and templates).
– Chat input plugins (mention, image handling, typeahead menus, etc.) which provide rich-text editing and context selection.
- Core Logic and Service Layer:
– LLM Manager and Provider Connectors: Include modules for OpenAI, Anthropic, Gemini, and the Ollama connector. Note that the “src/core/llm” folder has dedicated files that establish how requests are sent to external or local providers.
– Context and RAG (Retrieval-Augmented Generation) Engine: Illustrate the interaction with “src/core/rag” which takes note content from your vault and enhances context for AI responses.
- Database and Configuration Modules:
– Database Manager and modules from “src/database” (including JSON and module-specific managers for chat and vector data).
– Settings and schema changes stored in “src/settings” (which also maintains your custom system prompts and API key configurations).
- External Services & Local Hosts:
– External API endpoints provided by services like OpenAI, Anthropic, etc.
– Local model support via Ollama: Show that you have a connector in “src/core/llm/ollama.ts” to send requests and receive responses from a locally hosted AI model.

B. Data Flow & Interactions:
– From UI components (ChatView, settings modals) to the LLM Manager in the Core Logic layer.
– From LLM Manager and RAG engine to the Database Managers for retrieving vault notes and persisting conversation history.
– From LLM Manager to external API endpoints or local services (including your Ollama setup) for processing the AI query.

C. Architectural Patterns & Technologies:
- An MVC-like pattern in the plugin (React components as views, context managers and state hooks as controllers, and underlying database modules as the model).
- Plugin’s extensibility: e.g., support for external file types (images, YouTube transcripts, etc.) and multiple provider integrations.
- Integration of custom prompts and template management as additional modules.
- Build tools/scripting components such as “esbuild”, “drizzle”, or configurations (e.g., tsconfig.json).

──────────────────────────────

##### How to Use the Project for Chatting with Your Obsidian Notes
──────────────────────────────
- Installation & Setup:
1. Install the Smart Composer plugin via Obsidian’s Community Plugins section.
2. You have the latest Obsidian installer, as noted in the README.
3. Once installed, enable the plugin and navigate to its settings to configure your API key(s) for your preferred provider.

- Chat with Obsidian Notes:
1. Open the Chat view within the plugin interface (e.g., ChatView.tsx).
2. Type queries into the chat input; to include specific context from your vault, use the syntax “@<filenameOrFolder>”. This tells the RAG engine to retrieve and include relevant notes.
3. The plugin will use these selections to adjust the context sent to the chosen LLM (via the methods set up in “src/core/rag” and “src/core/llm”).

──────────────────────────────
##### How to Connect to Ollama for Local Model Support
──────────────────────────────
- Once selected, follow these steps:
1. You have Ollama installed and configured on your local machine.
2. In the settings, enter the necessary connection details — typically an API endpoint/port that corresponds to your local Ollama installation.
3. The connector code in “src/core/llm/ollama.ts” manages the integration. It sends your queries (with the vault context attached when necessary) to the Ollama service and waits for the AI response.

──────────────────────────────

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend UI Layer"
        ChatView["ChatView (UI)"]:::frontend
        ApplyView["ApplyView (UI)"]:::frontend
        OtherUI["Additional UI Components (Chat input, settings modals)"]:::frontend
        NoteChat["Note: To chat with your Obsidian notes, open ChatView and type '@<filenameOrFolder>' to trigger vault context retrieval."]:::note
    end

    subgraph "Core Logic Layer"
        LLM["LLM Manager"]:::core
        subgraph "Provider Connectors"
            OpenAI["OpenAI Connector"]:::core
            Anthropic["Anthropic Connector"]:::core
            Ollama["Ollama Connector"]:::core
        end
        RAG["Vault Context (RAG Engine)"]:::core
        Embedding["Embedding Module"]:::core
        NoteOllama["Note: To connect to a local Ollama model, select Ollama in settings and configure the connection details."]:::note
    end

    subgraph "Database & Config"
        Database["Database Manager"]:::database
        Settings["Settings Module"]:::database
    end

    subgraph "Build & Migration Tools"
        Drizzle["Drizzle Migrations"]:::database
    end

    subgraph "External Services"
        ExternalAPI["External API Endpoints"]:::external
        LocalOllama["Local Ollama Service"]:::external
    end

    %% Data Flow Connections
    ChatView -->|"UserQuery"| LLM
    ApplyView -->|"UserQuery"| LLM
    LLM -->|"VaultContext"| RAG
    RAG -->|"FetchNotes"| Database
    LLM -->|"APIRequest"| ExternalAPI
    LLM -->|"ConfigQuery"| Settings
    LLM -->|"LLMQuery"| OpenAI
    LLM -->|"LLMQuery"| Anthropic
    LLM -->|"LLMQuery"| Ollama
    Ollama -->|"LocalModelQuery"| LocalOllama
    Settings -->|"UpdateSettings"| LLM

    %% Click Events
    click ChatView "https://github.com/glowingjade/obsidian-smart-composer/blob/main/src/ChatView.tsx"
    click ApplyView "https://github.com/glowingjade/obsidian-smart-composer/blob/main/src/ApplyView.tsx"
    click OtherUI "https://github.com/glowingjade/obsidian-smart-composer/tree/main/src/components"
    click LLM "https://github.com/glowingjade/obsidian-smart-composer/blob/main/src/core/llm/manager.ts"
    click OpenAI "https://github.com/glowingjade/obsidian-smart-composer/blob/main/src/core/llm/openai.ts"
    click Anthropic "https://github.com/glowingjade/obsidian-smart-composer/blob/main/src/core/llm/anthropic.ts"
    click Ollama "https://github.com/glowingjade/obsidian-smart-composer/blob/main/src/core/llm/ollama.ts"
    click RAG "https://github.com/glowingjade/obsidian-smart-composer/blob/main/src/core/rag/ragEngine.ts"
    click Embedding "https://github.com/glowingjade/obsidian-smart-composer/blob/main/src/core/rag/embedding.ts"
    click Database "https://github.com/glowingjade/obsidian-smart-composer/blob/main/src/database/DatabaseManager.ts"
    click Settings "https://github.com/glowingjade/obsidian-smart-composer/blob/main/src/settings/SettingTab.tsx"
    click Drizzle "https://github.com/glowingjade/obsidian-smart-composer/tree/main/drizzle"

    %% Styles
    classDef frontend fill:#CCEEFF,stroke:#333,stroke-width:2px;
    classDef core fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef database fill:#FFEECC,stroke:#333,stroke-width:2px;
    classDef external fill:#FFCCCC,stroke:#333,stroke-width:2px;
    classDef note fill:#EEEEEE,stroke:#999,stroke-dasharray:5,5;
```
