# rachitnaruzu/mailclassifier architecture

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

- Interactive diagram: https://gitdiagram.com/rachitnaruzu/mailclassifier
- Repository: https://github.com/rachitnaruzu/mailclassifier

## Overview

##### Project Type and Purpose
- This is a standalone machine-learning pipeline (CLI/tool) for classifying emails into Spam/Ham using Logistic Regression, Feed-forward ANN, and SVM.
- It ingests raw email files, extracts features, builds datasets, trains multiple models, tests them, and generates results + charts.

##### Top-Level Components
a. Data Stores (raw and processed)
- Raw Emails Store:
- mails/spam/ (all spam emails)
- mails/ham/ (all non-spam emails)
- Feature Store (intermediate): a serialized dataset (e.g., NumPy arrays or pickles) created by create_data.py
- Model Artifacts (optional): saved model parameters or weight files (if persisted)
- Visualization Outputs: images/*.JPG

b. Processing Modules
- extract.py: tokenization, regex filtering, Porter stemming, builds vocabulary (top 400–500 words)
- create_data.py: reads raw emails + vocabulary, produces feature matrix (X) + label vector (y)
- logistic_regression.py: implements LR with regularization using NumPy
- artificial_neural_network.py: implements feed-forward ANN + backprop using NumPy
- SVM modules: calls out to LIBSVM/LIBLINEAR (via sklearn) for linear and Gaussian SVM
- demo.py: orchestration script that invokes data creation, trains all three models, evaluates on test set, prints accuracy, and outputs top predictors

c. Visualization Module
- matplotlib (in scripts) generates cost vs. iteration and hyperparameter curves, saved under images/

##### Data Flows and Interactions
1. Raw Emails → extract.py → Vocabulary List (400–500 words)
2. Raw Emails + Vocabulary → create_data.py → Feature Matrix + Labels
3. Feature Matrix + Labels → { logistic_regression.py | artificial_neural_network.py | sklearn SVM } → Trained Models + Training Metrics
4. Trained Models + Test Data → demo.py → Validation Metrics + Top Predictors
5. Training/Validation Metrics → matplotlib → Stored Plots in images/

##### Architectural Patterns & Design Principles
- Pipeline Pattern: sequential data-processing stages
- Separation of Concerns:
- extract.py (feature engineering)
- create_data.py (data preparation)
- modeling scripts (algorithm implementations)
- demo.py (orchestration)
- images/ (presentation)
- Modular CLI utilities, each with a single responsibility

##### Key Technologies & Libraries
- Python 3.x (language)
- NumPy (matrix operations for LR & ANN)
- NLTK (Porter stemmer)
- sklearn (SVM interface to LIBSVM/LIBLINEAR)
- matplotlib (plotting)
- re (regex filtering)
- SciPy (if needed by matplotlib)

##### Final Checklist
- [ ] All major scripts/modules labeled
- [ ] Data stores (raw emails, features, model files) clearly shown
- [ ] Third-party libraries called out as dependencies

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Stores
    RawEmails["Raw Emails Store\nmails/spam & mails/ham"]:::datastore
    Vocabulary["Vocabulary List\n(top 400-500 words)"]:::datastore
    FeatureStore["Feature Store\nX.npy + y.npy"]:::datastore
    ModelArtifacts["Model Artifacts\n(model parameters)"]:::datastore

    %% Processing Modules
    Extract["extract.py"]:::process
    CreateData["create_data.py"]:::process

    %% Model Implementations
    subgraph "Model Implementations"
        LR["logistic_regression.py"]:::model
        ANN["artificial_neural_network.py"]:::model
        SVM["SVM (sklearn)"]:::model
    end

    %% Orchestrator
    Demo["demo.py"]:::process

    %% Metrics & Predictions
    Metrics["Metrics Report\n(validation metrics)"]:::process
    TopPred["Top Predictors"]:::process

    %% Visualization
    MatPlot["matplotlib"]:::external
    Images["Visualization Outputs\nimages/*.JPG"]:::visualization

    %% External Dependencies & Docs
    Deps["Third-party Libraries"]:::external
    Req["requirements.txt"]:::external
    Readme["README.md"]:::external

    %% Data Flows
    RawEmails -->|raw emails| Extract
    Extract -->|vocabulary.txt| Vocabulary
    RawEmails -->|raw emails| CreateData
    Vocabulary -->|vocabulary.txt| CreateData
    CreateData -->|X.npy + y.npy| FeatureStore

    FeatureStore -->|features| LR
    FeatureStore -->|features| ANN
    FeatureStore -->|features| SVM

    LR -->|model parameters| ModelArtifacts
    ANN -->|model parameters| ModelArtifacts
    SVM -->|model parameters| ModelArtifacts

    ModelArtifacts -->|trained models| Demo
    FeatureStore -->|test split| Demo

    Demo -->|validation metrics| Metrics
    Demo -->|top predictors| TopPred

    Metrics -->|metrics data| MatPlot
    TopPred -->|predictor data| MatPlot
    MatPlot -->|plots| Images

    %% Dependencies Integration
    Deps --> Extract
    Deps --> CreateData
    Deps --> LR
    Deps --> ANN
    Deps --> SVM
    Deps --> MatPlot

    %% Click Events
    click Extract "https://github.com/rachitnaruzu/mailclassifier/blob/master/extract.py"
    click CreateData "https://github.com/rachitnaruzu/mailclassifier/blob/master/create_data.py"
    click LR "https://github.com/rachitnaruzu/mailclassifier/blob/master/logistic_regression.py"
    click ANN "https://github.com/rachitnaruzu/mailclassifier/blob/master/artificial_neural_network.py"
    click Demo "https://github.com/rachitnaruzu/mailclassifier/blob/master/demo.py"
    click Images "https://github.com/rachitnaruzu/mailclassifier/tree/master/images/"
    click Req "https://github.com/rachitnaruzu/mailclassifier/blob/master/requirements.txt"
    click Readme "https://github.com/rachitnaruzu/mailclassifier/blob/master/README.md"

    %% Styles
    classDef datastore fill:#1f77b4,stroke:#333,color:#fff;
    classDef process fill:#2ca02c,stroke:#333,color:#fff;
    classDef model fill:#ff7f0e,stroke:#333,color:#fff;
    classDef visualization fill:#9467bd,stroke:#333,color:#fff;
    classDef external fill:#7f7f7f,stroke:#333,color:#fff;
```
