# ms-jpq/coq_nvim architecture

> Architecture diagram of the GitHub repository ms-jpq/coq_nvim, 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/ms-jpq/coq_nvim
- Repository: https://github.com/ms-jpq/coq_nvim

## Overview

##### Main Components

a. Core Components:
- Server Component (coq/server/)
- Client Components (coq/clients/)
- LSP Integration (coq/lsp/)
- Database Layer (coq/databases/)
- Shared Utilities (coq/shared/)

b. Client Sources:
- LSP Client
- Buffer Client
- TreeSitter Client
- Snippet Client
- Tags Client
- Tmux Client
- Path Client
- Register Client
- Cache Client
- Third-party Clients (Tabnine, etc.)

**┌─────────────────────────────────────────────┐**
- Neovim Editor               │
- ┬─────────────────────┘

**┌───────────────────────┴─────────────────────┐**
- COQ Core Server                │
- ┌─────────────┐    ┌──────────────────┐   │
- Runtime    │    │    Completions   │   │
- ┘    └──────────────────┘   │
- ┬─────────────────┬──────────────┘

**┌───────────┴─────────┐    ┌─┴──────────────┐**
- Client Manager   │    │  SQLite Cache  │
- ┬─────────┘    └───────────────┘

**┌───────────┴─────────────────────────────────┐**
- Source Clients                  │
- ┌─────────┐ ┌────────┐ ┌───────────────┐  │
- LSP   │ │ Buffer │ │  TreeSitter   │  │
- ┘ └────────┘ └───────────────┘  │
- ┌─────────┐ ┌────────┐ ┌───────────────┐  │
- Snippet │ │  Tags  │ │    Tmux       │  │
- ┘ └────────┘ └───────────────┘  │
- ┘

##### Data Flow Indicators

- Completion requests from Neovim to COQ Server
- Server distribution to clients
- Client responses back through server
- Cache interactions
- LSP communication

##### Key Elements to Highlight

a. Performance Features:
- Native C in-memory B-trees
- SQLite VM interrupts
- Coroutine scheduler
- Flow control system

b. Integration Points:
- LSP protocol handlers
- Treesitter integration
- External source plugins
- Snippet engines

##### Additional Details

Small annotations for:
- Database schemas
- Configuration points
- Event handlers
- Cache mechanisms

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Editor["Neovim Editor"]
        NV[Neovim Interface]
    end

    subgraph Core["COQ Core Server"]
        RT["Runtime"]:::core
        CH["Completions Handler"]:::core
    end

    subgraph ClientMgr["Client Manager"]
        CM["Client Manager"]:::manager
    end

    subgraph DB["Database Layer"]
        SQL["SQLite Cache"]:::database
        INS["Insertions DB"]:::database
    end

    subgraph Shared["Shared Utilities"]
        FZ["Fuzzy Search"]:::util
        RU["Runtime Utils"]:::util
    end

    subgraph Sources["Source Clients"]
        direction TB
        LSP["LSP Client"]:::client
        BUF["Buffer Client"]:::client
        TS["TreeSitter Client"]:::client
        SNP["Snippet Client"]:::client
        TAG["Tags Client"]:::client
        TMX["Tmux Client"]:::client
        PTH["Path Client"]:::client
        REG["Register Client"]:::client
        CCH["Cache Client"]:::client
        TPP["Third-party Client"]:::client
    end

    subgraph LSPInt["LSP Integration"]
        LSPP["LSP Protocol"]:::lsp
        LSPR["LSP Requests"]:::lsp
    end

    subgraph Snippets["Snippet System"]
        SNC["Snippet Core"]:::snippet
        SNL["Snippet Loaders"]:::snippet
        SNR["Snippet Parsers"]:::snippet
    end

    subgraph Cache["Cache System"]
        CDB["Cache Database"]:::cache
    end

    %% Connections
    NV --> RT
    RT --> CH
    CH --> CM
    CM --> Sources
    Sources --> CH
    CH --> SQL
    LSP --> LSPP
    LSPP --> LSPR
    SNP --> SNC
    SNC --> SNL
    SNC --> SNR
    CCH --> CDB
    
    %% Click Events
    click RT "https://github.com/ms-jpq/coq_nvim/blob/coq/coq/server/runtime.py"
    click CH "https://github.com/ms-jpq/coq_nvim/blob/coq/coq/server/completions.py"
    click CM "https://github.com/ms-jpq/coq_nvim/blob/coq/coq/clients/__init__.py"
    click LSPP "https://github.com/ms-jpq/coq_nvim/blob/coq/coq/lsp/protocol.py"
    click LSPR "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/lsp/requests/"
    click INS "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/databases/insertions/"
    click FZ "https://github.com/ms-jpq/coq_nvim/blob/coq/coq/shared/fuzzy.py"
    click RU "https://github.com/ms-jpq/coq_nvim/blob/coq/coq/shared/runtime.py"
    click LSP "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/clients/lsp/"
    click BUF "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/clients/buffers/"
    click TS "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/clients/tree_sitter/"
    click SNP "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/clients/snippet/"
    click TAG "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/clients/tags/"
    click TMX "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/clients/tmux/"
    click PTH "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/clients/paths/"
    click REG "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/clients/registers/"
    click CCH "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/clients/cache/"
    click TPP "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/clients/third_party/"
    click SNC "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/snippets/"
    click SNL "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/snippets/loaders/"
    click SNR "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/snippets/parsers/"
    click CDB "https://github.com/ms-jpq/coq_nvim/tree/coq/coq/clients/cache/db/"

    %% Styles
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef manager fill:#4CAF50,stroke:#2E7D32,color:white
    classDef database fill:#FFC107,stroke:#FFA000,color:black
    classDef util fill:#9E9E9E,stroke:#616161,color:white
    classDef client fill:#4CAF50,stroke:#2E7D32,color:white
    classDef lsp fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef snippet fill:#00BCD4,stroke:#0097A7,color:white
    classDef cache fill:#FF9800,stroke:#F57C00,color:white
```
