# d-hackmt/8hr-marathon architecture

> Architecture diagram of the GitHub repository d-hackmt/8hr-marathon, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/d-hackmt/8hr-marathon
- Repository: https://github.com/d-hackmt/8hr-marathon

## Overview

#### Purpose and Entry Points
Enterprise agentic RAG for answering technical-document questions while rejecting irrelevant, jailbreak, and injection requests. Runtime entry points are FastAPI (`app/main.py`), Streamlit chat UI (`ui/app.py`), ingestion CLI (`app/ingestion/processor.py`), and evaluation UI (`evals/app.py`).

#### Request Boundary and Safety
`app/main.py` exposes `/query` and applies NeMo Guardrails before agent execution. Guardrails are defined in `app/guardrails/rails.py` and `app/guardrails/colang_rules.py`; blocked requests return without retrieval. This is the primary untrusted-user-input boundary, with output filtering also applied around generated answers.

#### Agent Orchestration
LangGraph coordinates the conversation workflow in `app/agents/graph.py`, carrying history and intermediate state via `app/agents/state.py`. The planner (`app/agents/nodes/planner.py`) classifies intent: conversational questions route directly to response generation, while technical/document requests route to retrieval. LangGraph memory preserves thread-level conversational context.

#### Retrieval and Answer Generation
The retriever node (`app/agents/nodes/retriever.py`) embeds the query, searches Qdrant, and locally reranks candidates before response construction. Retrieval services are separated into Gemini embedding integration (`app/services/retrieval/embedding.py`), Qdrant Cloud access (`app/services/retrieval/qdrant_service.py`), and FlashRank ranking (`app/services/retrieval/ranking_service.py`). The responder (`app/agents/nodes/responder.py`) receives either planner-only context or reranked source context and produces the final answer.

#### LLM Access and Observability
All generation is routed through the Portkey client in `app/gateway/client.py`, which fronts Groq/Llama calls and supports primary/fallback credentials. Configuration and external-service credentials are centralized in `app/config.py`. The deployed path depends on Portkey, Groq, Gemini Embeddings, Qdrant Cloud, Pydantic Logfire, and LangSmith; tracing spans the API and agent-node execution path.

#### Document Ingestion and Indexing
The ingestion CLI traverses source documents, dispatches format-specific local parsers, chunks extracted text, persists JSON artifacts, embeds chunks, and writes vectors to Qdrant. Core coordination is `app/ingestion/processor.py`; parsing boundary implementations are under `app/ingestion/loaders/` and chunking is `app/ingestion/chunking/splitter.py`. Source corpora reside in `DATA/true_data` and `DATA/noisy_data`; generated local parse outputs are under `processed_data/true` and `processed_data/noisy`.

#### User and Quality Feedback Loops
The Streamlit client in `ui/app.py` calls the FastAPI backend and surfaces reasoning-step transparency. The separate evaluation application (`evals/app.py`) runs an evaluation pipeline (`evals/pipeline.py`) against curated datasets such as `evals/golden_dataset.json`, using RAGAS metrics plus custom measurement. It is operationally separate from live serving but validates guardrails, retrieval, and answer quality against the same backend.

