# sreeragsreekanth/stockprice-predictor architecture

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

- Interactive diagram: https://gitdiagram.com/sreeragsreekanth/stockprice-predictor
- Repository: https://github.com/sreeragsreekanth/stockprice-predictor

## Overview

##### Project type and purpose
- This is a full-stack, local web application built with Flask (Python) that allows users to enter a stock symbol or company name, fetches historical price data in real-time from Yahoo Finance, runs an LSTM neural-network model to predict future prices, and then visualizes both historical and predicted data in the browser.

##### File structure
- Top level:
- app.py – Flask entry point defining routes, request handling, and template rendering.
- Procfile – deployment descriptor (e.g., for Heroku).
- requirements.txt – Python dependencies.
- ml/ directory: core ML logic split into:
- pipeline.py – orchestration of data loading, preprocessing, model inference.
- search_ticker.py – resolves company name → ticker symbol via yahooquery.
- utils.py – helper functions (data transforms, scaling, etc.).
- templates/: Jinja2 HTML templates (index.html, result.html).
- static/: static assets (CSS, JS, images if any).

##### README for additional insights
- Tech stack: Flask / Python backend, Pandas/NumPy/TensorFlow/Keras for ML, yfinance & yahooquery for data, Matplotlib for plotting.
- No persistent database—data fetch is real-time.
- User flow: submit query → backend fetch & preprocess → LSTM predict → plot graphs → render results.

a. Main components:
1. Client (Web Browser)
2. Flask Web Server (app.py)
3. ML Pipeline Module (ml/pipeline.py)
4. Ticker Resolution Service (ml/search_ticker.py)
5. External Data Source (Yahoo Finance API)
6. Visualization Engine (Matplotlib)
7. Templates & Static Assets

b. Relationships & interactions:
- Client → Flask Server: HTTP GET/POST requests.
- Flask app routes → calls search_ticker to map company name.
- Flask app → calls pipeline to fetch historical data (via yfinance), preprocess, load or run LSTM model, produce predictions.
- Pipeline → Visualization Engine to generate charts (PNG/SVG).
- Flask app → passes chart URLs/objects into Jinja2 templates → sends HTML response back to client.
- Pipeline may call utils for scaling and data transforms.

c. Architectural patterns & principles:
- MVC (Controller = app.py routes, Model = ML pipeline + data, View = HTML templates + plots).
- Separation of concerns: routing vs. ML logic vs. visualization vs. utilities.
- Modular design: distinct Python modules for search, pipeline, utils.

d. Key technologies & frameworks:
- Flask for HTTP serving and templating.
- yfinance & yahooquery for data ingestion.
- Pandas/NumPy for data manipulation.
- TensorFlow/Keras for LSTM model inference.
- Matplotlib for chart generation.
- Jinja2 templates for rendering.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser["Web Browser"]:::frontend
        TemplatesIndex["index.html"]:::frontend
        TemplatesResult["result.html"]:::frontend
        Static["Static Assets"]:::frontend
    end

    %% Web/API Layer
    subgraph "Web/API Layer"
        Flask["Flask Server\n(app.py)"]:::backend
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        Pipeline["ML Pipeline Module\n(pipeline.py)"]:::ml
        Search["Ticker Resolution Service\n(search_ticker.py)"]:::ml
        Utils["Utility Functions\n(utils.py)"]:::ml
    end

    %% Visualization Layer
    subgraph "Visualization Layer"
        Chart["Visualization Engine\n(Matplotlib)"]:::ml
    end

    %% External Services
    subgraph "Data Source Layer"
        Yahoo["Yahoo Finance API"]:::ext
    end

    %% Deployment Configuration
    subgraph "Deployment Configuration"
        ProcfileNode["Procfile"]:::deployment
        Requirements["requirements.txt"]:::deployment
    end

    %% Connections
    Browser -->|"GET /, POST: symbol + days"| Flask
    Flask -->|"resolve ticker"| Search
    Search -->|"ticker symbol"| Flask
    Flask -->|"LSTM inference request"| Pipeline
    Pipeline -->|"HTTP GET: price data"| Yahoo
    Pipeline -->|"data transforms"| Utils
    Pipeline -->|"prediction output"| Flask
    Pipeline -->|"generate chart PNG/SVG"| Chart
    Chart -->|"chart image"| Flask
    Flask -->|"render with index.html"| TemplatesIndex
    Flask -->|"render with result.html"| TemplatesResult
    TemplatesIndex -->|"HTML"| Browser
    TemplatesResult -->|"HTML"| Browser
    Flask -->|"serve CSS/JS"| Static
    ProcfileNode -.-> Flask
    Requirements -.-> Flask

    %% Click Events
    click Flask "https://github.com/sreeragsreekanth/stockprice-predictor/blob/main/app.py"
    click Pipeline "https://github.com/sreeragsreekanth/stockprice-predictor/blob/main/ml/pipeline.py"
    click Search "https://github.com/sreeragsreekanth/stockprice-predictor/blob/main/ml/search_ticker.py"
    click Utils "https://github.com/sreeragsreekanth/stockprice-predictor/blob/main/ml/utils.py"
    click TemplatesIndex "https://github.com/sreeragsreekanth/stockprice-predictor/blob/main/templates/index.html"
    click TemplatesResult "https://github.com/sreeragsreekanth/stockprice-predictor/blob/main/templates/result.html"
    click Static "https://github.com/sreeragsreekanth/stockprice-predictor/tree/main/static/"
    click ProcfileNode "https://github.com/sreeragsreekanth/stockprice-predictor/tree/main/Procfile"
    click Requirements "https://github.com/sreeragsreekanth/stockprice-predictor/blob/main/requirements.txt"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#5DADE2,color:#154360
    classDef backend fill:#D5F5E3,stroke:#58D68D,color:#145A32
    classDef ml fill:#FAD7A0,stroke:#EB984E,color:#6E2C00
    classDef ext fill:#D7DBDD,stroke:#A6ACAF,color:#424949
    classDef deployment fill:#E8DAEF,stroke:#BB8FCE,color:#4A235A
```
