# pankajsinghdeveloper26/nse-stock-predictor architecture

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

- Interactive diagram: https://gitdiagram.com/pankajsinghdeveloper26/nse-stock-predictor
- Repository: https://github.com/pankajsinghdeveloper26/nse-stock-predictor

## Overview

#### Purpose and Repository Shape
AlphaVision NSE Analytics is a research-oriented NSE equity analysis and forecasting system: historical prices are transformed into technical features, forecast models, trend assessments, and trading signals. The repository contains a root application plus a more complete duplicated snapshot under `nse-stock-predictor-zip/`; the latter adds modular backend stages such as authentication, caching, cleaning, features, and storage. Treat these as parallel copies unless consolidation is intentional.

#### Entry Points and Delivery Surfaces
- Python execution is centered on `cli.py`, `data_loader.py`, `models.py`, `services.py`, and `server.py`; the README identifies CLI forecasting as the primary workflow.
- The root dashboard is an Astro site with a React island: `src/pages/index.astro`, `src/components/react/Dashboard.tsx`, and `src/lib/api.ts`.
- A separate Astro-only frontend exists in `nse-frontend/src/pages/index.astro`, backed by `nse-frontend/src/lib/api.ts`.
- The expanded snapshot has equivalent backend/server entry points at `nse-stock-predictor-zip/cli.py` and `nse-stock-predictor-zip/server.py`.

#### Market Data Boundary
Data acquisition and dataset preparation begin in `data_loader.py` and feed model-ready tabular data into `models.py`. The architecture expects external historical market-data access (README names yFinance) or local CSV input; this is the principal external-data boundary. Offline behavior is explicitly represented by `test_data_loader_offline.py`.
- Expanded pipeline paths: `nse-stock-predictor-zip/data_loader.py`, `nse-stock-predictor-zip/loader.py`, `nse-stock-predictor-zip/cleaner.py`.

#### Analytics and Forecasting Pipeline
The core control flow is: acquire/load OHLCV data → validate/clean → engineer indicators and patterns → train or invoke forecasting model → classify trend/volatility/sentiment → emit a rule-based signal and forecast response. Root implementation anchors are `data_loader.py`, `models.py`, and `services.py`.
- The expanded implementation separates feature generation in `nse-stock-predictor-zip/features.py`, model logic in `nse-stock-predictor-zip/models.py`, and orchestration/services in `nse-stock-predictor-zip/services.py`.
- Intended model/runtime dependencies include Python, Pandas/NumPy, scikit-learn, XGBoost, and TensorFlow/Keras; indicators include SMA, RSI, MACD, Bollinger Bands, and ATR.

#### Service, State, and Security Layer
`server.py` is the backend boundary expected to expose analytics to a browser client, while `services.py` mediates higher-level operations between request handling and the forecasting pipeline. In the expanded copy, cross-cutting concerns are explicit:
- Configuration/environment handling: `nse-stock-predictor-zip/config.py`
- Authentication: `nse-stock-predictor-zip/auth.py`
- Cache and persistence abstractions: `nse-stock-predictor-zip/cache.py`, `nse-stock-predictor-zip/storage.py`

#### Dashboard Composition
The root UI is a dashboard-oriented Astro/React frontend. `src/pages/index.astro` hosts the application; `src/components/react/Dashboard.tsx` composes market metrics, index tiles, screening controls/table, signal feed, and sparklines. UI-to-backend calls should remain isolated in `src/lib/api.ts`, with domain/API shapes centralized in `src/lib/types.ts`.
- Major presentation components: `src/components/react/ScreenerTable.tsx`, `src/components/react/SignalFeed.tsx`, `src/components/react/IndexTile.tsx`.
- Astro and React/TypeScript run in the browser/build toolchain; Python services are the analytics runtime.

#### Key Architectural Risks
The README describes an `app/` package hierarchy that is absent from the supplied tree, while the actual code is split across root, `nse-frontend/`, and `nse-stock-predictor-zip/` duplicates. Before extending functionality, select a canonical backend/frontend pair, establish the server API contract used by `src/lib/api.ts`, and avoid implementing changes in both copies.

