# tiffintech/stock architecture

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

- Interactive diagram: https://gitdiagram.com/tiffintech/stock
- Repository: https://github.com/tiffintech/stock

## Overview

##### Project Type and Purpose
- This is a hybrid data-analysis tool with:
- A small web frontend (Flask + Jinja template)
- A core pipeline for fetching data, analyzing sentiment, and correlating with stock prices
- An optional CLI entry point (stock_sentiment.py) for running the pipeline directly

##### File Structure
Top-level:
- README.md, requirements.txt, .env (runtime config)
- stock_sentiment.py (CLI launcher)
- src/
– app.py (Flask server / controller)
– models/sentiment_analyzer.py (NLP model code)
– reddit_sentiment.py (Reddit fetcher module)
– stock_data.py (Stock price fetcher module)
– visualization/plotter.py (Graph-generation module)
– templates/index.html (UI view)

##### Pull Insights from the README
- External dependencies: Reddit API, stock-price API
- Core features: data fetch → NLP sentiment analysis → correlation & trend prediction → output (plots/JSON)

##### Main Components & Their Relationships
A. Frontend (only if running as a web app)
- index.html
- Served by Flask via app.py
B. Backend / Controller
- src/app.py – defines HTTP routes, triggers pipeline
- stock_sentiment.py – alternative CLI “main”
C. Data-Fetch Modules
- src/reddit_sentiment.py → connects to Reddit API
- src/stock_data.py → fetches stock prices from external API
D. Processing / Business Logic
- src/models/sentiment_analyzer.py → sentiment scoring
- Correlator (inside stock_sentiment.py or app.py) → aligns sentiment vs. price
E. Visualization
- src/visualization/plotter.py → generates charts (matplotlib, plotly, etc.)
F. External Services
- Reddit API
- Stock-price API

##### Architectural Patterns & Design Principles
- MVC-style layering for the web path:
- View → templates/index.html
- Controller → src/app.py
- Model → src/models/… + data-fetch modules
- Modular pipeline: each step is a separate module
- Single responsibility: fetchers, analyzer, plotter all encapsulated

– Reddit Fetcher
– Stock-Data Fetcher
– Browser (renders image/data)
– CLI (prints summary / saves image)

##### Detail
- Your environment loader (.env) in a small note near the fetchers

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "User Interaction"
        Browser["Browser"]:::ui
        CLI["CLI Console"]:::ui
    end

    Browser -->|"/"| Frontend["index.html"]:::ui
    CLI -->|"run pipeline"| CLI_Launcher["stock_sentiment.py"]:::controller

    Frontend -->|"HTTP Request"| WebController["app.py (Flask Controller)"]:::controller
    CLI_Launcher -->|"invoke pipeline"| CLI_Launcher

    subgraph "Data Fetch Modules"
        RedditFetcher["reddit_sentiment.py"]:::fetch
        StockFetcher["stock_data.py"]:::fetch
    end

    WebController -->|"trigger fetch"| RedditFetcher
    WebController -->|"trigger fetch"| StockFetcher
    CLI_Launcher -->|"trigger fetch"| RedditFetcher
    CLI_Launcher -->|"trigger fetch"| StockFetcher

    RedditFetcher -->|"GET posts+comments"| SentimentAnalyzer["sentiment_analyzer.py"]:::business
    StockFetcher -->|"Stock prices JSON"| SentimentAnalyzer

    SentimentAnalyzer -->|"Sentiment scores"| Correlator["Correlator Logic"]:::business
    Correlator -->|"Aligned data"| Plotter["plotter.py"]:::viz
    Plotter -->|"PNG graph/JSON"| Browser
    Plotter -->|"PNG graph/JSON"| CLI

    subgraph "External Services"
        RedditAPI["Reddit API"]:::external
        StockAPI["Stock-price API"]:::external
    end

    RedditAPI -->|"data"| RedditFetcher
    StockAPI -->|"data"| StockFetcher

    subgraph "Config & Dependencies"
        Env[".env"]
        Requirements["requirements.txt"]
        Readme["README.md"]
    end

    classDef ui fill:#ADD8E6,stroke:#000
    classDef controller fill:#87CEFA,stroke:#000
    classDef fetch fill:#90EE90,stroke:#000
    classDef business fill:#FFA500,stroke:#000
    classDef viz fill:#DDA0DD,stroke:#000
    classDef external fill:#D3D3D3,stroke:#000
    classDef config fill:#F0F0F0,stroke:#000

    click Frontend "https://github.com/tiffintech/stock/blob/main/src/templates/index.html"
    click WebController "https://github.com/tiffintech/stock/blob/main/src/app.py"
    click CLI_Launcher "https://github.com/tiffintech/stock/blob/main/stock_sentiment.py"
    click RedditFetcher "https://github.com/tiffintech/stock/blob/main/src/reddit_sentiment.py"
    click StockFetcher "https://github.com/tiffintech/stock/blob/main/src/stock_data.py"
    click SentimentAnalyzer "https://github.com/tiffintech/stock/blob/main/src/models/sentiment_analyzer.py"
    click Plotter "https://github.com/tiffintech/stock/blob/main/src/visualization/plotter.py"
    click Requirements "https://github.com/tiffintech/stock/blob/main/requirements.txt"
    click Readme "https://github.com/tiffintech/stock/blob/main/README.md"
```
