# esterkane/grounded-rag-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/esterkane/grounded-rag-assistant
- Repository: https://github.com/esterkane/grounded-rag-assistant

## Overview

grounded-rag-assistant is a documentation-grounded RAG service. Its main workflow is a user question entering the HTTP API, going through hybrid retrieval and optional reranking, then citation-validated generation; answers without sufficient cited evidence take an explicit insufficient-evidence path. Ingestion prepares and indexes the corpus, while PostgreSQL supports query logging and human review. MCP exposes the shared retrieval and answer functions, and a partially implemented agent orchestrates MCP tools. Evaluation and observability support quality and operations. Some subsystem links rely on README descriptions because their implementation files were not excerpted.

Main entry points: [`app/generation/answerer.py`](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/generation/answerer.py) (Grounded answerer), [`app/retrieval/retriever.py`](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/retrieval/retriever.py) (Hybrid retrieval), [`app/main.py`](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/main.py) (FastAPI app), [`app/api/ask.py`](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/api/ask.py) (Ask endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP API"]
  node_main["FastAPI app<br/>[main.py]"]
  node_ask["Ask endpoint<br/>[ask.py]"]
  node_search["Search endpoint<br/>[search.py]"]
end

subgraph group_rag["RAG Core"]
  node_answerer["Grounded answerer<br/>[answerer.py]"]
  node_retriever["Hybrid retrieval<br/>[retriever.py]"]
  node_reranker["Cross-encoder reranker<br/>[reranker.py]"]
  node_embedder["Query embeddings<br/>[embedder.py]"]
  node_provider["Provider selection<br/>[factory.py]"]
  node_fallback["Provider fallback<br/>[fallback.py]"]
  node_gemini["Gemini provider<br/>[gemini.py]"]
  node_ollama["Ollama provider<br/>[ollama.py]"]
end

subgraph group_corpus["Corpus Ingestion"]
  node_corpus_fetch["Corpus fetch<br/>[fetch_corpus.py]"]
  node_chunking["Document chunking<br/>[chunking.py]"]
  node_indexing["Index construction<br/>[index.py]"]
  node_ingest_run["Ingestion runner<br/>[run.py]"]
end

subgraph group_state["Review and State"]
  node_repository["Query and feedback data<br/>[repository.py]"]
  node_review["Review queue<br/>[review.py]"]
  node_metrics["Metrics endpoint<br/>[metrics.py]"]
end

subgraph group_extensions["Agent and Operations"]
  node_mcp["MCP tools and server<br/>[tools.py]"]
  node_agent["LangGraph agent<br/>[graph.py]"]
  node_mcp_client["MCP client<br/>[mcp_client.py]"]
  node_eval["Evaluation harness<br/>[harness.py]"]
  node_observability["Logging and tracing<br/>[logging.py]"]
end

node_user(("Questioner"))
node_es[("Elasticsearch")]
node_postgres[("PostgreSQL")]
node_mcp_user(("MCP host/client"))

node_user -->|"sends request"| node_main
node_main -->|"routes requests"| node_ask
node_main -->|"routes requests"| node_search
node_ask -->|"requests answer"| node_answerer
node_search -->|"requests search"| node_retriever
node_answerer -->|"runs retrieval"| node_retriever
node_answerer -->|"reranks candidates"| node_reranker
node_retriever -->|"embeds query"| node_embedder
node_retriever -->|"searches index"| node_es
node_answerer -->|"generates response"| node_provider
node_provider -->|"selects fallback"| node_fallback
node_provider -->|"selects provider"| node_gemini
node_provider -->|"selects provider"| node_ollama
node_fallback -->|"calls primary"| node_gemini
node_fallback -->|"falls back"| node_ollama
node_ingest_run -.->|"starts corpus fetch"| node_corpus_fetch
node_ingest_run -.->|"prepares chunks"| node_chunking
node_ingest_run -.->|"builds index"| node_indexing
node_indexing -.->|"embeds chunks"| node_embedder
node_indexing -.->|"writes documents"| node_es
node_ask -->|"logs query"| node_repository
node_review -->|"reads and records feedback"| node_repository
node_metrics -.->|"reads metrics"| node_repository
node_repository -.->|"reads and writes"| node_postgres
node_mcp_user -->|"calls tools"| node_mcp
node_mcp -->|"reuses retrieval"| node_retriever
node_mcp -->|"reuses answering"| node_answerer
node_agent -->|"dispatches tools"| node_mcp_client
node_mcp_client -.->|"calls tools"| node_mcp
node_eval -->|"evaluates retrieval"| node_retriever
node_eval -->|"evaluates answers"| node_answerer
node_main -->|"configures logging"| node_observability
node_ask -.->|"records activity"| node_observability

click node_main "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/main.py"
click node_ask "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/api/ask.py"
click node_search "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/api/search.py"
click node_answerer "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/generation/answerer.py"
click node_retriever "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/retrieval/retriever.py"
click node_reranker "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/retrieval/reranker.py"
click node_embedder "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/ingestion/embedder.py"
click node_provider "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/generation/providers/factory.py"
click node_fallback "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/generation/providers/fallback.py"
click node_gemini "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/generation/providers/gemini.py"
click node_ollama "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/generation/providers/ollama.py"
click node_corpus_fetch "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/ingestion/fetch_corpus.py"
click node_chunking "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/ingestion/chunking.py"
click node_indexing "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/ingestion/index.py"
click node_ingest_run "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/ingestion/run.py"
click node_repository "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/db/repository.py"
click node_review "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/api/review.py"
click node_metrics "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/api/metrics.py"
click node_mcp "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/mcp/tools.py"
click node_agent "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/agent/graph.py"
click node_mcp_client "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/agent/mcp_client.py"
click node_eval "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/eval/harness.py"
click node_observability "https://github.com/esterkane/grounded-rag-assistant/blob/main/app/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_main,node_ask,node_search,node_mcp_user toneBlue
class node_answerer,node_retriever,node_reranker,node_embedder,node_provider,node_fallback,node_gemini,node_ollama,node_es,node_postgres toneAmber
class node_corpus_fetch,node_chunking,node_indexing,node_ingest_run toneMint
class node_repository,node_review,node_metrics toneRose
class node_mcp,node_agent,node_mcp_client,node_eval,node_observability,node_user toneIndigo
```

## Components

### HTTP API

- [FastAPI app](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/main.py): `app/main.py`
- [Ask endpoint](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/api/ask.py): `app/api/ask.py`
- [Search endpoint](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/api/search.py): `app/api/search.py`

### RAG Core

- [Grounded answerer](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/generation/answerer.py): `app/generation/answerer.py`
- [Hybrid retrieval](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/retrieval/retriever.py): `app/retrieval/retriever.py`
- [Cross-encoder reranker](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/retrieval/reranker.py): `app/retrieval/reranker.py`
- [Query embeddings](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/ingestion/embedder.py): `app/ingestion/embedder.py`
- [Provider selection](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/generation/providers/factory.py): `app/generation/providers/factory.py`
- [Provider fallback](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/generation/providers/fallback.py): `app/generation/providers/fallback.py`
- [Gemini provider](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/generation/providers/gemini.py): `app/generation/providers/gemini.py`
- [Ollama provider](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/generation/providers/ollama.py): `app/generation/providers/ollama.py`

### Corpus Ingestion

- [Corpus fetch](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/ingestion/fetch_corpus.py): `app/ingestion/fetch_corpus.py`
- [Document chunking](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/ingestion/chunking.py): `app/ingestion/chunking.py`
- [Index construction](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/ingestion/index.py): `app/ingestion/index.py`
- [Ingestion runner](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/ingestion/run.py): `app/ingestion/run.py`

### Review and State

- [Query and feedback data](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/db/repository.py): `app/db/repository.py`
- [Review queue](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/api/review.py): `app/api/review.py`
- [Metrics endpoint](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/api/metrics.py): `app/api/metrics.py`

### Agent and Operations

- [MCP tools and server](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/mcp/tools.py): `app/mcp/tools.py`
- [LangGraph agent](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/agent/graph.py): `app/agent/graph.py`
- [MCP client](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/agent/mcp_client.py): `app/agent/mcp_client.py`
- [Evaluation harness](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/eval/harness.py): `app/eval/harness.py`
- [Logging and tracing](https://github.com/esterkane/grounded-rag-assistant/blob/main/app/observability/logging.py): `app/observability/logging.py`

### Other components

- **Questioner**
- **Elasticsearch**
- **PostgreSQL**
- **MCP host/client**

## Connections

- Questioner → FastAPI app: sends request (evidence: `README.md`)
- FastAPI app → Ask endpoint: routes requests (evidence: `app/main.py`)
- FastAPI app → Search endpoint: routes requests (evidence: `app/main.py`)
- Ask endpoint → Grounded answerer: requests answer (evidence: `app/api/ask.py`)
- Search endpoint → Hybrid retrieval: requests search (evidence: `app/api/search.py`)
- Grounded answerer → Hybrid retrieval: runs retrieval (evidence: `app/generation/answerer.py`)
- Grounded answerer → Cross-encoder reranker: reranks candidates (evidence: `app/generation/answerer.py`)
- Hybrid retrieval → Query embeddings: embeds query (evidence: `app/retrieval/retriever.py`)
- Hybrid retrieval → Elasticsearch: searches index (evidence: `README.md`)
- Grounded answerer → Provider selection: generates response (evidence: `app/generation/answerer.py`)
- Provider selection → Provider fallback: selects fallback (evidence: `app/generation/providers/factory.py`)
- Provider selection → Gemini provider: selects provider (evidence: `app/generation/providers/factory.py`)
- Provider selection → Ollama provider: selects provider (evidence: `app/generation/providers/factory.py`)
- Provider fallback → Gemini provider: calls primary (evidence: `app/generation/providers/fallback.py`)
- Provider fallback → Ollama provider: falls back (evidence: `app/generation/providers/fallback.py`)
- Ingestion runner → Corpus fetch: starts corpus fetch
- Ingestion runner → Document chunking: prepares chunks
- Ingestion runner → Index construction: builds index
- Index construction → Query embeddings: embeds chunks
- Index construction → Elasticsearch: writes documents
- Ask endpoint → Query and feedback data: logs query (evidence: `app/api/ask.py`)
- Review queue → Query and feedback data: reads and records feedback (evidence: `app/api/review.py`)
- Metrics endpoint → Query and feedback data: reads metrics
- Query and feedback data → PostgreSQL: reads and writes
- MCP host/client → MCP tools and server: calls tools (evidence: `README.md`)
- MCP tools and server → Hybrid retrieval: reuses retrieval (evidence: `README.md`)
- MCP tools and server → Grounded answerer: reuses answering (evidence: `README.md`)
- LangGraph agent → MCP client: dispatches tools (evidence: `app/agent/graph.py`)
- MCP client → MCP tools and server: calls tools
- Evaluation harness → Hybrid retrieval: evaluates retrieval (evidence: `app/eval/harness.py`)
- Evaluation harness → Grounded answerer: evaluates answers (evidence: `app/eval/harness.py`)
- FastAPI app → Logging and tracing: configures logging (evidence: `app/main.py`)
- Ask endpoint → Logging and tracing: records activity (evidence: `app/api/ask.py`)