Main entry points: [`nse-stock-predictor-zip/services.py`](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/services.py) (Analytics services), [`data_loader.py`](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/data_loader.py) (Data loader), [`services.py`](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/services.py) (Analytics services), [`nse-stock-predictor-zip/loader.py`](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/loader.py) (Load and clean)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_root_backend["Root Python backend"]
  node_root_cli["Forecast CLI<br/>Python entry point<br/>[cli.py]"]
  node_root_loader["Data loader<br/>data acquisition<br/>[data_loader.py]"]
  node_root_models["Forecast models<br/>analytics runtime<br/>[models.py]"]
  node_root_services["Analytics services<br/>orchestration<br/>[services.py]"]
  node_root_server["Analytics server<br/>backend API<br/>[server.py]"]
end

subgraph group_expanded_backend["Expanded backend snapshot"]
  node_expanded_cli["Forecast CLI<br/>Python entry point<br/>[cli.py]"]
  node_expanded_loader["Load and clean<br/>data pipeline<br/>[loader.py]"]
  node_expanded_features["Technical features<br/>feature engineering<br/>[features.py]"]
  node_expanded_models["Forecast models<br/>ML runtime<br/>[models.py]"]
  node_expanded_services["Analytics services<br/>orchestration<br/>[services.py]"]
  node_expanded_server["Analytics server<br/>backend API<br/>[server.py]"]
  node_auth["Authentication<br/>security<br/>[auth.py]"]
  node_cache_storage[("Cache and storage<br/>state layer<br/>[storage.py]")]
end

subgraph group_root_dashboard["Root dashboard"]
  node_root_page["Dashboard page<br/>Astro page<br/>[index.astro]"]
  node_dashboard["Analytics dashboard<br/>React UI<br/>[Dashboard.tsx]"]
  node_root_api_client["API client and types<br/>browser API boundary<br/>[api.ts]"]
end

subgraph group_alternate_frontend["Separate Astro frontend"]
  node_alternate_page["Astro frontend<br/>browser UI<br/>[index.astro]"]
  node_alternate_api_client["API client<br/>browser API boundary<br/>[api.ts]"]
end

node_market_data[("Historical market data<br/>external data source")]

node_market_data -->|"OHLCV / CSV"| node_root_loader
node_root_cli -->|"runs pipeline"| node_root_loader
node_root_loader -->|"prepared data"| node_root_models
node_root_models -->|"forecasts"| node_root_services
node_root_services -->|"analytics responses"| node_root_server
node_root_cli -->|"forecast output"| node_root_services
node_root_page -->|"hosts"| node_dashboard
node_dashboard -->|"requests"| node_root_api_client
node_root_api_client -.->|"analytics API"| node_root_server
node_market_data -->|"OHLCV / CSV"| node_expanded_loader
node_expanded_cli -->|"runs pipeline"| node_expanded_loader
node_expanded_loader -->|"clean data"| node_expanded_features
node_expanded_features -->|"feature table"| node_expanded_models
node_expanded_models -->|"forecasts"| node_expanded_services
node_expanded_services -->|"analytics responses"| node_expanded_server
node_auth -->|"protects"| node_expanded_server
node_cache_storage -->|"cached / persisted state"| node_expanded_services
node_expanded_cli -->|"forecast output"| node_expanded_services
node_alternate_page -->|"uses"| node_alternate_api_client
node_alternate_api_client -.->|"analytics API"| node_expanded_server

