# thrishok/rag-prod architecture

> Architecture diagram of the GitHub repository thrishok/rag-prod, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thrishok/rag-prod
- Repository: https://github.com/thrishok/rag-prod

## Overview

This is a FastAPI-based RAG question-answering service. A client submits a chat question; the API starts a LangGraph workflow that embeds the question, retrieves and reranks document chunks, generates a cited answer, and records run details. The repository also includes pgvector chunk storage and structured observability. The tree and excerpts show no document-ingestion endpoint or UI, so those capabilities are not mapped; some graph internals and API wiring are only partially excerpted, and uncertain links are omitted.

Main entry points: [`src/rag/core/graph.py`](https://github.com/thrishok/rag-prod/blob/main/src/rag/core/graph.py) (Workflow graph), [`src/rag/api/routes/chat.py`](https://github.com/thrishok/rag-prod/blob/main/src/rag/api/routes/chat.py) (Chat endpoint), [`src/rag/core/vector_store.py`](https://github.com/thrishok/rag-prod/blob/main/src/rag/core/vector_store.py) (Hybrid vector search), [`src/rag/main.py`](https://github.com/thrishok/rag-prod/blob/main/src/rag/main.py) (FastAPI app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Chat API"]
  node_app["FastAPI app<br/>[main.py]"]
  node_chat["Chat endpoint<br/>[chat.py]"]
end

subgraph group_workflow["RAG Workflow"]
  node_graph["Workflow graph<br/>[graph.py]"]
  node_generation["LLM generation<br/>[llm.py]"]
end

subgraph group_retrieval["Retrieval Services"]
  node_embedding["Question embedding<br/>[embeddings.py]"]
  node_vector["Hybrid vector search<br/>[vector_store.py]"]
  node_rank["Reranking &amp; fusion<br/>[retrieval.py]"]
end

subgraph group_state["Persistence &amp; Observability"]
  node_database[("RAG data models<br/>[database.py]")]
  node_logging["Structured logging<br/>[logging.py]"]
end

node_client(("Chat client"))
node_groq{{"Groq API"}}
node_postgres[("PostgreSQL / pgvector")]

node_client -->|"sends request"| node_app
node_app -->|"routes chat"| node_chat
node_chat -->|"builds and invokes"| node_graph
node_graph -.->|"embeds question"| node_embedding
node_graph -->|"retrieves chunks"| node_vector
node_graph -->|"reranks chunks"| node_rank
node_graph -.->|"generates answer"| node_generation
node_generation -->|"calls model"| node_groq
node_vector -.->|"queries and writes"| node_postgres
node_vector -.->|"uses chunk models"| node_database
node_graph -->|"records run events"| node_database
node_chat -->|"logs chat turn"| node_logging
node_chat -->|"returns answer"| node_client

click node_app "https://github.com/thrishok/rag-prod/blob/main/src/rag/main.py"
click node_chat "https://github.com/thrishok/rag-prod/blob/main/src/rag/api/routes/chat.py"
click node_graph "https://github.com/thrishok/rag-prod/blob/main/src/rag/core/graph.py"
click node_embedding "https://github.com/thrishok/rag-prod/blob/main/src/rag/core/embeddings.py"
click node_vector "https://github.com/thrishok/rag-prod/blob/main/src/rag/core/vector_store.py"
click node_rank "https://github.com/thrishok/rag-prod/blob/main/src/rag/core/retrieval.py"
click node_generation "https://github.com/thrishok/rag-prod/blob/main/src/rag/core/llm.py"
click node_database "https://github.com/thrishok/rag-prod/blob/main/src/rag/models/database.py"
click node_logging "https://github.com/thrishok/rag-prod/blob/main/src/rag/observability/logging.py"

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_app,node_chat,node_client toneBlue
class node_graph,node_generation,node_postgres toneAmber
class node_embedding,node_vector,node_rank,node_groq toneMint
class node_database,node_logging toneRose
```

## Components

### Chat API

- [FastAPI app](https://github.com/thrishok/rag-prod/blob/main/src/rag/main.py): `src/rag/main.py`
- [Chat endpoint](https://github.com/thrishok/rag-prod/blob/main/src/rag/api/routes/chat.py): `src/rag/api/routes/chat.py`

### RAG Workflow

- [Workflow graph](https://github.com/thrishok/rag-prod/blob/main/src/rag/core/graph.py): `src/rag/core/graph.py`
- [LLM generation](https://github.com/thrishok/rag-prod/blob/main/src/rag/core/llm.py): `src/rag/core/llm.py`

### Retrieval Services

- [Question embedding](https://github.com/thrishok/rag-prod/blob/main/src/rag/core/embeddings.py): `src/rag/core/embeddings.py`
- [Hybrid vector search](https://github.com/thrishok/rag-prod/blob/main/src/rag/core/vector_store.py): `src/rag/core/vector_store.py`
- [Reranking & fusion](https://github.com/thrishok/rag-prod/blob/main/src/rag/core/retrieval.py): `src/rag/core/retrieval.py`

### Persistence & Observability

- [RAG data models](https://github.com/thrishok/rag-prod/blob/main/src/rag/models/database.py): `src/rag/models/database.py`
- [Structured logging](https://github.com/thrishok/rag-prod/blob/main/src/rag/observability/logging.py): `src/rag/observability/logging.py`

### Other components

- **Chat client**
- **Groq API**
- **PostgreSQL / pgvector**

## Connections

- Chat client → FastAPI app: sends request (evidence: `src/rag/main.py`)
- FastAPI app → Chat endpoint: routes chat (evidence: `src/rag/main.py`)
- Chat endpoint → Workflow graph: builds and invokes (evidence: `src/rag/api/routes/chat.py`)
- Workflow graph → Question embedding: embeds question
- Workflow graph → Hybrid vector search: retrieves chunks (evidence: `src/rag/core/graph.py`)
- Workflow graph → Reranking & fusion: reranks chunks (evidence: `src/rag/core/graph.py`)
- Workflow graph → LLM generation: generates answer
- LLM generation → Groq API: calls model (evidence: `src/rag/core/llm.py`)
- Hybrid vector search → PostgreSQL / pgvector: queries and writes
- Hybrid vector search → RAG data models: uses chunk models
- Workflow graph → RAG data models: records run events (evidence: `src/rag/core/graph.py`)
- Chat endpoint → Structured logging: logs chat turn (evidence: `src/rag/api/routes/chat.py`)
- Chat endpoint → Chat client: returns answer (evidence: `src/rag/api/routes/chat.py`)
