# drag0nop/real-time-stock-prediction architecture

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

- Interactive diagram: https://gitdiagram.com/drag0nop/real-time-stock-prediction
- Repository: https://github.com/drag0nop/real-time-stock-prediction

## Overview

##### Project type and purpose
- This is a full‐stack web application for real‐time stock price prediction.
- It uses Flask as a backend REST API, an LSTM neural-network model for time-series forecasting, and a simple HTML/CSS/JavaScript frontend with Chart.js.

##### File structure
- Top-level files:
- app.py – Flask application and API endpoints
- config.py – API keys and configuration
- requirements.txt – Python dependencies
- Directories:
- models/ – ML model definition (model.py), training script (train.py), saved_models/
- utils/ – data_fetcher.py (Polygon.io integration), preprocessor.py
- static/ – frontend assets: css/style.css, js/main.js
- templates/ – Jinja2 HTML template index.html

##### README for additional insights
- Flask exposes an endpoint `/api/predict` that takes a ticker and horizon, returns JSON of forecasted prices.
- Frontend allows user input for ticker and period, calls the API, visualizes results via Chart.js.
- Data pipeline: fetch historical quotes → compute indicators (MA, RSI, MACD, Bollinger) → train or infer with LSTM → output.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        Browser["User's Browser"]:::frontend
        UI["index.html"]:::frontend
        CSS["style.css"]:::frontend
        JS["main.js"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        APICall["app.py (/api/predict)"]:::backend
        Config["config.py"]:::backend
        Fetcher["data_fetcher.py"]:::backend
        Preprocessor["preprocessor.py"]:::backend
    end

    %% ML Layer
    subgraph "ML Layer"
        Model["model.py (LSTM Inference)"]:::ml
    end

    %% External Services
    subgraph "External Services"
        External["Polygon.io REST API"]:::external
    end

    %% Offline Training Pipeline
    subgraph "Offline Training Pipeline"
        Train["train.py"]:::ml
        Saved["saved_models/"]:::storage
    end

    %% Documentation
    Docs["requirements.txt"]:::docs
    Readme["README.md"]:::docs

    %% Data Flows
    Browser --> UI
    UI --> CSS
    UI --> JS
    JS -->|calls `/api/predict`| APICall
    APICall --> Config
    APICall --> Fetcher
    APICall --> Preprocessor
    Fetcher --> External
    External --> Fetcher
    Preprocessor --> Model
    Model --> APICall
    APICall -->|JSON response| Browser

    Train --> Fetcher
    Train --> Preprocessor
    Train --> Model
    Train --> Saved

    %% Click Events
    click UI "https://github.com/drag0nop/real-time-stock-prediction/blob/main/Stock_Prediction/templates/index.html"
    click CSS "https://github.com/drag0nop/real-time-stock-prediction/blob/main/Stock_Prediction/static/css/style.css"
    click JS "https://github.com/drag0nop/real-time-stock-prediction/blob/main/Stock_Prediction/static/js/main.js"
    click APICall "https://github.com/drag0nop/real-time-stock-prediction/blob/main/Stock_Prediction/app.py"
    click Config "https://github.com/drag0nop/real-time-stock-prediction/blob/main/Stock_Prediction/config.py"
    click Fetcher "https://github.com/drag0nop/real-time-stock-prediction/blob/main/Stock_Prediction/utils/data_fetcher.py"
    click Preprocessor "https://github.com/drag0nop/real-time-stock-prediction/blob/main/Stock_Prediction/utils/preprocessor.py"
    click Model "https://github.com/drag0nop/real-time-stock-prediction/blob/main/Stock_Prediction/models/model.py"
    click Train "https://github.com/drag0nop/real-time-stock-prediction/blob/main/Stock_Prediction/models/train.py"
    click Docs "https://github.com/drag0nop/real-time-stock-prediction/blob/main/Stock_Prediction/requirements.txt"
    click Readme "https://github.com/drag0nop/real-time-stock-prediction/blob/main/README.md"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366D6,stroke-width:2px
    classDef backend fill:#E2F0D9,stroke:#2E7D32,stroke-width:2px
    classDef ml fill:#FFE6CC,stroke:#E65100,stroke-width:2px
    classDef external fill:#FDEDEC,stroke:#C62828,stroke-width:2px,stroke-dasharray: 5 5
    classDef storage fill:#F0F0F0,stroke:#777,stroke-width:2px
    classDef docs fill:#FFF8E1,stroke:#F9A825,stroke-width:2px
```
