# abhishekrdj/stock-price-prediction-using-machine-learning architecture

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

- Interactive diagram: https://gitdiagram.com/abhishekrdj/stock-price-prediction-using-machine-learning
- Repository: https://github.com/abhishekrdj/stock-price-prediction-using-machine-learning

## Overview

##### Project Type and Purpose
- Type: Full-stack (single-page) predictive analytics web application
- Purpose: Load historical stock data, preprocess it, train or load a pre-trained ML model, and expose predictions via a Streamlit web interface.

##### Main Components
a. Data Source
- Local CSV file (`stock_data.csv`) containing historical price data.
b. Data Preprocessing Module (in `model.py`)
- Reads CSV, cleans data, transforms it into time-series windows.
c. Model Training / Inference Module (in `model.py`)
- Defines the TensorFlow model architecture, trains it on the preprocessed data, serializes the trained model to disk (if training occurs at runtime).
d. Streamlit Frontend (in `main.py`)
- Web server component that imports the trained model, accepts user inputs (company ticker, date range), triggers inference, and renders charts.
e. User Interface / Visualization
- Uses Matplotlib or Streamlit’s built-in charting to plot historical vs. predicted prices.
f. Python Environment & Dependencies
- Virtual environment, `requirements.txt` driving installation of Pandas, NumPy, Scikit-learn, TensorFlow, Streamlit, Matplotlib.

##### Relationships and Data Flow
1) Streamlit UI (main.py)
↓
2) Loads trained model artifact (from disk or in-memory object)
↓
3) On user action, requests inference from Model Module
↓
4) Model Module uses Preprocessing logic to prepare the incoming data slice
↓
5) Model Module runs inference and returns predicted output array
↓
6) Streamlit UI visualizes predictions alongside historical data
7) Under the hood, the raw CSV is used by Preprocessing when retraining or updating the model.

##### Architectural Patterns / Design Principles
- Single-responsibility: split data prep, model logic, and UI into separate Python modules.
- Layered (presentation vs. business vs. data).
- Reproducibility: pinned dependencies in `requirements.txt`.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DataSource[("stock_data.csv")]:::data
        DataPreprocessor["Data Preprocessor\n(model.py)"]:::model
    end

    %% Model Layer
    subgraph "Model Layer"
        direction TB
        TFModel["TensorFlow Model\n(model.py)"]:::model
    end

    %% UI Layer
    subgraph "UI Layer"
        direction TB
        StreamlitUI["Streamlit UI\n(main.py)"]:::ui
        Visualization["Visualization\n(main.py)"]:::ui
    end

    %% Infrastructure
    subgraph "Infrastructure"
        direction TB
        Dependencies["requirements.txt"]:::infra
    end

    %% Data Flow
    DataSource -->|fetch CSV| DataPreprocessor
    DataPreprocessor -->|train/infer| TFModel
    StreamlitUI -->|loads model| TFModel
    StreamlitUI -->|trigger preprocess| DataPreprocessor
    TFModel -->|return predictions| StreamlitUI
    StreamlitUI -->|render charts| Visualization

    %% Click Events
    click DataSource "https://github.com/abhishekrdj/stock-price-prediction-using-machine-learning/blob/main/stock_data.csv"
    click DataPreprocessor "https://github.com/abhishekrdj/stock-price-prediction-using-machine-learning/blob/main/model.py"
    click TFModel "https://github.com/abhishekrdj/stock-price-prediction-using-machine-learning/blob/main/model.py"
    click StreamlitUI "https://github.com/abhishekrdj/stock-price-prediction-using-machine-learning/blob/main/main.py"
    click Visualization "https://github.com/abhishekrdj/stock-price-prediction-using-machine-learning/blob/main/main.py"
    click Dependencies "https://github.com/abhishekrdj/stock-price-prediction-using-machine-learning/blob/main/requirements.txt"

    %% Styles
    classDef data fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef model fill:#90EE90,stroke:#000,stroke-width:1px
    classDef ui fill:#FFA500,stroke:#000,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#000,stroke-width:1px
```