Main entry points: [`app/agents/nodes/retriever.py`](https://github.com/d-hackmt/8hr-marathon/blob/main/app/agents/nodes/retriever.py) (Retriever node), [`app/agents/nodes/responder.py`](https://github.com/d-hackmt/8hr-marathon/blob/main/app/agents/nodes/responder.py) (Responder node), [`app/guardrails/rails.py`](https://github.com/d-hackmt/8hr-marathon/blob/main/app/guardrails/rails.py) (NeMo Guardrails), [`app/agents/graph.py`](https://github.com/d-hackmt/8hr-marathon/blob/main/app/agents/graph.py) (LangGraph workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_serving["Live Serving"]
  node_streamlit["Streamlit chat UI<br/>client<br/>[app.py]"]
  node_api["FastAPI API<br/>[main.py]"]
  node_guardrails{{"NeMo Guardrails<br/>safety policy<br/>[rails.py]"}}
  node_colang["Colang rules<br/>guardrail rules<br/>[colang_rules.py]"]
  node_gateway["Portkey client<br/>LLM gateway<br/>[client.py]"]
  node_groq{{"Groq / Llama<br/>generation provider"}}
end

subgraph group_agent["Agent Workflow"]
  node_graph["LangGraph workflow<br/>orchestrator<br/>[graph.py]"]
  node_state["Conversation state<br/>workflow state<br/>[state.py]"]
  node_planner["Intent planner<br/>agent node<br/>[planner.py]"]
  node_retriever["Retriever node<br/>agent node<br/>[retriever.py]"]
  node_responder["Responder node<br/>agent node<br/>[responder.py]"]
end

subgraph group_retrieval["Retrieval"]
  node_embedding["Gemini embeddings<br/>embedding service<br/>[embedding.py]"]
  node_qdrant_service["Qdrant access<br/>vector-store adapter<br/>[qdrant_service.py]"]
  node_ranking["FlashRank reranker<br/>ranking service<br/>[ranking_service.py]"]
  node_qdrant[("Qdrant Cloud<br/>vector database")]
end

subgraph group_ingestion["Ingestion &amp; Indexing"]
  node_ingestion["Ingestion CLI<br/>indexing coordinator<br/>[processor.py]"]
  node_corpora["Source corpora<br/>document corpus"]
  node_loaders["Format parsers<br/>parser boundary"]
  node_splitter["Text chunker<br/>chunking service<br/>[splitter.py]"]
  node_artifacts["Processed artifacts<br/>local JSON output"]
end

subgraph group_quality["Evaluation"]
  node_eval_ui["Evaluation UI<br/>evaluation app<br/>[app.py]"]
  node_eval_pipeline["Evaluation pipeline<br/>quality pipeline<br/>[pipeline.py]"]
  node_golden_data["Golden dataset<br/>evaluation dataset"]
end

node_streamlit -->|"query requests"| node_api
node_api -->|"validate input/output"| node_guardrails
node_colang -->|"defines policies"| node_guardrails
node_guardrails -->|"allowed requests"| node_graph
node_graph -->|"reads and updates"| node_state
node_graph -->|"dispatches"| node_planner
node_planner -->|"technical/document intent"| node_retriever
node_planner -->|"conversational context"| node_responder
node_retriever -->|"embed query"| node_embedding
node_retriever -->|"search candidates"| node_qdrant_service
node_retriever -->|"rerank candidates"| node_ranking
node_qdrant_service -->|"vector queries"| node_qdrant
node_retriever -->|"reranked sources"| node_responder
node_responder -->|"generate answer"| node_gateway
node_gateway -->|"LLM calls"| node_groq
node_responder -->|"answer filtering"| node_guardrails
node_ingestion -->|"traverses"| node_corpora
node_ingestion -->|"parses documents"| node_loaders
node_loaders -->|"extracted text"| node_splitter
node_splitter -->|"persist chunks"| node_artifacts
node_splitter -->|"embed chunks"| node_embedding
node_embedding -->|"chunk vectors"| node_qdrant_service
node_eval_ui -->|"runs evaluation"| node_eval_pipeline
node_golden_data -->|"test cases"| node_eval_pipeline
node_eval_pipeline -.->|"validates backend"| node_api

click node_streamlit "https://github.com/d-hackmt/8hr-marathon/blob/main/ui/app.py"
click node_api "https://github.com/d-hackmt/8hr-marathon/blob/main/app/main.py"
click node_guardrails "https://github.com/d-hackmt/8hr-marathon/blob/main/app/guardrails/rails.py"
click node_colang "https://github.com/d-hackmt/8hr-marathon/blob/main/app/guardrails/colang_rules.py"
click node_graph "https://github.com/d-hackmt/8hr-marathon/blob/main/app/agents/graph.py"
click node_state "https://github.com/d-hackmt/8hr-marathon/blob/main/app/agents/state.py"
click node_planner "https://github.com/d-hackmt/8hr-marathon/blob/main/app/agents/nodes/planner.py"
click node_retriever "https://github.com/d-hackmt/8hr-marathon/blob/main/app/agents/nodes/retriever.py"
click node_responder "https://github.com/d-hackmt/8hr-marathon/blob/main/app/agents/nodes/responder.py"
click node_embedding "https://github.com/d-hackmt/8hr-marathon/blob/main/app/services/retrieval/embedding.py"
click node_qdrant_service "https://github.com/d-hackmt/8hr-marathon/blob/main/app/services/retrieval/qdrant_service.py"
click node_ranking "https://github.com/d-hackmt/8hr-marathon/blob/main/app/services/retrieval/ranking_service.py"
click node_gateway "https://github.com/d-hackmt/8hr-marathon/blob/main/app/gateway/client.py"
click node_ingestion "https://github.com/d-hackmt/8hr-marathon/blob/main/app/ingestion/processor.py"
click node_corpora "https://github.com/d-hackmt/8hr-marathon/tree/main/DATA/true_data"
click node_splitter "https://github.com/d-hackmt/8hr-marathon/blob/main/app/ingestion/chunking/splitter.py"
click node_artifacts "https://github.com/d-hackmt/8hr-marathon/tree/main/processed_data/true"
click node_eval_ui "https://github.com/d-hackmt/8hr-marathon/blob/main/evals/app.py"
click node_eval_pipeline "https://github.com/d-hackmt/8hr-marathon/blob/main/evals/pipeline.py"
click node_golden_data "https://github.com/d-hackmt/8hr-marathon/blob/main/evals/golden_dataset.json"

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_streamlit,node_api,node_guardrails,node_colang,node_gateway,node_groq toneBlue
class node_graph,node_state,node_planner,node_retriever,node_responder toneAmber
class node_embedding,node_qdrant_service,node_ranking,node_qdrant toneMint
class node_ingestion,node_corpora,node_loaders,node_splitter,node_artifacts toneRose
class node_eval_ui,node_eval_pipeline,node_golden_data toneIndigo
```

## Components

### Live Serving

- [Streamlit chat UI](https://github.com/d-hackmt/8hr-marathon/blob/main/ui/app.py): client · Displays answer and reasoning-step transparency. · `ui/app.py`
- [FastAPI API](https://github.com/d-hackmt/8hr-marathon/blob/main/app/main.py): api · Exposes the /query request boundary. · `app/main.py`
- [NeMo Guardrails](https://github.com/d-hackmt/8hr-marathon/blob/main/app/guardrails/rails.py): safety policy · Rejects jailbreak, injection, and irrelevant requests; filters output. · `app/guardrails/rails.py`
- [Colang rules](https://github.com/d-hackmt/8hr-marathon/blob/main/app/guardrails/colang_rules.py): guardrail rules · `app/guardrails/colang_rules.py`
- [Portkey client](https://github.com/d-hackmt/8hr-marathon/blob/main/app/gateway/client.py): LLM gateway · Routes generation through primary and fallback credentials. · `app/gateway/client.py`
- **Groq / Llama**: generation provider

### Agent Workflow

- [LangGraph workflow](https://github.com/d-hackmt/8hr-marathon/blob/main/app/agents/graph.py): orchestrator · Carries conversation state and thread memory. · `app/agents/graph.py`
- [Conversation state](https://github.com/d-hackmt/8hr-marathon/blob/main/app/agents/state.py): workflow state · `app/agents/state.py`
- [Intent planner](https://github.com/d-hackmt/8hr-marathon/blob/main/app/agents/nodes/planner.py): agent node · Routes conversational requests directly and technical requests to retrieval. · `app/agents/nodes/planner.py`
- [Retriever node](https://github.com/d-hackmt/8hr-marathon/blob/main/app/agents/nodes/retriever.py): agent node · Embeds, searches, and reranks technical-document candidates. · `app/agents/nodes/retriever.py`
- [Responder node](https://github.com/d-hackmt/8hr-marathon/blob/main/app/agents/nodes/responder.py): agent node · Builds the final answer from planner or source context. · `app/agents/nodes/responder.py`

### Retrieval

- [Gemini embeddings](https://github.com/d-hackmt/8hr-marathon/blob/main/app/services/retrieval/embedding.py): embedding service · `app/services/retrieval/embedding.py`
- [Qdrant access](https://github.com/d-hackmt/8hr-marathon/blob/main/app/services/retrieval/qdrant_service.py): vector-store adapter · `app/services/retrieval/qdrant_service.py`
- [FlashRank reranker](https://github.com/d-hackmt/8hr-marathon/blob/main/app/services/retrieval/ranking_service.py): ranking service · `app/services/retrieval/ranking_service.py`
- **Qdrant Cloud**: vector database

### Ingestion & Indexing

- [Ingestion CLI](https://github.com/d-hackmt/8hr-marathon/blob/main/app/ingestion/processor.py): indexing coordinator · Traverses, parses, chunks, embeds, and indexes documents. · `app/ingestion/processor.py`
- [Source corpora](https://github.com/d-hackmt/8hr-marathon/tree/main/DATA/true_data): document corpus · True and noisy technical-document inputs. · `DATA/true_data`
- **Format parsers**: parser boundary
- [Text chunker](https://github.com/d-hackmt/8hr-marathon/blob/main/app/ingestion/chunking/splitter.py): chunking service · `app/ingestion/chunking/splitter.py`
- [Processed artifacts](https://github.com/d-hackmt/8hr-marathon/tree/main/processed_data/true): local JSON output · Generated true/noisy parse artifacts. · `processed_data/true`

### Evaluation

- [Evaluation UI](https://github.com/d-hackmt/8hr-marathon/blob/main/evals/app.py): evaluation app · `evals/app.py`
- [Evaluation pipeline](https://github.com/d-hackmt/8hr-marathon/blob/main/evals/pipeline.py): quality pipeline · Uses RAGAS and custom measurements against curated cases. · `evals/pipeline.py`
- [Golden dataset](https://github.com/d-hackmt/8hr-marathon/blob/main/evals/golden_dataset.json): evaluation dataset · `evals/golden_dataset.json`

## Connections

- Streamlit chat UI → FastAPI API: query requests
- FastAPI API → NeMo Guardrails: validate input/output
- Colang rules → NeMo Guardrails: defines policies
- NeMo Guardrails → LangGraph workflow: allowed requests
- LangGraph workflow → Conversation state: reads and updates
- LangGraph workflow → Intent planner: dispatches
- Intent planner → Retriever node: technical/document intent
- Intent planner → Responder node: conversational context
- Retriever node → Gemini embeddings: embed query
- Retriever node → Qdrant access: search candidates
- Retriever node → FlashRank reranker: rerank candidates
- Qdrant access → Qdrant Cloud: vector queries
- Retriever node → Responder node: reranked sources
- Responder node → Portkey client: generate answer
- Portkey client → Groq / Llama: LLM calls
- Responder node → NeMo Guardrails: answer filtering
- Ingestion CLI → Source corpora: traverses
- Ingestion CLI → Format parsers: parses documents
- Format parsers → Text chunker: extracted text
- Text chunker → Processed artifacts: persist chunks
- Text chunker → Gemini embeddings: embed chunks
- Gemini embeddings → Qdrant access: chunk vectors
- Evaluation UI → Evaluation pipeline: runs evaluation
- Golden dataset → Evaluation pipeline: test cases
- Evaluation pipeline → FastAPI API: validates backend
