# kaffy-qaiser/sentiment-analysis-stock-predictor architecture

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

- Interactive diagram: https://gitdiagram.com/kaffy-qaiser/sentiment-analysis-stock-predictor
- Repository: https://github.com/kaffy-qaiser/sentiment-analysis-stock-predictor

## Overview

#### Purpose and entry point
This is a Python Dash dashboard for comparing actual stock prices with sentiment-informed LSTM predictions. The executable entry point is `app.py`; users run it locally and interact through the Dash server at port 8050.

#### Application orchestration
`app.py` is the central application boundary: it hosts the Dash layout, user ticker submission flow, data retrieval, sentiment processing, model execution, and Plotly visualization updates. There is no separate package structure, API service, worker, or persistence layer in the repository tree.

#### Sentiment data pipeline
The dashboard combines social/news text sentiment with market data. Reddit access is intended through PRAW and r/wallstreetbets; news is intended through News API. NLP dependencies include NLTK and VADER sentiment scoring. A bundled dataset, `wsb_posts_sentiment.csv`, provides local WallStreetBets sentiment data and is the only repository-managed data artifact.

#### Market-data integration
Stock-history retrieval is delegated to Yahoo Finance through `yfinance`. Ticker input drives the external market-data request and supplies the actual-price series used for comparison against predictions. This creates an external-service boundary where availability, ticker validity, and returned history affect dashboard results.

#### Prediction stage
The stated forecasting mechanism is a PyTorch LSTM model that uses sentiment-derived inputs to predict price trends. Numerical preparation and feature handling rely on `pandas`, `numpy`, and scikit-learn. Model training/inference logic, if implemented, resides in the monolithic `app.py`; no serialized model artifact or dedicated training pipeline is present in the tree.

#### Presentation layer
Dash provides the interactive UI and callback runtime, while Plotly renders actual-versus-predicted stock-price charts and sentiment-trend charts. The browser communicates only with the local Dash application; upstream Reddit, News API, and Yahoo Finance calls occur server-side in Python.

#### Runtime and configuration boundaries
The runtime is Python 3.8+ with dependencies declared in `requirements.txt`. Credentials are expected from environment variables for Reddit and News API, rather than committed configuration. Required external resources include Reddit API, News API, Yahoo Finance, and downloadable NLTK corpora/lexicons. Key paths: `app.py`, `requirements.txt`, `wsb_posts_sentiment.csv`.

