How gbnathworkspace/stockservs works
Purpose and Entry Points
Stock Servs is a market-data and virtual-trading platform centered on Indian equities, F&O/options, portfolios, watchlists, and market analytics. The Python backend starts from main.py; database initialization is represented by init_db.py and setup_db.py. The primary React/Vite client starts at frontend/src/main.jsx and renders frontend/src/App.jsx.
Backend API Boundary
The backend is organized as route modules that expose domain APIs and delegate business work to services. Major API surfaces include authentication, users, market data, broker connectivity, portfolios, and watchlists: routes/auth.py, routes/market_data.py, routes/fyers.py, routes/portfolio.py, and routes/watchlist.py. Specialized analytical/trading endpoints are split into routes/option_apex.py, routes/option_clock.py, routes/market_pulse.py, routes/swing_spectrum.py, and routes/insider_strategy.py.
Service and Market-Data Layer
Services isolate data acquisition, caching, scheduling, and domain calculations from HTTP routes. Core components are services/market_data_service.py, services/cache.py, services/data_scheduler.py, services/fii_dii_scheduler.py, and services/portfolio_service.py. Broker-facing integrations are encapsulated in services/fyers_service.py and services/zerodha_service.py, providing a boundary between application workflows and external trading/data-provider APIs.
NSE Ingestion and Analytics
NSE-specific source adapters provide discrete market datasets—indices, F&O, movers, sector data, activity, delivery, and FII/DII figures—under nse_data/indices.py, nse_data/fno.py, nse_data/movers.py, nse_data/fii_dii.py, and nse_data/most_active.py. Symbol master files in data/symbols/NSE_CM.csv and data/symbols/NSE_FO.csv support cash-market and derivatives instrument lookup. Scheduled fetching and caching should feed API services rather than the frontend directly.
Persistence
Database access is centralized through connection, ORM/model, and repository layers: database/connection.py, database/models.py, and database/repository.py. This boundary likely owns persisted users, credentials or broker state, portfolios/orders, and watchlists. Schema lifecycle is handled through init_db.py, setup_db.py, and SQL migrations such as migrations/add_is_default_to_watchlists.sql.
Frontend Application
The React single-page application provides dashboard, market-data, FII/DII, watchlist, wallet, order-history, settings, and documentation views: frontend/src/components/sections/Dashboard.jsx, frontend/src/components/sections/MarketData.jsx, frontend/src/components/sections/Watchlist.jsx, frontend/src/components/sections/FiiDiiActivity.jsx, and frontend/src/components/sections/OrderHistory.jsx. Virtual trading is assembled from trading views and trade/chart modals in frontend/src/components/VirtualTrading.jsx, frontend/src/components/trading/TradeModal.jsx, and frontend/src/components/trading/PortfolioView.jsx. HTTP communication is centralized at frontend/src/lib/api.js; shared loading, theme, and notification state use frontend/src/contexts/LoadingContext.jsx, frontend/src/contexts/ThemeContext.jsx, and frontend/src/contexts/ToastContext.jsx.
Runtime and Deployment
The system uses a Python backend runtime with dependencies declared in requirements.txt, plus a Node/Vite frontend defined by frontend/package.json and frontend/vite.config.js. Container and process deployment artifacts are Dockerfile, Procfile, and render.yaml; automated deployment is configured at .github/workflows/deploy.yml. Built frontend assets also exist under static/app/index.html, indicating the backend may serve a production frontend bundle.
Main entry points: main.py Backend entry · market_data.py Core domain APIs · market_data_service.py Market-data service · data_scheduler.py Data schedulers
Components 21
React Client
- React entry
frontend/src/main.jsx - Application shell
frontend/src/App.jsx - Market & portfolio views · Dashboard, market, watchlist, FII/DII, and order-history screens.
frontend/src/components/sections/Dashboard.jsx - Virtual trading UI
frontend/src/components/VirtualTrading.jsx - HTTP client
frontend/src/lib/api.js
Python API
- Backend entry
main.py - Core domain APIs · Authentication, market data, broker, portfolio, and watchlist APIs.
routes/market_data.py - Analytics & strategy APIs · Options, pulse, swing, and insider strategy endpoints.
routes/option_apex.py
Market Services
- Market-data service
services/market_data_service.py - Portfolio service
services/portfolio_service.py - Broker integrations · Fyers and Zerodha integration boundary.
services/fyers_service.py - Market cache
services/cache.py - Data schedulers · Refreshes market and FII/DII datasets.
services/data_scheduler.py
Data & Persistence
- NSE source adapters · Indices, F&O, movers, activity, and FII/DII sources.
nse_data/indices.py - NSE symbol masters · Cash and derivatives symbol lookup.
data/symbols/NSE_CM.csv - Repository layer
database/repository.py - ORM models
database/models.py - Application database · Stores users, broker state, portfolios, orders, and watchlists.
database/connection.py - Schema lifecycle · Initialization, setup, and SQL migrations.
init_db.py
Runtime & Delivery
- Deployment runtime · Container, process, Render, and GitHub deployment artifacts.
Dockerfile - Production frontend bundle · Backend-served built SPA assets.
static/app/index.html
Connections 24
- React entry → Application shell: renders
- Application shell → Market & portfolio views: hosts
- Application shell → Virtual trading UI: hosts
- Market & portfolio views → HTTP client: uses
- Virtual trading UI → HTTP client: uses
- HTTP client → Backend entry: HTTP requests
- Backend entry → Core domain APIs: mounts
- Backend entry → Analytics & strategy APIs: mounts
- Core domain APIs → Market-data service: delegates market work
- Core domain APIs → Portfolio service: delegates portfolio work
- Core domain APIs → Broker integrations: delegates broker work
- Analytics & strategy APIs → Market-data service: uses market data
- Market-data service → Market cache: reads and writes
- Data schedulers → NSE source adapters: fetches from
- Data schedulers → NSE symbol masters: uses instruments
- Data schedulers → Market cache: refreshes
- Market-data service → NSE source adapters: acquires data
- Portfolio service → Repository layer: persists through
- Broker integrations → Repository layer: stores state through
- Repository layer → ORM models: uses
- ORM models → Application database: maps to
- Schema lifecycle → Application database: initializes
- Deployment runtime → Backend entry: runs
- Backend entry → Production frontend bundle: serves