# sheacrow/jev-rag architecture

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

- Interactive diagram: https://gitdiagram.com/sheacrow/jev-rag
- Repository: https://github.com/sheacrow/jev-rag

## Overview

Jev RAG turns uploaded PDFs into section trees and semantic chunks, then answers chat questions through Jev-guided hierarchical retrieval and verbatim, cited sentence selection. The graph preserves the documented fallback hierarchy and printed-TOC capabilities. Source excerpts establish the main ingestion, retrieval, client, and storage relationships; unsampled implementation details are omitted where their links are not evidenced.

Main entry points: [`jev/client.py`](https://github.com/sheacrow/jev-rag/blob/main/jev/client.py) (Jev REST client), [`pdf_ingestion/pipeline.py`](https://github.com/sheacrow/jev-rag/blob/main/pdf_ingestion/pipeline.py) (Ingestion orchestration), [`storage/store.py`](https://github.com/sheacrow/jev-rag/blob/main/storage/store.py) (Chunk library), [`app/common.py`](https://github.com/sheacrow/jev-rag/blob/main/app/common.py) (App services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["User interface"]
  node_chat["Chat page<br/>[Chat.py]"]
  node_upload["PDF upload<br/>[1_Upload_PDF.py]"]
  node_app_shared["App services<br/>[common.py]"]
end

subgraph group_ingest["PDF ingestion"]
  node_extract["Text extraction<br/>[extract.py]"]
  node_hierarchy["Section hierarchy<br/>[hierarchy.py]"]
  node_chunking["Semantic chunking<br/>[chunking.py]"]
  node_ingest_pipeline["Ingestion orchestration<br/>[pipeline.py]"]
  node_printed_toc["Printed TOC reader<br/>[printed_toc.py]"]
  node_outline_tool["Bookmark writer<br/>[add_outline.py]"]
end

subgraph group_retrieve["Retrieval and answers"]
  node_answer["Answer assembly<br/>[answer.py]"]
  node_retriever["Hierarchical retriever<br/>[hierarchical.py]"]
end

subgraph group_jev["Jev integration"]
  node_client["Jev REST client<br/>[client.py]"]
  node_models["Typed API models<br/>[models.py]"]
  node_mock["Offline mock<br/>[mock.py]"]
end

subgraph group_persist["Document storage"]
  node_store[("Chunk library<br/>[store.py]")]
  node_chunk_files[("Ingested document files")]
end

node_user(("Reader / uploader"))
node_jev_service{{"TypeSafe Jev API"}}
node_pdf_files["Source PDFs"]

node_user -->|"asks questions"| node_chat
node_user -->|"uploads PDFs"| node_upload
node_chat -->|"gets services"| node_app_shared
node_chat -->|"requests answers"| node_answer
node_answer -->|"retrieves passages"| node_retriever
node_answer -->|"scores sentences"| node_client
node_answer -->|"reads citations"| node_store
node_retriever -->|"ranks choices"| node_client
node_retriever -->|"reads chunks"| node_store
node_app_shared -->|"loads library"| node_store
node_app_shared -->|"creates client"| node_client
node_app_shared -.->|"selects offline mode"| node_mock
node_upload -->|"starts ingestion"| node_ingest_pipeline
node_upload -->|"manages documents"| node_store
node_pdf_files -->|"provides input"| node_ingest_pipeline
node_ingest_pipeline -->|"extracts lines"| node_extract
node_ingest_pipeline -->|"builds tree"| node_hierarchy
node_ingest_pipeline -->|"creates chunks"| node_chunking
node_ingest_pipeline -->|"persists output"| node_store
node_extract -->|"supplies lines"| node_hierarchy
node_hierarchy -->|"provides sections"| node_chunking
node_printed_toc -.->|"provides headings"| node_hierarchy
node_outline_tool -->|"reads printed TOC"| node_printed_toc
node_store -->|"reads and writes"| node_chunk_files
node_client -->|"validates requests"| node_models
node_client -->|"sends API requests"| node_jev_service
node_jev_service -->|"returns typed results"| node_client
node_mock -->|"validates mock requests"| node_models
node_mock -->|"provides offline transport"| node_client

click node_chat "https://github.com/sheacrow/jev-rag/blob/main/app/Chat.py"
click node_upload "https://github.com/sheacrow/jev-rag/blob/main/app/pages/1_Upload_PDF.py"
click node_app_shared "https://github.com/sheacrow/jev-rag/blob/main/app/common.py"
click node_extract "https://github.com/sheacrow/jev-rag/blob/main/pdf_ingestion/extract.py"
click node_hierarchy "https://github.com/sheacrow/jev-rag/blob/main/pdf_ingestion/hierarchy.py"
click node_chunking "https://github.com/sheacrow/jev-rag/blob/main/pdf_ingestion/chunking.py"
click node_ingest_pipeline "https://github.com/sheacrow/jev-rag/blob/main/pdf_ingestion/pipeline.py"
click node_printed_toc "https://github.com/sheacrow/jev-rag/blob/main/pdf_ingestion/printed_toc.py"
click node_outline_tool "https://github.com/sheacrow/jev-rag/blob/main/scripts/add_outline.py"
click node_answer "https://github.com/sheacrow/jev-rag/blob/main/retrieval/answer.py"
click node_retriever "https://github.com/sheacrow/jev-rag/blob/main/retrieval/hierarchical.py"
click node_client "https://github.com/sheacrow/jev-rag/blob/main/jev/client.py"
click node_models "https://github.com/sheacrow/jev-rag/blob/main/jev/models.py"
click node_mock "https://github.com/sheacrow/jev-rag/blob/main/jev/mock.py"
click node_store "https://github.com/sheacrow/jev-rag/blob/main/storage/store.py"
click node_chunk_files "https://github.com/sheacrow/jev-rag/tree/main/chunks"
click node_pdf_files "https://github.com/sheacrow/jev-rag/tree/main/raw_data"

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_chat,node_upload,node_app_shared toneBlue
class node_extract,node_hierarchy,node_chunking,node_ingest_pipeline,node_printed_toc,node_outline_tool toneAmber
class node_answer,node_retriever,node_jev_service toneMint
class node_client,node_models,node_mock toneRose
class node_store,node_chunk_files,node_user toneIndigo
class node_pdf_files toneTeal
```

## Components

### User interface

- [Chat page](https://github.com/sheacrow/jev-rag/blob/main/app/Chat.py): `app/Chat.py`
- [PDF upload](https://github.com/sheacrow/jev-rag/blob/main/app/pages/1_Upload_PDF.py): `app/pages/1_Upload_PDF.py`
- [App services](https://github.com/sheacrow/jev-rag/blob/main/app/common.py): `app/common.py`

### PDF ingestion

- [Text extraction](https://github.com/sheacrow/jev-rag/blob/main/pdf_ingestion/extract.py): `pdf_ingestion/extract.py`
- [Section hierarchy](https://github.com/sheacrow/jev-rag/blob/main/pdf_ingestion/hierarchy.py): `pdf_ingestion/hierarchy.py`
- [Semantic chunking](https://github.com/sheacrow/jev-rag/blob/main/pdf_ingestion/chunking.py): `pdf_ingestion/chunking.py`
- [Ingestion orchestration](https://github.com/sheacrow/jev-rag/blob/main/pdf_ingestion/pipeline.py): `pdf_ingestion/pipeline.py`
- [Printed TOC reader](https://github.com/sheacrow/jev-rag/blob/main/pdf_ingestion/printed_toc.py): `pdf_ingestion/printed_toc.py`
- [Bookmark writer](https://github.com/sheacrow/jev-rag/blob/main/scripts/add_outline.py): `scripts/add_outline.py`

### Retrieval and answers

- [Answer assembly](https://github.com/sheacrow/jev-rag/blob/main/retrieval/answer.py): `retrieval/answer.py`
- [Hierarchical retriever](https://github.com/sheacrow/jev-rag/blob/main/retrieval/hierarchical.py): `retrieval/hierarchical.py`

### Jev integration

- [Jev REST client](https://github.com/sheacrow/jev-rag/blob/main/jev/client.py): `jev/client.py`
- [Typed API models](https://github.com/sheacrow/jev-rag/blob/main/jev/models.py): `jev/models.py`
- [Offline mock](https://github.com/sheacrow/jev-rag/blob/main/jev/mock.py): `jev/mock.py`

### Document storage

- [Chunk library](https://github.com/sheacrow/jev-rag/blob/main/storage/store.py): `storage/store.py`
- [Ingested document files](https://github.com/sheacrow/jev-rag/tree/main/chunks): `chunks`

### Other components

- **Reader / uploader**
- **TypeSafe Jev API**
- [Source PDFs](https://github.com/sheacrow/jev-rag/tree/main/raw_data): `raw_data`

## Connections

- Reader / uploader → Chat page: asks questions (evidence: `README.md`)
- Reader / uploader → PDF upload: uploads PDFs (evidence: `README.md`)
- Chat page → App services: gets services (evidence: `app/Chat.py`)
- Chat page → Answer assembly: requests answers (evidence: `app/Chat.py`)
- Answer assembly → Hierarchical retriever: retrieves passages (evidence: `retrieval/answer.py`)
- Answer assembly → Jev REST client: scores sentences (evidence: `retrieval/answer.py`)
- Answer assembly → Chunk library: reads citations (evidence: `retrieval/answer.py`)
- Hierarchical retriever → Jev REST client: ranks choices (evidence: `retrieval/hierarchical.py`)
- Hierarchical retriever → Chunk library: reads chunks (evidence: `retrieval/hierarchical.py`)
- App services → Chunk library: loads library (evidence: `app/common.py`)
- App services → Jev REST client: creates client (evidence: `app/common.py`)
- App services → Offline mock: selects offline mode (evidence: `app/common.py`)
- PDF upload → Ingestion orchestration: starts ingestion (evidence: `app/pages/1_Upload_PDF.py`)
- PDF upload → Chunk library: manages documents (evidence: `app/pages/1_Upload_PDF.py`)
- Source PDFs → Ingestion orchestration: provides input (evidence: `README.md`)
- Ingestion orchestration → Text extraction: extracts lines (evidence: `pdf_ingestion/pipeline.py`)
- Ingestion orchestration → Section hierarchy: builds tree (evidence: `pdf_ingestion/pipeline.py`)
- Ingestion orchestration → Semantic chunking: creates chunks (evidence: `pdf_ingestion/pipeline.py`)
- Ingestion orchestration → Chunk library: persists output (evidence: `pdf_ingestion/pipeline.py`)
- Text extraction → Section hierarchy: supplies lines (evidence: `pdf_ingestion/hierarchy.py`)
- Section hierarchy → Semantic chunking: provides sections (evidence: `pdf_ingestion/chunking.py`)
- Printed TOC reader → Section hierarchy: provides headings (evidence: `pdf_ingestion/printed_toc.py`)
- Bookmark writer → Printed TOC reader: reads printed TOC (evidence: `scripts/add_outline.py`)
- Chunk library → Ingested document files: reads and writes (evidence: `storage/store.py`)
- Jev REST client → Typed API models: validates requests (evidence: `jev/client.py`)
- Jev REST client → TypeSafe Jev API: sends API requests (evidence: `jev/client.py`)
- TypeSafe Jev API → Jev REST client: returns typed results (evidence: `jev/client.py`)
- Offline mock → Typed API models: validates mock requests (evidence: `jev/mock.py`)
- Offline mock → Jev REST client: provides offline transport
