# naveen3830/ai_stock_prediction architecture

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

- Interactive diagram: https://gitdiagram.com/naveen3830/ai_stock_prediction
- Repository: https://github.com/naveen3830/ai_stock_prediction

## Overview

1. This repo is a Python stock-forecasting application centered on two model families: `ARIMA` for classical time-series forecasting and `LSTM` for sequence learning. The runtime app is organized under `src/`, with `src/main.py` acting as the orchestration layer for the Streamlit experience described in the README.

2. The main data boundary is external market data. `src/stock_data.py` is the ingestion layer that pulls historical price series from `yfinance`, likely returning a cleaned time-indexed dataset of S&P 500 stock prices. All downstream modeling depends on this module’s output.

3. Preprocessing and feature shaping are split across the model modules and `src/models/indicators.py`. This is where the repo’s two different modeling pipelines diverge: ARIMA expects stationary series and differencing-style transforms, while LSTM expects scaled sliding-window sequences, consistent with the README’s use of `MinMaxScaler` and 60-day windows.

4. `src/models/arima.py` is the classical forecasting subsystem. It likely handles stationarity transforms, parameter selection/tuning, model fitting, and forecast generation. In the architecture diagram, this is a self-contained branch from raw series to prediction output, optimized for short-horizon univariate forecasts.

5. `src/models/lstm.py` is the deep-learning forecasting subsystem. It likely builds, trains, and evaluates an LSTM network over normalized sequences, with dropout and dense output layers as described in the README. This branch is heavier-weight and computationally more expensive than ARIMA, but is the main non-linear forecasting path.

6. `src/charts.py` is the presentation/visualization layer. Its role is to turn model outputs and historical series into comparison plots, forecast charts, and other UI visuals. This sits at the edge of the application, consuming results from both model pipelines rather than participating in training.

7. `src/main.py` ties the whole flow together as the application controller: user input from the Streamlit UI selects a stock, data is fetched, preprocessing/model execution happens, and charts are rendered. In architecture terms, it is the central coordination point rather than a domain model itself.

8. `src/styles.py` and `src/logging_config.py` are cross-cutting support modules. Styles affect only the UI layer, while logging supports observability across data loading, preprocessing, training, and prediction steps. They don’t define business logic, but they do shape operational behavior and presentation.

9. The `notebooks/` directory is an exploratory/research workspace, not the primary runtime path. The ARIMA and LSTM notebooks suggest model experimentation, tuning, and validation happened there before hardening the logic into `src/models/`.

10. The architecture has a clear separation between offline experimentation and interactive inference. The reusable Python package code in `src/` is the deployable core, while the notebooks document model development. That distinction is important if you diagram the repo: notebooks are supporting assets, not a production subsystem.

11. The main external dependencies that materially affect architecture are `yfinance` for market data access and the Python ML stack implied by ARIMA/LSTM modeling. The app is built for Streamlit-based interactive execution, so the user interface, model execution, and visualization are coupled in a single Python process rather than split into separate services.

12. Overall, the system is a single-app architecture with three major flows: market data ingestion, dual-model forecasting, and visualization/UI rendering. The key boundaries are between data acquisition, preprocessing, model-specific forecasting, and presentation, with shared utility modules providing styling and logging.

