# aditipatil38/scamdetekt architecture

> Architecture diagram of the GitHub repository aditipatil38/scamdetekt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aditipatil38/scamdetekt
- Repository: https://github.com/aditipatil38/scamdetekt

## Overview

##### Project Type and Purpose
- ScamDetekt is a full-stack data science web application for real-time spam email classification.
- Frontend: simple HTML/CSS (Jinja2 templates).
- Backend: Python Flask server that loads a pickled SVM model and TF-IDF vectorizer for inference.
- Offline pipeline: Jupyter notebooks and a training script to preprocess data, engineer features, train models, and serialize artifacts.

##### File Structure
- Top-level:
- Notebooks/ — EDA and model comparison experiments
- train_model.py — standalone training script
- requirements.txt, README.md, LICENSE
- app/ directory:
- app.py — Flask application and route definitions
- model/ — serialized artifacts (svm_model.pkl, vectorizer.pkl)
- templates/ — index.html, result.html (Jinja2 views)
- static/ — style.css, images (UI assets)
- scamdetekt/ — UI screenshot examples

##### Extract Architectural Insights from README
- Text preprocessing: lowercase, punctuation removal, NLTK stopwords
- Feature engineering: TF-IDF unigrams + bigrams (top 3000 features)
- Classification: Support Vector Machine (best balanced performance)
- Persistence: model and vectorizer stored as .pkl files

##### Main Components
a. User Interface (Browser)
b. Flask Application Server
- HTTP Request Handler (routes in app.py)
- Preprocessing Module (text cleaning)
- Feature Extraction Module (TF-IDF vectorizer)
- Inference Module (SVM model prediction)
c. Model Artifact Store (Pickle files on disk)
d. Offline Training Pipeline
- Data Source (email_spams.csv)
- Preprocessing & Feature Engineering
- Model Trainer (scikit-learn, NLTK)
- Serialization (vectorizer.pkl, svm_model.pkl)
e. (Optional) Development Notebooks

##### Relationships and Data Flows
- Browser → HTTP POST /predict → Flask Server
- Flask Server → Preprocessing → Cleaned Text
- Cleaned Text → TF-IDF Vectorizer → Feature Vector
- Feature Vector → SVM Model → Prediction
- Prediction → Render result.html → Browser
- Offline: CSV → train_model.py / Notebooks → serialized artifacts → model/

##### Architectural Patterns and Design Principles
- MVC (Model-View-Controller):
- Model: pickled ML artifacts
- View: Jinja2 templates (HTML/CSS)
- Controller: Flask route handlers
- Separation of Concerns: training vs. inference code is modular
- Single Responsibility: distinct modules for preprocessing, vectorization, and inference

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Frontend Layer"
        Index["index.html"]:::ui
        Result["result.html"]:::ui
        CSS["style.css"]:::ui
        Images["images/"]:::ui
        Browser["User Interface (Browser)"]:::ui
    end

    subgraph "Backend Layer"
        App["Flask Application Server"]:::backend
        Preproc["Preprocessing Module"]:::backend
        Vector["TF-IDF Vectorizer Module"]:::backend
        Inference["Inference Module (SVM Prediction)"]:::backend
    end

    subgraph "Data Layer"
        CSV["email_spams.csv"]:::data
        EDA1["EDA.ipynb"]:::data
        EDA2["spam_safe_classification.ipynb"]:::data
        Trainer["Offline Training Script"]:::data
        VPKL["vectorizer.pkl"]:::data
        MPKL["svm_model.pkl"]:::data
    end

    Browser -->|"POST /predict"| App
    App -->|"clean_text()"| Preproc
    Preproc -->|"vectorize()"| Vector
    Vector -->|"predict()"| Inference
    Inference -->|"result"| App
    App -->|"render result.html"| Browser

    CSV -->|provides data| Trainer
    EDA1 -->|analysis| Trainer
    EDA2 -->|analysis| Trainer
    Trainer -->|serializes| VPKL
    Trainer -->|serializes| MPKL

    VPKL -->|load vectorizer| Vector
    MPKL -->|load model| Inference

    click Index "https://github.com/aditipatil38/scamdetekt/blob/main/app/templates/index.html"
    click Result "https://github.com/aditipatil38/scamdetekt/blob/main/app/templates/result.html"
    click CSS "https://github.com/aditipatil38/scamdetekt/blob/main/app/static/style.css"
    click Images "https://github.com/aditipatil38/scamdetekt/tree/main/app/static/images/"
    click App "https://github.com/aditipatil38/scamdetekt/blob/main/app/app.py"
    click Preproc "https://github.com/aditipatil38/scamdetekt/blob/main/app/app.py"
    click Vector "https://github.com/aditipatil38/scamdetekt/blob/main/app/app.py"
    click Inference "https://github.com/aditipatil38/scamdetekt/blob/main/app/app.py"
    click Trainer "https://github.com/aditipatil38/scamdetekt/blob/main/app/train_model.py"
    click CSV "https://github.com/aditipatil38/scamdetekt/blob/main/Notebooks/email_spams.csv"
    click EDA1 "https://github.com/aditipatil38/scamdetekt/blob/main/Notebooks/EDA.ipynb"
    click EDA2 "https://github.com/aditipatil38/scamdetekt/blob/main/Notebooks/spam_safe_classification.ipynb"
    click VPKL "https://github.com/aditipatil38/scamdetekt/blob/main/app/model/vectorizer.pkl"
    click MPKL "https://github.com/aditipatil38/scamdetekt/blob/main/app/model/svm_model.pkl"

    classDef ui fill:#cce5ff,stroke:#0066cc,color:#003366
    classDef backend fill:#d4edda,stroke:#34a853,color:#0f5132
    classDef data fill:#fff3cd,stroke:#d39e00,color:#664d03
```
