# sourabhr23/spam_sms_detector architecture

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

- Interactive diagram: https://gitdiagram.com/sourabhr23/spam_sms_detector
- Repository: https://github.com/sourabhr23/spam_sms_detector

## Overview

##### Project type and purpose
- This is a full-stack web application (“Spam SMS Detector”) built in Python using Flask.
- It exposes a UI for end users to submit SMS messages and returns a classification (“spam” vs. “ham”) by invoking a pre-trained NLP model.

##### File structure
Top-level files and directories:
- Procfile – For Heroku deployment, launches a Gunicorn (WSGI) server pointing at app.py.
- app.py – The Flask application entry point: defines routes, orchestrates request handling.
- preprocessing.py – Houses text‐cleanup and feature‐extraction logic (e.g., tokenization, stopword removal).
- cv-transform.pkl, mnb-model-spam-analysis.pkl – Serialized sklearn artifacts: CountVectorizer and the trained Multinomial Naive Bayes classifier.
- requirements.txt – Lists Python dependencies (Flask, NLTK, sklearn, Gunicorn, etc.).
- static/ – CSS (styles5.css), JavaScript, images for the front end.
- templates/ – Jinja2 HTML templates (layout.html, home.html, result.html).

##### README for additional insights
- Confirms use of Flask, NLTK, Python 3.6, deployment on Heroku.
- No external databases or message queues—entire state and models are in-memory and on-disk.

a. Main components
1. Client Browser (UI)
2. Heroku Load Balancer (HTTPS endpoint)
3. Gunicorn WSGI Server (Heroku Dyno)
4. Flask Application (app.py)
5. Preprocessing Module (preprocessing.py)
6. Model Artifacts (cv-transform.pkl, mnb-model-spam-analysis.pkl)
7. Templates & Static Assets (templates/, static/)

b. Relationships & data flow
1. Client → (HTTPS) → Heroku Load Balancer
2. Load Balancer → Gunicorn → Flask app route “/” or “/predict”
3. Flask route handler → invoke preprocessing module
4. Preprocessing → transform raw text via CountVectorizer (.pkl)
5. Transformed features → MultinomialNB (.pkl) → classification label
6. Flask → render result.html with label → response back to client

c. Architectural patterns & principles
- Monolithic service with MVC-style separation:
- Model (pretrained .pkl files)
- View (Jinja templates + static CSS)
- Controller (Flask route handlers in app.py)
- Twelve-factor compliance for deployment (Procfile, requirements.txt)
- External dependency injection via pre-serialized artifacts

d. Key technologies & libraries
- Flask + Jinja2 (web framework, templating)
- Gunicorn (WSGI production server)
- scikit-learn (CountVectorizer, MultinomialNB)
- NLTK (text preprocessing)
- Heroku (deployment PaaS, dyno orchestration)

##### Detail without overcomplication
- Static/templates grouped under a “Frontend assets” boundary.
- You do not need to illustrate every CSS rule—focus on architectural boundaries and data flows.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["Client Browser"]:::client

    %% Heroku PaaS
    subgraph "Heroku PaaS"
        LB["Heroku Load Balancer\n(HTTPS/443)"]:::cloud
        Dyno["Gunicorn WSGI Server"]:::service
    end

    %% Backend Components
    subgraph "Backend Service"
        FM["Flask App\n(app.py)"]:::backend
        PP["Preprocessing Module\n(preprocessing.py)"]:::backend
        CV["CountVectorizer\n(cv-transform.pkl)"]:::artifact
        MNB["MultinomialNB\n(mnb-model-spam-analysis.pkl)"]:::artifact
    end

    %% Frontend Assets
    subgraph "Frontend Assets"
        TPL["Templates\n(templates/)"]:::frontend
        STA["Static Assets\n(static/)"]:::frontend
    end

    %% Configuration & Docs
    subgraph "Configuration"
        Procfile["Procfile"]:::config
        Reqs["requirements.txt"]:::config
        Readme["README.md"]:::doc
    end

    %% Data Flows
    Client -->|HTTPS/443| LB
    LB -->|WSGI Request| Dyno
    Dyno -->|launches via Procfile| Procfile
    Dyno -->|routes to| FM
    FM -->|invoke preprocessing| PP
    PP -->|transform text| CV
    CV -->|feature vectors| MNB
    MNB -->|classification label| FM
    FM -->|render view| TPL
    FM -->|serve static files| STA
    FM -->|HTTP Response| Client

    %% Click Events
    click Procfile "https://github.com/sourabhr23/spam_sms_detector/tree/main/Procfile"
    click FM "https://github.com/sourabhr23/spam_sms_detector/blob/main/app.py"
    click PP "https://github.com/sourabhr23/spam_sms_detector/blob/main/preprocessing.py"
    click CV "https://github.com/sourabhr23/spam_sms_detector/blob/main/cv-transform.pkl"
    click MNB "https://github.com/sourabhr23/spam_sms_detector/blob/main/mnb-model-spam-analysis.pkl"
    click Reqs "https://github.com/sourabhr23/spam_sms_detector/blob/main/requirements.txt"
    click STA "https://github.com/sourabhr23/spam_sms_detector/tree/main/static/"
    click TPL "https://github.com/sourabhr23/spam_sms_detector/tree/main/templates/"
    click Readme "https://github.com/sourabhr23/spam_sms_detector/blob/main/README.md"

    %% Styles
    classDef client fill:#a3d5ff,stroke:#333,stroke-width:1px
    classDef cloud fill:#c2f0c2,stroke:#333,stroke-width:1px
    classDef service fill:#ffd966,stroke:#333,stroke-width:1px
    classDef backend fill:#f4cccc,stroke:#333,stroke-width:1px
    classDef artifact fill:#d9d2e9,stroke:#333,stroke-width:1px,stroke-dasharray:5 5
    classDef frontend fill:#fff2cc,stroke:#333,stroke-width:1px
    classDef config fill:#e6b8af,stroke:#333,stroke-width:1px
    classDef doc fill:#d9d9d9,stroke:#333,stroke-width:1px,stroke-dasharray:2 2
```
