# vadimsiminenco/pad architecture

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

- Interactive diagram: https://gitdiagram.com/vadimsiminenco/pad
- Repository: https://github.com/vadimsiminenco/pad

## Overview

This is a Unity documentation RAG application. Its user path is a question through language validation, semantic retrieval, evidence filtering/reranking, and cited answer generation; separate commands acquire documentation, preprocess and chunk it, then embed and index it. The tree and sampled files show these stages and several call relationships, but much of the command wiring and preprocessing/indexing implementation was not excerpted, so those links are omitted or marked unverified.

Main entry points: [`lab1/src/UnityDocsRag.Ingestion/Program.cs`](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Ingestion/Program.cs) (RAG CLI), [`lab1/src/UnityDocsRag.Infrastructure/Query/RagQueryService.cs`](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Query/RagQueryService.cs) (RAG query service), [`lab1/src/UnityDocsRag.Ingestion/IndexingRunner.cs`](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Ingestion/IndexingRunner.cs) (Embedding indexer), [`lab1/src/UnityDocsRag.Infrastructure/Retrieval/SemanticSearchService.cs`](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Retrieval/SemanticSearchService.cs) (Semantic search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Document ingestion"]
  node_cli["RAG CLI<br/>[Program.cs]"]
  node_api["API host<br/>[Program.cs]"]
  node_docfetch["Documentation fetch<br/>[IngestionRunner.cs]"]
  node_doccache["Document cache<br/>[Documentation]"]
end

subgraph group_index["Processing and indexing"]
  node_process["HTML preprocessing"]
  node_chunk["Heading-aware chunks"]
  node_artifacts["Processing artifacts"]
  node_artifactread["Artifact reader"]
  node_indexrunner["Embedding indexer<br/>[IndexingRunner.cs]"]
end

subgraph group_search["Retrieval and answering"]
  node_askrunner["Ask runner<br/>[AskRunner.cs]"]
  node_query["RAG query service<br/>[RagQueryService.cs]"]
  node_language["Language detector"]
  node_semantic["Semantic search"]
  node_retriever["Vector retriever"]
  node_reranker["Ollama reranker<br/>[OllamaReranker.cs]"]
  node_generator["Answer generator"]
  node_prompt["Answer prompt builder"]
  node_evaluation["RAG evaluation"]
end

subgraph group_infra["Infrastructure"]
  node_embed["Ollama embeddings"]
  node_vectorstore[("Vector store")]
end

node_user(("Questioner"))
node_unitydocs(("Unity docs source"))
node_ollama{{"Ollama"}}
node_postgres[("PostgreSQL pgvector")]

node_cli -.->|"runs ingestion"| node_docfetch
node_unitydocs -.->|"provides documents"| node_docfetch
node_docfetch -->|"saves changes"| node_doccache
node_cli -.->|"runs processing"| node_process
node_process -.->|"prepares chunks"| node_chunk
node_cli -.->|"stores artifacts"| node_artifacts
node_artifactread -->|"reads artifacts"| node_artifacts
node_cli -->|"runs indexing"| node_indexrunner
node_indexrunner -.->|"creates embeddings"| node_embed
node_indexrunner -.->|"writes vectors"| node_vectorstore
node_embed -->|"requests vectors"| node_ollama
node_vectorstore -->|"persists vectors"| node_postgres
node_user -.->|"asks question"| node_cli
node_cli -->|"runs ask"| node_askrunner
node_askrunner -.->|"dispatches query"| node_query
node_query -->|"detects language"| node_language
node_query -->|"searches evidence"| node_semantic
node_semantic -->|"embeds query"| node_embed
node_semantic -->|"retrieves chunks"| node_retriever
node_retriever -->|"queries vectors"| node_postgres
node_query -->|"reranks candidates"| node_reranker
node_query -->|"generates answer"| node_generator
node_generator -->|"builds prompt"| node_prompt
node_generator -.->|"requests completion"| node_ollama
node_user -.->|"submits request"| node_api
node_evaluation -.->|"evaluates answers"| node_query

click node_cli "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Ingestion/Program.cs"
click node_api "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Api/Program.cs"
click node_docfetch "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Ingestion/IngestionRunner.cs"
click node_doccache "https://github.com/vadimsiminenco/pad/tree/main/lab1/src/UnityDocsRag.Infrastructure/Documentation"
click node_process "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Preprocessing/UnityHtmlDocumentPreprocessor.cs"
click node_chunk "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Preprocessing/HeadingAwareDocumentChunker.cs"
click node_artifacts "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Preprocessing/FileProcessingArtifactStore.cs"
click node_artifactread "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Preprocessing/ProcessingArtifactReader.cs"
click node_indexrunner "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Ingestion/IndexingRunner.cs"
click node_embed "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Embeddings/OllamaEmbeddingProvider.cs"
click node_vectorstore "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Storage/PostgresVectorStore.cs"
click node_askrunner "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Ingestion/AskRunner.cs"
click node_query "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Query/RagQueryService.cs"
click node_language "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Query/RussianEnglishLanguageDetector.cs"
click node_semantic "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Retrieval/SemanticSearchService.cs"
click node_retriever "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Retrieval/PostgresVectorRetriever.cs"
click node_reranker "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Reranking/OllamaReranker.cs"
click node_generator "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Generation/OllamaAnswerGenerator.cs"
click node_prompt "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Generation/RagPromptBuilder.cs"
click node_evaluation "https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Evaluation/EvaluationMetrics.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_cli,node_api,node_docfetch,node_doccache toneBlue
class node_process,node_chunk,node_artifacts,node_artifactread,node_indexrunner,node_postgres toneAmber
class node_askrunner,node_query,node_language,node_semantic,node_retriever,node_reranker,node_generator,node_prompt,node_evaluation toneMint
class node_embed,node_vectorstore toneRose
class node_user,node_unitydocs,node_ollama toneIndigo
```

## Components

### Document ingestion

- [RAG CLI](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Ingestion/Program.cs): `lab1/src/UnityDocsRag.Ingestion/Program.cs`
- [API host](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Api/Program.cs): `lab1/src/UnityDocsRag.Api/Program.cs`
- [Documentation fetch](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Ingestion/IngestionRunner.cs): `lab1/src/UnityDocsRag.Ingestion/IngestionRunner.cs`
- [Document cache](https://github.com/vadimsiminenco/pad/tree/main/lab1/src/UnityDocsRag.Infrastructure/Documentation): `lab1/src/UnityDocsRag.Infrastructure/Documentation`

### Processing and indexing

- [HTML preprocessing](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Preprocessing/UnityHtmlDocumentPreprocessor.cs): `lab1/src/UnityDocsRag.Infrastructure/Preprocessing/UnityHtmlDocumentPreprocessor.cs`
- [Heading-aware chunks](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Preprocessing/HeadingAwareDocumentChunker.cs): `lab1/src/UnityDocsRag.Infrastructure/Preprocessing/HeadingAwareDocumentChunker.cs`
- [Processing artifacts](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Preprocessing/FileProcessingArtifactStore.cs): `lab1/src/UnityDocsRag.Infrastructure/Preprocessing/FileProcessingArtifactStore.cs`
- [Artifact reader](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Preprocessing/ProcessingArtifactReader.cs): `lab1/src/UnityDocsRag.Infrastructure/Preprocessing/ProcessingArtifactReader.cs`
- [Embedding indexer](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Ingestion/IndexingRunner.cs): `lab1/src/UnityDocsRag.Ingestion/IndexingRunner.cs`

### Retrieval and answering

- [Ask runner](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Ingestion/AskRunner.cs): `lab1/src/UnityDocsRag.Ingestion/AskRunner.cs`
- [RAG query service](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Query/RagQueryService.cs): `lab1/src/UnityDocsRag.Infrastructure/Query/RagQueryService.cs`
- [Language detector](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Query/RussianEnglishLanguageDetector.cs): `lab1/src/UnityDocsRag.Infrastructure/Query/RussianEnglishLanguageDetector.cs`
- [Semantic search](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Retrieval/SemanticSearchService.cs): `lab1/src/UnityDocsRag.Infrastructure/Retrieval/SemanticSearchService.cs`
- [Vector retriever](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Retrieval/PostgresVectorRetriever.cs): `lab1/src/UnityDocsRag.Infrastructure/Retrieval/PostgresVectorRetriever.cs`
- [Ollama reranker](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Reranking/OllamaReranker.cs): `lab1/src/UnityDocsRag.Infrastructure/Reranking/OllamaReranker.cs`
- [Answer generator](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Generation/OllamaAnswerGenerator.cs): `lab1/src/UnityDocsRag.Infrastructure/Generation/OllamaAnswerGenerator.cs`
- [Answer prompt builder](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Generation/RagPromptBuilder.cs): `lab1/src/UnityDocsRag.Infrastructure/Generation/RagPromptBuilder.cs`
- [RAG evaluation](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Evaluation/EvaluationMetrics.cs): `lab1/src/UnityDocsRag.Evaluation/EvaluationMetrics.cs`

### Infrastructure

- [Ollama embeddings](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Embeddings/OllamaEmbeddingProvider.cs): `lab1/src/UnityDocsRag.Infrastructure/Embeddings/OllamaEmbeddingProvider.cs`
- [Vector store](https://github.com/vadimsiminenco/pad/blob/main/lab1/src/UnityDocsRag.Infrastructure/Storage/PostgresVectorStore.cs): `lab1/src/UnityDocsRag.Infrastructure/Storage/PostgresVectorStore.cs`

### Other components

- **Questioner**
- **Unity docs source**
- **Ollama**
- **PostgreSQL pgvector**

## Connections

- RAG CLI → Documentation fetch: runs ingestion (evidence: `lab1/src/UnityDocsRag.Ingestion/Program.cs`)
- Unity docs source → Documentation fetch: provides documents
- Documentation fetch → Document cache: saves changes (evidence: `lab1/src/UnityDocsRag.Ingestion/IngestionRunner.cs`)
- RAG CLI → HTML preprocessing: runs processing (evidence: `lab1/src/UnityDocsRag.Ingestion/Program.cs`)
- HTML preprocessing → Heading-aware chunks: prepares chunks
- RAG CLI → Processing artifacts: stores artifacts (evidence: `lab1/src/UnityDocsRag.Ingestion/Program.cs`)
- Artifact reader → Processing artifacts: reads artifacts (evidence: `lab1/src/UnityDocsRag.Infrastructure/Preprocessing/ProcessingArtifactReader.cs`)
- RAG CLI → Embedding indexer: runs indexing (evidence: `lab1/src/UnityDocsRag.Ingestion/Program.cs`)
- Embedding indexer → Ollama embeddings: creates embeddings
- Embedding indexer → Vector store: writes vectors
- Ollama embeddings → Ollama: requests vectors (evidence: `lab1/src/UnityDocsRag.Infrastructure/Embeddings/OllamaEmbeddingProvider.cs`)
- Vector store → PostgreSQL pgvector: persists vectors (evidence: `lab1/src/UnityDocsRag.Infrastructure/Storage/PostgresVectorStore.cs`)
- Questioner → RAG CLI: asks question
- RAG CLI → Ask runner: runs ask (evidence: `lab1/src/UnityDocsRag.Ingestion/Program.cs`)
- Ask runner → RAG query service: dispatches query
- RAG query service → Language detector: detects language (evidence: `lab1/src/UnityDocsRag.Infrastructure/Query/RagQueryService.cs`)
- RAG query service → Semantic search: searches evidence (evidence: `lab1/src/UnityDocsRag.Infrastructure/Query/RagQueryService.cs`)
- Semantic search → Ollama embeddings: embeds query (evidence: `lab1/src/UnityDocsRag.Infrastructure/Retrieval/SemanticSearchService.cs`)
- Semantic search → Vector retriever: retrieves chunks (evidence: `lab1/src/UnityDocsRag.Infrastructure/Retrieval/SemanticSearchService.cs`)
- Vector retriever → PostgreSQL pgvector: queries vectors (evidence: `lab1/src/UnityDocsRag.Infrastructure/Retrieval/PostgresVectorRetriever.cs`)
- RAG query service → Ollama reranker: reranks candidates (evidence: `lab1/src/UnityDocsRag.Infrastructure/Query/RagQueryService.cs`)
- RAG query service → Answer generator: generates answer (evidence: `lab1/src/UnityDocsRag.Infrastructure/Query/RagQueryService.cs`)
- Answer generator → Answer prompt builder: builds prompt (evidence: `lab1/src/UnityDocsRag.Infrastructure/Generation/OllamaAnswerGenerator.cs`)
- Answer generator → Ollama: requests completion
- Questioner → API host: submits request
- RAG evaluation → RAG query service: evaluates answers
