# hanfia-sattar/sentiment-analysis architecture

> Architecture diagram of the GitHub repository hanfia-sattar/sentiment-analysis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hanfia-sattar/sentiment-analysis
- Repository: https://github.com/hanfia-sattar/sentiment-analysis

## Overview

This is a small Reddit-comment sentiment analysis app. A user submits a Reddit post URL in the Streamlit interface; the analysis function fetches comments, preprocesses text, classifies sentiment, writes an analyzed CSV, and returns a dataframe for display, charts, and download. A separate scraper script fetches comments to a raw CSV. The README documents bar and pie visualizations; sampled source shows those are built in the app. Unsampled files and CSV data flow beyond the shown writes are not inferred.

Main entry points: [`reddit_sentiment_analysis.py`](https://github.com/hanfia-sattar/sentiment-analysis/blob/master/reddit_sentiment_analysis.py) (Analysis workflow), [`streamlit_app.py`](https://github.com/hanfia-sattar/sentiment-analysis/blob/master/streamlit_app.py) (Streamlit app), [`scraper.py`](https://github.com/hanfia-sattar/sentiment-analysis/blob/master/scraper.py) (Standalone scraper)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Web interface"]
  node_app["Streamlit app<br/>[streamlit_app.py]"]
end

subgraph group_analysis["Comment analysis"]
  node_analyze["Analysis workflow"]
  node_preprocess["Text preprocessing"]
  node_sentiment["Sentiment classification"]
end

subgraph group_collection["Data collection"]
  node_fetch["Comment retrieval"]
  node_rawscraper["Standalone scraper<br/>[scraper.py]"]
end

subgraph group_outputs["Results and exports"]
  node_rawcsv["Raw comments CSV<br/>[scraper.py]"]
  node_analyzedcsv["Analyzed comments CSV"]
  node_results["Results dataframe"]
  node_bar["Sentiment bar chart<br/>[streamlit_app.py]"]
  node_pie["Sentiment pie chart<br/>[streamlit_app.py]"]
end

node_user(("Analyst"))
node_reddit["Reddit API"]
node_textblob["TextBlob"]
node_plotly["Plotly"]

node_user -->|"enters URL"| node_app
node_app -->|"requests analysis"| node_analyze
node_analyze -->|"fetches comments"| node_fetch
node_fetch -->|"requests comments"| node_reddit
node_analyze -->|"preprocesses text"| node_preprocess
node_analyze -->|"classifies text"| node_sentiment
node_sentiment -->|"computes polarity"| node_textblob
node_analyze -->|"writes CSV"| node_analyzedcsv
node_analyze -->|"returns dataframe"| node_results
node_results -->|"displays results"| node_app
node_app -->|"builds chart"| node_bar
node_app -->|"builds chart"| node_pie
node_bar -->|"creates plot"| node_plotly
node_pie -->|"creates plot"| node_plotly
node_app -->|"exports CSV"| node_results
node_rawscraper -->|"requests comments"| node_reddit
node_rawscraper -->|"writes CSV"| node_rawcsv

click node_app "https://github.com/hanfia-sattar/sentiment-analysis/blob/master/streamlit_app.py"
click node_analyze "https://github.com/hanfia-sattar/sentiment-analysis/blob/master/reddit_sentiment_analysis.py"
click node_fetch "https://github.com/hanfia-sattar/sentiment-analysis/blob/master/reddit_sentiment_analysis.py"
click node_preprocess "https://github.com/hanfia-sattar/sentiment-analysis/blob/master/reddit_sentiment_analysis.py"
click node_sentiment "https://github.com/hanfia-sattar/sentiment-analysis/blob/master/reddit_sentiment_analysis.py"
click node_rawscraper "https://github.com/hanfia-sattar/sentiment-analysis/blob/master/scraper.py"
click node_rawcsv "https://github.com/hanfia-sattar/sentiment-analysis/blob/master/scraper.py"
click node_analyzedcsv "https://github.com/hanfia-sattar/sentiment-analysis/blob/master/reddit_sentiment_analysis.py"
click node_results "https://github.com/hanfia-sattar/sentiment-analysis/blob/master/reddit_sentiment_analysis.py"
click node_bar "https://github.com/hanfia-sattar/sentiment-analysis/blob/master/streamlit_app.py"
click node_pie "https://github.com/hanfia-sattar/sentiment-analysis/blob/master/streamlit_app.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app toneBlue
class node_analyze,node_preprocess,node_sentiment toneAmber
class node_fetch,node_rawscraper,node_reddit toneMint
class node_rawcsv,node_analyzedcsv,node_results,node_bar,node_pie toneRose
class node_user,node_textblob,node_plotly toneIndigo
```

## Components

### Web interface

- [Streamlit app](https://github.com/hanfia-sattar/sentiment-analysis/blob/master/streamlit_app.py): `streamlit_app.py`

### Comment analysis

- [Analysis workflow](https://github.com/hanfia-sattar/sentiment-analysis/blob/master/reddit_sentiment_analysis.py): `reddit_sentiment_analysis.py`
- [Text preprocessing](https://github.com/hanfia-sattar/sentiment-analysis/blob/master/reddit_sentiment_analysis.py): `reddit_sentiment_analysis.py`
- [Sentiment classification](https://github.com/hanfia-sattar/sentiment-analysis/blob/master/reddit_sentiment_analysis.py): `reddit_sentiment_analysis.py`

### Data collection

- [Comment retrieval](https://github.com/hanfia-sattar/sentiment-analysis/blob/master/reddit_sentiment_analysis.py): `reddit_sentiment_analysis.py`
- [Standalone scraper](https://github.com/hanfia-sattar/sentiment-analysis/blob/master/scraper.py): `scraper.py`

### Results and exports

- [Raw comments CSV](https://github.com/hanfia-sattar/sentiment-analysis/blob/master/scraper.py): `scraper.py`
- [Analyzed comments CSV](https://github.com/hanfia-sattar/sentiment-analysis/blob/master/reddit_sentiment_analysis.py): `reddit_sentiment_analysis.py`
- [Results dataframe](https://github.com/hanfia-sattar/sentiment-analysis/blob/master/reddit_sentiment_analysis.py): `reddit_sentiment_analysis.py`
- [Sentiment bar chart](https://github.com/hanfia-sattar/sentiment-analysis/blob/master/streamlit_app.py): `streamlit_app.py`
- [Sentiment pie chart](https://github.com/hanfia-sattar/sentiment-analysis/blob/master/streamlit_app.py): `streamlit_app.py`

### Other components

- **Analyst**
- **Reddit API**
- **TextBlob**
- **Plotly**

## Connections

- Analyst → Streamlit app: enters URL (evidence: `streamlit_app.py`)
- Streamlit app → Analysis workflow: requests analysis (evidence: `streamlit_app.py`)
- Analysis workflow → Comment retrieval: fetches comments (evidence: `reddit_sentiment_analysis.py`)
- Comment retrieval → Reddit API: requests comments (evidence: `reddit_sentiment_analysis.py`)
- Analysis workflow → Text preprocessing: preprocesses text (evidence: `reddit_sentiment_analysis.py`)
- Analysis workflow → Sentiment classification: classifies text (evidence: `reddit_sentiment_analysis.py`)
- Sentiment classification → TextBlob: computes polarity (evidence: `reddit_sentiment_analysis.py`)
- Analysis workflow → Analyzed comments CSV: writes CSV (evidence: `reddit_sentiment_analysis.py`)
- Analysis workflow → Results dataframe: returns dataframe (evidence: `reddit_sentiment_analysis.py`)
- Results dataframe → Streamlit app: displays results (evidence: `streamlit_app.py`)
- Streamlit app → Sentiment bar chart: builds chart (evidence: `streamlit_app.py`)
- Streamlit app → Sentiment pie chart: builds chart (evidence: `streamlit_app.py`)
- Sentiment bar chart → Plotly: creates plot (evidence: `streamlit_app.py`)
- Sentiment pie chart → Plotly: creates plot (evidence: `streamlit_app.py`)
- Streamlit app → Results dataframe: exports CSV (evidence: `streamlit_app.py`)
- Standalone scraper → Reddit API: requests comments (evidence: `scraper.py`)
- Standalone scraper → Raw comments CSV: writes CSV (evidence: `scraper.py`)
