# ziyad-alabduljabbar/al-warraq architecture

> Architecture diagram of the GitHub repository ziyad-alabduljabbar/al-warraq, 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/ziyad-alabduljabbar/al-warraq
- Repository: https://github.com/ziyad-alabduljabbar/al-warraq

## Overview

Al-Warraq is a Flask academic-book discovery and recommendation application. Students search the catalogue, optionally using corrected queries or personalized signals from interests and favorites; the application returns book results and supports book-detail chatbot conversations. Account management and favorites persist through the application database. The README also documents Groq and SambaNova chatbot providers. The main runtime is concentrated in app.py; excerpts do not expose every route or model, so some capability links rely on the README rather than sampled route code.

Main entry points: [`app.py`](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py) (Book search), [`templates`](https://github.com/ziyad-alabduljabbar/al-warraq/tree/main/templates) (Web interface), [`static/app.js`](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/static/app.js) (Chat interface), [`train_model.py`](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/train_model.py) (Model preparation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_browser["Web interface"]
  node_browser_logic["Browser interactions<br/>[app.js]"]
  node_flask["Application routes<br/>[app.py]"]
end

subgraph group_discovery["Book discovery"]
  node_search["Book search<br/>[app.py]"]
  node_spell["Query correction<br/>[app.py]"]
  node_recommender["TF-IDF recommender<br/>[app.py]"]
  node_interests["Interest recommendations<br/>[app.py]"]
  node_favorites_recs["Favorite-based recommendations<br/>[app.py]"]
  node_book_details["Book details<br/>[book_details.html]"]
end

subgraph group_accounts["Accounts and personalization"]
  node_authentication["Authentication<br/>[app.py]"]
  node_profile["Profile and password<br/>[profile.html]"]
  node_favorites["Favorites management<br/>[app.py]"]
  node_database[("Application database<br/>[app.py]")]
end

subgraph group_assistant["AI librarian"]
  node_chat_ui["Chat interface<br/>[app.js]"]
  node_chatbot["Chatbot service<br/>[app.py]"]
  node_groq{{"Groq API"}}
  node_sambanova{{"SambaNova API"}}
end

subgraph group_catalog["Catalogue artifacts"]
  node_training["Model preparation<br/>[train_model.py]"]
  node_dataset["Book dataset"]
  node_artifacts["TF-IDF artifacts"]
end

node_student(("Student"))

node_student -->|"uses"| node_browser
node_browser -->|"submits requests"| node_flask
node_browser_logic -->|"posts chat"| node_flask
node_flask -->|"routes search"| node_search
node_search -->|"corrects query"| node_spell
node_search -->|"gets recommendations"| node_recommender
node_search -->|"uses interests"| node_interests
node_search -->|"uses favorites"| node_favorites_recs
node_recommender -->|"loads artifacts"| node_artifacts
node_flask -->|"renders pages"| node_book_details
node_student -->|"registers or logs in"| node_authentication
node_flask -->|"handles accounts"| node_authentication
node_authentication -->|"queries users"| node_database
node_student -->|"manages profile"| node_profile
node_flask -->|"handles favorites"| node_favorites
node_favorites -->|"reads and writes"| node_database
node_search -->|"reads favorites"| node_database
node_student -->|"asks about books"| node_chat_ui
node_chat_ui -->|"sends context"| node_chatbot
node_chatbot -.->|"queries provider"| node_groq
node_chatbot -.->|"falls back"| node_sambanova
node_dataset -->|"provides book data"| node_training
node_training -->|"saves model files"| node_artifacts

click node_browser "https://github.com/ziyad-alabduljabbar/al-warraq/tree/main/templates"
click node_browser_logic "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/static/app.js"
click node_flask "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py"
click node_search "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py"
click node_spell "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py"
click node_recommender "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py"
click node_interests "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py"
click node_favorites_recs "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py"
click node_book_details "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/templates/book_details.html"
click node_authentication "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py"
click node_profile "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/templates/profile.html"
click node_favorites "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py"
click node_database "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py"
click node_chat_ui "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/static/app.js"
click node_chatbot "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py"
click node_training "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/train_model.py"
click node_dataset "https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/dataset/AlWarraq_Final_Version.csv"
click node_artifacts "https://github.com/ziyad-alabduljabbar/al-warraq/tree/main/models"

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_browser,node_browser_logic,node_flask toneBlue
class node_search,node_spell,node_recommender,node_interests,node_favorites_recs,node_book_details toneAmber
class node_authentication,node_profile,node_favorites,node_database toneMint
class node_chat_ui,node_chatbot,node_groq,node_sambanova toneRose
class node_training,node_dataset,node_artifacts,node_student toneIndigo
```

## Components

### Web experience

- [Web interface](https://github.com/ziyad-alabduljabbar/al-warraq/tree/main/templates): `templates`
- [Browser interactions](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/static/app.js): `static/app.js`
- [Application routes](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py): `app.py`

### Book discovery

- [Book search](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py): `app.py`
- [Query correction](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py): `app.py`
- [TF-IDF recommender](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py): `app.py`
- [Interest recommendations](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py): `app.py`
- [Favorite-based recommendations](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py): `app.py`
- [Book details](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/templates/book_details.html): `templates/book_details.html`

### Accounts and personalization

- [Authentication](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py): `app.py`
- [Profile and password](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/templates/profile.html): `templates/profile.html`
- [Favorites management](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py): `app.py`
- [Application database](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py): `app.py`

### AI librarian

- [Chat interface](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/static/app.js): `static/app.js`
- [Chatbot service](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/app.py): `app.py`
- **Groq API**
- **SambaNova API**

### Catalogue artifacts

- [Model preparation](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/train_model.py): `train_model.py`
- [Book dataset](https://github.com/ziyad-alabduljabbar/al-warraq/blob/main/dataset/AlWarraq_Final_Version.csv): `dataset/AlWarraq_Final_Version.csv`
- [TF-IDF artifacts](https://github.com/ziyad-alabduljabbar/al-warraq/tree/main/models): `models`

### Other components

- **Student**

## Connections

- Student → Web interface: uses (evidence: `README.md`)
- Web interface → Application routes: submits requests (evidence: `app.py`)
- Browser interactions → Application routes: posts chat (evidence: `static/app.js`)
- Application routes → Book search: routes search (evidence: `app.py`)
- Book search → Query correction: corrects query (evidence: `README.md`)
- Book search → TF-IDF recommender: gets recommendations (evidence: `app.py`)
- Book search → Interest recommendations: uses interests (evidence: `app.py`)
- Book search → Favorite-based recommendations: uses favorites (evidence: `app.py`)
- TF-IDF recommender → TF-IDF artifacts: loads artifacts (evidence: `app.py`)
- Application routes → Book details: renders pages (evidence: `app.py`)
- Student → Authentication: registers or logs in (evidence: `README.md`)
- Application routes → Authentication: handles accounts (evidence: `app.py`)
- Authentication → Application database: queries users (evidence: `app.py`)
- Student → Profile and password: manages profile (evidence: `README.md`)
- Application routes → Favorites management: handles favorites (evidence: `app.py`)
- Favorites management → Application database: reads and writes (evidence: `app.py`)
- Book search → Application database: reads favorites (evidence: `app.py`)
- Student → Chat interface: asks about books (evidence: `README.md`)
- Chat interface → Chatbot service: sends context (evidence: `static/app.js`)
- Chatbot service → Groq API: queries provider (evidence: `README.md`)
- Chatbot service → SambaNova API: falls back (evidence: `README.md`)
- Book dataset → Model preparation: provides book data (evidence: `train_model.py`)
- Model preparation → TF-IDF artifacts: saves model files (evidence: `train_model.py`)
