# loki-git001/email_spamclassification architecture

> Architecture diagram of the GitHub repository loki-git001/email_spamclassification, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/loki-git001/email_spamclassification
- Repository: https://github.com/loki-git001/email_spamclassification

## Overview

1. This repository is a small machine-learning application for email spam classification. The core architecture is split into data preparation, feature engineering, model training, and a packaged inference artifact.

2. The data layer is organized under `dataset/` with a clear raw-to-processed boundary:
   - `dataset/raw/emails.csv` is the source dataset.
   - `dataset/processed_data/emails_processed.csv` is the cleaned/normalized version used downstream.
   This suggests an offline preprocessing step rather than live data ingestion.

3. `feature_engineering.py` is the main code module in the repo and likely contains reusable text-cleaning and feature-construction logic. It acts as the shared transformation layer between the raw dataset and the training/inference stages.

4. The exploratory and experimental workflow is notebook-driven:
   - `eda.ipynb` for dataset inspection and analysis.
   - `feature_extraction.ipynb` for text/vector feature experimentation.
   - `train_model.ipynb` for model selection and training.
   These notebooks are the research/iteration side of the system, not the deployed runtime.

5. The trained model is persisted as `models/svm_pipeline.joblib`. That artifact indicates the deployed classifier is a scikit-learn pipeline, probably combining preprocessing/vectorization with an SVM classifier in a single serialized object.

6. `app.py` appears to be the runtime entrypoint for using the trained model. It likely loads `models/svm_pipeline.joblib`, accepts email text input, and returns a spam/ham prediction. In architecture terms, this is the inference boundary between user input and the saved model artifact.

7. The repository therefore has a simple flow:
   raw email data -> preprocessing/feature engineering -> training notebooks -> serialized pipeline -> `app.py` inference.
   The processed CSV sits in the middle as an intermediate, reproducible dataset.

8. The `models/` directory is the model registry for this project, while `dataset/processed_data/` is the curated training input. Those two directories define the main persisted state of the system.

9. `requirements.txt` and `.devcontainer/devcontainer.json` define the execution environment. This matters architecturally because the project likely depends on a Python ML stack, and the devcontainer provides a reproducible development setup.

10. `images/model_selection/` and `Email-Spam-Classification.pptx` are supporting artifacts for documentation and presentation, not runtime components. They reflect the experimental/model-comparison process around the classifier.

11. Overall, this is an offline-trained, file-based ML application with no obvious external services or databases. The main architectural boundaries are between dataset processing, model training, and model serving via a lightweight local app.

