# silasmarvin/lsp-ai architecture

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

- Interactive diagram: https://gitdiagram.com/silasmarvin/lsp-ai
- Repository: https://github.com/silasmarvin/lsp-ai

## Overview

##### Main Components

a. Core LSP Server Component:
- LSP protocol communication handlers
- Custom request handlers (visible in custom_requests directory)

b. Backend Services Layer:
- Transformer Backends (Multiple AI Model Providers):
- OpenAI
- Anthropic
- Gemini
- Llama.cpp
- Ollama
- Mistral FIM
- Memory Backends:
- File Store
- PostgresML
- Vector Store

c. Editor Integration Layer:
- Supported editors (VSCode, Neovim, Helix, etc.)
- LSP protocol communication

d. Processing Components:
- Memory Worker
- Transformer Worker
- Text Splitters (including Tree-sitter integration)

##### Relationship Flows to Illustrate

a. Primary Data Flow:
##### Results returning to Editor

b. Secondary Flows:
- Memory management operations
- Embedding processing
- Text splitting and processing

##### Component Details

LSP Server Core (Central):
**┌─────────────────────────┐**
- LSP-AI Server      │
- ┤
- Custom Requests       │
- Memory Management     │
- Transformer Workers   │
- Text Splitters       │
- ┘

Backend Services (Right side):
**┌─────────────────┐**
- AI Backends     │
- ┤
- OpenAI        │
- Anthropic     │
- Gemini        │
- Llama.cpp     │
- Ollama        │
- Mistral FIM   │
- ┘

Memory Systems (Bottom):
**┌─────────────────┐**
- Memory Backends │
- ┤
- File Store    │
- PostgresML    │
- Vector Store  │
- ┘

##### Additional Elements

- Version compatibility information
- Configuration flow
- Scaling indicators for components that can be scaled
- Extension points for future features

Remember to include notes about:
- Asynchronous operations
- Fallback mechanisms
- Configuration options
- Extension points for future features like semantic search

This will provide a clear understanding of how LSP-AI serves as a bridge between editors and AI services while maintaining its core mission of empowering programmers through existing tools.

## Diagram (Mermaid)

```mermaid
%%{init: {'theme': 'neutral', 'themeVariables': { 'fontSize': '16px'}}}%%
flowchart TB
    classDef core fill:#e1f5fe,stroke:#01579b
    classDef backend fill:#f3e5f5,stroke:#4a148c
    classDef storage fill:#e8f5e9,stroke:#1b5e20
    classDef editor fill:#fff3e0,stroke:#e65100
    classDef processing fill:#f3e5f5,stroke:#4a148c
    classDef embedding fill:#e0f2f1,stroke:#004d40

    subgraph Editors
        VSCode["VSCode"]:::editor
        Neovim["Neovim"]:::editor
        Helix["Helix"]:::editor
    end

    subgraph "Core LSP Server"
        LSPCore["LSP-AI Server"]:::core
        Config["Configuration"]:::core
        CustomReq["Custom Requests"]:::core
    end

    subgraph "Transformer Backends"
        OpenAI["OpenAI"]:::backend
        Anthropic["Anthropic"]:::backend
        Gemini["Gemini"]:::backend
        LlamaCpp["Llama.cpp"]:::backend
        Ollama["Ollama"]:::backend
        MistralFIM["Mistral FIM"]:::backend
    end

    subgraph "Memory Systems"
        FileStore[(File Store)]:::storage
        PostgresML[(PostgresML)]:::storage
        VectorStore[(Vector Store)]:::storage
    end

    subgraph "Processing"
        MemoryWorker["Memory Worker"]:::processing
        TransformerWorker["Transformer Worker"]:::processing
        TextSplitter["Text Splitters"]:::processing
        TreeSitter["Tree-sitter Integration"]:::processing
    end

    subgraph "Embedding Models"
        EmbeddingCore["Embedding Models"]:::embedding
        OllamaEmbed["Ollama Embeddings"]:::embedding
    end

    VSCode & Neovim & Helix --> LSPCore
    LSPCore --> |Requests| CustomReq
    LSPCore --> |Configuration| Config
    
    CustomReq --> TransformerWorker
    TransformerWorker --> OpenAI & Anthropic & Gemini & LlamaCpp & Ollama & MistralFIM
    
    LSPCore --> MemoryWorker
    MemoryWorker --> FileStore & PostgresML & VectorStore
    
    LSPCore --> TextSplitter
    TextSplitter --> TreeSitter
    
    LSPCore --> EmbeddingCore
    EmbeddingCore --> OllamaEmbed

    %% Click events for component mapping
    click LSPCore "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/main.rs"
    click Config "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/config.rs"
    click CustomReq "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/custom_requests/mod.rs"
    click OpenAI "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/transformer_backends/open_ai/mod.rs"
    click Anthropic "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/transformer_backends/anthropic.rs"
    click Gemini "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/transformer_backends/gemini.rs"
    click LlamaCpp "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/transformer_backends/llama_cpp/mod.rs"
    click Ollama "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/transformer_backends/ollama.rs"
    click MistralFIM "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/transformer_backends/mistral_fim.rs"
    click FileStore "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/memory_backends/file_store.rs"
    click PostgresML "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/memory_backends/postgresml/mod.rs"
    click VectorStore "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/memory_backends/vector_store.rs"
    click MemoryWorker "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/memory_worker.rs"
    click TransformerWorker "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/transformer_worker.rs"
    click TextSplitter "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/splitters/mod.rs"
    click TreeSitter "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/splitters/tree_sitter.rs"
    click VSCode "https://github.com/SilasMarvin/lsp-ai/blob/main/editors/vscode/src/index.ts"
    click Helix "https://github.com/SilasMarvin/lsp-ai/tree/main/examples/helix/"
    click Neovim "https://github.com/SilasMarvin/lsp-ai/blob/main/examples/nvim/init.lua"
    click EmbeddingCore "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/embedding_models/mod.rs"
    click OllamaEmbed "https://github.com/SilasMarvin/lsp-ai/blob/main/crates/lsp-ai/src/embedding_models/ollama.rs"
```
