# harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking architecture

> Architecture diagram of the GitHub repository harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking
- Repository: https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking

## Overview

MarketLens collects hourly candles, builds features, trains and serves calibrated UP/DOWN/NEUTRAL forecasts, explains them with SHAP, and checks predictions against later prices. Users access forecasts, market data, explanations, trends, and live performance through the API or Streamlit dashboard. The README and source index establish several subsystem links, but unsampled implementations leave some internal details unverified; those links are omitted rather than inferred.

Main entry points: [`app/database.py`](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/database.py) (Market and Prediction Data), [`app/services/ml_predictor.py`](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/services/ml_predictor.py) (Live Predictor), [`app/main.py`](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/main.py) (FastAPI Application), [`app/scheduler.py`](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/scheduler.py) (Background Scheduler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_collection["Market Data"]
  node_fetcher["Candle Fetcher"]
  node_ingester["Candle Ingestion<br/>[candle_ingester.py]"]
  node_store[("Market and Prediction Data<br/>[database.py]")]
end

subgraph group_modeling["Forecasting"]
  node_data_loader["Training Data Loader<br/>[data_loader.py]"]
  node_features["Features and Targets"]
  node_training["Offline Training<br/>[train_offline.py]"]
  node_models["Trained Models"]
end

subgraph group_serving["API and Explanations"]
  node_predictor["Live Predictor<br/>[ml_predictor.py]"]
  node_prediction_store["Prediction Persistence"]
  node_explainer["SHAP Explanations<br/>[explainer.py]"]
  node_api["FastAPI Application<br/>[main.py]"]
  node_market_routes["Market Data Route<br/>[market_routes.py]"]
  node_predict_route["Prediction Route<br/>[predict.py]"]
  node_explain_route["Explanation Route<br/>[explain.py]"]
end

subgraph group_tracking["Tracking and Trends"]
  node_scheduler["Background Scheduler<br/>[scheduler.py]"]
  node_outcomes["Outcome Tracker<br/>[outcome_tracker.py]"]
  node_trend_engine["Trend Analysis<br/>[trend_engine.py]"]
  node_save_trends["Trend Persistence<br/>[save_trends.py]"]
end

subgraph group_interface["User Interfaces"]
  node_dashboard["Streamlit Dashboard<br/>[app.py]"]
end

node_yahoo(("Yahoo Finance"))
node_user(("User"))

node_yahoo -->|"provides candles"| node_fetcher
node_fetcher -->|"fetches candles"| node_ingester
node_ingester -->|"writes candles"| node_store
node_store -->|"supplies history"| node_data_loader
node_data_loader -->|"loads data"| node_training
node_fetcher -->|"fetches training candles"| node_training
node_training -->|"builds training features"| node_features
node_training -->|"produces models"| node_models
node_predictor -->|"loads candles"| node_store
node_predictor -->|"requests backfill"| node_ingester
node_predictor -->|"builds inference features"| node_features
node_predictor -->|"loads trained model"| node_models
node_predictor -->|"saves prediction"| node_prediction_store
node_prediction_store -->|"writes prediction"| node_store
node_explainer -->|"gets prediction"| node_predictor
node_explainer -->|"rebuilds features"| node_features
node_explainer -->|"loads tree model"| node_models
node_api -->|"registers route"| node_market_routes
node_api -->|"registers route"| node_predict_route
node_api -->|"registers route"| node_explain_route
node_api -->|"starts scheduler"| node_scheduler
node_market_routes -->|"queries market data"| node_store
node_predict_route -->|"requests forecast"| node_predictor
node_explain_route -->|"requests explanation"| node_explainer
node_scheduler -->|"runs ingestion"| node_ingester
node_scheduler -->|"runs resolution"| node_outcomes
node_scheduler -->|"runs trend analysis"| node_save_trends
node_outcomes -->|"resolves outcomes"| node_store
node_save_trends -->|"analyzes trends"| node_trend_engine
node_trend_engine -->|"reads market history"| node_store
node_save_trends -->|"writes trend insights"| node_store
node_user -->|"views insights"| node_dashboard
node_dashboard -.->|"uses live API"| node_api
node_dashboard -->|"reads market and performance data"| node_store

click node_fetcher "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/ml/market_data_fetcher.py"
click node_ingester "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/services/candle_ingester.py"
click node_store "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/database.py"
click node_data_loader "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/ml/data_loader.py"
click node_features "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/ml/feature_engineering.py"
click node_training "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/ml/train_offline.py"
click node_models "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/tree/main/ml/models"
click node_predictor "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/services/ml_predictor.py"
click node_prediction_store "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/services/prediction_store.py"
click node_explainer "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/services/explainer.py"
click node_api "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/main.py"
click node_market_routes "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/routes/market_routes.py"
click node_predict_route "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/routes/predict.py"
click node_explain_route "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/routes/explain.py"
click node_scheduler "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/scheduler.py"
click node_outcomes "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/services/outcome_tracker.py"
click node_trend_engine "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/analysis/trend_engine.py"
click node_save_trends "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/analysis/save_trends.py"
click node_dashboard "https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/dashboard/app.py"

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_fetcher,node_ingester,node_store,node_user toneBlue
class node_data_loader,node_features,node_training,node_models toneAmber
class node_predictor,node_prediction_store,node_explainer,node_api,node_market_routes,node_predict_route,node_explain_route toneMint
class node_scheduler,node_outcomes,node_trend_engine,node_save_trends toneRose
class node_dashboard,node_yahoo toneIndigo
```

## Components

### Market Data

- [Candle Fetcher](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/ml/market_data_fetcher.py): `ml/market_data_fetcher.py`
- [Candle Ingestion](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/services/candle_ingester.py): `app/services/candle_ingester.py`
- [Market and Prediction Data](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/database.py): `app/database.py`

### Forecasting

- [Training Data Loader](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/ml/data_loader.py): `ml/data_loader.py`
- [Features and Targets](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/ml/feature_engineering.py): `ml/feature_engineering.py`
- [Offline Training](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/ml/train_offline.py): `ml/train_offline.py`
- [Trained Models](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/tree/main/ml/models): `ml/models`

### API and Explanations

- [Live Predictor](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/services/ml_predictor.py): `app/services/ml_predictor.py`
- [Prediction Persistence](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/services/prediction_store.py): `app/services/prediction_store.py`
- [SHAP Explanations](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/services/explainer.py): `app/services/explainer.py`
- [FastAPI Application](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/main.py): `app/main.py`
- [Market Data Route](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/routes/market_routes.py): `app/routes/market_routes.py`
- [Prediction Route](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/routes/predict.py): `app/routes/predict.py`
- [Explanation Route](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/routes/explain.py): `app/routes/explain.py`

### Tracking and Trends

- [Background Scheduler](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/scheduler.py): `app/scheduler.py`
- [Outcome Tracker](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/services/outcome_tracker.py): `app/services/outcome_tracker.py`
- [Trend Analysis](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/analysis/trend_engine.py): `app/analysis/trend_engine.py`
- [Trend Persistence](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/app/analysis/save_trends.py): `app/analysis/save_trends.py`

### User Interfaces

- [Streamlit Dashboard](https://github.com/harshnyati/marketlens-explainable-market-trend-forecasting-with-live-performance-tracking/blob/main/dashboard/app.py): `dashboard/app.py`

### Other components

- **Yahoo Finance**
- **User**

## Connections

- Yahoo Finance → Candle Fetcher: provides candles (evidence: `ml/market_data_fetcher.py`)
- Candle Fetcher → Candle Ingestion: fetches candles (evidence: `app/services/candle_ingester.py`)
- Candle Ingestion → Market and Prediction Data: writes candles (evidence: `app/services/candle_ingester.py`)
- Market and Prediction Data → Training Data Loader: supplies history (evidence: `ml/data_loader.py`)
- Training Data Loader → Offline Training: loads data (evidence: `ml/train_offline.py`)
- Candle Fetcher → Offline Training: fetches training candles (evidence: `ml/train_offline.py`)
- Offline Training → Features and Targets: builds training features (evidence: `ml/train_offline.py`)
- Offline Training → Trained Models: produces models (evidence: `README.md`)
- Live Predictor → Market and Prediction Data: loads candles (evidence: `app/services/ml_predictor.py`)
- Live Predictor → Candle Ingestion: requests backfill (evidence: `app/services/ml_predictor.py`)
- Live Predictor → Features and Targets: builds inference features (evidence: `ml/feature_engineering.py`)
- Live Predictor → Trained Models: loads trained model (evidence: `README.md`)
- Live Predictor → Prediction Persistence: saves prediction (evidence: `app/services/ml_predictor.py`)
- Prediction Persistence → Market and Prediction Data: writes prediction (evidence: `app/services/prediction_store.py`)
- SHAP Explanations → Live Predictor: gets prediction (evidence: `app/services/explainer.py`)
- SHAP Explanations → Features and Targets: rebuilds features (evidence: `app/services/explainer.py`)
- SHAP Explanations → Trained Models: loads tree model (evidence: `README.md`)
- FastAPI Application → Market Data Route: registers route (evidence: `app/main.py`)
- FastAPI Application → Prediction Route: registers route (evidence: `app/main.py`)
- FastAPI Application → Explanation Route: registers route (evidence: `app/main.py`)
- FastAPI Application → Background Scheduler: starts scheduler (evidence: `app/main.py`)
- Market Data Route → Market and Prediction Data: queries market data (evidence: `app/routes/market_routes.py`)
- Prediction Route → Live Predictor: requests forecast (evidence: `app/routes/predict.py`)
- Explanation Route → SHAP Explanations: requests explanation (evidence: `app/routes/explain.py`)
- Background Scheduler → Candle Ingestion: runs ingestion (evidence: `app/scheduler.py`)
- Background Scheduler → Outcome Tracker: runs resolution (evidence: `app/scheduler.py`)
- Background Scheduler → Trend Persistence: runs trend analysis (evidence: `app/scheduler.py`)
- Outcome Tracker → Market and Prediction Data: resolves outcomes (evidence: `app/services/outcome_tracker.py`)
- Trend Persistence → Trend Analysis: analyzes trends (evidence: `app/analysis/save_trends.py`)
- Trend Analysis → Market and Prediction Data: reads market history (evidence: `app/analysis/trend_engine.py`)
- Trend Persistence → Market and Prediction Data: writes trend insights (evidence: `app/analysis/save_trends.py`)
- User → Streamlit Dashboard: views insights (evidence: `README.md`)
- Streamlit Dashboard → FastAPI Application: uses live API
- Streamlit Dashboard → Market and Prediction Data: reads market and performance data (evidence: `dashboard/app.py`)
