# paryagsahni1845/tweet-sentiment-analyzer architecture

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

- Interactive diagram: https://gitdiagram.com/paryagsahni1845/tweet-sentiment-analyzer
- Repository: https://github.com/paryagsahni1845/tweet-sentiment-analyzer

## Overview

##### Project Type and Purpose
- This is a full-stack, web-based NLP application called “Tweet Sentiment Analyzer.”
- It provides a user interface for submitting tweets (or topics), invokes a backend Flask service that performs TF-IDF vectorization + Logistic Regression classification, then returns sentiment (Positive/Negative) with confidence. It also supports batch/topic aggregation.

##### File Structure Analysis
- Top-level files:
- `app.py` – Flask application entrypoint (routing, request handling, model invocation)
- `requirements.txt` – Python dependencies
- `analysis.ipynb` – Data exploration/model training notebook (offline)
- `README.md` – Project overview
- Directory:
- `templates/index.html` – Frontend HTML template (user form + result display)
- No database, so model artifacts are likely loaded from disk or memory within `app.py`.

##### Key Architectural Components
a. Frontend Layer
- Browser clients
- `index.html` served by Flask (HTML/CSS, form input for tweet or topic)
b. Backend Layer (Flask API)
- HTTP Server (Flask)
- Request routing (`/`, `/analyze`) in `app.py`
- Input validation & sanitization
c. NLP Model Layer
- TF-IDF Vectorizer (from scikit-learn & NLTK preprocessor)
- Logistic Regression classifier
- Model and vectorizer loaded into memory at startup or on first request
d. Aggregation Layer
- Topic/keyword extraction logic (batch inputs)
- Computation of aggregated sentiment scores
e. Deployment Environment
- Hosted on Render (PaaS)
- Exposed HTTPS endpoint

##### Relationships and Data Flow
- Browser → HTTP POST to Flask endpoint with tweet/topic
- Flask handler → Preprocess text via NLTK → Vectorize using TF-IDF → Classify with Logistic Regression
- Model returns label + confidence → Flask packages JSON or renders template → Response to Browser
- For batch/topic, loop through input set → aggregate per-topic metrics → return summary

##### Architectural Patterns & Principles
- Layered architecture (Presentation → API → Business/Model logic)
- Separation of concerns (UI template vs. request handling vs. ML logic)
- Stateless HTTP API (no persistent session state)
- Single-process, in-memory model for low-volume workloads

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["Web Browser"]:::frontend
        Index["index.html"]:::frontend
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        direction TB
        Flask["Python / Flask\napp.py"]:::backend
    end

    %% Model/ML Layer
    subgraph "Model Layer"
        direction TB
        Preprocess["NLTK Preprocessor"]:::model
        Vectorizer["TF-IDF Vectorizer\n(scikit-learn)"]:::model
        Classifier["Logistic Regression\n(scikit-learn)"]:::model
        Aggregator["Topic Aggregation Logic"]:::model
    end

    %% Deployment/Infra Layer
    subgraph "Deployment & Docs"
        direction TB
        Render["Render PaaS\n(HTTPS Endpoint)"]:::infra
        Notebook["analysis.ipynb"]:::infra
        Requirements["requirements.txt"]:::infra
        README["README.md"]:::infra
    end

    %% Data Flow
    Browser -->|"GET /"| Index
    Index -->|"POST /analyze"| Flask
    Flask -->|"clean_text()"| Preprocess
    Preprocess -->|"TF-IDF vectors"| Vectorizer
    Vectorizer -->|"features"| Classifier
    Classifier -->|"sentiment + confidence"| Flask
    Flask -->|"render or JSON"| Browser

    %% Aggregation Flow
    Flask -->|"batch input"| Aggregator
    Aggregator -->|"aggregated scores"| Flask

    %% Deployment Links
    Flask --> Render

    %% Click Events
    click Index "https://github.com/paryagsahni1845/tweet-sentiment-analyzer/blob/main/templates/index.html"
    click Flask "https://github.com/paryagsahni1845/tweet-sentiment-analyzer/blob/main/app.py"
    click Preprocess "https://github.com/paryagsahni1845/tweet-sentiment-analyzer/blob/main/app.py"
    click Vectorizer "https://github.com/paryagsahni1845/tweet-sentiment-analyzer/blob/main/app.py"
    click Classifier "https://github.com/paryagsahni1845/tweet-sentiment-analyzer/blob/main/app.py"
    click Aggregator "https://github.com/paryagsahni1845/tweet-sentiment-analyzer/blob/main/app.py"
    click Notebook "https://github.com/paryagsahni1845/tweet-sentiment-analyzer/blob/main/analysis.ipynb"
    click Requirements "https://github.com/paryagsahni1845/tweet-sentiment-analyzer/blob/main/requirements.txt"
    click README "https://github.com/paryagsahni1845/tweet-sentiment-analyzer/blob/main/README.md"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#0366d6,color:#000;
    classDef backend fill:#90EE90,stroke:#028a0f,color:#000;
    classDef model fill:#FFA500,stroke:#cc7000,color:#000;
    classDef infra fill:#D3D3D3,stroke:#888,color:#000;
```
