The backend (nifty_fifty_bank_nifty_NodeJS) is an Express + TypeScript API that handles authentication, index configuration, Zerodha broker integration, automated trading strategies, and real-time market data distribution.

Repository

This folder is a standalone git repository with its own remote, separate from the React frontend.

Tech stack

Architecture

Request flow:
  1. REST requests hit Express routes → controller → Mongoose models / Zerodha SDK.
  2. Socket.io clients connect with ?userId=<id> and receive order, settings, and tick events.
  3. Cron jobs in app.ts handle daily token refresh, market session open/close, and data cleanup.
  4. All live order placement converges on handlePlaceOrder in zerodha.controller.ts.

API routes

All routes are mounted under /api (see routes/index.ts).

Notable Zerodha endpoints

See the full API Reference section for request/response details.

Database models

See Database models overview for field-level documentation.

Real-time events (Socket.io)

Socket connects with ?userId=<id> query param. Key event groups from socket-manager.ts: The in-memory latestDataMap cache is updated alongside tick broadcasts and is read by recurring buy and trailing sell controllers.

Scheduled jobs

Defined in app.ts via node-schedule (timezone: Asia/Kolkata by default). Market hour defaults are configurable via env vars (MCX_START_HOUR, NFO_START_HOUR, etc.) in marketHours.ts. Order services (recurring buy, trailing sell) are gated on market hours. Market data streaming runs whenever a valid Zerodha token exists.

Core features

Code map

For environment variables, see Backend environment. For deployment, see Production deployment.