# furkan-sailpeak/jfk-files-rag architecture

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

- Interactive diagram: https://gitdiagram.com/furkan-sailpeak/jfk-files-rag
- Repository: https://github.com/furkan-sailpeak/jfk-files-rag

## Overview

JFK Files Research System is a web-based research assistant for grounded questions about declassified JFK records. The principal workflow routes a query, retrieves and reranks archive evidence, generates a streamed answer, then checks grounding and citations. Document-ID lookups and metadata, conversational, and out-of-scope queries have distinct branches; the UI also exposes text analysis and archive statistics. The repository includes a separate evaluation and prompt-optimization toolkit. Backend internals and some UI wiring were not excerpted, so those links rely on README documentation or are omitted where evidence is insufficient.

Main entry points: [`rag/app.py`](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py) (Flask API), [`rag/frontend/src/App.jsx`](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/frontend/src/App.jsx) (Research UI), [`eval/run.py`](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/eval/run.py) (Evaluation runner), [`eval/score.py`](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/eval/score.py) (Evaluation scoring)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Research interface"]
  node_webapp["Research UI<br/>[App.jsx]"]
  node_auth["Sign-in<br/>[Auth.jsx]"]
end

subgraph group_pipeline["Query pipeline"]
  node_backend["Flask API<br/>[app.py]"]
  node_idlookup["ID shortcut<br/>[app.py]"]
  node_router["Query router<br/>[app.py]"]
  node_chatbranch["Chat and refusal<br/>[app.py]"]
  node_metadata["Archive queries<br/>[app.py]"]
  node_retrieval["Hybrid retrieval<br/>[app.py]"]
  node_rerank["Evidence reranker<br/>[app.py]"]
  node_generation["Answer generation<br/>[app.py]"]
  node_grounding["Grounding check<br/>[app.py]"]
  node_citation["Citation verifier<br/>[app.py]"]
  node_stats["Archive statistics<br/>[app.py]"]
  node_analysis["Text analysis<br/>[app.py]"]
end

subgraph group_services["Data and models"]
  node_database[("PostgreSQL archive")]
  node_groq["Groq LLM"]
  node_openai["OpenAI embeddings"]
  node_supabase["Supabase auth"]
  node_nara["National Archives PDFs"]
end

subgraph group_evaluation["Evaluation toolkit"]
  node_evalrun["Evaluation runner<br/>[run.py]"]
  node_evalscore["Evaluation scoring<br/>[score.py]"]
  node_optimizer["Prompt optimizer<br/>[optimize.py]"]
  node_gepa["GEPA optimizer<br/>[optimize_gepa.py]"]
  node_abtest["Blind A/B collection<br/>[collect_ab.py]"]
end

node_researcher(("Researcher"))
node_evaluator(("Evaluator"))

node_researcher -->|"submits query"| node_webapp
node_webapp -->|"streams chat request"| node_backend
node_webapp -->|"opens sign-in"| node_auth
node_auth -->|"requests sign-in link"| node_supabase
node_backend -->|"checks document ID"| node_idlookup
node_idlookup -->|"fetches pages"| node_database
node_backend -->|"routes query"| node_router
node_router -->|"dispatches chat or refusal"| node_chatbranch
node_router -->|"dispatches metadata query"| node_metadata
node_router -->|"dispatches simple or research"| node_retrieval
node_retrieval -->|"searches archive"| node_database
node_retrieval -->|"embeds query"| node_openai
node_retrieval -->|"provides candidates"| node_rerank
node_rerank -->|"judges evidence"| node_groq
node_rerank -->|"provides selected sources"| node_generation
node_generation -->|"generates answer"| node_groq
node_generation -->|"checks answer"| node_grounding
node_grounding -->|"retries with expansion"| node_generation
node_grounding -->|"passes grounded answer"| node_citation
node_citation -->|"streams verified answer"| node_webapp
node_metadata -->|"counts and samples records"| node_database
node_backend -->|"serves stats endpoint"| node_stats
node_backend -->|"serves analyze endpoint"| node_analysis
node_webapp -->|"fetches archive stats"| node_stats
node_webapp -->|"submits analysis"| node_analysis
node_citation -->|"links cited pages"| node_nara
node_evaluator -->|"runs questions"| node_evalrun
node_evalrun -->|"posts chat requests"| node_backend
node_evalrun -->|"scores captured results"| node_evalscore
node_optimizer -->|"evaluates prompts"| node_evalrun
node_optimizer -->|"uses scoring"| node_evalscore
node_gepa -->|"scores candidates"| node_evalscore
node_gepa -->|"evaluates candidate prompts"| node_backend
node_abtest -->|"collects paired answers"| node_evalrun
node_evaluator -->|"rates blinded pairs"| node_abtest

