# mohamedbr-dev/arabic-sentiment-analysis architecture

> Architecture diagram of the GitHub repository mohamedbr-dev/arabic-sentiment-analysis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mohamedbr-dev/arabic-sentiment-analysis
- Repository: https://github.com/mohamedbr-dev/arabic-sentiment-analysis

## Overview

This repository builds and serves a three-class Arabic sentiment classifier. Its main workflow prepares labeled data, fine-tunes AraBERT, merges two trained models, and serves predictions through FastAPI; evaluation and an in-browser ONNX demo are additional product capabilities. The graph also shows shared text cleaning and request limiting. Some links reflect explicit README descriptions; unsampled implementation details are not inferred.

Main entry points: [`src/day3_api.py`](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/day3_api.py) (FastAPI endpoints), [`src/day1_arabic_sentiment.py`](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/day1_arabic_sentiment.py) (Dataset preparation), [`src/day2_finetune_arabert.py`](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/day2_finetune_arabert.py) (AraBERT fine-tuning), [`deploy/static/index.html`](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/deploy/static/index.html) (Static demo page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data Preparation"]
  node_prep["Dataset preparation"]
  node_review_data["Review labels<br/>[review_data.py]"]
  node_cleaner["Text cleaning<br/>[text_clean.py]"]
end

subgraph group_model["Model Development"]
  node_training["AraBERT fine-tuning"]
  node_trained_models[("Trained model variants")]
  node_merge["Model weight merge<br/>[merge_models.py]"]
  node_served_model[("Served model")]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
end

subgraph group_server["API Serving"]
  node_api["FastAPI endpoints<br/>[day3_api.py]"]
  node_limiter["Request limiter<br/>[rate_limit.py]"]
  node_api_page["Interactive API page<br/>[index.html]"]
end

subgraph group_browser["Browser Demo"]
  node_export["ONNX export<br/>[export_onnx.py]"]
  node_browser_model["Browser inference<br/>[model.js]"]
  node_browser_cleaner["Browser text cleaning<br/>[text_clean.js]"]
  node_browser_page["Static demo page<br/>[index.html]"]
  node_onnx_model[("Quantized ONNX model<br/>[export_onnx.py]")]
end

node_analyst(("Data / model user"))
node_huggingface{{"Hugging Face"}}
node_datasets[("Labeled datasets")]
node_client(("API / demo visitor"))

node_analyst -->|"runs preparation"| node_prep
node_huggingface -->|"provides ArSAS"| node_prep
node_huggingface -->|"provides reviews"| node_review_data
node_prep -->|"loads review sources"| node_review_data
node_prep -->|"cleans text"| node_cleaner
node_prep -->|"writes splits"| node_datasets
node_datasets -->|"supplies splits"| node_training
node_analyst -->|"runs fine-tuning"| node_training
node_training -->|"uses cleaning"| node_cleaner
node_huggingface -->|"provides base model"| node_training
node_training -->|"saves checkpoints"| node_trained_models
node_analyst -->|"runs merge"| node_merge
node_trained_models -->|"provides weights"| node_merge
node_merge -->|"writes merged weights"| node_served_model
node_analyst -->|"runs scoring"| node_evaluation
node_trained_models -->|"provides candidates"| node_evaluation
node_served_model -->|"provides model"| node_evaluation
node_client -->|"sends predictions"| node_api
node_api -->|"loads model"| node_served_model
node_api -->|"cleans requests"| node_cleaner
node_api -->|"checks request rate"| node_limiter
node_api -->|"serves page"| node_api_page
node_analyst -->|"runs export"| node_export
node_served_model -->|"provides source model"| node_export
node_export -->|"writes quantized model"| node_onnx_model
node_client -->|"opens demo"| node_browser_page
node_browser_page -->|"runs inference"| node_browser_model
node_browser_page -->|"cleans input"| node_browser_cleaner
node_browser_model -->|"loads model"| node_onnx_model

click node_prep "https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/day1_arabic_sentiment.py"
click node_review_data "https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/review_data.py"
click node_cleaner "https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/text_clean.py"
click node_training "https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/day2_finetune_arabert.py"
click node_merge "https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/merge_models.py"
click node_evaluation "https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/evaluate.py"
click node_api "https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/day3_api.py"
click node_limiter "https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/rate_limit.py"
click node_api_page "https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/static/index.html"
click node_export "https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/deploy/export_onnx.py"
click node_browser_model "https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/deploy/static/model.js"
click node_browser_cleaner "https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/deploy/static/text_clean.js"
click node_browser_page "https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/deploy/static/index.html"
click node_onnx_model "https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/deploy/export_onnx.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_prep,node_review_data,node_cleaner,node_analyst toneBlue
class node_training,node_trained_models,node_merge,node_served_model,node_evaluation,node_datasets toneAmber
class node_api,node_limiter,node_api_page,node_client toneMint
class node_export,node_browser_model,node_browser_cleaner,node_browser_page,node_onnx_model toneRose
class node_huggingface toneIndigo
```

## Components

### Data Preparation

- [Dataset preparation](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/day1_arabic_sentiment.py): `src/day1_arabic_sentiment.py`
- [Review labels](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/review_data.py): `src/review_data.py`
- [Text cleaning](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/text_clean.py): `src/text_clean.py`

### Model Development

- [AraBERT fine-tuning](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/day2_finetune_arabert.py): `src/day2_finetune_arabert.py`
- **Trained model variants**
- [Model weight merge](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/merge_models.py): `src/merge_models.py`
- **Served model**
- [Model evaluation](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/evaluate.py): `src/evaluate.py`

### API Serving

- [FastAPI endpoints](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/day3_api.py): `src/day3_api.py`
- [Request limiter](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/rate_limit.py): `src/rate_limit.py`
- [Interactive API page](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/src/static/index.html): `src/static/index.html`

### Browser Demo

- [ONNX export](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/deploy/export_onnx.py): `deploy/export_onnx.py`
- [Browser inference](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/deploy/static/model.js): `deploy/static/model.js`
- [Browser text cleaning](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/deploy/static/text_clean.js): `deploy/static/text_clean.js`
- [Static demo page](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/deploy/static/index.html): `deploy/static/index.html`
- [Quantized ONNX model](https://github.com/mohamedbr-dev/arabic-sentiment-analysis/blob/main/deploy/export_onnx.py): `deploy/export_onnx.py`

### Other components

- **Data / model user**
- **Hugging Face**
- **Labeled datasets**
- **API / demo visitor**

## Connections

- Data / model user → Dataset preparation: runs preparation (evidence: `README.md`)
- Hugging Face → Dataset preparation: provides ArSAS (evidence: `README.md`)
- Hugging Face → Review labels: provides reviews (evidence: `src/review_data.py`)
- Dataset preparation → Review labels: loads review sources (evidence: `src/day1_arabic_sentiment.py`)
- Dataset preparation → Text cleaning: cleans text (evidence: `src/day1_arabic_sentiment.py`)
- Dataset preparation → Labeled datasets: writes splits (evidence: `README.md`)
- Labeled datasets → AraBERT fine-tuning: supplies splits (evidence: `README.md`)
- Data / model user → AraBERT fine-tuning: runs fine-tuning (evidence: `README.md`)
- AraBERT fine-tuning → Text cleaning: uses cleaning (evidence: `src/day2_finetune_arabert.py`)
- Hugging Face → AraBERT fine-tuning: provides base model (evidence: `README.md`)
- AraBERT fine-tuning → Trained model variants: saves checkpoints (evidence: `README.md`)
- Data / model user → Model weight merge: runs merge (evidence: `README.md`)
- Trained model variants → Model weight merge: provides weights (evidence: `README.md`)
- Model weight merge → Served model: writes merged weights (evidence: `README.md`)
- Data / model user → Model evaluation: runs scoring (evidence: `README.md`)
- Trained model variants → Model evaluation: provides candidates (evidence: `README.md`)
- Served model → Model evaluation: provides model (evidence: `README.md`)
- API / demo visitor → FastAPI endpoints: sends predictions (evidence: `README.md`)
- FastAPI endpoints → Served model: loads model (evidence: `src/day3_api.py`)
- FastAPI endpoints → Text cleaning: cleans requests (evidence: `src/day3_api.py`)
- FastAPI endpoints → Request limiter: checks request rate (evidence: `src/day3_api.py`)
- FastAPI endpoints → Interactive API page: serves page (evidence: `src/day3_api.py`)
- Data / model user → ONNX export: runs export (evidence: `README.md`)
- Served model → ONNX export: provides source model (evidence: `README.md`)
- ONNX export → Quantized ONNX model: writes quantized model (evidence: `deploy/export_onnx.py`)
- API / demo visitor → Static demo page: opens demo (evidence: `README.md`)
- Static demo page → Browser inference: runs inference (evidence: `README.md`)
- Static demo page → Browser text cleaning: cleans input (evidence: `README.md`)
- Browser inference → Quantized ONNX model: loads model (evidence: `deploy/static/model.js`)
