# vidhvath28/nixos-docs-copilot architecture

> Architecture diagram of the GitHub repository vidhvath28/nixos-docs-copilot, 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/vidhvath28/nixos-docs-copilot
- Repository: https://github.com/vidhvath28/nixos-docs-copilot

## Overview

NixOS Docs Copilot ingests the NixOS manual into a persistent vector index, then serves cited answers through a corrective-RAG workflow. The graph separates retrieval, relevance grading, query rewriting, and answer generation; the API exposes that workflow and a small web UI. The README also documents an evaluation harness, included as a separate capability. Edges reflect the sampled source and README; the UI’s browser-to-API behavior is not shown, so that link is marked unverified.

Main entry points: [`app/main.py`](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/main.py) (FastAPI endpoints), [`app/llm.py`](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/llm.py) (Vector store access), [`app/graph.py`](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/graph.py) (RAG state machine), [`app/ingest.py`](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/ingest.py) (Fetch and chunk)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Manual ingestion"]
  node_ingest["Fetch and chunk<br/>[ingest.py]"]
end

subgraph group_serving["Answer service"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_webui["Web UI<br/>[index.html]"]
end

subgraph group_agent["Corrective RAG"]
  node_search["Similarity search<br/>[graph.py]"]
  node_graph["RAG state machine<br/>[graph.py]"]
  node_retrieve["Retrieve passages<br/>[graph.py]"]
  node_grade["Grade relevance<br/>[graph.py]"]
  node_rewrite["Rewrite query<br/>[graph.py]"]
  node_generate["Generate citations<br/>[graph.py]"]
end

subgraph group_runtime["Runtime services"]
  node_settings["Settings<br/>[config.py]"]
  node_embeddings["Local embeddings<br/>[embeddings.py]"]
  node_index[("Chroma index<br/>[ingest.py]")]
  node_vectorstore["Vector store access<br/>[llm.py]"]
  node_model["Chat model factory<br/>[llm.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_evals["Eval harness<br/>[run_evals.py]"]
end

node_user(("Questioner"))
node_manual["NixOS manual"]
node_provider{{"LLM provider"}}

node_user -->|"asks"| node_api
node_api -->|"invokes"| node_graph
node_api -->|"serves"| node_webui
node_webui -.->|"submits questions"| node_api
node_settings -->|"configures"| node_ingest
node_ingest -->|"fetches"| node_manual
node_ingest -->|"embeds chunks"| node_embeddings
node_ingest -->|"writes chunks"| node_index
node_settings -->|"configures"| node_vectorstore
node_vectorstore -->|"embeds queries"| node_embeddings
node_vectorstore -->|"opens"| node_index
node_api -->|"opens"| node_vectorstore
node_api -->|"builds search"| node_search
node_search -->|"searches"| node_vectorstore
node_graph -->|"starts"| node_retrieve
node_retrieve -->|"queries"| node_search
node_retrieve -->|"passes passages"| node_grade
node_grade -->|"routes if empty"| node_rewrite
node_grade -->|"routes if relevant"| node_generate
node_rewrite -->|"retries query"| node_retrieve
node_generate -->|"returns answer"| node_graph
node_graph -->|"uses model"| node_model
node_model -->|"calls"| node_provider
node_evals -->|"measures retrieval"| node_vectorstore
node_evals -->|"runs modes"| node_graph
node_evals -->|"judges answers"| node_model

click node_settings "https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/config.py"
click node_ingest "https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/ingest.py"
click node_embeddings "https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/embeddings.py"
click node_index "https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/ingest.py"
click node_vectorstore "https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/llm.py"
click node_search "https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/graph.py"
click node_api "https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/main.py"
click node_webui "https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/static/index.html"
click node_graph "https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/graph.py"
click node_retrieve "https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/graph.py"
click node_grade "https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/graph.py"
click node_rewrite "https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/graph.py"
click node_generate "https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/graph.py"
click node_model "https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/llm.py"
click node_evals "https://github.com/vidhvath28/nixos-docs-copilot/blob/main/evals/run_evals.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_ingest toneBlue
class node_api,node_webui toneAmber
class node_search,node_graph,node_retrieve,node_grade,node_rewrite,node_generate toneMint
class node_settings,node_embeddings,node_index,node_vectorstore,node_model toneRose
class node_evals,node_user,node_manual,node_provider toneIndigo
```

## Components

### Manual ingestion

- [Fetch and chunk](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/ingest.py): `app/ingest.py`

### Answer service

- [FastAPI endpoints](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/main.py): `app/main.py`
- [Web UI](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/static/index.html): `app/static/index.html`

### Corrective RAG

- [Similarity search](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/graph.py): `app/graph.py`
- [RAG state machine](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/graph.py): `app/graph.py`
- [Retrieve passages](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/graph.py): `app/graph.py`
- [Grade relevance](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/graph.py): `app/graph.py`
- [Rewrite query](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/graph.py): `app/graph.py`
- [Generate citations](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/graph.py): `app/graph.py`

### Runtime services

- [Settings](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/config.py): `app/config.py`
- [Local embeddings](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/embeddings.py): `app/embeddings.py`
- [Chroma index](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/ingest.py): `app/ingest.py`
- [Vector store access](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/llm.py): `app/llm.py`
- [Chat model factory](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/app/llm.py): `app/llm.py`

### Evaluation

- [Eval harness](https://github.com/vidhvath28/nixos-docs-copilot/blob/main/evals/run_evals.py): `evals/run_evals.py`

### Other components

- **Questioner**
- **NixOS manual**
- **LLM provider**

## Connections

- Questioner → FastAPI endpoints: asks (evidence: `README.md`)
- FastAPI endpoints → RAG state machine: invokes (evidence: `app/main.py`)
- FastAPI endpoints → Web UI: serves (evidence: `app/main.py`)
- Web UI → FastAPI endpoints: submits questions
- Settings → Fetch and chunk: configures (evidence: `app/ingest.py`)
- Fetch and chunk → NixOS manual: fetches (evidence: `app/ingest.py`)
- Fetch and chunk → Local embeddings: embeds chunks (evidence: `app/ingest.py`)
- Fetch and chunk → Chroma index: writes chunks (evidence: `app/ingest.py`)
- Settings → Vector store access: configures (evidence: `app/llm.py`)
- Vector store access → Local embeddings: embeds queries (evidence: `app/llm.py`)
- Vector store access → Chroma index: opens (evidence: `app/llm.py`)
- FastAPI endpoints → Vector store access: opens (evidence: `app/main.py`)
- FastAPI endpoints → Similarity search: builds search (evidence: `app/main.py`)
- Similarity search → Vector store access: searches (evidence: `app/graph.py`)
- RAG state machine → Retrieve passages: starts (evidence: `app/graph.py`)
- Retrieve passages → Similarity search: queries (evidence: `app/graph.py`)
- Retrieve passages → Grade relevance: passes passages (evidence: `app/graph.py`)
- Grade relevance → Rewrite query: routes if empty (evidence: `app/graph.py`)
- Grade relevance → Generate citations: routes if relevant (evidence: `app/graph.py`)
- Rewrite query → Retrieve passages: retries query (evidence: `app/graph.py`)
- Generate citations → RAG state machine: returns answer (evidence: `app/graph.py`)
- RAG state machine → Chat model factory: uses model (evidence: `app/main.py`)
- Chat model factory → LLM provider: calls (evidence: `README.md`)
- Eval harness → Vector store access: measures retrieval (evidence: `evals/run_evals.py`)
- Eval harness → RAG state machine: runs modes (evidence: `evals/run_evals.py`)
- Eval harness → Chat model factory: judges answers (evidence: `evals/run_evals.py`)
