# aashmitmckenzie/apif-adaptive-phishing-intelligence-framework architecture

> Architecture diagram of the GitHub repository aashmitmckenzie/apif-adaptive-phishing-intelligence-framework, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aashmitmckenzie/apif-adaptive-phishing-intelligence-framework
- Repository: https://github.com/aashmitmckenzie/apif-adaptive-phishing-intelligence-framework

## Overview

##### Project type and purpose
- This is a full-stack, “real-time phishing detection” Python application with an interactive Streamlit dashboard.
- Core functions: URL feature extraction, three parallel detection pipelines (ML, DL, Heuristic), weighted ensemble fusion with reinforcement learning updates, and a feedback loop persisted in SQLite.

##### Main components
a. Streamlit UI (streamlit_app.py)
b. Data Preprocessor (data_preprocessor.py)
c. ML Pipeline (ml_pipeline.py) – Random Forest + XGBoost
d. DL Pipeline (dl_pipeline.py) – PyTorch feed-forward network
e. Heuristic Rules Engine (embedded in ensemble_rl.py)
f. Ensemble & RL Weight Optimizer (ensemble_rl.py)
g. Training Orchestrator (train_models.py)
h. Feedback Store (SQLite used by streamlit_app.py & ensemble_rl.py)
i. EDA Notebook (APIF_EDA_Analysis.ipynb) – offline analysis

##### Relationships & data flow
1. URL Input → Streamlit UI
2. UI calls Feature Extraction → output 21 numeric features
3. Split features in parallel into three pipelines:
– ML Pipeline → ML probability
– DL Pipeline → DL probability
– Heuristic Rules → Heuristic probability
4. Probabilities → Ensemble Fusion (weights from ensemble_weights.pkl, updated by RL)
6. User feedback → written to SQLite → triggers Q-Learning update of ensemble weights → saved back

##### Architectural patterns & principles
- Modular separation: each detection pipeline in its own module
- Parallel execution: concurrency drives low latency (total ≈ slowest pipeline)
- Feedback loop: Reinforcement Learning adjusts ensemble weights over time
- Offline analytics: EDA notebook uses same preprocessor + models for deep dives

## Diagram (Mermaid)

```mermaid
graph TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        A["/ URL Input /"]:::data
        B["Streamlit UI"]:::ui
    end

    %% Backend Layer
    subgraph "Backend Layer"
        C["Data Preprocessor<br>(21 features)"]:::data
        subgraph "Detection Pipelines"
            D["ML Pipeline<br>(RF & XGB)<br>5–10ms"]:::detection
            E["DL Pipeline<br>(PyTorch NN)<br>15–25ms"]:::detection
            F["Heuristic Rules<br>1–5ms"]:::detection
        end
        G["Ensemble & RL Weight Optimizer<br>Weights: ML0.65 DL0.25 H0.10<br>Threshold:0.4"]:::ensemble
        I[(SQLite DB)]:::db
    end

    %% Offline Analytics
    subgraph "Offline Analytics"
        J["EDA Notebook"]:::ui
    end

    %% Training
    K["Training Orchestrator"]:::ensemble

    %% Data Flow
    A --> B
    B --> C
    C --> D
    C --> E
    C --> F
    D --> G
    E --> G
    F --> G
    G --> B
    B -->|"User Feedback"| I
    I --> G
    J --> C
    K --> D
    K --> E
    K --> F

    %% Click Events
    click B "https://github.com/aashmitmckenzie/apif-adaptive-phishing-intelligence-framework/blob/main/streamlit_app.py"
    click C "https://github.com/aashmitmckenzie/apif-adaptive-phishing-intelligence-framework/blob/main/data_preprocessor.py"
    click D "https://github.com/aashmitmckenzie/apif-adaptive-phishing-intelligence-framework/blob/main/ml_pipeline.py"
    click E "https://github.com/aashmitmckenzie/apif-adaptive-phishing-intelligence-framework/blob/main/dl_pipeline.py"
    click F "https://github.com/aashmitmckenzie/apif-adaptive-phishing-intelligence-framework/blob/main/ensemble_rl.py"
    click G "https://github.com/aashmitmckenzie/apif-adaptive-phishing-intelligence-framework/blob/main/ensemble_rl.py"
    click I "https://github.com/aashmitmckenzie/apif-adaptive-phishing-intelligence-framework/blob/main/streamlit_app.py"
    click J "https://github.com/aashmitmckenzie/apif-adaptive-phishing-intelligence-framework/blob/main/APIF_EDA_Analysis.ipynb"
    click K "https://github.com/aashmitmckenzie/apif-adaptive-phishing-intelligence-framework/blob/main/train_models.py"

    %% Styles
    classDef data fill:#D0E6FF,stroke:#0366d6,color:#0366d6;
    classDef detection fill:#DFFFD0,stroke:#228B22,color:#228B22;
    classDef ensemble fill:#FFE0B2,stroke:#FF8C00,color:#FF8C00;
    classDef ui fill:#FFF4B8,stroke:#DAA520,color:#DAA520;
    classDef db fill:#E0E0E0,stroke:#A9A9A9,color:#333;
```
