# binapani/llm-chat-api architecture

> Architecture diagram of the GitHub repository binapani/llm-chat-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/binapani/llm-chat-api
- Repository: https://github.com/binapani/llm-chat-api

## Overview

LLM Chat API is a local, SQLite-backed RAG and agent application. Users can upload documents for extraction and ingestion, then query them through grounded RAG or agent tool use; separate endpoints expose chat, hybrid/BM25 search, and retrieval evaluation. The sampled code establishes the main ingestion, retrieval, and generation calls. Agent internals, document extraction/repository behavior, and some persistence wiring are unsampled, so those relationships are shown only when documented or left unconnected. Planned roadmap capabilities are excluded.

Main entry points: [`src/LLMChat.Api/Controllers/ChatController.cs`](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Controllers/ChatController.cs) (Chat endpoints), [`src/LLMChat.Api/Data/VectorDbContext.cs`](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Data/VectorDbContext.cs) (SQLite context), [`src/LLMChat.Api/Services/RAGService.cs`](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/RAGService.cs) (RAG pipeline), [`src/LLMChat.Api/Services/EmbeddingService.cs`](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/EmbeddingService.cs) (Embedding service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API entry points"]
  node_chat["Chat endpoints<br/>[ChatController.cs]"]
  node_documents["Document endpoints"]
  node_bm25api["BM25 endpoint<br/>[Bm25Controller.cs]"]
end

subgraph group_knowledge["Knowledge ingestion"]
  node_ingestion["Ingestion pipeline"]
  node_extractors["Text extraction"]
  node_chunker["Chunking<br/>[DocumentChunker.cs]"]
  node_embedding["Embedding service"]
  node_repository["Document repository"]
end

subgraph group_retrieval["Retrieval and RAG"]
  node_rag["RAG pipeline<br/>[RAGService.cs]"]
  node_vector["Vector search"]
  node_bm25["BM25 search"]
  node_hybrid["Hybrid search"]
  node_reranker["Reranking"]
  node_evaluation["RAG evaluation"]
  node_llm["LLM service<br/>[LLMService.cs]"]
end

subgraph group_agent["Agent and memory"]
  node_agent["Agent orchestration<br/>[AgentService.cs]"]
  node_agenttools["Agent tools<br/>[AgentTools.cs]"]
  node_memory["Conversation memory"]
end

subgraph group_infrastructure["Models and persistence"]
  node_db[("SQLite context<br/>[VectorDbContext.cs]")]
  node_documentsdata[("Document records<br/>[DocumentEntity.cs]")]
  node_vectorsdata[("Vector records")]
  node_sessionsdata[("Conversation records")]
end

node_user(("User"))
node_ollama["Ollama"]

node_user -->|"sends query"| node_chat
node_user -->|"uploads documents"| node_documents
node_user -->|"submits query"| node_bm25api
node_documents -->|"resolves extractor"| node_extractors
node_documents -->|"ingests content"| node_ingestion
node_documents -->|"stores metadata"| node_repository
node_ingestion -->|"chunks content"| node_chunker
node_ingestion -->|"embeds chunks"| node_embedding
node_ingestion -->|"stores vectors"| node_vector
node_chat -->|"generates embedding"| node_embedding
node_chat -->|"searches vectors"| node_vector
node_chat -->|"requests answer"| node_rag
node_chat -->|"requests hybrid search"| node_hybrid
node_chat -->|"evaluates retrieval"| node_evaluation
node_chat -->|"runs agent"| node_agent
node_bm25api -->|"searches keywords"| node_bm25
node_rag -->|"embeds query"| node_embedding
node_rag -->|"retrieves candidates"| node_vector
node_rag -->|"reranks candidates"| node_reranker
node_rag -->|"generates grounded answer"| node_llm
node_hybrid -->|"embeds query"| node_embedding
node_hybrid -->|"gets dense candidates"| node_vector
node_hybrid -->|"gets keyword candidates"| node_bm25
node_hybrid -.->|"reranks merged results"| node_reranker
node_evaluation -->|"embeds questions"| node_embedding
node_evaluation -->|"retrieves candidates"| node_vector
node_evaluation -->|"scores candidates"| node_reranker
node_embedding -.->|"requests embeddings"| node_ollama
node_llm -->|"requests generation"| node_ollama
node_agent -.->|"dispatches tools"| node_agenttools
node_agent -.->|"uses session memory"| node_memory
node_agenttools -.->|"searches knowledge"| node_rag
node_agent -.->|"uses model"| node_ollama
node_db -->|"maps entity"| node_documentsdata
node_db -->|"maps entity"| node_vectorsdata
node_db -->|"maps entity"| node_sessionsdata
node_vector -.->|"persists vectors"| node_db
node_bm25 -->|"reads vectors"| node_db
node_repository -.->|"persists metadata"| node_db
node_memory -.->|"persists messages"| node_db

click node_chat "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Controllers/ChatController.cs"
click node_documents "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Controllers/DocumentsController.cs"
click node_bm25api "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Controllers/Bm25Controller.cs"
click node_ingestion "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/DocumentIngestionService.cs"
click node_extractors "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/DocumentTextExtractorResolver.cs"
click node_chunker "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/DocumentChunker.cs"
click node_embedding "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/EmbeddingService.cs"
click node_rag "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/RAGService.cs"
click node_vector "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/SQLiteVectorStore.cs"
click node_bm25 "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/SQLiteBm25SearchService.cs"
click node_hybrid "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/HybridSearchService.cs"
click node_reranker "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/HybridRerankerService.cs"
click node_evaluation "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/RAGEvaluationService.cs"
click node_llm "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/LLMService.cs"
click node_agent "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/AgentService.cs"
click node_agenttools "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/AgentTools.cs"
click node_memory "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/EfConversationMemoryService.cs"
click node_repository "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/SQLiteDocumentRepository.cs"
click node_db "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Data/VectorDbContext.cs"
click node_documentsdata "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Data/Entities/DocumentEntity.cs"
click node_vectorsdata "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Data/Entities/DocumentVectorEntity.cs"
click node_sessionsdata "https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Data/Entities/ConversationSessionEntity.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_chat,node_documents,node_bm25api,node_user toneBlue
class node_ingestion,node_extractors,node_chunker,node_embedding,node_repository toneAmber
class node_rag,node_vector,node_bm25,node_hybrid,node_reranker,node_evaluation,node_llm toneMint
class node_agent,node_agenttools,node_memory toneRose
class node_db,node_documentsdata,node_vectorsdata,node_sessionsdata,node_ollama toneIndigo
```

## Components

### API entry points

- [Chat endpoints](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Controllers/ChatController.cs): `src/LLMChat.Api/Controllers/ChatController.cs`
- [Document endpoints](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Controllers/DocumentsController.cs): `src/LLMChat.Api/Controllers/DocumentsController.cs`
- [BM25 endpoint](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Controllers/Bm25Controller.cs): `src/LLMChat.Api/Controllers/Bm25Controller.cs`

### Knowledge ingestion

- [Ingestion pipeline](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/DocumentIngestionService.cs): `src/LLMChat.Api/Services/DocumentIngestionService.cs`
- [Text extraction](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/DocumentTextExtractorResolver.cs): `src/LLMChat.Api/Services/DocumentTextExtractorResolver.cs`
- [Chunking](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/DocumentChunker.cs): `src/LLMChat.Api/Services/DocumentChunker.cs`
- [Embedding service](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/EmbeddingService.cs): `src/LLMChat.Api/Services/EmbeddingService.cs`
- [Document repository](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/SQLiteDocumentRepository.cs): `src/LLMChat.Api/Services/SQLiteDocumentRepository.cs`

### Retrieval and RAG

- [RAG pipeline](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/RAGService.cs): `src/LLMChat.Api/Services/RAGService.cs`
- [Vector search](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/SQLiteVectorStore.cs): `src/LLMChat.Api/Services/SQLiteVectorStore.cs`
- [BM25 search](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/SQLiteBm25SearchService.cs): `src/LLMChat.Api/Services/SQLiteBm25SearchService.cs`
- [Hybrid search](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/HybridSearchService.cs): `src/LLMChat.Api/Services/HybridSearchService.cs`
- [Reranking](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/HybridRerankerService.cs): `src/LLMChat.Api/Services/HybridRerankerService.cs`
- [RAG evaluation](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/RAGEvaluationService.cs): `src/LLMChat.Api/Services/RAGEvaluationService.cs`
- [LLM service](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/LLMService.cs): `src/LLMChat.Api/Services/LLMService.cs`

### Agent and memory

- [Agent orchestration](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/AgentService.cs): `src/LLMChat.Api/Services/AgentService.cs`
- [Agent tools](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/AgentTools.cs): `src/LLMChat.Api/Services/AgentTools.cs`
- [Conversation memory](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Services/EfConversationMemoryService.cs): `src/LLMChat.Api/Services/EfConversationMemoryService.cs`

### Models and persistence

- [SQLite context](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Data/VectorDbContext.cs): `src/LLMChat.Api/Data/VectorDbContext.cs`
- [Document records](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Data/Entities/DocumentEntity.cs): `src/LLMChat.Api/Data/Entities/DocumentEntity.cs`
- [Vector records](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Data/Entities/DocumentVectorEntity.cs): `src/LLMChat.Api/Data/Entities/DocumentVectorEntity.cs`
- [Conversation records](https://github.com/binapani/llm-chat-api/blob/main/src/LLMChat.Api/Data/Entities/ConversationSessionEntity.cs): `src/LLMChat.Api/Data/Entities/ConversationSessionEntity.cs`

### Other components

- **User**
- **Ollama**

## Connections

- User → Chat endpoints: sends query (evidence: `src/LLMChat.Api/Controllers/ChatController.cs`)
- User → Document endpoints: uploads documents (evidence: `src/LLMChat.Api/Controllers/DocumentsController.cs`)
- User → BM25 endpoint: submits query (evidence: `src/LLMChat.Api/Controllers/Bm25Controller.cs`)
- Document endpoints → Text extraction: resolves extractor (evidence: `src/LLMChat.Api/Controllers/DocumentsController.cs`)
- Document endpoints → Ingestion pipeline: ingests content (evidence: `src/LLMChat.Api/Controllers/DocumentsController.cs`)
- Document endpoints → Document repository: stores metadata (evidence: `src/LLMChat.Api/Controllers/DocumentsController.cs`)
- Ingestion pipeline → Chunking: chunks content (evidence: `src/LLMChat.Api/Services/DocumentIngestionService.cs`)
- Ingestion pipeline → Embedding service: embeds chunks (evidence: `src/LLMChat.Api/Services/DocumentIngestionService.cs`)
- Ingestion pipeline → Vector search: stores vectors (evidence: `src/LLMChat.Api/Services/DocumentIngestionService.cs`)
- Chat endpoints → Embedding service: generates embedding (evidence: `src/LLMChat.Api/Controllers/ChatController.cs`)
- Chat endpoints → Vector search: searches vectors (evidence: `src/LLMChat.Api/Controllers/ChatController.cs`)
- Chat endpoints → RAG pipeline: requests answer (evidence: `src/LLMChat.Api/Controllers/ChatController.cs`)
- Chat endpoints → Hybrid search: requests hybrid search (evidence: `src/LLMChat.Api/Controllers/ChatController.cs`)
- Chat endpoints → RAG evaluation: evaluates retrieval (evidence: `src/LLMChat.Api/Controllers/ChatController.cs`)
- Chat endpoints → Agent orchestration: runs agent (evidence: `src/LLMChat.Api/Controllers/ChatController.cs`)
- BM25 endpoint → BM25 search: searches keywords (evidence: `src/LLMChat.Api/Controllers/Bm25Controller.cs`)
- RAG pipeline → Embedding service: embeds query (evidence: `src/LLMChat.Api/Services/RAGService.cs`)
- RAG pipeline → Vector search: retrieves candidates (evidence: `src/LLMChat.Api/Services/RAGService.cs`)
- RAG pipeline → Reranking: reranks candidates (evidence: `src/LLMChat.Api/Services/RAGService.cs`)
- RAG pipeline → LLM service: generates grounded answer (evidence: `src/LLMChat.Api/Services/RAGService.cs`)
- Hybrid search → Embedding service: embeds query (evidence: `src/LLMChat.Api/Services/HybridSearchService.cs`)
- Hybrid search → Vector search: gets dense candidates (evidence: `src/LLMChat.Api/Services/HybridSearchService.cs`)
- Hybrid search → BM25 search: gets keyword candidates (evidence: `src/LLMChat.Api/Services/HybridSearchService.cs`)
- Hybrid search → Reranking: reranks merged results
- RAG evaluation → Embedding service: embeds questions (evidence: `src/LLMChat.Api/Services/RAGEvaluationService.cs`)
- RAG evaluation → Vector search: retrieves candidates (evidence: `src/LLMChat.Api/Services/RAGEvaluationService.cs`)
- RAG evaluation → Reranking: scores candidates (evidence: `src/LLMChat.Api/Services/RAGEvaluationService.cs`)
- Embedding service → Ollama: requests embeddings
- LLM service → Ollama: requests generation (evidence: `src/LLMChat.Api/Services/LLMService.cs`)
- Agent orchestration → Agent tools: dispatches tools
- Agent orchestration → Conversation memory: uses session memory
- Agent tools → RAG pipeline: searches knowledge
- Agent orchestration → Ollama: uses model
- SQLite context → Document records: maps entity (evidence: `src/LLMChat.Api/Data/VectorDbContext.cs`)
- SQLite context → Vector records: maps entity (evidence: `src/LLMChat.Api/Data/VectorDbContext.cs`)
- SQLite context → Conversation records: maps entity (evidence: `src/LLMChat.Api/Data/VectorDbContext.cs`)
- Vector search → SQLite context: persists vectors
- BM25 search → SQLite context: reads vectors (evidence: `src/LLMChat.Api/Services/SQLiteBm25SearchService.cs`)
- Document repository → SQLite context: persists metadata
- Conversation memory → SQLite context: persists messages
