# vamshidhar-reddy/efficient-spam-detection architecture

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

- Interactive diagram: https://gitdiagram.com/vamshidhar-reddy/efficient-spam-detection
- Repository: https://github.com/vamshidhar-reddy/efficient-spam-detection

## Overview

##### Project Type and Purpose
- This is a full-stack, Flask-based web application for Machine Learning inference. The purpose is to detect “spam” values coming from smart home appliances: users upload CSV data, the backend runs a pre-trained model, and the frontend displays predictions and performance metrics.

##### File Structure Analysis
- Top Level:
- Efficient_Spam_Detection.docx (design or requirements doc)
- README.md (project description)
- requirements.txt (Python dependencies)
- SOURCE_CODE/Efficient_Spam_Detection (application root)
- Within SOURCE_CODE/Efficient_Spam_Detection:
- app.py – Flask application entry point (routes, request handling).
- model/ – Jupyter notebooks, intermediate files, spam.pkl (the pickled ML model).
- static/ – CSS, JS, images (client assets).
- templates/ – HTML templates (Jinja2).
- test_data/ – sample CSVs for local testing.
- upload.csv – possibly a sample or placeholder for user uploads.

##### Architectural Patterns and Key Components
a. Presentation Layer (Frontend)
- Templates: index.html, upload.html, prediction.html, performance.html, chart.html, preview.html, login.html
- Static Assets: CSS (style.css, styles.css), JS (main.js), images and vendor assets
- Technology: HTML5, CSS3, JavaScript
b. Application Layer (Backend)
- Flask app (app.py) handling URL routes, form submissions, file uploads
- Controllers correspond to view functions in app.py
- Business logic: loading the `spam.pkl` model, preprocessing uploaded CSV via Pandas (implicit), running predictions
c. Data Layer
- Pre-trained ML model (spam.pkl) in two locations (model folder and root for fallback)
- Test CSV data (test_data/test.csv)
- Uploads stored temporarily (upload.csv)
d. ML Layer
- Jupyter notebooks (Untitled1.ipynb) represent the model training/prototyping stage
- Final `spam.pkl` used at runtime for inference

##### Relationships and Data Flow
1. User → Frontend: interacts with HTML forms (upload data, view charts)
2. Frontend → Backend: HTTP POST with CSV file or GET for pages
3. Backend (Flask)
- Receives CSV → invokes model loader → preprocesses data → runs prediction → sends results
- Renders templates or returns JSON for charts
4. Backend → ML Model: loads pickled classifier (`spam.pkl`) into memory at startup or on demand
5. Backend → Templates: injects prediction results, metrics
6. Frontend → User: displays predictions, performance charts

##### Architectural Patterns / Principles
- MVC-like separation:
- Model: `spam.pkl` + data preprocessing
- View: Jinja2 templates + static assets
- Controller: routes in app.py
- Single Python process serving both static and dynamic content (no microservices)
- Stateless inference: each request loads or reuses the pickled model

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Frontend Layer
  subgraph "Frontend Layer"
    Browser["Browser / Client"]:::frontend
    Templates["Templates (HTML)"]:::frontend
    CSS1["style.css"]:::frontend
    CSS2["styles.css"]:::frontend
    JS["main.js"]:::frontend
    Images["Images"]:::frontend
    Vendor["Vendor Assets"]:::frontend
  end

  %% Application Layer
  subgraph "Application Layer"
    Flask["Flask Application (app.py)"]:::backend
  end

  %% ML Layer
  subgraph "ML Layer"
    ModelLoader["Model Loader & Inference Engine"]:::ml
    SpamModel["spam.pkl"]:::ml
    Notebook["Untitled1.ipynb"]:::ml
    Checkpoint["Untitled1-checkpoint.ipynb"]:::ml
  end

  %% Data Layer
  subgraph "Data Layer"
    TestCSV["test.csv"]:::data
    UploadFile["upload.csv"]:::data
  end

  %% Connections
  Browser -->|"HTTP GET/POST"| Flask
  Flask -->|"renders templates"| Templates
  Flask -->|"serves static assets"| CSS1
  Flask -->|"serves static assets"| CSS2
  Flask -->|"serves static assets"| JS
  Flask -->|"serves static assets"| Images
  Flask -->|"serves static assets"| Vendor
  Flask -->|"loads model"| ModelLoader
  ModelLoader -->|"loads pickled model"| SpamModel
  ModelLoader -->|"runs inference"| SpamModel
  ModelLoader -->|"prototyping reference"| Notebook
  Notebook -->|"checkpoint"| Checkpoint
  Flask -->|"reads test data"| TestCSV
  Flask -->|"reads/writes upload"| UploadFile
  Browser -->|"views pages & charts"| Templates

  %% Click Events
  click Templates "https://github.com/vamshidhar-reddy/efficient-spam-detection/tree/main/SOURCE_CODE/Efficient_Spam_Detection/templates"
  click CSS1 "https://github.com/vamshidhar-reddy/efficient-spam-detection/blob/main/SOURCE_CODE/Efficient_Spam_Detection/static/css/style.css"
  click CSS2 "https://github.com/vamshidhar-reddy/efficient-spam-detection/blob/main/SOURCE_CODE/Efficient_Spam_Detection/static/css/styles.css"
  click JS "https://github.com/vamshidhar-reddy/efficient-spam-detection/blob/main/SOURCE_CODE/Efficient_Spam_Detection/static/js/main.js"
  click Images "https://github.com/vamshidhar-reddy/efficient-spam-detection/tree/main/SOURCE_CODE/Efficient_Spam_Detection/static/img"
  click Vendor "https://github.com/vamshidhar-reddy/efficient-spam-detection/tree/main/SOURCE_CODE/Efficient_Spam_Detection/static/vendor"
  click Flask "https://github.com/vamshidhar-reddy/efficient-spam-detection/blob/main/SOURCE_CODE/Efficient_Spam_Detection/app.py"
  click SpamModel "https://github.com/vamshidhar-reddy/efficient-spam-detection/blob/main/SOURCE_CODE/Efficient_Spam_Detection/model/spam.pkl"
  click SpamModel "https://github.com/vamshidhar-reddy/efficient-spam-detection/blob/main/SOURCE_CODE/Efficient_Spam_Detection/spam.pkl"
  click TestCSV "https://github.com/vamshidhar-reddy/efficient-spam-detection/blob/main/SOURCE_CODE/Efficient_Spam_Detection/test_data/test.csv"
  click UploadFile "https://github.com/vamshidhar-reddy/efficient-spam-detection/blob/main/SOURCE_CODE/Efficient_Spam_Detection/upload.csv"
  click Notebook "https://github.com/vamshidhar-reddy/efficient-spam-detection/blob/main/SOURCE_CODE/Efficient_Spam_Detection/model/Untitled1.ipynb"
  click Checkpoint "https://github.com/vamshidhar-reddy/efficient-spam-detection/blob/main/SOURCE_CODE/Efficient_Spam_Detection/model/.ipynb_checkpoints/Untitled1-checkpoint.ipynb"

  %% Styles
  classDef frontend fill:#D0E6FF,stroke:#333,stroke-width:1px
  classDef backend fill:#D0FFD8,stroke:#333,stroke-width:1px
  classDef ml fill:#FFE6B0,stroke:#333,stroke-width:1px
  classDef data fill:#F0F0F0,stroke:#333,stroke-width:1px
```
