# tar7nic/envint architecture

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

- Interactive diagram: https://gitdiagram.com/tar7nic/envint
- Repository: https://github.com/tar7nic/envint

## Overview

This repository is a compliance Q&A engine and retrieval-strategy benchmark over hospital policy documents. Its primary workflow chunks and indexes policies, retrieves evidence through a selected strategy, then generates an answer with validated citations or a refusal. The graph also preserves the benchmark and observability capabilities documented in the README. Retrieval and answer paths are supported by source excerpts; benchmark internals were not sampled, so their detailed connections are omitted.

Main entry points: [`app/api/main.py`](https://github.com/tar7nic/envint/blob/main/app/api/main.py) (FastAPI routes), [`app/llm/qa.py`](https://github.com/tar7nic/envint/blob/main/app/llm/qa.py) (QA orchestration), [`app/retrieval/factory.py`](https://github.com/tar7nic/envint/blob/main/app/retrieval/factory.py) (Strategy factory), [`app/retrieval/hybrid.py`](https://github.com/tar7nic/envint/blob/main/app/retrieval/hybrid.py) (Hybrid fusion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Policy ingestion"]
  node_corpus["Policy corpus"]
  node_chunker["Clause chunker<br/>[chunker.py]"]
  node_indexer["Embedding indexer<br/>[indexer.py]"]
  node_qdrant[("Qdrant store")]
end

subgraph group_retrieval["Retrieval strategies"]
  node_factory["Strategy factory<br/>[factory.py]"]
  node_retriever["Retriever interface<br/>[base.py]"]
  node_vector["Vector search<br/>[vector.py]"]
  node_bm25["BM25 search<br/>[bm25.py]"]
  node_hybrid["Hybrid fusion<br/>[hybrid.py]"]
  node_rrf["RRF fusion<br/>[rrf.py]"]
  node_reranker["Cross-encoder reranker<br/>[reranker.py]"]
end

subgraph group_answer["Answer generation"]
  node_qa["QA orchestration<br/>[qa.py]"]
  node_prompts["Prompt construction<br/>[prompts.py]"]
  node_guardrails["Citation validation<br/>[guardrails.py]"]
  node_llm_client["LLM client<br/>[client.py]"]
end

subgraph group_service["API and operations"]
  node_api["FastAPI routes<br/>[main.py]"]
  node_config["Runtime settings<br/>[config.py]"]
  node_schemas["Data contracts<br/>[schemas.py]"]
  node_tracing["Tracing and metrics<br/>[tracing.py]"]
end

subgraph group_evaluation["Benchmark evaluation"]
  node_benchmark["Strategy benchmarks"]
  node_metrics["Ranking metrics<br/>[metrics.py]"]
  node_pareto["Pareto comparison<br/>[pareto.py]"]
end

node_user(("API caller"))
node_llm_service{{"OpenAI-compatible LLM"}}

node_user -->|"submits query"| node_api
node_corpus -->|"chunks policies"| node_chunker
node_chunker -->|"indexes chunks"| node_indexer
node_indexer -->|"embeds and upserts"| node_qdrant
node_api -->|"builds strategies"| node_factory
node_api -->|"answers requests"| node_qa
node_api -->|"records requests"| node_tracing
node_api -->|"loads settings"| node_config
node_factory -->|"constructs"| node_vector
node_factory -->|"constructs"| node_bm25
node_factory -->|"constructs"| node_hybrid
node_factory -->|"constructs"| node_reranker
node_vector -->|"searches vectors"| node_qdrant
node_vector -->|"embeds queries"| node_indexer
node_bm25 -->|"loads corpus"| node_qdrant
node_hybrid -->|"retrieves candidates"| node_vector
node_hybrid -->|"retrieves candidates"| node_bm25
node_hybrid -->|"fuses rankings"| node_rrf
node_reranker -->|"gets candidates"| node_hybrid
node_api -->|"dispatches strategy"| node_retriever
node_qa -->|"retrieves evidence"| node_retriever
node_qa -->|"builds prompt"| node_prompts
node_qa -->|"requests completion"| node_llm_client
node_qa -->|"validates answer"| node_guardrails
node_llm_client -->|"sends completion"| node_llm_service
node_api -->|"validates API data"| node_schemas
node_qa -->|"returns answer data"| node_schemas
node_benchmark -.->|"compares strategies"| node_retriever
node_benchmark -.->|"scores rankings"| node_metrics
node_benchmark -.->|"plots trade-offs"| node_pareto

click node_corpus "https://github.com/tar7nic/envint/tree/main/data/corpus"
click node_chunker "https://github.com/tar7nic/envint/blob/main/app/ingestion/chunker.py"
click node_indexer "https://github.com/tar7nic/envint/blob/main/app/ingestion/indexer.py"
click node_api "https://github.com/tar7nic/envint/blob/main/app/api/main.py"
click node_config "https://github.com/tar7nic/envint/blob/main/app/config.py"
click node_schemas "https://github.com/tar7nic/envint/blob/main/app/schemas.py"
click node_factory "https://github.com/tar7nic/envint/blob/main/app/retrieval/factory.py"
click node_retriever "https://github.com/tar7nic/envint/blob/main/app/retrieval/base.py"
click node_vector "https://github.com/tar7nic/envint/blob/main/app/retrieval/vector.py"
click node_bm25 "https://github.com/tar7nic/envint/blob/main/app/retrieval/bm25.py"
click node_hybrid "https://github.com/tar7nic/envint/blob/main/app/retrieval/hybrid.py"
click node_rrf "https://github.com/tar7nic/envint/blob/main/app/retrieval/rrf.py"
click node_reranker "https://github.com/tar7nic/envint/blob/main/app/retrieval/reranker.py"
click node_qa "https://github.com/tar7nic/envint/blob/main/app/llm/qa.py"
click node_prompts "https://github.com/tar7nic/envint/blob/main/app/llm/prompts.py"
click node_guardrails "https://github.com/tar7nic/envint/blob/main/app/llm/guardrails.py"
click node_llm_client "https://github.com/tar7nic/envint/blob/main/app/llm/client.py"
click node_tracing "https://github.com/tar7nic/envint/blob/main/app/observability/tracing.py"
click node_benchmark "https://github.com/tar7nic/envint/tree/main/benchmark"
click node_metrics "https://github.com/tar7nic/envint/blob/main/benchmark/metrics.py"
click node_pareto "https://github.com/tar7nic/envint/blob/main/benchmark/pareto.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_corpus,node_chunker,node_indexer,node_qdrant toneBlue
class node_factory,node_retriever,node_vector,node_bm25,node_hybrid,node_rrf,node_reranker toneAmber
class node_qa,node_prompts,node_guardrails,node_llm_client,node_user toneMint
class node_api,node_config,node_schemas,node_tracing toneRose
class node_benchmark,node_metrics,node_pareto,node_llm_service toneIndigo
```

## Components

### Policy ingestion

- [Policy corpus](https://github.com/tar7nic/envint/tree/main/data/corpus): `data/corpus`
- [Clause chunker](https://github.com/tar7nic/envint/blob/main/app/ingestion/chunker.py): `app/ingestion/chunker.py`
- [Embedding indexer](https://github.com/tar7nic/envint/blob/main/app/ingestion/indexer.py): `app/ingestion/indexer.py`
- **Qdrant store**

### Retrieval strategies

- [Strategy factory](https://github.com/tar7nic/envint/blob/main/app/retrieval/factory.py): `app/retrieval/factory.py`
- [Retriever interface](https://github.com/tar7nic/envint/blob/main/app/retrieval/base.py): `app/retrieval/base.py`
- [Vector search](https://github.com/tar7nic/envint/blob/main/app/retrieval/vector.py): `app/retrieval/vector.py`
- [BM25 search](https://github.com/tar7nic/envint/blob/main/app/retrieval/bm25.py): `app/retrieval/bm25.py`
- [Hybrid fusion](https://github.com/tar7nic/envint/blob/main/app/retrieval/hybrid.py): `app/retrieval/hybrid.py`
- [RRF fusion](https://github.com/tar7nic/envint/blob/main/app/retrieval/rrf.py): `app/retrieval/rrf.py`
- [Cross-encoder reranker](https://github.com/tar7nic/envint/blob/main/app/retrieval/reranker.py): `app/retrieval/reranker.py`

### Answer generation

- [QA orchestration](https://github.com/tar7nic/envint/blob/main/app/llm/qa.py): `app/llm/qa.py`
- [Prompt construction](https://github.com/tar7nic/envint/blob/main/app/llm/prompts.py): `app/llm/prompts.py`
- [Citation validation](https://github.com/tar7nic/envint/blob/main/app/llm/guardrails.py): `app/llm/guardrails.py`
- [LLM client](https://github.com/tar7nic/envint/blob/main/app/llm/client.py): `app/llm/client.py`

### API and operations

- [FastAPI routes](https://github.com/tar7nic/envint/blob/main/app/api/main.py): `app/api/main.py`
- [Runtime settings](https://github.com/tar7nic/envint/blob/main/app/config.py): `app/config.py`
- [Data contracts](https://github.com/tar7nic/envint/blob/main/app/schemas.py): `app/schemas.py`
- [Tracing and metrics](https://github.com/tar7nic/envint/blob/main/app/observability/tracing.py): `app/observability/tracing.py`

### Benchmark evaluation

- [Strategy benchmarks](https://github.com/tar7nic/envint/tree/main/benchmark): `benchmark`
- [Ranking metrics](https://github.com/tar7nic/envint/blob/main/benchmark/metrics.py): `benchmark/metrics.py`
- [Pareto comparison](https://github.com/tar7nic/envint/blob/main/benchmark/pareto.py): `benchmark/pareto.py`

### Other components

- **API caller**
- **OpenAI-compatible LLM**

## Connections

- API caller → FastAPI routes: submits query (evidence: `README.md`)
- Policy corpus → Clause chunker: chunks policies (evidence: `README.md`)
- Clause chunker → Embedding indexer: indexes chunks (evidence: `README.md`)
- Embedding indexer → Qdrant store: embeds and upserts (evidence: `app/ingestion/indexer.py`)
- FastAPI routes → Strategy factory: builds strategies (evidence: `app/api/main.py`)
- FastAPI routes → QA orchestration: answers requests (evidence: `app/api/main.py`)
- FastAPI routes → Tracing and metrics: records requests (evidence: `app/api/main.py`)
- FastAPI routes → Runtime settings: loads settings (evidence: `app/api/main.py`)
- Strategy factory → Vector search: constructs (evidence: `app/retrieval/factory.py`)
- Strategy factory → BM25 search: constructs (evidence: `app/retrieval/factory.py`)
- Strategy factory → Hybrid fusion: constructs (evidence: `app/retrieval/factory.py`)
- Strategy factory → Cross-encoder reranker: constructs (evidence: `app/retrieval/factory.py`)
- Vector search → Qdrant store: searches vectors (evidence: `app/retrieval/vector.py`)
- Vector search → Embedding indexer: embeds queries (evidence: `app/retrieval/vector.py`)
- BM25 search → Qdrant store: loads corpus (evidence: `app/retrieval/bm25.py`)
- Hybrid fusion → Vector search: retrieves candidates (evidence: `app/retrieval/hybrid.py`)
- Hybrid fusion → BM25 search: retrieves candidates (evidence: `app/retrieval/hybrid.py`)
- Hybrid fusion → RRF fusion: fuses rankings (evidence: `app/retrieval/hybrid.py`)
- Cross-encoder reranker → Hybrid fusion: gets candidates (evidence: `app/retrieval/reranker.py`)
- FastAPI routes → Retriever interface: dispatches strategy (evidence: `app/api/main.py`)
- QA orchestration → Retriever interface: retrieves evidence (evidence: `app/llm/qa.py`)
- QA orchestration → Prompt construction: builds prompt (evidence: `app/llm/qa.py`)
- QA orchestration → LLM client: requests completion (evidence: `app/llm/qa.py`)
- QA orchestration → Citation validation: validates answer (evidence: `app/llm/qa.py`)
- LLM client → OpenAI-compatible LLM: sends completion (evidence: `app/llm/client.py`)
- FastAPI routes → Data contracts: validates API data (evidence: `app/api/main.py`)
- QA orchestration → Data contracts: returns answer data (evidence: `app/llm/qa.py`)
- Strategy benchmarks → Retriever interface: compares strategies (evidence: `README.md`)
- Strategy benchmarks → Ranking metrics: scores rankings (evidence: `README.md`)
- Strategy benchmarks → Pareto comparison: plots trade-offs (evidence: `README.md`)