click node_root_cli "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/cli.py"
click node_root_loader "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/data_loader.py"
click node_root_models "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/models.py"
click node_root_services "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/services.py"
click node_root_server "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/server.py"
click node_expanded_cli "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/cli.py"
click node_expanded_loader "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/loader.py"
click node_expanded_features "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/features.py"
click node_expanded_models "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/models.py"
click node_expanded_services "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/services.py"
click node_expanded_server "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/server.py"
click node_auth "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/auth.py"
click node_cache_storage "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/storage.py"
click node_root_page "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/src/pages/index.astro"
click node_dashboard "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/src/components/react/Dashboard.tsx"
click node_root_api_client "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/src/lib/api.ts"
click node_alternate_page "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-frontend/src/pages/index.astro"
click node_alternate_api_client "https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-frontend/src/lib/api.ts"

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_root_cli,node_root_loader,node_root_models,node_root_services,node_root_server toneBlue
class node_expanded_cli,node_expanded_loader,node_expanded_features,node_expanded_models,node_expanded_services,node_expanded_server,node_auth,node_cache_storage toneAmber
class node_root_page,node_dashboard,node_root_api_client toneMint
class node_alternate_page,node_alternate_api_client toneRose
class node_market_data toneNeutral
```

## Components

### Root Python backend

- [Forecast CLI](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/cli.py): Python entry point · Primary documented forecasting workflow. · `cli.py`
- [Data loader](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/data_loader.py): data acquisition · Loads and prepares market datasets. · `data_loader.py`
- [Forecast models](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/models.py): analytics runtime · Technical analysis and forecasting model logic. · `models.py`
- [Analytics services](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/services.py): orchestration · Coordinates forecasts, assessments, and signals. · `services.py`
- [Analytics server](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/server.py): backend API · Browser-facing analytics boundary. · `server.py`

### Expanded backend snapshot

A parallel, more modular copy under nse-stock-predictor-zip/.

- [Forecast CLI](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/cli.py): Python entry point · `nse-stock-predictor-zip/cli.py`
- [Load and clean](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/loader.py): data pipeline · Acquisition, validation, and cleaning stages. · `nse-stock-predictor-zip/loader.py`
- [Technical features](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/features.py): feature engineering · Indicators and price-pattern features. · `nse-stock-predictor-zip/features.py`
- [Forecast models](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/models.py): ML runtime · scikit-learn, XGBoost, and TensorFlow/Keras model logic. · `nse-stock-predictor-zip/models.py`
- [Analytics services](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/services.py): orchestration · Produces forecasts, trend assessments, and rule-based signals. · `nse-stock-predictor-zip/services.py`
- [Analytics server](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/server.py): backend API · `nse-stock-predictor-zip/server.py`
- [Authentication](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/auth.py): security · `nse-stock-predictor-zip/auth.py`
- [Cache and storage](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-stock-predictor-zip/storage.py): state layer · Caching and persistence abstractions. · `nse-stock-predictor-zip/storage.py`

### Root dashboard

- [Dashboard page](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/src/pages/index.astro): Astro page · Hosts the React dashboard island. · `src/pages/index.astro`
- [Analytics dashboard](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/src/components/react/Dashboard.tsx): React UI · Composes metrics, index tiles, screener, signals, and sparklines. · `src/components/react/Dashboard.tsx`
- [API client and types](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/src/lib/api.ts): browser API boundary · Isolates backend calls and shared API/domain shapes. · `src/lib/api.ts`

### Separate Astro frontend

- [Astro frontend](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-frontend/src/pages/index.astro): browser UI · Separate Astro-only frontend with its own API client. · `nse-frontend/src/pages/index.astro`
- [API client](https://github.com/pankajsinghdeveloper26/nse-stock-predictor/blob/main/nse-frontend/src/lib/api.ts): browser API boundary · `nse-frontend/src/lib/api.ts`

### Other components

- **Historical market data**: external data source · yFinance access or local CSV OHLCV input.

## Connections

- Historical market data → Data loader: OHLCV / CSV
- Forecast CLI → Data loader: runs pipeline
- Data loader → Forecast models: prepared data
- Forecast models → Analytics services: forecasts
- Analytics services → Analytics server: analytics responses
- Forecast CLI → Analytics services: forecast output
- Dashboard page → Analytics dashboard: hosts
- Analytics dashboard → API client and types: requests
- API client and types → Analytics server: analytics API · API contract must be established for the canonical backend.
- Historical market data → Load and clean: OHLCV / CSV
- Forecast CLI → Load and clean: runs pipeline
- Load and clean → Technical features: clean data
- Technical features → Forecast models: feature table
- Forecast models → Analytics services: forecasts
- Analytics services → Analytics server: analytics responses
- Authentication → Analytics server: protects
- Cache and storage → Analytics services: cached / persisted state
- Forecast CLI → Analytics services: forecast output
- Astro frontend → API client: uses
- API client → Analytics server: analytics API · Potential client/server pairing; duplicates require canonicalization.
