# vinayhr01/twitter-sentiment-analysis-web-application-project architecture

> Architecture diagram of the GitHub repository vinayhr01/twitter-sentiment-analysis-web-application-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vinayhr01/twitter-sentiment-analysis-web-application-project
- Repository: https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project

## Overview

##### Project Type and Purpose
- This is a full-stack web application built with the Django framework that performs real-time Twitter sentiment analysis focused on economic consequences of COVID-19.
- The README explains that three ML models (Naive Bayes, SVM, Logistic Regression) are trained on a historical dataset (finalD.csv), compared for accuracy, and the best (SVM) is used in production alongside the VADER social-media sentiment library.
- Users land on a web interface, submit or trigger live tweet fetches, and view classification results.

##### File Structure
- Top Level
- manage.py, requirements.txt → Django project entry, dependencies
- finalD.csv, compare.csv, results/... → training data and outputs
- sentiment_analysis/ → Django project settings & WSGI
- sentiment_home/ → “home” Django app for landing pages
- sentiment/ → core Django app handling forms, views, ML code
- “sentiment” app
- sentiment_analysis_code.py → offline training and model-loading logic
- tweepy_sentiment.py → real-time tweet fetch from Twitter API
- views.py, forms.py, models.py → request handling, form definitions, and any persisted models
- templates/ & static/ → HTML pages and assets for sentiment features
- “sentiment_home” app
- views.py, templates/ & static/ → home page UI
- Configuration files
- sentiment_analysis/settings.py → database & app registration
- urls.py in each app plus root → URL routing

##### README for Additional Insights
- Confirms Python/Django stack, NLTK downloads for preprocessing, CSV-based training pipeline, real-time classification via Tweepy + SVM + VADER.
- No mention of heavy external infrastructure—uses Django runserver and SQLite by default.

