# sagargupta16/stocksage-ai architecture

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

- Interactive diagram: https://gitdiagram.com/sagargupta16/stocksage-ai
- Repository: https://github.com/sagargupta16/stocksage-ai

## Overview

StockSage-AI is a planned Indian-market paper-trading, prediction, and competition platform; the README says the repository is currently an empty scaffold, so these are intended capabilities rather than verified runtime behavior. The principal workflow is a user viewing market information, requesting predictions, placing virtual trades, and tracking portfolio results; leaderboard rankings and the autonomous AI trader are additional product branches. Source excerpts are empty, so relationships rely on README descriptions, with uncertain implementation links left dashed.

Main entry points: [`backend/app/main.py`](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/main.py) (FastAPI application), [`frontend/lib/api.ts`](https://github.com/sagargupta16/stocksage-ai/blob/main/frontend/lib/api.ts) (API client), [`backend/tasks/celery_app.py`](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/tasks/celery_app.py) (Scheduled jobs), [`backend/ml/data/fetcher.py`](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/ml/data/fetcher.py) (Market and news data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_web["Web interface<br/>[page.tsx]"]
  node_market_pages["Stock views<br/>[page.tsx]"]
  node_trade_page["Trading view<br/>[page.tsx]"]
  node_portfolio_page["Portfolio view<br/>[page.tsx]"]
  node_leaderboard_page["Leaderboard view<br/>[page.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_backend["API and trading"]
  node_api["FastAPI application<br/>[main.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_stock_service["Market data service<br/>[stock_service.py]"]
  node_prediction_service["Prediction service<br/>[ml_service.py]"]
  node_trading_service["Paper trading<br/>[trading_service.py]"]
  node_portfolio_service["Portfolio analytics"]
  node_leaderboard_service["Rankings"]
  node_database[("Application database<br/>[database.py]")]
end

subgraph group_ml["Prediction pipeline"]
  node_fetcher["Market and news data<br/>[fetcher.py]"]
  node_features["Feature engineering<br/>[builder.py]"]
  node_models["Prediction models<br/>[ensemble.py]"]
  node_inference["Model inference<br/>[predictor.py]"]
  node_training["Model training<br/>[train.py]"]
end

subgraph group_jobs["Background work"]
  node_tasks["Scheduled jobs<br/>[celery_app.py]"]
end

node_user(("User"))
node_market_source["Market and news sources"]
node_ai_trader(("Autonomous AI trader"))

node_user -->|"uses"| node_web
node_web -.->|"requests data"| node_api_client
node_api_client -.->|"calls API"| node_api
node_api -.->|"routes authentication"| node_auth
node_api -.->|"serves market data"| node_stock_service
node_api -.->|"serves predictions"| node_prediction_service
node_api -.->|"processes trades"| node_trading_service
node_api -.->|"serves portfolios"| node_portfolio_service
node_api -.->|"serves rankings"| node_leaderboard_service
node_trading_service -.->|"stores orders"| node_database
node_portfolio_service -.->|"reads portfolio"| node_database
node_leaderboard_service -.->|"reads rankings"| node_database
node_market_pages -.->|"requests stock data"| node_api_client
node_trade_page -.->|"requests predictions"| node_api_client
node_portfolio_page -.->|"requests portfolio"| node_api_client
node_leaderboard_page -.->|"requests rankings"| node_api_client
node_prediction_service -.->|"requests predictions"| node_inference
node_inference -.->|"uses models"| node_models
node_fetcher -.->|"fetches data"| node_market_source
node_fetcher -.->|"provides data"| node_features
node_features -.->|"builds model inputs"| node_models
node_training -.->|"uses features"| node_features
node_training -.->|"trains models"| node_models
node_tasks -.->|"schedules fetching"| node_fetcher
node_tasks -.->|"schedules retraining"| node_training
node_tasks -.->|"updates rankings"| node_leaderboard_service
node_ai_trader -.->|"places virtual trades"| node_trading_service

click node_web "https://github.com/sagargupta16/stocksage-ai/blob/main/frontend/app/(dashboard)/dashboard/page.tsx"
click node_market_pages "https://github.com/sagargupta16/stocksage-ai/blob/main/frontend/app/(dashboard)/stocks/page.tsx"
click node_trade_page "https://github.com/sagargupta16/stocksage-ai/blob/main/frontend/app/(dashboard)/ai-trader/page.tsx"
click node_portfolio_page "https://github.com/sagargupta16/stocksage-ai/blob/main/frontend/app/(dashboard)/portfolio/page.tsx"
click node_leaderboard_page "https://github.com/sagargupta16/stocksage-ai/blob/main/frontend/app/(dashboard)/leaderboard/page.tsx"
click node_api_client "https://github.com/sagargupta16/stocksage-ai/blob/main/frontend/lib/api.ts"
click node_api "https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/main.py"
click node_auth "https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/routers/auth.py"
click node_stock_service "https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/services/stock_service.py"
click node_prediction_service "https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/services/ml_service.py"
click node_trading_service "https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/services/trading_service.py"
click node_portfolio_service "https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/services/portfolio_service.py"
click node_leaderboard_service "https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/services/leaderboard_service.py"
click node_database "https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/database.py"
click node_fetcher "https://github.com/sagargupta16/stocksage-ai/blob/main/backend/ml/data/fetcher.py"
click node_features "https://github.com/sagargupta16/stocksage-ai/blob/main/backend/ml/features/builder.py"
click node_models "https://github.com/sagargupta16/stocksage-ai/blob/main/backend/ml/models/ensemble.py"
click node_inference "https://github.com/sagargupta16/stocksage-ai/blob/main/backend/ml/inference/predictor.py"
click node_training "https://github.com/sagargupta16/stocksage-ai/blob/main/backend/ml/training/train.py"
click node_tasks "https://github.com/sagargupta16/stocksage-ai/blob/main/backend/tasks/celery_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_web,node_market_pages,node_trade_page,node_portfolio_page,node_leaderboard_page,node_api_client,node_user toneBlue
class node_api,node_auth,node_stock_service,node_prediction_service,node_trading_service,node_portfolio_service,node_leaderboard_service,node_database toneAmber
class node_fetcher,node_features,node_models,node_inference,node_training toneMint
class node_tasks toneRose
class node_market_source,node_ai_trader toneIndigo
```

## Components

### Web application

- [Web interface](https://github.com/sagargupta16/stocksage-ai/blob/main/frontend/app/(dashboard)/dashboard/page.tsx): `frontend/app/(dashboard)/dashboard/page.tsx`
- [Stock views](https://github.com/sagargupta16/stocksage-ai/blob/main/frontend/app/(dashboard)/stocks/page.tsx): `frontend/app/(dashboard)/stocks/page.tsx`
- [Trading view](https://github.com/sagargupta16/stocksage-ai/blob/main/frontend/app/(dashboard)/ai-trader/page.tsx): `frontend/app/(dashboard)/ai-trader/page.tsx`
- [Portfolio view](https://github.com/sagargupta16/stocksage-ai/blob/main/frontend/app/(dashboard)/portfolio/page.tsx): `frontend/app/(dashboard)/portfolio/page.tsx`
- [Leaderboard view](https://github.com/sagargupta16/stocksage-ai/blob/main/frontend/app/(dashboard)/leaderboard/page.tsx): `frontend/app/(dashboard)/leaderboard/page.tsx`
- [API client](https://github.com/sagargupta16/stocksage-ai/blob/main/frontend/lib/api.ts): `frontend/lib/api.ts`

### API and trading

- [FastAPI application](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/routers/auth.py): `backend/app/routers/auth.py`
- [Market data service](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/services/stock_service.py): `backend/app/services/stock_service.py`
- [Prediction service](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/services/ml_service.py): `backend/app/services/ml_service.py`
- [Paper trading](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/services/trading_service.py): `backend/app/services/trading_service.py`
- [Portfolio analytics](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/services/portfolio_service.py): `backend/app/services/portfolio_service.py`
- [Rankings](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/services/leaderboard_service.py): `backend/app/services/leaderboard_service.py`
- [Application database](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/app/database.py): `backend/app/database.py`

### Prediction pipeline

- [Market and news data](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/ml/data/fetcher.py): `backend/ml/data/fetcher.py`
- [Feature engineering](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/ml/features/builder.py): `backend/ml/features/builder.py`
- [Prediction models](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/ml/models/ensemble.py): `backend/ml/models/ensemble.py`
- [Model inference](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/ml/inference/predictor.py): `backend/ml/inference/predictor.py`
- [Model training](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/ml/training/train.py): `backend/ml/training/train.py`

### Background work

- [Scheduled jobs](https://github.com/sagargupta16/stocksage-ai/blob/main/backend/tasks/celery_app.py): `backend/tasks/celery_app.py`

### Other components

- **User**
- **Market and news sources**
- **Autonomous AI trader**

## Connections

- User → Web interface: uses
- Web interface → API client: requests data
- API client → FastAPI application: calls API
- FastAPI application → Authentication: routes authentication
- FastAPI application → Market data service: serves market data
- FastAPI application → Prediction service: serves predictions
- FastAPI application → Paper trading: processes trades
- FastAPI application → Portfolio analytics: serves portfolios
- FastAPI application → Rankings: serves rankings
- Paper trading → Application database: stores orders
- Portfolio analytics → Application database: reads portfolio
- Rankings → Application database: reads rankings
- Stock views → API client: requests stock data
- Trading view → API client: requests predictions
- Portfolio view → API client: requests portfolio
- Leaderboard view → API client: requests rankings
- Prediction service → Model inference: requests predictions
- Model inference → Prediction models: uses models
- Market and news data → Market and news sources: fetches data
- Market and news data → Feature engineering: provides data
- Feature engineering → Prediction models: builds model inputs
- Model training → Feature engineering: uses features
- Model training → Prediction models: trains models
- Scheduled jobs → Market and news data: schedules fetching
- Scheduled jobs → Model training: schedules retraining
- Scheduled jobs → Rankings: updates rankings
- Autonomous AI trader → Paper trading: places virtual trades
