# athifu/ai-based-phishing-detection-system architecture

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

- Interactive diagram: https://gitdiagram.com/athifu/ai-based-phishing-detection-system
- Repository: https://github.com/athifu/ai-based-phishing-detection-system

## Overview

This is a browser-based phishing detection application for URLs and email text. A user submits content through the frontend; the API validates and dispatches it to URL machine-learning prediction or heuristic email analysis, then returns a risk result for display. A separate documented training workflow generates synthetic URL examples, extracts features, evaluates a Random Forest, and saves its model artifact. Email detection is heuristic, not a separate trained model. Source excerpts support the main code relationships; the README documents the browser-to-API workflow and UI capabilities.

Main entry points: [`backend/ml/model.py`](https://github.com/athifu/ai-based-phishing-detection-system/blob/main/backend/ml/model.py) (URL Prediction), [`frontend/app.js`](https://github.com/athifu/ai-based-phishing-detection-system/blob/main/frontend/app.js) (Analysis Interface), [`backend/main.py`](https://github.com/athifu/ai-based-phishing-detection-system/blob/main/backend/main.py) (FastAPI Endpoint), [`backend/ml/train_model.py`](https://github.com/athifu/ai-based-phishing-detection-system/blob/main/backend/ml/train_model.py) (Model Training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User Interface"]
  node_frontend["Analysis Interface<br/>[app.js]"]
end

subgraph group_service["Analysis Service"]
  node_api["FastAPI Endpoint<br/>[main.py]"]
end

subgraph group_ml["Detection and Training"]
  node_model["URL Prediction<br/>[model.py]"]
  node_urlfeatures["URL Features"]
  node_emailfeatures["Email Features"]
  node_emailheuristic["Email Heuristic<br/>[model.py]"]
  node_trainer["Model Training<br/>[train_model.py]"]
  node_artifact[("Trained Model")]
end

node_user(("User"))

node_user -->|"enters content"| node_frontend
node_frontend -->|"submits analysis"| node_api
node_api -->|"requests prediction"| node_model
node_model -->|"extracts URL features"| node_urlfeatures
node_model -->|"extracts email features"| node_emailfeatures
node_model -->|"scores email"| node_emailheuristic
node_model -->|"loads model"| node_artifact
node_trainer -->|"extracts training features"| node_urlfeatures
node_trainer -->|"saves model"| node_artifact
node_api -->|"returns result"| node_frontend
node_frontend -->|"displays risk"| node_user

click node_frontend "https://github.com/athifu/ai-based-phishing-detection-system/blob/main/frontend/app.js"
click node_api "https://github.com/athifu/ai-based-phishing-detection-system/blob/main/backend/main.py"
click node_model "https://github.com/athifu/ai-based-phishing-detection-system/blob/main/backend/ml/model.py"
click node_urlfeatures "https://github.com/athifu/ai-based-phishing-detection-system/blob/main/backend/ml/feature_extractor.py"
click node_emailfeatures "https://github.com/athifu/ai-based-phishing-detection-system/blob/main/backend/ml/feature_extractor.py"
click node_emailheuristic "https://github.com/athifu/ai-based-phishing-detection-system/blob/main/backend/ml/model.py"
click node_trainer "https://github.com/athifu/ai-based-phishing-detection-system/blob/main/backend/ml/train_model.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_frontend,node_user toneBlue
class node_api toneAmber
class node_model,node_urlfeatures,node_emailfeatures,node_emailheuristic,node_trainer,node_artifact toneMint
```

## Components

### User Interface

- [Analysis Interface](https://github.com/athifu/ai-based-phishing-detection-system/blob/main/frontend/app.js): `frontend/app.js`

### Analysis Service

- [FastAPI Endpoint](https://github.com/athifu/ai-based-phishing-detection-system/blob/main/backend/main.py): `backend/main.py`

### Detection and Training

- [URL Prediction](https://github.com/athifu/ai-based-phishing-detection-system/blob/main/backend/ml/model.py): `backend/ml/model.py`
- [URL Features](https://github.com/athifu/ai-based-phishing-detection-system/blob/main/backend/ml/feature_extractor.py): `backend/ml/feature_extractor.py`
- [Email Features](https://github.com/athifu/ai-based-phishing-detection-system/blob/main/backend/ml/feature_extractor.py): `backend/ml/feature_extractor.py`
- [Email Heuristic](https://github.com/athifu/ai-based-phishing-detection-system/blob/main/backend/ml/model.py): `backend/ml/model.py`
- [Model Training](https://github.com/athifu/ai-based-phishing-detection-system/blob/main/backend/ml/train_model.py): `backend/ml/train_model.py`
- **Trained Model**

### Other components

- **User**

## Connections

- User → Analysis Interface: enters content (evidence: `README.md`)
- Analysis Interface → FastAPI Endpoint: submits analysis (evidence: `frontend/app.js`)
- FastAPI Endpoint → URL Prediction: requests prediction (evidence: `backend/main.py`)
- URL Prediction → URL Features: extracts URL features (evidence: `backend/ml/model.py`)
- URL Prediction → Email Features: extracts email features (evidence: `backend/ml/model.py`)
- URL Prediction → Email Heuristic: scores email (evidence: `backend/ml/model.py`)
- URL Prediction → Trained Model: loads model (evidence: `backend/ml/model.py`)
- Model Training → URL Features: extracts training features (evidence: `backend/ml/train_model.py`)
- Model Training → Trained Model: saves model (evidence: `backend/ml/train_model.py`)
- FastAPI Endpoint → Analysis Interface: returns result (evidence: `frontend/app.js`)
- Analysis Interface → User: displays risk (evidence: `frontend/app.js`)