a. Main Components
- Client Browser (User Interface)
- Django Web Server
‑ URL Dispatcher
‑ Views & Forms
‑ Template Renderer
‑ Static File Server
- Database (SQLite/MySQL/PostgreSQL)
- Machine Learning Engine
‑ Offline Trainer (NaiveBayes, SVM, LogisticRegression)
‑ Runtime Classifier (SVM model + VADER)
- External Service: Twitter API (via Tweepy)
- Auxiliary: NLTK data store (punkt, wordnet, tagger)
b. Relationships & Data Flow
1. Browser → HTTP request → Django URL Dispatcher
2. URL → sentiment.views or sentiment_home.views
3. If classification requested:
‑ sentiment.views invokes tweepy_sentiment.py to fetch tweets
‑ Preprocess via sentiment_analysis_code.py (tokenize, vectorize)
‑ Pass text to SVM classifier & VADER library
‑ Receive sentiment label
4. View renders sentiment HTML template with results → Response to Browser
5. Optionally, persistence: view writes query & result to Database via Django models
c. Architectural Patterns & Principles
- Monolithic MVC (Model-View-Controller) via Django
- Separation of concerns:
- sentiment_home app for static landing pages
- sentiment app for dynamic ML-driven features
- Reuse of third-party libraries (NLTK, Scikit-Learn, VADER, Tweepy)
d. Key Technologies/Frameworks
- Backend: Python 3.x, Django
- ML: Scikit-Learn, NLTK, VADER
- External API: Tweepy (Twitter)
- Frontend: HTML5, CSS3, Bootstrap, custom JS
- Data store: SQLite (default) or any Django-supported RDBMS

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["Client Browser"]:::frontend

    subgraph "Django Monolith"
        subgraph "Configuration"
            Entry["manage.py"]:::backend
            Req["requirements.txt"]:::backend
            Settings["settings.py"]:::backend
            URLsRoot["urls.py"]:::backend
            WSGI["wsgi.py"]:::backend
            StaticAdmin["Admin Static Files"]:::frontend
            GlobalStatic["Global Static Files"]:::frontend
        end
        subgraph "Apps"
            subgraph "Home App"
                HAApps["apps.py"]:::backend
                HAUrls["urls.py"]:::backend
                HAViews["views.py"]:::backend
                TemplateHome["home.html"]:::frontend
                StaticHome["static/home/"]:::frontend
            end
            subgraph "Sentiment App"
                SApps["apps.py"]:::backend
                SUrls["urls.py"]:::backend
                SViews["views.py"]:::backend
                SForms["forms.py"]:::backend
                SModels["models.py"]:::backend
                STests["tests.py"]:::backend
                TemplatesSentiment["templates/home/"]:::frontend
                StaticSentiment["static/home/"]:::frontend
                Trainer["sentiment_analysis_code.py"]:::ml
                Tweepy["tweepy_sentiment.py"]:::external
            end
        end
        DB["Database (SQLite)"]:::db
        NLTK["NLTK Data Store"]:::db
    end

    External["Twitter API"]:::external

    OfflineDataset["finalD.csv"]:::backend
    CompareCSV["compare.csv"]:::backend
    ResultsAcc["resAcc.csv"]:::backend
    ResultsML["resML.csv"]:::backend
    ResultsVader["resVader.csv"]:::backend

    %% Data Flows
    Browser -->|"HTTP GET"| URLsRoot
    URLsRoot -->|route to home| HAViews
    URLsRoot -->|route to sentiment| SViews
    SViews -->|"fetch_tweets()"| Tweepy
    Tweepy -->|API call| External
    External -->|tweets JSON| Tweepy
    Tweepy -->|tweets data| SViews
    SViews -->|"preprocess()"| Trainer
    Trainer -->|"classify_text()"| Trainer
    Trainer -->|uses NLTK data| NLTK
    Trainer -->|output label| SViews
    SViews -->|persist query & result| SModels
    SViews -->|render template| TemplatesSentiment
    SViews -->|HTTP Response| Browser

    Trainer -->|"offline train"| OfflineDataset
    Trainer -->|"generate"| CompareCSV
    CompareCSV -->|results| ResultsAcc
    CompareCSV -->|results| ResultsML
    CompareCSV -->|results| ResultsVader

    %% Click Events
    click Entry "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/manage.py"
    click Req "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/requirements.txt"
    click Settings "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/sentiment_analysis/settings.py"
    click URLsRoot "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/sentiment_analysis/urls.py"
    click WSGI "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/sentiment_analysis/wsgi.py"
    click StaticAdmin "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/tree/master/sentiment_analysis/static/admin/"
    click GlobalStatic "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/tree/master/sentiment_analysis/static/"
    click HAApps "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/sentiment_home/apps.py"
    click HAUrls "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/sentiment_home/urls.py"
    click HAViews "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/sentiment_home/views.py"
    click TemplateHome "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/sentiment_home/templates/home/home.html"
    click StaticHome "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/tree/master/sentiment_home/static/home/"
    click SApps "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/sentiment/apps.py"
    click SUrls "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/sentiment/urls.py"
    click SViews "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/sentiment/views.py"
    click SForms "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/sentiment/forms.py"
    click SModels "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/sentiment/models.py"
    click STests "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/sentiment/tests.py"
    click TemplatesSentiment "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/tree/master/sentiment/templates/home/"
    click StaticSentiment "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/tree/master/sentiment/static/home/"
    click Trainer "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/sentiment/sentiment_analysis_code.py"
    click Tweepy "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/sentiment/tweepy_sentiment.py"
    click OfflineDataset "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/finalD.csv"
    click CompareCSV "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/compare.csv"
    click ResultsAcc "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/results/resAcc.csv"
    click ResultsML "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/results/resML.csv"
    click ResultsVader "https://github.com/vinayhr01/twitter-sentiment-analysis-web-application-project/blob/master/results/resVader.csv"

    classDef frontend fill:#E8F1F2,stroke:#2B7A78,color:#17252A
    classDef backend fill:#F6F7EB,stroke:#3A5A40,color:#1B263B
    classDef ml fill:#FFF4E6,stroke:#F08A5D,color:#662E1C
    classDef db fill:#E0FBFC,stroke:#1B4965,color:#0F4C5C
    classDef external fill:#FEF9C7,stroke:#F4D35E,color:#F48484
```