Main entry points: [`src/main.py`](https://github.com/naveen3830/ai_stock_prediction/blob/main/src/main.py) (Main app), [`src/models/arima.py`](https://github.com/naveen3830/ai_stock_prediction/blob/main/src/models/arima.py) (ARIMA), [`src/models/lstm.py`](https://github.com/naveen3830/ai_stock_prediction/blob/main/src/models/lstm.py) (LSTM), [`src/stock_data.py`](https://github.com/naveen3830/ai_stock_prediction/blob/main/src/stock_data.py) (Market data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_app["Runtime app"]
  node_node_main["Main app<br/>controller<br/>[main.py]"]
  node_node_styles["Styles<br/>ui support<br/>[styles.py]"]
  node_node_logging["Logging<br/>ops support<br/>[logging_config.py]"]
  node_node_charts["Charts<br/>visualization<br/>[charts.py]"]
  node_node_streamlit(("Streamlit UI<br/>runtime boundary"))
end

subgraph group_grp_models["Forecasting models"]
  node_node_data[("Market data<br/>ingestion<br/>[stock_data.py]")]
  node_node_indicators["Indicators<br/>feature shaping<br/>[indicators.py]"]
  node_node_arima["ARIMA<br/>classical forecast<br/>[arima.py]"]
  node_node_lstm["LSTM<br/>deep forecast<br/>[lstm.py]"]
end

subgraph group_grp_explore["Research workspace"]
  node_node_notebook_arma["ARMA notebook<br/>experiment notebook<br/>[ARMA.ipynb]"]
  node_node_notebook_model["Model notebook<br/>experiment notebook<br/>[Model.ipynb]"]
  node_node_notebook_arima["ARIMA notebook<br/>experiment notebook<br/>[arima.ipynb]"]
end

node_node_yfinance(("yfinance<br/>external data source"))
node_node_mlstack(("ML stack<br/>external library set"))

node_node_streamlit -->|"drives"| node_node_main
node_node_main -->|"loads"| node_node_data
node_node_data -->|"fetches from"| node_node_yfinance
node_node_main -->|"prepares"| node_node_indicators
node_node_indicators -->|"feeds"| node_node_arima
node_node_indicators -->|"feeds"| node_node_lstm
node_node_main -->|"runs"| node_node_arima
node_node_main -->|"runs"| node_node_lstm
node_node_arima -->|"uses"| node_node_mlstack
node_node_lstm -->|"uses"| node_node_mlstack
node_node_arima -->|"outputs to"| node_node_charts
node_node_lstm -->|"outputs to"| node_node_charts
node_node_data -->|"supplies"| node_node_charts
node_node_main -->|"applies"| node_node_styles
node_node_main -->|"logs via"| node_node_logging
node_node_notebook_arma -.->|"prototypes"| node_node_arima
node_node_notebook_arima -.->|"prototypes"| node_node_arima
node_node_notebook_model -.->|"prototypes"| node_node_lstm

click node_node_main "https://github.com/naveen3830/ai_stock_prediction/blob/main/src/main.py"
click node_node_styles "https://github.com/naveen3830/ai_stock_prediction/blob/main/src/styles.py"
click node_node_logging "https://github.com/naveen3830/ai_stock_prediction/blob/main/src/logging_config.py"
click node_node_data "https://github.com/naveen3830/ai_stock_prediction/blob/main/src/stock_data.py"
click node_node_indicators "https://github.com/naveen3830/ai_stock_prediction/blob/main/src/models/indicators.py"
click node_node_arima "https://github.com/naveen3830/ai_stock_prediction/blob/main/src/models/arima.py"
click node_node_lstm "https://github.com/naveen3830/ai_stock_prediction/blob/main/src/models/lstm.py"
click node_node_charts "https://github.com/naveen3830/ai_stock_prediction/blob/main/src/charts.py"
click node_node_notebook_arma "https://github.com/naveen3830/ai_stock_prediction/blob/main/notebooks/ARMA.ipynb"
click node_node_notebook_model "https://github.com/naveen3830/ai_stock_prediction/blob/main/notebooks/Model.ipynb"
click node_node_notebook_arima "https://github.com/naveen3830/ai_stock_prediction/blob/main/notebooks/arima.ipynb"

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_node_main,node_node_styles,node_node_logging,node_node_charts,node_node_streamlit toneBlue
class node_node_data,node_node_indicators,node_node_arima,node_node_lstm toneAmber
class node_node_notebook_arma,node_node_notebook_model,node_node_notebook_arima toneMint
class node_node_yfinance,node_node_mlstack toneNeutral
```

## Components

### Runtime app

Interactive Streamlit application and cross-cutting presentation/ops modules.

- [Main app](https://github.com/naveen3830/ai_stock_prediction/blob/main/src/main.py): controller · Orchestrates the Streamlit flow from input to forecast and charts. · `src/main.py`
- [Styles](https://github.com/naveen3830/ai_stock_prediction/blob/main/src/styles.py): ui support · UI styling and presentation constants for the app. · `src/styles.py`
- [Logging](https://github.com/naveen3830/ai_stock_prediction/blob/main/src/logging_config.py): ops support · Application logging configuration used across the runtime. · `src/logging_config.py`
- [Charts](https://github.com/naveen3830/ai_stock_prediction/blob/main/src/charts.py): visualization · Renders forecast and comparison plots for the UI. · `src/charts.py`
- **Streamlit UI**: runtime boundary · Interactive user-facing experience hosted inside the Python app.

### Forecasting models

Data ingestion, feature shaping, and the two forecasting branches.

- [Market data](https://github.com/naveen3830/ai_stock_prediction/blob/main/src/stock_data.py): ingestion · Fetches historical price data from external market sources. · `src/stock_data.py`
- [Indicators](https://github.com/naveen3830/ai_stock_prediction/blob/main/src/models/indicators.py): feature shaping · Shared preprocessing and indicator/sequence feature preparation. · `src/models/indicators.py`
- [ARIMA](https://github.com/naveen3830/ai_stock_prediction/blob/main/src/models/arima.py): classical forecast · Stationary-series forecasting pipeline for short-horizon predictions. · `src/models/arima.py`
- [LSTM](https://github.com/naveen3830/ai_stock_prediction/blob/main/src/models/lstm.py): deep forecast · Neural sequence forecasting pipeline using scaled windows. · `src/models/lstm.py`

### Research workspace

Notebook-based experimentation and validation.

- [ARMA notebook](https://github.com/naveen3830/ai_stock_prediction/blob/main/notebooks/ARMA.ipynb): experiment notebook · Exploratory notebook for classical time-series experimentation. · `notebooks/ARMA.ipynb`
- [Model notebook](https://github.com/naveen3830/ai_stock_prediction/blob/main/notebooks/Model.ipynb): experiment notebook · Notebook for model development, tuning, and validation. · `notebooks/Model.ipynb`
- [ARIMA notebook](https://github.com/naveen3830/ai_stock_prediction/blob/main/notebooks/arima.ipynb): experiment notebook · Notebook focused on ARIMA exploration and iteration. · `notebooks/arima.ipynb`

### Other components

- **yfinance**: external data source · External API/library used to obtain historical market prices.
- **ML stack**: external library set · Underlying numerical and machine-learning dependencies used by the models.

## Connections

- Streamlit UI → Main app: drives · User interactions enter the main orchestration layer.
- Main app → Market data: loads · The app fetches the selected stock's historical series.
- Market data → yfinance: fetches from · Market data is retrieved from the external source.
- Main app → Indicators: prepares · Main flow sends raw series into preprocessing and feature shaping.
- Indicators → ARIMA: feeds · Classical pipeline consumes transformed time series features.
- Indicators → LSTM: feeds · Sequence pipeline consumes scaled windowed features.
- Main app → ARIMA: runs · The controller can execute the ARIMA forecasting path.
- Main app → LSTM: runs · The controller can execute the LSTM forecasting path.
- ARIMA → ML stack: uses · ARIMA relies on the scientific Python forecasting stack.
- LSTM → ML stack: uses · LSTM relies on the numerical and deep-learning stack.
- ARIMA → Charts: outputs to · Forecast results are passed to visualization.
- LSTM → Charts: outputs to · Deep-model predictions are passed to visualization.
- Market data → Charts: supplies · Historical series are included in comparison charts.
- Main app → Styles: applies · UI styling is applied within the app shell.
- Main app → Logging: logs via · Runtime events are recorded through shared logging configuration.
- ARMA notebook → ARIMA: prototypes · Notebook experimentation informs the ARIMA implementation.
- ARIMA notebook → ARIMA: prototypes · Notebook experimentation informs the ARIMA implementation.
- Model notebook → LSTM: prototypes · Notebook experimentation informs the LSTM implementation.
