# pwskills-datascienceteam/spam-detection architecture

> Architecture diagram of the GitHub repository pwskills-datascienceteam/spam-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pwskills-datascienceteam/spam-detection
- Repository: https://github.com/pwskills-datascienceteam/spam-detection

## Overview

This repository implements a spam-versus-ham classifier with a web-facing training and prediction workflow. Training retrieves labeled messages, splits and validates data, transforms text, trains and evaluates a model, then can publish an accepted model; prediction loads the stored model and classifies supplied text. The graph emphasizes these domain stages and the storage/model-serving layer. Some implementation files were not excerpted, so their subsystem relationships are included only where the source index or README supports them.

Main entry points: [`src/pipeline/train_pipeline.py`](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/pipeline/train_pipeline.py) (Training orchestrator), [`src/entity/artifact_entity.py`](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/entity/artifact_entity.py) (Pipeline artifacts), [`src/cloud_storage/aws_storage.py`](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/cloud_storage/aws_storage.py) (S3 storage service), [`app.py`](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/app.py) (Web application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web workflows"]
  node_app["Web application<br/>[app.py]"]
  node_prediction["Prediction pipeline"]
end

subgraph group_training["Model training"]
  node_trainflow["Training orchestrator<br/>[train_pipeline.py]"]
  node_ingest["Data ingestion<br/>[data_ingestion.py]"]
  node_validation["Data validation<br/>[data_validation.py]"]
  node_transform["Text transformation"]
  node_trainer["Model training<br/>[model_trainer.py]"]
  node_evaluation["Model evaluation"]
  node_pusher["Model publishing<br/>[model_pusher.py]"]
end

subgraph group_serving["Model serving"]
  node_estimator["S3 model adapter<br/>[s3_estimator.py]"]
  node_model["Classifier model<br/>[estimator.py]"]
end

subgraph group_shared["Shared infrastructure"]
  node_dataaccess["Mongo data access<br/>[spamham_data.py]"]
  node_artifacts["Pipeline artifacts<br/>[artifact_entity.py]"]
  node_utils["ML utilities<br/>[main_utils.py]"]
  node_storage["S3 storage service<br/>[aws_storage.py]"]
  node_awsconfig["AWS connection<br/>[aws_connection.py]"]
end

node_user(("User"))
node_mongo[("MongoDB")]
node_s3[("AWS S3")]

node_user -->|"submits requests"| node_app
node_app -->|"starts training"| node_trainflow
node_app -->|"requests predictions"| node_prediction
node_trainflow -->|"runs ingestion"| node_ingest
node_ingest -->|"exports collection"| node_dataaccess
node_dataaccess -->|"reads messages"| node_mongo
node_trainflow -->|"runs validation"| node_validation
node_trainflow -->|"runs transformation"| node_transform
node_trainflow -->|"runs training"| node_trainer
node_trainflow -->|"evaluates model"| node_evaluation
node_trainflow -->|"publishes accepted"| node_pusher
node_ingest -->|"returns paths"| node_artifacts
node_validation -.->|"returns status"| node_artifacts
node_transform -.->|"returns outputs"| node_artifacts
node_trainer -.->|"returns metrics"| node_artifacts
node_evaluation -.->|"returns decision"| node_artifacts
node_pusher -->|"uploads model"| node_storage
node_storage -->|"creates client"| node_awsconfig
node_storage -->|"reads and writes"| node_s3
node_prediction -->|"loads and predicts"| node_estimator
node_estimator -->|"loads model"| node_storage
node_estimator -->|"delegates prediction"| node_model
node_trainer -->|"tunes models"| node_utils

click node_app "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/app.py"
click node_trainflow "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/pipeline/train_pipeline.py"
click node_ingest "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/components/data_ingestion.py"
click node_dataaccess "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/data_access/spamham_data.py"
click node_validation "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/components/data_validation.py"
click node_transform "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/components/data_transformation.py"
click node_trainer "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/components/model_trainer.py"
click node_evaluation "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/components/model_evaluation.py"
click node_pusher "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/components/model_pusher.py"
click node_artifacts "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/entity/artifact_entity.py"
click node_utils "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/utils/main_utils.py"
click node_estimator "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/ml/model/s3_estimator.py"
click node_model "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/ml/model/estimator.py"
click node_storage "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/cloud_storage/aws_storage.py"
click node_awsconfig "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/configuration/aws_connection.py"
click node_prediction "https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/pipeline/prediction_pipeline.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_app,node_prediction,node_user toneBlue
class node_trainflow,node_ingest,node_validation,node_transform,node_trainer,node_evaluation,node_pusher,node_mongo,node_s3 toneAmber
class node_estimator,node_model toneMint
class node_dataaccess,node_artifacts,node_utils,node_storage,node_awsconfig toneRose
```

## Components

### Web workflows

- [Web application](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/app.py): `app.py`
- [Prediction pipeline](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/pipeline/prediction_pipeline.py): `src/pipeline/prediction_pipeline.py`

### Model training

- [Training orchestrator](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/pipeline/train_pipeline.py): `src/pipeline/train_pipeline.py`
- [Data ingestion](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/components/data_ingestion.py): `src/components/data_ingestion.py`
- [Data validation](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/components/data_validation.py): `src/components/data_validation.py`
- [Text transformation](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/components/data_transformation.py): `src/components/data_transformation.py`
- [Model training](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/components/model_trainer.py): `src/components/model_trainer.py`
- [Model evaluation](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/components/model_evaluation.py): `src/components/model_evaluation.py`
- [Model publishing](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/components/model_pusher.py): `src/components/model_pusher.py`

### Model serving

- [S3 model adapter](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/ml/model/s3_estimator.py): `src/ml/model/s3_estimator.py`
- [Classifier model](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/ml/model/estimator.py): `src/ml/model/estimator.py`

### Shared infrastructure

- [Mongo data access](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/data_access/spamham_data.py): `src/data_access/spamham_data.py`
- [Pipeline artifacts](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/entity/artifact_entity.py): `src/entity/artifact_entity.py`
- [ML utilities](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/utils/main_utils.py): `src/utils/main_utils.py`
- [S3 storage service](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/cloud_storage/aws_storage.py): `src/cloud_storage/aws_storage.py`
- [AWS connection](https://github.com/pwskills-datascienceteam/spam-detection/blob/main/src/configuration/aws_connection.py): `src/configuration/aws_connection.py`

### Other components

- **User**
- **MongoDB**
- **AWS S3**

## Connections

- User → Web application: submits requests (evidence: `README.md`)
- Web application → Training orchestrator: starts training (evidence: `README.md`)
- Web application → Prediction pipeline: requests predictions (evidence: `README.md`)
- Training orchestrator → Data ingestion: runs ingestion (evidence: `src/pipeline/train_pipeline.py`)
- Data ingestion → Mongo data access: exports collection (evidence: `src/components/data_ingestion.py`)
- Mongo data access → MongoDB: reads messages (evidence: `src/data_access/spamham_data.py`)
- Training orchestrator → Data validation: runs validation (evidence: `src/pipeline/train_pipeline.py`)
- Training orchestrator → Text transformation: runs transformation (evidence: `src/pipeline/train_pipeline.py`)
- Training orchestrator → Model training: runs training (evidence: `src/pipeline/train_pipeline.py`)
- Training orchestrator → Model evaluation: evaluates model (evidence: `src/pipeline/train_pipeline.py`)
- Training orchestrator → Model publishing: publishes accepted (evidence: `src/pipeline/train_pipeline.py`)
- Data ingestion → Pipeline artifacts: returns paths (evidence: `src/components/data_ingestion.py`)
- Data validation → Pipeline artifacts: returns status (evidence: `src/components/data_validation.py`)
- Text transformation → Pipeline artifacts: returns outputs (evidence: `src/components/data_transformation.py`)
- Model training → Pipeline artifacts: returns metrics (evidence: `src/components/model_trainer.py`)
- Model evaluation → Pipeline artifacts: returns decision (evidence: `src/components/model_evaluation.py`)
- Model publishing → S3 storage service: uploads model (evidence: `src/components/model_pusher.py`)
- S3 storage service → AWS connection: creates client (evidence: `src/cloud_storage/aws_storage.py`)
- S3 storage service → AWS S3: reads and writes (evidence: `src/cloud_storage/aws_storage.py`)
- Prediction pipeline → S3 model adapter: loads and predicts (evidence: `src/pipeline/prediction_pipeline.py`)
- S3 model adapter → S3 storage service: loads model (evidence: `src/ml/model/s3_estimator.py`)
- S3 model adapter → Classifier model: delegates prediction (evidence: `src/ml/model/s3_estimator.py`)
- Model training → ML utilities: tunes models (evidence: `src/components/model_trainer.py`)