Main entry points: [`app.py`](https://github.com/kaffy-qaiser/sentiment-analysis-stock-predictor/blob/main/app.py) (Dash application), [`requirements.txt`](https://github.com/kaffy-qaiser/sentiment-analysis-stock-predictor/blob/main/requirements.txt) (Runtime dependencies), [`wsb_posts_sentiment.csv`](https://github.com/kaffy-qaiser/sentiment-analysis-stock-predictor/blob/main/wsb_posts_sentiment.csv) (WSB sentiment dataset)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dashboard["Local Dashboard"]
  node_app["Dash application<br/>Python entry point<br/>[app.py]"]
  node_requirements["Runtime dependencies<br/>Python requirements<br/>[requirements.txt]"]
  node_env["Environment credentials<br/>runtime configuration"]
  node_charts["Plotly charts<br/>presentation"]
end

subgraph group_inputs["Data Sources"]
  node_csv[("WSB sentiment dataset<br/>bundled CSV")]
  node_reddit{{"Reddit r/wallstreetbets<br/>external API"}}
  node_news{{"News API<br/>external API"}}
  node_yahoo{{"Yahoo Finance<br/>external market data"}}
end

subgraph group_analytics["Analytics Pipeline"]
  node_text["Sentiment text inputs<br/>social and news text"]
  node_sentiment["VADER sentiment scoring<br/>NLP stage"]
  node_features["Feature preparation<br/>pandas/NumPy/scikit-learn"]
  node_lstm["PyTorch LSTM<br/>forecast model"]
  node_prices["Actual price history<br/>market series"]
end

node_browser(("User browser<br/>client"))

node_browser -->|"ticker input and UI events"| node_app
node_app -->|"requests ticker history"| node_yahoo
node_yahoo -->|"returns market history"| node_prices
node_app -->|"fetches social posts"| node_reddit
node_app -->|"fetches news text"| node_news
node_csv -->|"local sentiment records"| node_text
node_reddit -->|"post text"| node_text
node_news -->|"article text"| node_text
node_text -->|"score text"| node_sentiment
node_sentiment -->|"sentiment features"| node_features
node_features -->|"model inputs"| node_lstm
node_lstm -->|"predicted trends"| node_charts
node_prices -->|"actual prices"| node_charts
node_app -->|"updates callback output"| node_charts
node_charts -->|"interactive visualizations"| node_browser
node_env -.->|"credentials"| node_app
node_requirements -.->|"runtime packages"| node_app

click node_app "https://github.com/kaffy-qaiser/sentiment-analysis-stock-predictor/blob/main/app.py"
click node_requirements "https://github.com/kaffy-qaiser/sentiment-analysis-stock-predictor/blob/main/requirements.txt"
click node_csv "https://github.com/kaffy-qaiser/sentiment-analysis-stock-predictor/blob/main/wsb_posts_sentiment.csv"

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,node_requirements,node_env,node_charts toneBlue
class node_csv,node_reddit,node_news,node_yahoo toneAmber
class node_text,node_sentiment,node_features,node_lstm,node_prices toneMint
class node_browser toneNeutral
```

## Components

### Local Dashboard

Single-process Python Dash application.

- [Dash application](https://github.com/kaffy-qaiser/sentiment-analysis-stock-predictor/blob/main/app.py): Python entry point · Hosts UI, callbacks, retrieval, processing, inference, and chart updates. · `app.py`
- [Runtime dependencies](https://github.com/kaffy-qaiser/sentiment-analysis-stock-predictor/blob/main/requirements.txt): Python requirements · Declares Python 3.8+ package dependencies. · `requirements.txt`
- **Environment credentials**: runtime configuration · Provides Reddit and News API credentials.
- **Plotly charts**: presentation · Renders actual-versus-predicted prices and sentiment trends.

### Data Sources

Local and external inputs used server-side.

- [WSB sentiment dataset](https://github.com/kaffy-qaiser/sentiment-analysis-stock-predictor/blob/main/wsb_posts_sentiment.csv): bundled CSV · Repository-managed WallStreetBets sentiment data. · `wsb_posts_sentiment.csv`
- **Reddit r/wallstreetbets**: external API · Social-text source accessed through PRAW.
- **News API**: external API · News-text source.
- **Yahoo Finance**: external market data · Returns ticker-driven stock-price history through yfinance.

### Analytics Pipeline

Sentiment processing and forecast preparation inside the app.

- **Sentiment text inputs**: social and news text
- **VADER sentiment scoring**: NLP stage · Scores text using NLTK/VADER resources.
- **Feature preparation**: pandas/NumPy/scikit-learn · Prepares sentiment-derived numerical model inputs.
- **PyTorch LSTM**: forecast model · Predicts price trends; training and inference are implemented in the app.
- **Actual price history**: market series · Ticker-specific series used as the actual comparison baseline.

### Other components

- **User browser**: client · Interacts with the local dashboard on port 8050.

## Connections

- User browser → Dash application: ticker input and UI events
- Dash application → Yahoo Finance: requests ticker history
- Yahoo Finance → Actual price history: returns market history
- Dash application → Reddit r/wallstreetbets: fetches social posts
- Dash application → News API: fetches news text
- WSB sentiment dataset → Sentiment text inputs: local sentiment records
- Reddit r/wallstreetbets → Sentiment text inputs: post text
- News API → Sentiment text inputs: article text
- Sentiment text inputs → VADER sentiment scoring: score text
- VADER sentiment scoring → Feature preparation: sentiment features
- Feature preparation → PyTorch LSTM: model inputs
- PyTorch LSTM → Plotly charts: predicted trends
- Actual price history → Plotly charts: actual prices
- Dash application → Plotly charts: updates callback output
- Plotly charts → User browser: interactive visualizations
- Environment credentials → Dash application: credentials
- Runtime dependencies → Dash application: runtime packages
