# abdelrahman-atef-elsayed/document-section-finder architecture

> Architecture diagram of the GitHub repository abdelrahman-atef-elsayed/document-section-finder, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abdelrahman-atef-elsayed/document-section-finder
- Repository: https://github.com/abdelrahman-atef-elsayed/document-section-finder

## Overview

Document Section Finder is a local Streamlit application for finding relevant paragraphs in uploaded PDF, DOCX, and TXT files. Its main workflow is upload and parse, split text while preserving page references, embed paragraphs, search and optionally rerank, then display results and snippets. Optional branches generate cited answers with a local LLM, persist embeddings, and export reports. The graph follows the README and shown source; unsampled app sections limit certainty about some call details.

Main entry points: [`app.py`](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/app.py) (Streamlit app), [`semantic_search.py`](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/semantic_search.py) (Hybrid ranking), [`document_processor.py`](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/document_processor.py) (Format parsing), [`vector_index.py`](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/vector_index.py) (Persistent vector index)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_app["Streamlit app<br/>[app.py]"]
  node_render["Result display<br/>[app.py]"]
end

subgraph group_ingestion["Document ingestion"]
  node_parse["Format parsing"]
  node_ocr["Scanned PDF OCR"]
  node_paragraphs["Paragraphs and pages"]
end

subgraph group_retrieval["Search and relevance"]
  node_embeddings["Embedding and search<br/>[semantic_search.py]"]
  node_hybrid["Hybrid ranking<br/>[semantic_search.py]"]
  node_rerank["Cross-encoder reranking<br/>[semantic_search.py]"]
  node_snippets["Snippets and highlights<br/>[semantic_search.py]"]
end

subgraph group_outputs["Results and persistence"]
  node_vector[("Persistent vector index<br/>[vector_index.py]")]
  node_rag["Local answer generation<br/>[rag_engine.py]"]
  node_export["PDF report export<br/>[export_utils.py]"]
end

node_user(("Document user"))

node_user -->|"uploads and queries"| node_app
node_app -->|"parses uploads"| node_parse
node_parse -->|"falls back"| node_ocr
node_app -->|"splits text"| node_paragraphs
node_paragraphs -->|"provides paragraphs"| node_embeddings
node_app -->|"encodes and searches"| node_embeddings
node_embeddings -->|"ranks candidates"| node_hybrid
node_hybrid -->|"optionally reranks"| node_rerank
node_hybrid -->|"extracts matches"| node_snippets
node_app -->|"saves and loads"| node_vector
node_app -->|"requests answers"| node_rag
node_app -->|"renders results"| node_render
node_app -->|"exports reports"| node_export

click node_app "https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/app.py"
click node_parse "https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/document_processor.py"
click node_ocr "https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/document_processor.py"
click node_paragraphs "https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/document_processor.py"
click node_embeddings "https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/semantic_search.py"
click node_hybrid "https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/semantic_search.py"
click node_rerank "https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/semantic_search.py"
click node_snippets "https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/semantic_search.py"
click node_vector "https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/vector_index.py"
click node_rag "https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/rag_engine.py"
click node_render "https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/app.py"
click node_export "https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/export_utils.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_render,node_user toneBlue
class node_parse,node_ocr,node_paragraphs toneAmber
class node_embeddings,node_hybrid,node_rerank,node_snippets toneMint
class node_vector,node_rag,node_export toneRose
```

## Components

### User interface

- [Streamlit app](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/app.py): `app.py`
- [Result display](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/app.py): `app.py`

### Document ingestion

- [Format parsing](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/document_processor.py): `document_processor.py`
- [Scanned PDF OCR](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/document_processor.py): `document_processor.py`
- [Paragraphs and pages](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/document_processor.py): `document_processor.py`

### Search and relevance

- [Embedding and search](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/semantic_search.py): `semantic_search.py`
- [Hybrid ranking](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/semantic_search.py): `semantic_search.py`
- [Cross-encoder reranking](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/semantic_search.py): `semantic_search.py`
- [Snippets and highlights](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/semantic_search.py): `semantic_search.py`

### Results and persistence

- [Persistent vector index](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/vector_index.py): `vector_index.py`
- [Local answer generation](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/rag_engine.py): `rag_engine.py`
- [PDF report export](https://github.com/abdelrahman-atef-elsayed/document-section-finder/blob/main/export_utils.py): `export_utils.py`

### Other components

- **Document user**

## Connections

- Document user → Streamlit app: uploads and queries (evidence: `README.md`)
- Streamlit app → Format parsing: parses uploads (evidence: `app.py`)
- Format parsing → Scanned PDF OCR: falls back (evidence: `document_processor.py`)
- Streamlit app → Paragraphs and pages: splits text (evidence: `app.py`)
- Paragraphs and pages → Embedding and search: provides paragraphs (evidence: `README.md`)
- Streamlit app → Embedding and search: encodes and searches (evidence: `README.md`)
- Embedding and search → Hybrid ranking: ranks candidates (evidence: `semantic_search.py`)
- Hybrid ranking → Cross-encoder reranking: optionally reranks (evidence: `semantic_search.py`)
- Hybrid ranking → Snippets and highlights: extracts matches (evidence: `semantic_search.py`)
- Streamlit app → Persistent vector index: saves and loads (evidence: `README.md`)
- Streamlit app → Local answer generation: requests answers (evidence: `app.py`)
- Streamlit app → Result display: renders results (evidence: `README.md`)
- Streamlit app → PDF report export: exports reports (evidence: `README.md`)