click node_webapp "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/frontend/src/App.jsx"
click node_auth "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/frontend/src/Auth.jsx"
click node_backend "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py"
click node_idlookup "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py"
click node_router "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py"
click node_chatbranch "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py"
click node_metadata "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py"
click node_retrieval "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py"
click node_rerank "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py"
click node_generation "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py"
click node_grounding "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py"
click node_citation "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py"
click node_stats "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py"
click node_analysis "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py"
click node_evalrun "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/eval/run.py"
click node_evalscore "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/eval/score.py"
click node_optimizer "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/eval/optimize.py"
click node_gepa "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/eval/optimize_gepa.py"
click node_abtest "https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/eval/collect_ab.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_webapp,node_auth toneBlue
class node_backend,node_idlookup,node_router,node_chatbranch,node_metadata,node_retrieval,node_rerank,node_generation,node_grounding,node_citation,node_stats,node_analysis toneAmber
class node_database,node_groq,node_openai,node_supabase,node_nara toneMint
class node_evalrun,node_evalscore,node_optimizer,node_gepa,node_abtest toneRose
class node_researcher,node_evaluator toneIndigo
```

## Components

### Research interface

- [Research UI](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/frontend/src/App.jsx): `rag/frontend/src/App.jsx`
- [Sign-in](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/frontend/src/Auth.jsx): `rag/frontend/src/Auth.jsx`

### Query pipeline

- [Flask API](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py): `rag/app.py`
- [ID shortcut](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py): `rag/app.py`
- [Query router](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py): `rag/app.py`
- [Chat and refusal](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py): `rag/app.py`
- [Archive queries](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py): `rag/app.py`
- [Hybrid retrieval](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py): `rag/app.py`
- [Evidence reranker](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py): `rag/app.py`
- [Answer generation](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py): `rag/app.py`
- [Grounding check](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py): `rag/app.py`
- [Citation verifier](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py): `rag/app.py`
- [Archive statistics](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py): `rag/app.py`
- [Text analysis](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/rag/app.py): `rag/app.py`

### Data and models

- **PostgreSQL archive**
- **Groq LLM**
- **OpenAI embeddings**
- **Supabase auth**
- **National Archives PDFs**

### Evaluation toolkit

- [Evaluation runner](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/eval/run.py): `eval/run.py`
- [Evaluation scoring](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/eval/score.py): `eval/score.py`
- [Prompt optimizer](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/eval/optimize.py): `eval/optimize.py`
- [GEPA optimizer](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/eval/optimize_gepa.py): `eval/optimize_gepa.py`
- [Blind A/B collection](https://github.com/furkan-sailpeak/jfk-files-rag/blob/main/eval/collect_ab.py): `eval/collect_ab.py`

### Other components

- **Researcher**
- **Evaluator**

## Connections

- Researcher → Research UI: submits query (evidence: `README.md`)
- Research UI → Flask API: streams chat request (evidence: `rag/frontend/src/App.jsx`)
- Research UI → Sign-in: opens sign-in (evidence: `rag/frontend/src/App.jsx`)
- Sign-in → Supabase auth: requests sign-in link (evidence: `rag/frontend/src/Auth.jsx`)
- Flask API → ID shortcut: checks document ID (evidence: `README.md`)
- ID shortcut → PostgreSQL archive: fetches pages (evidence: `README.md`)
- Flask API → Query router: routes query (evidence: `README.md`)
- Query router → Chat and refusal: dispatches chat or refusal (evidence: `README.md`)
- Query router → Archive queries: dispatches metadata query (evidence: `README.md`)
- Query router → Hybrid retrieval: dispatches simple or research (evidence: `README.md`)
- Hybrid retrieval → PostgreSQL archive: searches archive (evidence: `README.md`)
- Hybrid retrieval → OpenAI embeddings: embeds query (evidence: `README.md`)
- Hybrid retrieval → Evidence reranker: provides candidates (evidence: `README.md`)
- Evidence reranker → Groq LLM: judges evidence (evidence: `README.md`)
- Evidence reranker → Answer generation: provides selected sources (evidence: `README.md`)
- Answer generation → Groq LLM: generates answer (evidence: `README.md`)
- Answer generation → Grounding check: checks answer (evidence: `README.md`)
- Grounding check → Answer generation: retries with expansion (evidence: `README.md`)
- Grounding check → Citation verifier: passes grounded answer (evidence: `README.md`)
- Citation verifier → Research UI: streams verified answer (evidence: `README.md`)
- Archive queries → PostgreSQL archive: counts and samples records (evidence: `README.md`)
- Flask API → Archive statistics: serves stats endpoint (evidence: `README.md`)
- Flask API → Text analysis: serves analyze endpoint (evidence: `README.md`)
- Research UI → Archive statistics: fetches archive stats (evidence: `rag/frontend/src/App.jsx`)
- Research UI → Text analysis: submits analysis (evidence: `rag/frontend/src/App.jsx`)
- Citation verifier → National Archives PDFs: links cited pages (evidence: `README.md`)
- Evaluator → Evaluation runner: runs questions (evidence: `eval/run.py`)
- Evaluation runner → Flask API: posts chat requests (evidence: `eval/run.py`)
- Evaluation runner → Evaluation scoring: scores captured results (evidence: `eval/score.py`)
- Prompt optimizer → Evaluation runner: evaluates prompts (evidence: `eval/optimize.py`)
- Prompt optimizer → Evaluation scoring: uses scoring (evidence: `eval/optimize.py`)
- GEPA optimizer → Evaluation scoring: scores candidates (evidence: `eval/optimize_gepa.py`)
- GEPA optimizer → Flask API: evaluates candidate prompts (evidence: `eval/optimize_gepa.py`)
- Blind A/B collection → Evaluation runner: collects paired answers (evidence: `eval/collect_ab.py`)
- Evaluator → Blind A/B collection: rates blinded pairs (evidence: `README.md`)
