# abdulrahman-s-asiri/bahith architecture

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

- Interactive diagram: https://gitdiagram.com/abdulrahman-s-asiri/bahith
- Repository: https://github.com/abdulrahman-s-asiri/bahith

## Overview

باحث is a local-first Arabic document search application, with a separate, limited public demo that searches only the bundled corpus. The main workflow is upload and extract text, split it into page-aware passages, store originals and passages locally, then retrieve and display source-linked results; users can browse documents and passages and save local feedback. Search offers semantic, BM25, fused, and staged ranking with Matryoshka dimensions. The graph also preserves the documented Pages export and reproducible evaluation branches. Some route and template wiring is unsampled; edges below rely on shown calls or README statements.

Main entry points: [`app.py`](https://github.com/abdulrahman-s-asiri/bahith/blob/main/app.py) (Web application), [`documents.py`](https://github.com/abdulrahman-s-asiri/bahith/blob/main/documents.py) (SQLite library), [`search.py`](https://github.com/abdulrahman-s-asiri/bahith/blob/main/search.py) (Arabic retrieval), [`templates`](https://github.com/abdulrahman-s-asiri/bahith/tree/main/templates) (Search and library UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_app["Web application<br/>[app.py]"]
  node_webui["Search and library UI"]
  node_localjs["Interactive search<br/>[app.js]"]
  node_pagesjs["Pages search UI<br/>[pages.js]"]
  node_publicconfig["Demo safeguards<br/>[public_demo.py]"]
end

subgraph group_library["Document library"]
  node_upload["Upload and replace<br/>[app.py]"]
  node_extract["Text extraction<br/>[documents.py]"]
  node_chunk["Passage splitting<br/>[documents.py]"]
  node_store[("SQLite library<br/>[documents.py]")]
  node_browse["Document browsing"]
  node_feedback["Local feedback<br/>[app.py]"]
end

subgraph group_retrieval["Search and ranking"]
  node_orchestrator["Search orchestration<br/>[app.py]"]
  node_searcher["Arabic retrieval<br/>[search.py]"]
  node_results["Source-linked results<br/>[_results.html]"]
  node_corpus["Bundled demo corpus<br/>[corpus.json]"]
end

subgraph group_evaluation["Evaluation and publishing"]
  node_evaluation["Retrieval evaluation<br/>[evaluate.py]"]
  node_exporter["Static Pages export<br/>[export_pages.py]"]
end

node_reader(("Reader"))
node_embedmodel["Embedding model"]
node_staticpages["GitHub Pages site"]

node_reader -->|"uses"| node_app
node_app -->|"renders"| node_webui
node_webui -->|"enhanced by"| node_localjs
node_webui -->|"enhanced by"| node_pagesjs
node_reader -->|"uploads"| node_upload
node_upload -->|"extracts"| node_extract
node_extract -->|"splits"| node_chunk
node_chunk -->|"stores"| node_store
node_app -->|"uses"| node_store
node_reader -->|"browses"| node_browse
node_browse -->|"reads"| node_store
node_reader -->|"rates results"| node_feedback
node_feedback -->|"saves"| node_store
node_app -->|"applies limits"| node_publicconfig
node_reader -->|"submits query"| node_orchestrator
node_orchestrator -->|"retrieves"| node_searcher
node_searcher -->|"encodes text"| node_embedmodel
node_orchestrator -->|"loads passages"| node_store
node_orchestrator -->|"renders results"| node_results
node_results -->|"shows sources"| node_reader
node_searcher -->|"searches demo text"| node_corpus
node_evaluation -->|"measures retrieval"| node_searcher
node_exporter -->|"renders pages from"| node_app
node_exporter -->|"exports site"| node_staticpages
node_pagesjs -.->|"requests search"| node_orchestrator

click node_app "https://github.com/abdulrahman-s-asiri/bahith/blob/main/app.py"
click node_webui "https://github.com/abdulrahman-s-asiri/bahith/tree/main/templates"
click node_localjs "https://github.com/abdulrahman-s-asiri/bahith/blob/main/static/js/app.js"
click node_pagesjs "https://github.com/abdulrahman-s-asiri/bahith/blob/main/static/js/pages.js"
click node_publicconfig "https://github.com/abdulrahman-s-asiri/bahith/blob/main/public_demo.py"
click node_upload "https://github.com/abdulrahman-s-asiri/bahith/blob/main/app.py"
click node_extract "https://github.com/abdulrahman-s-asiri/bahith/blob/main/documents.py"
click node_chunk "https://github.com/abdulrahman-s-asiri/bahith/blob/main/documents.py"
click node_store "https://github.com/abdulrahman-s-asiri/bahith/blob/main/documents.py"
click node_browse "https://github.com/abdulrahman-s-asiri/bahith/tree/main/templates"
click node_feedback "https://github.com/abdulrahman-s-asiri/bahith/blob/main/app.py"
click node_orchestrator "https://github.com/abdulrahman-s-asiri/bahith/blob/main/app.py"
click node_searcher "https://github.com/abdulrahman-s-asiri/bahith/blob/main/search.py"
click node_results "https://github.com/abdulrahman-s-asiri/bahith/blob/main/templates/_results.html"
click node_corpus "https://github.com/abdulrahman-s-asiri/bahith/blob/main/corpus.json"
click node_evaluation "https://github.com/abdulrahman-s-asiri/bahith/blob/main/evaluate.py"
click node_exporter "https://github.com/abdulrahman-s-asiri/bahith/blob/main/deploy/export_pages.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_webui,node_localjs,node_pagesjs,node_publicconfig toneBlue
class node_upload,node_extract,node_chunk,node_store,node_browse,node_feedback toneAmber
class node_orchestrator,node_searcher,node_results,node_corpus toneMint
class node_evaluation,node_exporter toneRose
class node_reader,node_embedmodel,node_staticpages toneIndigo
```

## Components

### Web experience

- [Web application](https://github.com/abdulrahman-s-asiri/bahith/blob/main/app.py): `app.py`
- [Search and library UI](https://github.com/abdulrahman-s-asiri/bahith/tree/main/templates): `templates`
- [Interactive search](https://github.com/abdulrahman-s-asiri/bahith/blob/main/static/js/app.js): `static/js/app.js`
- [Pages search UI](https://github.com/abdulrahman-s-asiri/bahith/blob/main/static/js/pages.js): `static/js/pages.js`
- [Demo safeguards](https://github.com/abdulrahman-s-asiri/bahith/blob/main/public_demo.py): `public_demo.py`

### Document library

- [Upload and replace](https://github.com/abdulrahman-s-asiri/bahith/blob/main/app.py): `app.py`
- [Text extraction](https://github.com/abdulrahman-s-asiri/bahith/blob/main/documents.py): `documents.py`
- [Passage splitting](https://github.com/abdulrahman-s-asiri/bahith/blob/main/documents.py): `documents.py`
- [SQLite library](https://github.com/abdulrahman-s-asiri/bahith/blob/main/documents.py): `documents.py`
- [Document browsing](https://github.com/abdulrahman-s-asiri/bahith/tree/main/templates): `templates`
- [Local feedback](https://github.com/abdulrahman-s-asiri/bahith/blob/main/app.py): `app.py`

### Search and ranking

- [Search orchestration](https://github.com/abdulrahman-s-asiri/bahith/blob/main/app.py): `app.py`
- [Arabic retrieval](https://github.com/abdulrahman-s-asiri/bahith/blob/main/search.py): `search.py`
- [Source-linked results](https://github.com/abdulrahman-s-asiri/bahith/blob/main/templates/_results.html): `templates/_results.html`
- [Bundled demo corpus](https://github.com/abdulrahman-s-asiri/bahith/blob/main/corpus.json): `corpus.json`

### Evaluation and publishing

- [Retrieval evaluation](https://github.com/abdulrahman-s-asiri/bahith/blob/main/evaluate.py): `evaluate.py`
- [Static Pages export](https://github.com/abdulrahman-s-asiri/bahith/blob/main/deploy/export_pages.py): `deploy/export_pages.py`

### Other components

- **Reader**
- **Embedding model**
- **GitHub Pages site**

## Connections

- Reader → Web application: uses (evidence: `README.md`)
- Web application → Search and library UI: renders (evidence: `README.md`)
- Search and library UI → Interactive search: enhanced by (evidence: `static/js/app.js`)
- Search and library UI → Pages search UI: enhanced by (evidence: `static/js/pages.js`)
- Reader → Upload and replace: uploads (evidence: `README.md`)
- Upload and replace → Text extraction: extracts (evidence: `README.md`)
- Text extraction → Passage splitting: splits (evidence: `README.md`)
- Passage splitting → SQLite library: stores (evidence: `README.md`)
- Web application → SQLite library: uses (evidence: `app.py`)
- Reader → Document browsing: browses (evidence: `README.md`)
- Document browsing → SQLite library: reads (evidence: `README.md`)
- Reader → Local feedback: rates results (evidence: `README.md`)
- Local feedback → SQLite library: saves (evidence: `app.py`)
- Web application → Demo safeguards: applies limits (evidence: `app.py`)
- Reader → Search orchestration: submits query (evidence: `README.md`)
- Search orchestration → Arabic retrieval: retrieves (evidence: `app.py`)
- Arabic retrieval → Embedding model: encodes text (evidence: `README.md`)
- Search orchestration → SQLite library: loads passages (evidence: `README.md`)
- Search orchestration → Source-linked results: renders results (evidence: `app.py`)
- Source-linked results → Reader: shows sources (evidence: `README.md`)
- Arabic retrieval → Bundled demo corpus: searches demo text (evidence: `README.md`)
- Retrieval evaluation → Arabic retrieval: measures retrieval (evidence: `evaluate.py`)
- Static Pages export → Web application: renders pages from (evidence: `deploy/export_pages.py`)
- Static Pages export → GitHub Pages site: exports site (evidence: `deploy/export_pages.py`)
- Pages search UI → Search orchestration: requests search