Main entry points: [`feature_engineering.py`](https://github.com/loki-git001/email_spamclassification/blob/main/feature_engineering.py) (Features), [`train_model.ipynb`](https://github.com/loki-git001/email_spamclassification/blob/main/train_model.ipynb) (Train model), [`dataset/processed_data/emails_processed.csv`](https://github.com/loki-git001/email_spamclassification/blob/main/dataset/processed_data/emails_processed.csv) (Processed data), [`requirements.txt`](https://github.com/loki-git001/email_spamclassification/blob/main/requirements.txt) (Requirements)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data"]
  node_raw_emails["Raw emails<br/>raw dataset<br/>[emails.csv]"]
  node_processed_emails["Processed data<br/>curated dataset"]
end

subgraph group_research["Research"]
  node_eda_notebook["EDA<br/>analysis notebook<br/>[eda.ipynb]"]
  node_feature_extraction_notebook["Feature exp.<br/>experiment notebook"]
  node_train_notebook["Train model<br/>training notebook<br/>[train_model.ipynb]"]
end

subgraph group_model["Model"]
  node_svm_pipeline[("SVM pipeline<br/>serialized model")]
end

subgraph group_runtime["Runtime"]
  node_app["App<br/>inference entrypoint<br/>[app.py]"]
end

subgraph group_env["Environment"]
  node_requirements["Requirements<br/>dependency spec<br/>[requirements.txt]"]
  node_devcontainer["Devcontainer<br/>dev env<br/>[devcontainer.json]"]
end

subgraph group_docs["Docs"]
  node_model_selection_images["Model plots<br/>analysis artifacts"]
  node_presentation["Presentation<br/>report deck"]
end

node_feature_engineering["Features<br/>transform module"]

node_raw_emails -->|"clean"| node_feature_engineering
node_feature_engineering -->|"produce"| node_processed_emails
node_processed_emails -->|"inspect"| node_eda_notebook
node_processed_emails -->|"experiment"| node_feature_extraction_notebook
node_processed_emails -->|"train"| node_train_notebook
node_feature_engineering -->|"reuse"| node_feature_extraction_notebook
node_feature_engineering -->|"reuse"| node_train_notebook
node_train_notebook -->|"serialize"| node_svm_pipeline
node_feature_extraction_notebook -->|"export"| node_model_selection_images
node_train_notebook -->|"report"| node_presentation
node_svm_pipeline -->|"load"| node_app
node_feature_engineering -->|"preprocess"| node_app
node_requirements -->|"support"| node_devcontainer
node_requirements -->|"run"| node_app
node_requirements -->|"run"| node_train_notebook

click node_raw_emails "https://github.com/loki-git001/email_spamclassification/blob/main/dataset/raw/emails.csv"
click node_processed_emails "https://github.com/loki-git001/email_spamclassification/blob/main/dataset/processed_data/emails_processed.csv"
click node_feature_engineering "https://github.com/loki-git001/email_spamclassification/blob/main/feature_engineering.py"
click node_eda_notebook "https://github.com/loki-git001/email_spamclassification/blob/main/eda.ipynb"
click node_feature_extraction_notebook "https://github.com/loki-git001/email_spamclassification/blob/main/feature_extraction.ipynb"
click node_train_notebook "https://github.com/loki-git001/email_spamclassification/blob/main/train_model.ipynb"
click node_svm_pipeline "https://github.com/loki-git001/email_spamclassification/blob/main/models/svm_pipeline.joblib"
click node_app "https://github.com/loki-git001/email_spamclassification/blob/main/app.py"
click node_requirements "https://github.com/loki-git001/email_spamclassification/blob/main/requirements.txt"
click node_devcontainer "https://github.com/loki-git001/email_spamclassification/blob/main/.devcontainer/devcontainer.json"
click node_model_selection_images "https://github.com/loki-git001/email_spamclassification/tree/main/images/model_selection"
click node_presentation "https://github.com/loki-git001/email_spamclassification/blob/main/Email-Spam-Classification.pptx"

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_raw_emails,node_processed_emails toneBlue
class node_eda_notebook,node_feature_extraction_notebook,node_train_notebook toneAmber
class node_svm_pipeline toneMint
class node_app toneRose
class node_requirements,node_devcontainer toneIndigo
class node_model_selection_images,node_presentation toneTeal
class node_feature_engineering toneNeutral
```

## Components

### Data

Offline dataset and curated training input

- [Raw emails](https://github.com/loki-git001/email_spamclassification/blob/main/dataset/raw/emails.csv): raw dataset · Source email corpus · `dataset/raw/emails.csv`
- [Processed data](https://github.com/loki-git001/email_spamclassification/blob/main/dataset/processed_data/emails_processed.csv): curated dataset · Cleaned and normalized dataset used downstream · `dataset/processed_data/emails_processed.csv`

### Research

Notebook-driven exploration and training

- [EDA](https://github.com/loki-git001/email_spamclassification/blob/main/eda.ipynb): analysis notebook · Dataset inspection and exploratory analysis · `eda.ipynb`
- [Feature exp.](https://github.com/loki-git001/email_spamclassification/blob/main/feature_extraction.ipynb): experiment notebook · Feature and vectorization experimentation · `feature_extraction.ipynb`
- [Train model](https://github.com/loki-git001/email_spamclassification/blob/main/train_model.ipynb): training notebook · Model selection and training workflow · `train_model.ipynb`

### Model

Persisted classifier artifact and related outputs

- [SVM pipeline](https://github.com/loki-git001/email_spamclassification/blob/main/models/svm_pipeline.joblib): serialized model · Saved scikit-learn inference pipeline · `models/svm_pipeline.joblib`

### Runtime

Inference entrypoint

- [App](https://github.com/loki-git001/email_spamclassification/blob/main/app.py): inference entrypoint · Runtime interface that loads the model and predicts spam · `app.py`

### Environment

Reproducible development and dependency setup

- [Requirements](https://github.com/loki-git001/email_spamclassification/blob/main/requirements.txt): dependency spec · Python package dependencies · `requirements.txt`
- [Devcontainer](https://github.com/loki-git001/email_spamclassification/blob/main/.devcontainer/devcontainer.json): dev env · Containerized development environment · `.devcontainer/devcontainer.json`

### Docs

Presentation and visual artifacts

- [Model plots](https://github.com/loki-git001/email_spamclassification/tree/main/images/model_selection): analysis artifacts · Model-selection visual outputs · `images/model_selection`
- [Presentation](https://github.com/loki-git001/email_spamclassification/blob/main/Email-Spam-Classification.pptx): report deck · Project presentation artifact · `Email-Spam-Classification.pptx`

### Other components

- [Features](https://github.com/loki-git001/email_spamclassification/blob/main/feature_engineering.py): transform module · Shared text cleaning and feature construction logic · `feature_engineering.py`

## Connections

- Raw emails → Features: clean · Raw data is transformed by the shared preprocessing layer
- Features → Processed data: produce · Feature and cleaning logic yields the curated dataset
- Processed data → EDA: inspect · Processed data supports exploratory analysis
- Processed data → Feature exp.: experiment · Curated data feeds feature engineering experiments
- Processed data → Train model: train · Training consumes the processed dataset
- Features → Feature exp.: reuse · Notebook experiments share the transformation logic
- Features → Train model: reuse · Training reuses the shared feature pipeline
- Train model → SVM pipeline: serialize · Training produces the persisted pipeline artifact
- Feature exp. → Model plots: export · Exploration generates comparison plots and figures
- Train model → Presentation: report · Training results are summarized in the presentation deck
- SVM pipeline → App: load · Inference app loads the serialized model
- Features → App: preprocess · Runtime input is normalized before prediction
- Requirements → Devcontainer: support · Dependencies and dev container define the working environment
- Requirements → App: run · Application runtime depends on the Python ML stack
- Requirements → Train model: run · Notebook training depends on the same environment
