# naveen-kumar-r-n/ragapi architecture

> Architecture diagram of the GitHub repository naveen-kumar-r-n/ragapi, 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/naveen-kumar-r-n/ragapi
- Repository: https://github.com/naveen-kumar-r-n/ragapi

## Overview

This ASP.NET Core API supports document ingestion and conversational question answering over locally hosted models. Uploads are saved, extracted, chunked, embedded and stored; chat embeds a question, retrieves similar chunks, combines them with session history, asks LM Studio, and persists the exchange. The README also documents session creation/history, but the tree has no session controller, so that capability is not mapped to an implementation node. Relationships reflect excerpts or README statements; unsampled chunking and chat routing details are omitted where caller evidence is unavailable.

Main entry points: [`RagDbContext.cs`](https://github.com/naveen-kumar-r-n/ragapi/blob/master/RagDbContext.cs) (EF data context), [`Controllers/DocumentsController.cs`](https://github.com/naveen-kumar-r-n/ragapi/blob/master/Controllers/DocumentsController.cs) (Document upload API), [`Services/RagService.cs`](https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/RagService.cs) (RAG orchestration), [`Services/EmbeddingService.cs`](https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/EmbeddingService.cs) (Embedding generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API entry points"]
  node_documents_api["Document upload API"]
  node_chat_api["Chat API<br/>[ChatController.cs]"]
end

subgraph group_ingestion["Document ingestion"]
  node_document_service["File extraction<br/>[DocumentService.cs]"]
  node_chunk_service["Text chunking<br/>[ChunkService.cs]"]
end

subgraph group_rag["Question answering"]
  node_embedding["Embedding generation"]
  node_lmstudio["Local model API<br/>[LmStudioService.cs]"]
  node_rag_service["RAG orchestration<br/>[RagService.cs]"]
  node_retrieval["Similarity retrieval"]
end

subgraph group_state["Persistence"]
  node_memory["Conversation memory<br/>[MemoryService.cs]"]
  node_vector_store["Chunk storage"]
  node_db_context["EF data context<br/>[RagDbContext.cs]"]
  node_document_chunks["Document chunks<br/>[DocumentChunk.cs]"]
  node_chat_messages["Chat messages<br/>[ChatMessage.cs]"]
end

node_client(("Client"))
node_postgres[("PostgreSQL + pgvector")]
node_lm_service{{"LM Studio"}}

node_client -->|"uploads files"| node_documents_api
node_client -->|"asks questions"| node_chat_api
node_documents_api -->|"saves and extracts"| node_document_service
node_documents_api -->|"creates chunks"| node_chunk_service
node_documents_api -->|"embeds chunks"| node_embedding
node_documents_api -->|"stores chunks"| node_vector_store
node_chat_api -->|"asks"| node_rag_service
node_rag_service -->|"embeds question"| node_embedding
node_rag_service -->|"searches chunks"| node_retrieval
node_rag_service -->|"loads and saves history"| node_memory
node_rag_service -->|"requests answer"| node_lmstudio
node_embedding -.->|"requests embeddings"| node_lm_service
node_lmstudio -->|"serves completion"| node_lm_service
node_vector_store -->|"writes chunks"| node_db_context
node_retrieval -->|"queries vectors"| node_db_context
node_memory -->|"reads and writes messages"| node_db_context
node_db_context -->|"maps"| node_document_chunks
node_db_context -->|"maps"| node_chat_messages
node_db_context -->|"persists data"| node_postgres

click node_documents_api "https://github.com/naveen-kumar-r-n/ragapi/blob/master/Controllers/DocumentsController.cs"
click node_chat_api "https://github.com/naveen-kumar-r-n/ragapi/blob/master/Controllers/ChatController.cs"
click node_document_service "https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/DocumentService.cs"
click node_chunk_service "https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/ChunkService.cs"
click node_embedding "https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/EmbeddingService.cs"
click node_lmstudio "https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/LmStudioService.cs"
click node_rag_service "https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/RagService.cs"
click node_retrieval "https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/RetrievalService.cs"
click node_memory "https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/MemoryService.cs"
click node_vector_store "https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/VectorStoreService.cs"
click node_db_context "https://github.com/naveen-kumar-r-n/ragapi/blob/master/RagDbContext.cs"
click node_document_chunks "https://github.com/naveen-kumar-r-n/ragapi/blob/master/Models/DocumentChunk.cs"
click node_chat_messages "https://github.com/naveen-kumar-r-n/ragapi/blob/master/Models/ChatMessage.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_documents_api,node_chat_api,node_client toneBlue
class node_document_service,node_chunk_service,node_postgres toneAmber
class node_embedding,node_lmstudio,node_rag_service,node_retrieval toneMint
class node_memory,node_vector_store,node_db_context,node_document_chunks,node_chat_messages toneRose
class node_lm_service toneIndigo
```

## Components

### API entry points

- [Document upload API](https://github.com/naveen-kumar-r-n/ragapi/blob/master/Controllers/DocumentsController.cs): `Controllers/DocumentsController.cs`
- [Chat API](https://github.com/naveen-kumar-r-n/ragapi/blob/master/Controllers/ChatController.cs): `Controllers/ChatController.cs`

### Document ingestion

- [File extraction](https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/DocumentService.cs): `Services/DocumentService.cs`
- [Text chunking](https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/ChunkService.cs): `Services/ChunkService.cs`

### Question answering

- [Embedding generation](https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/EmbeddingService.cs): `Services/EmbeddingService.cs`
- [Local model API](https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/LmStudioService.cs): `Services/LmStudioService.cs`
- [RAG orchestration](https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/RagService.cs): `Services/RagService.cs`
- [Similarity retrieval](https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/RetrievalService.cs): `Services/RetrievalService.cs`

### Persistence

- [Conversation memory](https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/MemoryService.cs): `Services/MemoryService.cs`
- [Chunk storage](https://github.com/naveen-kumar-r-n/ragapi/blob/master/Services/VectorStoreService.cs): `Services/VectorStoreService.cs`
- [EF data context](https://github.com/naveen-kumar-r-n/ragapi/blob/master/RagDbContext.cs): `RagDbContext.cs`
- [Document chunks](https://github.com/naveen-kumar-r-n/ragapi/blob/master/Models/DocumentChunk.cs): `Models/DocumentChunk.cs`
- [Chat messages](https://github.com/naveen-kumar-r-n/ragapi/blob/master/Models/ChatMessage.cs): `Models/ChatMessage.cs`

### Other components

- **Client**
- **PostgreSQL + pgvector**
- **LM Studio**

## Connections

- Client → Document upload API: uploads files (evidence: `README.md`)
- Client → Chat API: asks questions (evidence: `README.md`)
- Document upload API → File extraction: saves and extracts (evidence: `Controllers/DocumentsController.cs`)
- Document upload API → Text chunking: creates chunks (evidence: `Controllers/DocumentsController.cs`)
- Document upload API → Embedding generation: embeds chunks (evidence: `Controllers/DocumentsController.cs`)
- Document upload API → Chunk storage: stores chunks (evidence: `Controllers/DocumentsController.cs`)
- Chat API → RAG orchestration: asks (evidence: `Controllers/ChatController.cs`)
- RAG orchestration → Embedding generation: embeds question (evidence: `Services/RagService.cs`)
- RAG orchestration → Similarity retrieval: searches chunks (evidence: `Services/RagService.cs`)
- RAG orchestration → Conversation memory: loads and saves history (evidence: `Services/RagService.cs`)
- RAG orchestration → Local model API: requests answer (evidence: `Services/RagService.cs`)
- Embedding generation → LM Studio: requests embeddings
- Local model API → LM Studio: serves completion (evidence: `README.md`)
- Chunk storage → EF data context: writes chunks (evidence: `Services/VectorStoreService.cs`)
- Similarity retrieval → EF data context: queries vectors (evidence: `Services/RetrievalService.cs`)
- Conversation memory → EF data context: reads and writes messages (evidence: `Services/MemoryService.cs`)
- EF data context → Document chunks: maps (evidence: `RagDbContext.cs`)
- EF data context → Chat messages: maps (evidence: `RagDbContext.cs`)
- EF data context → PostgreSQL + pgvector: persists data (evidence: `README.md`)
