# narayan-bhattarai/bidhibot architecture

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

- Interactive diagram: https://gitdiagram.com/narayan-bhattarai/bidhibot
- Repository: https://github.com/narayan-bhattarai/bidhibot

## Overview

BidhiBot is a self-hosted legal-document RAG assistant. Users upload PDFs, which the API extracts page text from, chunks and embeds, then stores for semantic retrieval; questions are embedded, matched to relevant chunks, and passed to a local LLM for grounded answers with page citations. The graph also shows authentication and document management. The controller workflow is excerpted; Ollama and persistence details are supported by the source index and README, while unverified wiring is omitted or dashed.

Main entry points: [`src/main/java/com/ragdesk/controllers/RagController.java`](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/controllers/RagController.java) (RAG API), [`src/main/java/com/ragdesk/services/OllamaServiceImpl.java`](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/OllamaServiceImpl.java) (Ollama models), [`src/main/java/com/ragdesk/services/AuthService.java`](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/AuthService.java) (Authentication), [`src/main/java/com/ragdesk/repositories/DocumentRepository.java`](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/repositories/DocumentRepository.java) (Document repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_rag_api["RAG API<br/>[RagController.java]"]
  node_auth_api["Auth API"]
  node_auth_service["Authentication<br/>[AuthService.java]"]
end

subgraph group_ingest["Document ingestion"]
  node_pdf["PDF extraction"]
  node_pdf_contract["PDF service contract<br/>[IPdfService.java]"]
  node_page["Page content<br/>[PageContent.java]"]
  node_chunking["Text chunking"]
end

subgraph group_rag["Retrieval and answers"]
  node_embedding_contract["Embedding contract"]
  node_ollama["Ollama models"]
  node_vector_contract["Vector service contract"]
  node_vector_impl["Vector search"]
  node_llm_contract["Answer service contract<br/>[ILlmService.java]"]
  node_ollama_runtime["Local Ollama runtime"]
end

subgraph group_data["Domain and persistence"]
  node_user_repo["User repository"]
  node_user_model["User record<br/>[User.java]"]
  node_document_repo["Document repository"]
  node_chunk_repo["Chunk repository"]
  node_document["Document metadata<br/>[Document.java]"]
  node_chunk["Page chunks<br/>[DocumentChunk.java]"]
  node_postgres[("PostgreSQL / pgvector")]
end

node_user(("User"))

node_user -->|"uploads and asks"| node_rag_api
node_user -.->|"authenticates"| node_auth_api
node_rag_api -->|"extracts pages"| node_pdf
node_pdf -->|"returns pages"| node_page
node_rag_api -->|"splits page text"| node_chunking
node_rag_api -->|"embeds chunks and queries"| node_embedding_contract
node_ollama -->|"implements"| node_embedding_contract
node_rag_api -->|"saves and searches"| node_vector_contract
node_vector_impl -->|"implements"| node_vector_contract
node_rag_api -->|"asks with matches"| node_llm_contract
node_ollama -->|"implements"| node_llm_contract
node_rag_api -->|"saves and lists metadata"| node_document_repo
node_vector_impl -->|"persists and retrieves chunks"| node_chunk_repo
node_auth_api -->|"delegates auth"| node_auth_service
node_auth_service -->|"looks up and saves users"| node_user_repo
node_auth_service -->|"creates users"| node_user_model
node_document_repo -.->|"stores metadata"| node_document
node_chunk_repo -->|"stores chunks"| node_chunk
node_document -->|"owns chunks"| node_chunk
node_document_repo -.->|"persists through JPA"| node_postgres
node_chunk_repo -.->|"uses pgvector storage"| node_postgres
node_ollama -.->|"calls locally"| node_ollama_runtime

click node_rag_api "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/controllers/RagController.java"
click node_auth_api "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/controllers/AuthController.java"
click node_auth_service "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/AuthService.java"
click node_user_repo "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/repositories/UserRepository.java"
click node_user_model "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/models/User.java"
click node_pdf "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/PdfServiceImpl.java"
click node_pdf_contract "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/IPdfService.java"
click node_page "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/PageContent.java"
click node_chunking "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/RecursiveChunkingService.java"
click node_embedding_contract "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/IEmbeddingService.java"
click node_ollama "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/OllamaServiceImpl.java"
click node_vector_contract "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/IVectorDbService.java"
click node_vector_impl "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/VectorDbServiceImpl.java"
click node_llm_contract "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/ILlmService.java"
click node_document_repo "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/repositories/DocumentRepository.java"
click node_chunk_repo "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/repositories/DocumentChunkRepository.java"
click node_document "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/models/Document.java"
click node_chunk "https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/models/DocumentChunk.java"

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_rag_api,node_auth_api,node_auth_service,node_user toneBlue
class node_pdf,node_pdf_contract,node_page,node_chunking toneAmber
class node_embedding_contract,node_ollama,node_vector_contract,node_vector_impl,node_llm_contract,node_ollama_runtime toneMint
class node_user_repo,node_user_model,node_document_repo,node_chunk_repo,node_document,node_chunk,node_postgres toneRose
```

## Components

### API and access

- [RAG API](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/controllers/RagController.java): `src/main/java/com/ragdesk/controllers/RagController.java`
- [Auth API](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/controllers/AuthController.java): `src/main/java/com/ragdesk/controllers/AuthController.java`
- [Authentication](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/AuthService.java): `src/main/java/com/ragdesk/services/AuthService.java`

### Document ingestion

- [PDF extraction](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/PdfServiceImpl.java): `src/main/java/com/ragdesk/services/PdfServiceImpl.java`
- [PDF service contract](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/IPdfService.java): `src/main/java/com/ragdesk/services/IPdfService.java`
- [Page content](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/PageContent.java): `src/main/java/com/ragdesk/services/PageContent.java`
- [Text chunking](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/RecursiveChunkingService.java): `src/main/java/com/ragdesk/services/RecursiveChunkingService.java`

### Retrieval and answers

- [Embedding contract](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/IEmbeddingService.java): `src/main/java/com/ragdesk/services/IEmbeddingService.java`
- [Ollama models](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/OllamaServiceImpl.java): `src/main/java/com/ragdesk/services/OllamaServiceImpl.java`
- [Vector service contract](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/IVectorDbService.java): `src/main/java/com/ragdesk/services/IVectorDbService.java`
- [Vector search](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/VectorDbServiceImpl.java): `src/main/java/com/ragdesk/services/VectorDbServiceImpl.java`
- [Answer service contract](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/services/ILlmService.java): `src/main/java/com/ragdesk/services/ILlmService.java`
- **Local Ollama runtime**

### Domain and persistence

- [User repository](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/repositories/UserRepository.java): `src/main/java/com/ragdesk/repositories/UserRepository.java`
- [User record](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/models/User.java): `src/main/java/com/ragdesk/models/User.java`
- [Document repository](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/repositories/DocumentRepository.java): `src/main/java/com/ragdesk/repositories/DocumentRepository.java`
- [Chunk repository](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/repositories/DocumentChunkRepository.java): `src/main/java/com/ragdesk/repositories/DocumentChunkRepository.java`
- [Document metadata](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/models/Document.java): `src/main/java/com/ragdesk/models/Document.java`
- [Page chunks](https://github.com/narayan-bhattarai/bidhibot/blob/main/src/main/java/com/ragdesk/models/DocumentChunk.java): `src/main/java/com/ragdesk/models/DocumentChunk.java`
- **PostgreSQL / pgvector**

### Other components

- **User**

## Connections

- User → RAG API: uploads and asks (evidence: `src/main/java/com/ragdesk/controllers/RagController.java`)
- User → Auth API: authenticates
- RAG API → PDF extraction: extracts pages (evidence: `src/main/java/com/ragdesk/controllers/RagController.java`)
- PDF extraction → Page content: returns pages (evidence: `src/main/java/com/ragdesk/services/PdfServiceImpl.java`)
- RAG API → Text chunking: splits page text (evidence: `src/main/java/com/ragdesk/controllers/RagController.java`)
- RAG API → Embedding contract: embeds chunks and queries (evidence: `src/main/java/com/ragdesk/controllers/RagController.java`)
- Ollama models → Embedding contract: implements (evidence: `src/main/java/com/ragdesk/services/OllamaServiceImpl.java`)
- RAG API → Vector service contract: saves and searches (evidence: `src/main/java/com/ragdesk/controllers/RagController.java`)
- Vector search → Vector service contract: implements (evidence: `src/main/java/com/ragdesk/services/VectorDbServiceImpl.java`)
- RAG API → Answer service contract: asks with matches (evidence: `src/main/java/com/ragdesk/controllers/RagController.java`)
- Ollama models → Answer service contract: implements (evidence: `src/main/java/com/ragdesk/services/OllamaServiceImpl.java`)
- RAG API → Document repository: saves and lists metadata (evidence: `src/main/java/com/ragdesk/controllers/RagController.java`)
- Vector search → Chunk repository: persists and retrieves chunks (evidence: `src/main/java/com/ragdesk/services/VectorDbServiceImpl.java`)
- Auth API → Authentication: delegates auth (evidence: `src/main/java/com/ragdesk/controllers/AuthController.java`)
- Authentication → User repository: looks up and saves users (evidence: `src/main/java/com/ragdesk/services/AuthService.java`)
- Authentication → User record: creates users (evidence: `src/main/java/com/ragdesk/services/AuthService.java`)
- Document repository → Document metadata: stores metadata (evidence: `src/main/java/com/ragdesk/repositories/DocumentRepository.java`)
- Chunk repository → Page chunks: stores chunks (evidence: `src/main/java/com/ragdesk/repositories/DocumentChunkRepository.java`)
- Document metadata → Page chunks: owns chunks (evidence: `src/main/java/com/ragdesk/models/Document.java`)
- Document repository → PostgreSQL / pgvector: persists through JPA
- Chunk repository → PostgreSQL / pgvector: uses pgvector storage
- Ollama models → Local Ollama runtime: calls locally
