# mdayanabbas/reddit_sentiment_analysis architecture

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

- Interactive diagram: https://gitdiagram.com/mdayanabbas/reddit_sentiment_analysis
- Repository: https://github.com/mdayanabbas/reddit_sentiment_analysis

## Overview

##### Project type and purpose
- This is a full-stack, single-page web application (a monolith) for sentiment analysis of Reddit comments.
- The README indicates it’s built with Python/Flask on the backend, uses NLP/ML libraries, queries the Reddit API, and renders interactive visualizations to the user.

##### File structure
- Top-level files:
- Dockerfile – defines a container image
- requirements.txt – Python dependencies
- app.py – the entire Flask app, including routes, API calls, ML/NLP logic, and rendering
- README.md – documentation
- No separate frontend code or database directories; everything lives in the monolithic app.py.
- Environment variables (CLIENT_ID, CLIENT_SECRET, USER_AGENT) configure access to the Reddit API.
- No persistent database – data is fetched on demand and processed in memory.

##### README for additional insights
- Uses PRAW (Reddit API client) or direct HTTP calls for comment fetching.
- NLP pipeline built with NLTK and scikit-learn: tokenization, feature extraction, classification.
- Visualization with Matplotlib/Seaborn, likely rendered as images or embedded plots.
- Deployed via Docker (containerization) and hosted on Render.

a. Main components:
- User Browser (UI)
- Flask Web Server (app.py inside a Docker container)
- Reddit API (external service)
- NLP/ML Module (NLTK + scikit-learn pipeline)
- Visualization Module (Matplotlib/Seaborn)
- Environment (Docker container + environment variables)
b. Relationships and interactions:
1. User sends an HTTP request (entering a post URL or subreddit) to the Flask server.
2. Flask handler reads environment variables and invokes the Reddit API to fetch comments.
3. Fetched data is passed to the NLP/ML module for sentiment classification.
4. Classification results are handed to the visualization module to generate charts.
5. Flask renders an HTML response embedding the plots and metrics and sends it back to the user.
c. Architectural patterns/design principles:
- Monolithic service – single deployable unit.
- Layered structure within app.py:
– API Client Layer
– Data Processing/NLP Layer
– Visualization Layer
– Presentation Layer
- Configuration via environment variables for secrets and API credentials.
- Containerization for environment consistency and deployment simplicity.
d. Key technologies:
- Flask – request routing and templating
- PRAW or requests – Reddit API integration
- NLTK + scikit-learn – NLP and model inference
- Matplotlib/Seaborn – static or interactive charts
- Docker – container image and runtime

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Entities
    Browser["User Browser"]:::external
    RedditApi["Reddit API"]:::external

    %% Container Boundary
    subgraph "Container (Docker & Render)"
        DockerfileNode["Dockerfile"]:::config
        Env["Environment Variables\nCLIENT_ID, CLIENT_SECRET, USER_AGENT"]:::config
        Requirements["requirements.txt"]:::config
        Readme["README.md"]:::config

        Flask["Flask Web Server\napp.py"]:::webserver

        subgraph "app.py Modules"
            ApiClient["Reddit API Client Layer"]:::compute
            NLP["NLP/ML Module\n(NLTK + scikit-learn)"]:::compute
            Visual["Visualization Module\n(Matplotlib/Seaborn)"]:::compute
        end
    end

    %% Data Flow
    Browser -->|"HTTP Request"| Flask
    Flask -->|"fetch_comments()"| ApiClient
    ApiClient -->|"API Call"| RedditApi
    RedditApi -->|"JSON Comments"| ApiClient
    ApiClient -->|"raw_data"| NLP
    NLP -->|"sentiment_results"| Visual
    Visual -->|"plots/images"| Flask
    Flask -->|"HTML Response"| Browser

    %% Dependencies
    DockerfileNode --> Flask
    Env --> Flask
    Requirements --> Flask
    Readme -.-> Flask

    %% Click Events
    click Flask "https://github.com/mdayanabbas/reddit_sentiment_analysis/blob/main/app.py"
    click ApiClient "https://github.com/mdayanabbas/reddit_sentiment_analysis/blob/main/app.py"
    click NLP "https://github.com/mdayanabbas/reddit_sentiment_analysis/blob/main/app.py"
    click Visual "https://github.com/mdayanabbas/reddit_sentiment_analysis/blob/main/app.py"
    click DockerfileNode "https://github.com/mdayanabbas/reddit_sentiment_analysis/tree/main/Dockerfile"
    click Requirements "https://github.com/mdayanabbas/reddit_sentiment_analysis/blob/main/requirements.txt"
    click Readme "https://github.com/mdayanabbas/reddit_sentiment_analysis/blob/main/README.md"

    %% Styles
    classDef external fill:#cce5ff,stroke:#0066cc,color:#000;
    classDef compute fill:#d4edda,stroke:#3c763d,color:#000;
    classDef webserver fill:#fff3cd,stroke:#856404,color:#000;
    classDef config fill:#e2e3e5,stroke:#6c757d,color:#000;
    classDef boundary fill:#f8f9fa,stroke:#343a40,color:#000,stroke-dasharray: 5 5;
```
