# khushi-1304/the-relay architecture

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

- Interactive diagram: https://gitdiagram.com/khushi-1304/the-relay
- Repository: https://github.com/khushi-1304/the-relay

## Overview

The Relay is an asynchronous, citation-grounded RAG service. An HTTP client submits a research question; the API applies bounded admission, quota checks, and retry handling before invoking the pipeline. The pipeline retrieves page-aware evidence, refuses insufficiently supported questions, builds model context, calls a configured provider, and verifies citations with a bounded correction attempt. The main internal layers are the BM25 retrieval stack and traffic-control mechanisms. The README documents these capabilities; some implementation details, especially unsampled reliability and monitoring code, are represented only where the excerpts or README support their relationships.

Main entry points: [`app/api/routes.py`](https://github.com/khushi-1304/the-relay/blob/main/app/api/routes.py) (Research Endpoint), [`app/pipeline/orchestrator.py`](https://github.com/khushi-1304/the-relay/blob/main/app/pipeline/orchestrator.py) (Pipeline Orchestrator), [`app/retrieval/retriever.py`](https://github.com/khushi-1304/the-relay/blob/main/app/retrieval/retriever.py) (Passage Retriever), [`app/main.py`](https://github.com/khushi-1304/the-relay/blob/main/app/main.py) (FastAPI App)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_app["FastAPI App<br/>[main.py]"]
  node_routes["Research Endpoint<br/>[routes.py]"]
  node_schemas["Request Schemas<br/>[schemas.py]"]
  node_config["Runtime Settings<br/>[config.py]"]
end

subgraph group_control["Traffic Control"]
  node_queue["Admission Queue<br/>[queue_manager.py]"]
  node_limiter["Sliding Quotas<br/>[rate_limiter.py]"]
  node_retry["Retry Policy<br/>[retry_policy.py]"]
  node_telemetry["Request Telemetry<br/>[telemetry.py]"]
  node_results[("Results Logger<br/>[results_logger.py]")]
end

subgraph group_research["Research Pipeline"]
  node_pipeline["Pipeline Orchestrator<br/>[orchestrator.py]"]
  node_context["Context Builder<br/>[context_builder.py]"]
  node_verifier["Citation Verifier<br/>[answer_verifier.py]"]
end

subgraph group_retrieval["Evidence Retrieval"]
  node_retriever["Passage Retriever<br/>[retriever.py]"]
  node_loader["PDF Loader<br/>[document_loader.py]"]
  node_chunker["Page Chunker<br/>[chunker.py]"]
  node_index[("BM25 Index<br/>[index.py]")]
  node_reranker["Heuristic Reranker<br/>[reranker.py]"]
end

subgraph group_providers["Model Providers"]
  node_provider_contract["Provider Interface<br/>[base.py]"]
  node_groq["Groq Adapter<br/>[groq_provider.py]"]
  node_standin_adapter["Stand-in Adapter"]
end

subgraph group_simulator["Stand-in Service"]
  node_standin_api["Stand-in HTTP API<br/>[main.py]"]
  node_simulator["Behavior Simulator<br/>[simulator.py]"]
  node_sim_config["Simulator Settings<br/>[config.py]"]
end

node_client(("HTTP Client"))
node_groq_service{{"Groq API"}}

node_client -->|"sends request"| node_app
node_app -->|"mounts routes"| node_routes
node_routes -->|"validates input"| node_schemas
node_routes -->|"admits request"| node_queue
node_routes -->|"checks quota"| node_limiter
node_routes -->|"evaluates retry"| node_retry
node_routes -->|"runs pipeline"| node_pipeline
node_routes -->|"records trace"| node_telemetry
node_routes -.->|"logs results"| node_results
node_app -->|"loads settings"| node_config
node_pipeline -->|"retrieves passages"| node_retriever
node_pipeline -->|"builds context"| node_context
node_pipeline -->|"invokes provider"| node_provider_contract
node_pipeline -->|"checks citations"| node_verifier
node_retriever -->|"loads papers"| node_loader
node_retriever -->|"builds chunks"| node_chunker
node_retriever -->|"searches index"| node_index
node_retriever -->|"reranks candidates"| node_reranker
node_provider_contract -->|"implemented by"| node_groq
node_provider_contract -->|"implemented by"| node_standin_adapter
node_groq -->|"sends completion"| node_groq_service
node_standin_adapter -->|"sends completion"| node_standin_api
node_standin_api -->|"checks admission"| node_simulator
node_simulator -->|"uses profile"| node_sim_config

click node_app "https://github.com/khushi-1304/the-relay/blob/main/app/main.py"
click node_routes "https://github.com/khushi-1304/the-relay/blob/main/app/api/routes.py"
click node_schemas "https://github.com/khushi-1304/the-relay/blob/main/app/api/schemas.py"
click node_config "https://github.com/khushi-1304/the-relay/blob/main/app/config.py"
click node_queue "https://github.com/khushi-1304/the-relay/blob/main/app/reliability/queue_manager.py"
click node_limiter "https://github.com/khushi-1304/the-relay/blob/main/app/reliability/rate_limiter.py"
click node_retry "https://github.com/khushi-1304/the-relay/blob/main/app/reliability/retry_policy.py"
click node_telemetry "https://github.com/khushi-1304/the-relay/blob/main/app/reliability/telemetry.py"
click node_pipeline "https://github.com/khushi-1304/the-relay/blob/main/app/pipeline/orchestrator.py"
click node_context "https://github.com/khushi-1304/the-relay/blob/main/app/pipeline/context_builder.py"
click node_verifier "https://github.com/khushi-1304/the-relay/blob/main/app/pipeline/answer_verifier.py"
click node_retriever "https://github.com/khushi-1304/the-relay/blob/main/app/retrieval/retriever.py"
click node_loader "https://github.com/khushi-1304/the-relay/blob/main/app/retrieval/document_loader.py"
click node_chunker "https://github.com/khushi-1304/the-relay/blob/main/app/retrieval/chunker.py"
click node_index "https://github.com/khushi-1304/the-relay/blob/main/app/retrieval/index.py"
click node_reranker "https://github.com/khushi-1304/the-relay/blob/main/app/retrieval/reranker.py"
click node_provider_contract "https://github.com/khushi-1304/the-relay/blob/main/app/providers/base.py"
click node_groq "https://github.com/khushi-1304/the-relay/blob/main/app/providers/groq_provider.py"
click node_standin_adapter "https://github.com/khushi-1304/the-relay/blob/main/app/providers/standin_provider.py"
click node_standin_api "https://github.com/khushi-1304/the-relay/blob/main/standin_service/main.py"
click node_simulator "https://github.com/khushi-1304/the-relay/blob/main/standin_service/simulator.py"
click node_sim_config "https://github.com/khushi-1304/the-relay/blob/main/standin_service/config.py"
click node_results "https://github.com/khushi-1304/the-relay/blob/main/app/monitoring/results_logger.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_routes,node_schemas,node_config,node_client toneBlue
class node_queue,node_limiter,node_retry,node_telemetry,node_results toneAmber
class node_pipeline,node_context,node_verifier,node_groq_service toneMint
class node_retriever,node_loader,node_chunker,node_index,node_reranker toneRose
class node_provider_contract,node_groq,node_standin_adapter toneIndigo
class node_standin_api,node_simulator,node_sim_config toneTeal
```

## Components

### HTTP API

- [FastAPI App](https://github.com/khushi-1304/the-relay/blob/main/app/main.py): `app/main.py`
- [Research Endpoint](https://github.com/khushi-1304/the-relay/blob/main/app/api/routes.py): `app/api/routes.py`
- [Request Schemas](https://github.com/khushi-1304/the-relay/blob/main/app/api/schemas.py): `app/api/schemas.py`
- [Runtime Settings](https://github.com/khushi-1304/the-relay/blob/main/app/config.py): `app/config.py`

### Traffic Control

- [Admission Queue](https://github.com/khushi-1304/the-relay/blob/main/app/reliability/queue_manager.py): `app/reliability/queue_manager.py`
- [Sliding Quotas](https://github.com/khushi-1304/the-relay/blob/main/app/reliability/rate_limiter.py): `app/reliability/rate_limiter.py`
- [Retry Policy](https://github.com/khushi-1304/the-relay/blob/main/app/reliability/retry_policy.py): `app/reliability/retry_policy.py`
- [Request Telemetry](https://github.com/khushi-1304/the-relay/blob/main/app/reliability/telemetry.py): `app/reliability/telemetry.py`
- [Results Logger](https://github.com/khushi-1304/the-relay/blob/main/app/monitoring/results_logger.py): `app/monitoring/results_logger.py`

### Research Pipeline

- [Pipeline Orchestrator](https://github.com/khushi-1304/the-relay/blob/main/app/pipeline/orchestrator.py): `app/pipeline/orchestrator.py`
- [Context Builder](https://github.com/khushi-1304/the-relay/blob/main/app/pipeline/context_builder.py): `app/pipeline/context_builder.py`
- [Citation Verifier](https://github.com/khushi-1304/the-relay/blob/main/app/pipeline/answer_verifier.py): `app/pipeline/answer_verifier.py`

### Evidence Retrieval

- [Passage Retriever](https://github.com/khushi-1304/the-relay/blob/main/app/retrieval/retriever.py): `app/retrieval/retriever.py`
- [PDF Loader](https://github.com/khushi-1304/the-relay/blob/main/app/retrieval/document_loader.py): `app/retrieval/document_loader.py`
- [Page Chunker](https://github.com/khushi-1304/the-relay/blob/main/app/retrieval/chunker.py): `app/retrieval/chunker.py`
- [BM25 Index](https://github.com/khushi-1304/the-relay/blob/main/app/retrieval/index.py): `app/retrieval/index.py`
- [Heuristic Reranker](https://github.com/khushi-1304/the-relay/blob/main/app/retrieval/reranker.py): `app/retrieval/reranker.py`

### Model Providers

- [Provider Interface](https://github.com/khushi-1304/the-relay/blob/main/app/providers/base.py): `app/providers/base.py`
- [Groq Adapter](https://github.com/khushi-1304/the-relay/blob/main/app/providers/groq_provider.py): `app/providers/groq_provider.py`
- [Stand-in Adapter](https://github.com/khushi-1304/the-relay/blob/main/app/providers/standin_provider.py): `app/providers/standin_provider.py`

### Stand-in Service

- [Stand-in HTTP API](https://github.com/khushi-1304/the-relay/blob/main/standin_service/main.py): `standin_service/main.py`
- [Behavior Simulator](https://github.com/khushi-1304/the-relay/blob/main/standin_service/simulator.py): `standin_service/simulator.py`
- [Simulator Settings](https://github.com/khushi-1304/the-relay/blob/main/standin_service/config.py): `standin_service/config.py`

### Other components

- **HTTP Client**
- **Groq API**

## Connections

- HTTP Client → FastAPI App: sends request (evidence: `app/main.py`)
- FastAPI App → Research Endpoint: mounts routes (evidence: `app/main.py`)
- Research Endpoint → Request Schemas: validates input (evidence: `app/api/routes.py`)
- Research Endpoint → Admission Queue: admits request (evidence: `app/api/routes.py`)
- Research Endpoint → Sliding Quotas: checks quota (evidence: `app/api/routes.py`)
- Research Endpoint → Retry Policy: evaluates retry (evidence: `app/api/routes.py`)
- Research Endpoint → Pipeline Orchestrator: runs pipeline (evidence: `app/api/routes.py`)
- Research Endpoint → Request Telemetry: records trace (evidence: `app/api/routes.py`)
- Research Endpoint → Results Logger: logs results
- FastAPI App → Runtime Settings: loads settings (evidence: `app/main.py`)
- Pipeline Orchestrator → Passage Retriever: retrieves passages (evidence: `app/pipeline/orchestrator.py`)
- Pipeline Orchestrator → Context Builder: builds context (evidence: `app/pipeline/orchestrator.py`)
- Pipeline Orchestrator → Provider Interface: invokes provider (evidence: `app/pipeline/orchestrator.py`)
- Pipeline Orchestrator → Citation Verifier: checks citations (evidence: `app/pipeline/orchestrator.py`)
- Passage Retriever → PDF Loader: loads papers (evidence: `app/retrieval/retriever.py`)
- Passage Retriever → Page Chunker: builds chunks (evidence: `app/retrieval/retriever.py`)
- Passage Retriever → BM25 Index: searches index (evidence: `app/retrieval/retriever.py`)
- Passage Retriever → Heuristic Reranker: reranks candidates (evidence: `app/retrieval/retriever.py`)
- Provider Interface → Groq Adapter: implemented by (evidence: `app/providers/groq_provider.py`)
- Provider Interface → Stand-in Adapter: implemented by (evidence: `app/providers/standin_provider.py`)
- Groq Adapter → Groq API: sends completion (evidence: `app/providers/groq_provider.py`)
- Stand-in Adapter → Stand-in HTTP API: sends completion (evidence: `app/providers/standin_provider.py`)
- Stand-in HTTP API → Behavior Simulator: checks admission (evidence: `standin_service/main.py`)
- Behavior Simulator → Simulator Settings: uses profile (evidence: `standin_service/simulator.py`)
