How collab-with-sudhar/stock-market-decision-optimizer works
Purpose and System Shape
An end-to-end trading decision platform: reinforcement-learning models generate BUY/HOLD/SELL signals from market data; a Node backend exposes authenticated trading/monitoring APIs; a React client visualizes portfolio, orders, decisions, and live updates. Python services support model training, inference, and market-data streaming.
Client Application and Entry
The Vite/React SPA starts at client/src/main.jsx and composes routing/application state in client/src/App.jsx. Dashboard-oriented pages cover landing, authentication, portfolio, orders, and operational views under client/src/pages/. client/src/components/DashboardLayout.jsx forms the authenticated workspace shell.
Client State, API, and Live Updates
Redux slices partition client state for auth, orders, portfolio, trades, signals, charts, and WebSocket status in client/src/redux/store.js, client/src/redux/signalsSlice.js, and client/src/redux/websocketSlice.js. HTTP calls are centralized through Axios/API wrappers (client/src/api/axiosInstance.js, client/src/api/api.js), while socket lifecycle and event consumption are handled by client/src/services/socket.js and client/src/hooks/useWebSocket.js. Protected navigation is enforced client-side by client/src/components/ProtectedRoute.jsx.
Backend API and Trading Boundary
The Node server enters at server/index.js; configuration is established in server/config.js. Route groups separate authentication, market access, signals, monitoring, and trading: server/routes/auth.js, server/routes/market.js, and server/routes/trading.js. Controllers implement request-level orchestration (server/controllers/userController.js, server/controllers/marketController.js, server/controllers/tradingController.js), with JWT middleware at server/middlewares/auth.js.
Execution, Decisions, and Persistence
Trading orchestration crosses two critical service boundaries: model prediction via server/services/modelClient.js, and broker/order execution through server/services/executionAdapter.js. Persistent domain records represent users/accounts and trading lifecycle state: server/models/userModel.js, server/models/Order.js, server/models/Position.js, server/models/Trade.js, and server/models/Decision.js. This is the audit boundary between generated signals, submitted orders, fills/positions, and user-visible portfolio metrics.
Model Serving and RL Lifecycle
A Python model-serving process is rooted at model_server/app.py; it loads artifacts from models/, including NIFTY PPO and DQN models such as models/ppo_nifty_finetuned.zip and models/dqn_nifty.zip. The ML pipeline defines trading environments in src/envs/gym_trading_env.py and src/envs/trading_env_improved.py, with training/inference/evaluation entry scripts in src/train_ppo.py, src/model_inference.py, and src/evaluate_ppo.py. Prepared and raw NIFTY data live in data/processed/NIFTY_15m_enriched.csv and data/raw/^NSEI.csv.
Real-Time Market Feed
The realtime subsystem integrates SmartAPI-style market access: realtime/smartapi_streamer.py receives ticks, realtime/tick_to_candle.py converts them into candle data, and realtime/market_schedule.py gates activity around market hours. Its output is the likely operational input to signal inference and backend market/monitoring endpoints. Relevant external dependencies are the broker/SmartAPI service, the Python model server, database infrastructure implied by server models, and Vercel client deployment configuration at client/vercel.json.
Main entry points: DashboardLayout.jsx Dashboard workspace · trading.js Trading API · auth.js Auth boundary · index.js API server
Components 21
React Client
- SPA entry
client/src/main.jsx - App routing
client/src/App.jsx - Dashboard workspace · Portfolio, orders, decisions, and operational views.
client/src/components/DashboardLayout.jsx - Client state · Auth, portfolio, orders, trades, signals, charts, and socket state.
client/src/redux/store.js - HTTP API client
client/src/api/axiosInstance.js - Live updates
client/src/services/socket.js
Node Backend
- API server
server/index.js - Auth boundary
server/middlewares/auth.js - Trading API · Orchestrates order and decision requests.
server/routes/trading.js - Market API · Serves market and monitoring access.
server/routes/market.js - Model client
server/services/modelClient.js - Execution adapter
server/services/executionAdapter.js - Trading records · Users, orders, positions, trades, and decisions form the audit trail.
server/models/Decision.js
RL Model Pipeline
- Model serving · Loads trained RL artifacts and returns trading predictions.
model_server/app.py - Trading environment
src/envs/gym_trading_env.py - PPO training
src/train_ppo.py - RL model artifacts
models/ppo_nifty_finetuned.zip
Market Data Stream
- Tick stream
realtime/smartapi_streamer.py - Candle builder · Converts scheduled ticks into candle data.
realtime/tick_to_candle.py
Other components
- Broker / SmartAPI
- Database
Connections 23
- SPA entry → App routing: mounts
- App routing → Dashboard workspace: renders protected workspace
- Dashboard workspace → Client state: reads and updates
- Dashboard workspace → HTTP API client: requests data
- Dashboard workspace → Live updates: subscribes
- HTTP API client → API server: HTTPS API
- Live updates → API server: live events
- API server → Auth boundary: authenticates requests
- Auth boundary → Trading API: authorizes
- Auth boundary → Market API: authorizes
- Trading API → Model client: requests signal
- Model client → Model serving: prediction request
- Trading API → Execution adapter: submits order
- Execution adapter → Broker / SmartAPI: executes orders
- Trading API → Trading records: records decisions and lifecycle
- Market API → Trading records: reads portfolio state
- Trading records → Database: persists
- Broker / SmartAPI → Tick stream: market ticks
- Tick stream → Candle builder: ticks
- Candle builder → Model serving: inference input
- Trading environment → PPO training: simulates trading
- PPO training → RL model artifacts: produces
- RL model artifacts → Model serving: loaded by