# imad-ah/spam-detection-system architecture

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

- Interactive diagram: https://gitdiagram.com/imad-ah/spam-detection-system
- Repository: https://github.com/imad-ah/spam-detection-system

## Overview

SafeMail is a Flask-based spam-detection dashboard. A user submits a message for single inference or uploads a CSV for batch analysis; the server tokenizes text, runs a local DistilBERT sequence classifier, and returns labels and confidence scores. The dashboard also presents analysis history, statistics, charts, and tools for filtering and exporting results. The sampled backend establishes its routes and inference flow; some dashboard behaviors are documented or visible only in partial JavaScript excerpts, so those connections are marked unverified.

Main entry points: [`app.py`](https://github.com/imad-ah/spam-detection-system/blob/main/app.py) (Prediction function), [`static/script.js`](https://github.com/imad-ah/spam-detection-system/blob/main/static/script.js) (Single-message form), [`templates/index.html`](https://github.com/imad-ah/spam-detection-system/blob/main/templates/index.html) (Dashboard page), [`model.safetensors`](https://github.com/imad-ah/spam-detection-system/blob/main/model.safetensors) (Model assets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dashboard["Dashboard UI"]
  node_page["Dashboard page<br/>[index.html]"]
  node_ui["Dashboard interactions<br/>[script.js]"]
  node_singleform["Single-message form<br/>[script.js]"]
  node_csvform["CSV upload form<br/>[script.js]"]
  node_results["Results and tools<br/>[script.js]"]
  node_history["History and charts<br/>[script.js]"]
  node_localization["Language options<br/>[script.js]"]
end

subgraph group_web["Web and Analysis"]
  node_flask["Flask application<br/>[app.py]"]
  node_home["Dashboard route<br/>[app.py]"]
  node_single["Single prediction route<br/>[app.py]"]
  node_batch["CSV prediction route<br/>[app.py]"]
  node_csvanalysis["CSV analysis<br/>[app.py]"]
end

subgraph group_inference["Model Inference"]
  node_predict["Prediction function<br/>[app.py]"]
  node_tokenizer["Text tokenizer<br/>[app.py]"]
  node_classifier["Sequence classifier<br/>[app.py]"]
  node_modelassets["Model assets<br/>[model.safetensors]"]
  node_tokenassets["Tokenizer assets<br/>[tokenizer.json]"]
end

node_user(("Dashboard user"))

node_user -->|"opens"| node_page
node_page -->|"served by"| node_flask
node_flask -->|"routes"| node_home
node_home -->|"renders"| node_page
node_user -->|"enters text"| node_singleform
node_singleform -.->|"submits"| node_single
node_single -->|"calls"| node_predict
node_user -->|"uploads CSV"| node_csvform
node_csvform -.->|"submits"| node_batch
node_batch -->|"analyzes"| node_csvanalysis
node_csvanalysis -->|"classifies rows"| node_predict
node_predict -->|"tokenizes"| node_tokenizer
node_predict -->|"runs inference"| node_classifier
node_classifier -->|"loads weights"| node_modelassets
node_tokenizer -->|"loads vocabulary"| node_tokenassets
node_single -->|"returns result"| node_singleform
node_batch -.->|"returns rows"| node_results
node_ui -->|"handles"| node_singleform
node_ui -->|"handles"| node_csvform
node_results -->|"updates views"| node_history
node_results -.->|"exports results"| node_user
node_localization -->|"localizes"| node_ui

click node_page "https://github.com/imad-ah/spam-detection-system/blob/main/templates/index.html"
click node_ui "https://github.com/imad-ah/spam-detection-system/blob/main/static/script.js"
click node_singleform "https://github.com/imad-ah/spam-detection-system/blob/main/static/script.js"
click node_csvform "https://github.com/imad-ah/spam-detection-system/blob/main/static/script.js"
click node_results "https://github.com/imad-ah/spam-detection-system/blob/main/static/script.js"
click node_history "https://github.com/imad-ah/spam-detection-system/blob/main/static/script.js"
click node_localization "https://github.com/imad-ah/spam-detection-system/blob/main/static/script.js"
click node_flask "https://github.com/imad-ah/spam-detection-system/blob/main/app.py"
click node_home "https://github.com/imad-ah/spam-detection-system/blob/main/app.py"
click node_single "https://github.com/imad-ah/spam-detection-system/blob/main/app.py"
click node_batch "https://github.com/imad-ah/spam-detection-system/blob/main/app.py"
click node_csvanalysis "https://github.com/imad-ah/spam-detection-system/blob/main/app.py"
click node_predict "https://github.com/imad-ah/spam-detection-system/blob/main/app.py"
click node_tokenizer "https://github.com/imad-ah/spam-detection-system/blob/main/app.py"
click node_classifier "https://github.com/imad-ah/spam-detection-system/blob/main/app.py"
click node_modelassets "https://github.com/imad-ah/spam-detection-system/blob/main/model.safetensors"
click node_tokenassets "https://github.com/imad-ah/spam-detection-system/blob/main/tokenizer.json"

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_page,node_ui,node_singleform,node_csvform,node_results,node_history,node_localization,node_user toneBlue
class node_flask,node_home,node_single,node_batch,node_csvanalysis toneAmber
class node_predict,node_tokenizer,node_classifier,node_modelassets,node_tokenassets toneMint
```

## Components

### Dashboard UI

- [Dashboard page](https://github.com/imad-ah/spam-detection-system/blob/main/templates/index.html): `templates/index.html`
- [Dashboard interactions](https://github.com/imad-ah/spam-detection-system/blob/main/static/script.js): `static/script.js`
- [Single-message form](https://github.com/imad-ah/spam-detection-system/blob/main/static/script.js): `static/script.js`
- [CSV upload form](https://github.com/imad-ah/spam-detection-system/blob/main/static/script.js): `static/script.js`
- [Results and tools](https://github.com/imad-ah/spam-detection-system/blob/main/static/script.js): `static/script.js`
- [History and charts](https://github.com/imad-ah/spam-detection-system/blob/main/static/script.js): `static/script.js`
- [Language options](https://github.com/imad-ah/spam-detection-system/blob/main/static/script.js): `static/script.js`

### Web and Analysis

- [Flask application](https://github.com/imad-ah/spam-detection-system/blob/main/app.py): `app.py`
- [Dashboard route](https://github.com/imad-ah/spam-detection-system/blob/main/app.py): `app.py`
- [Single prediction route](https://github.com/imad-ah/spam-detection-system/blob/main/app.py): `app.py`
- [CSV prediction route](https://github.com/imad-ah/spam-detection-system/blob/main/app.py): `app.py`
- [CSV analysis](https://github.com/imad-ah/spam-detection-system/blob/main/app.py): `app.py`

### Model Inference

- [Prediction function](https://github.com/imad-ah/spam-detection-system/blob/main/app.py): `app.py`
- [Text tokenizer](https://github.com/imad-ah/spam-detection-system/blob/main/app.py): `app.py`
- [Sequence classifier](https://github.com/imad-ah/spam-detection-system/blob/main/app.py): `app.py`
- [Model assets](https://github.com/imad-ah/spam-detection-system/blob/main/model.safetensors): `model.safetensors`
- [Tokenizer assets](https://github.com/imad-ah/spam-detection-system/blob/main/tokenizer.json): `tokenizer.json`

### Other components

- **Dashboard user**

## Connections

- Dashboard user → Dashboard page: opens (evidence: `README.md`)
- Dashboard page → Flask application: served by (evidence: `app.py`)
- Flask application → Dashboard route: routes (evidence: `app.py`)
- Dashboard route → Dashboard page: renders (evidence: `app.py`)
- Dashboard user → Single-message form: enters text (evidence: `README.md`)
- Single-message form → Single prediction route: submits
- Single prediction route → Prediction function: calls (evidence: `app.py`)
- Dashboard user → CSV upload form: uploads CSV (evidence: `README.md`)
- CSV upload form → CSV prediction route: submits
- CSV prediction route → CSV analysis: analyzes (evidence: `app.py`)
- CSV analysis → Prediction function: classifies rows (evidence: `app.py`)
- Prediction function → Text tokenizer: tokenizes (evidence: `app.py`)
- Prediction function → Sequence classifier: runs inference (evidence: `app.py`)
- Sequence classifier → Model assets: loads weights (evidence: `app.py`)
- Text tokenizer → Tokenizer assets: loads vocabulary (evidence: `app.py`)
- Single prediction route → Single-message form: returns result (evidence: `app.py`)
- CSV prediction route → Results and tools: returns rows
- Dashboard interactions → Single-message form: handles (evidence: `static/script.js`)
- Dashboard interactions → CSV upload form: handles (evidence: `static/script.js`)
- Results and tools → History and charts: updates views (evidence: `static/script.js`)
- Results and tools → Dashboard user: exports results
- Language options → Dashboard interactions: localizes (evidence: `static/script.js`)
