How kishorejegan/nifty-optionchain-ai works
Purpose and Product Surface
NIFTY-OPTIONCHAIN-AI is a B2C SaaS for Indian NIFTY options traders: it collects/analyzes option-chain market data, produces AI-assisted trading insights, supports automated monitoring/alerts, and exposes chat and analysis interfaces. The repo contains multiple client implementations and legacy/alternate artifacts; the primary server-side product is under Backend/.
Backend API Runtime
The FastAPI-style application is entered through Backend/app/main.py, with application settings in Backend/app/config.py. HTTP concerns are separated into route modules for market data, analysis, recipes, control operations, and files:
• Backend/app/routers/market.py
• Backend/app/routers/analysis.py
• Backend/app/routers/recipes.py
Cross-cutting request boundaries include Firebase authentication, logging, rate limiting, and security middleware:
• Backend/app/auth/firebase_auth.py
• Backend/app/middleware/rate_limit.py
• Backend/app/middleware/security.py
Market Data and Quantitative Analysis
Market acquisition is centered on an NSE client and supporting scraper paths, then passed into analysis/domain models. The main boundary isolates external NSE responses from API-facing market representations:
• Backend/app/services/nse_client.py
• Backend/nse_scraper.py
• Backend/app/models/market.py
Quant modules calculate option-chain signals such as open-interest/strike analysis, divergence, charts, and trading logic:
• Backend/ai_brain/data_engine.py
• Backend/ai_brain/strike_analyzer.py
• Backend/ai_brain/quant_logic.py
This data layer is the core dependency for both direct market endpoints and AI-driven analysis.
AI Agent and Orchestration Layer
ai_brain is a separate intelligence subsystem, with an agent core, tool registry, tool implementations, and persistence/auth support:
• Backend/ai_brain/agent/agent_core.py
• Backend/ai_brain/agent/tool_registry.py
• Backend/ai_brain/agent/tools/analysis_tools.py
The agent can invoke market, analysis, scheduling, and alert tools rather than coupling LLM conversation directly to data sources. Higher-level application orchestration coordinates analysis execution, classification, RAG, safety, and recipe-driven workflows:
• Backend/app/services/orchestrator.py
• Backend/app/services/analysis_runner.py
• Backend/app/services/rag.py
LLM/server and conversational entry modules exist in Backend/ai_brain/llm_server.py and Backend/ai_brain/copilot.py; provider credentials/configuration are expected through environment files.
Alerts, Notifications, and Persistence Boundaries
Alert evaluation is modeled in the agent layer and exposed through application notification services:
• Backend/ai_brain/agent/alert_engine.py
• Backend/ai_brain/agent/tools/alert_tools.py
• Backend/app/services/notifications.py
Firebase is the material external identity/backend integration, used via:
• Backend/app/auth/firebase_auth.py
• Backend/app/services/firebase.py
Recipes provide reusable/user-configurable analysis or automation flows:
• Backend/app/services/recipe_engine.py
• Backend/app/models/recipe.py
• Backend/app/routers/recipes.py
Client and Extension Entry Points
A Vite/React browser extension client lives in Backend/extension/, beginning at Backend/extension/src/main.jsx and communicating through Backend/extension/src/services/api.js; Chrome extension lifecycle is configured in Backend/extension/public/manifest.json.
A richer TypeScript Vite UI exists independently in New UI/, with app composition and workspace tabs at:
• New UI/src/main.tsx
• New UI/src/App.tsx
• New UI/src/components/AgentWorkspace.tsx
intraday-extension/ appears to be another packaged extension variant, with its own API client and manifest:
• intraday-extension/src/services/api.ts
• intraday-extension/public/manifest.json
Operational Entry Points and Infrastructure
Standalone scripts support server/system startup and market-monitor/analysis modes:
• Backend/server.py
• Backend/start_all.py
• Backend/run_analysis_system.py
Python dependencies are split between backend and AI-brain requirements:
• Backend/requirements.txt
• Backend/ai_brain/requirements.txt
GitHub Actions defines backend and extension CI workflows:
• Backend/.github/workflows/backend.yml
• Backend/.github/workflows/extension.yml
Main entry points: main.py FastAPI application · orchestrator.py Analysis orchestrator · nse_client.py NSE market client · agent_core.py Agent core
Components 20
Backend API
- FastAPI application
Backend/app/main.py - Auth & request controls · Firebase auth, rate limiting, and security boundaries.
Backend/app/auth/firebase_auth.py - Market API
Backend/app/routers/market.py - Analysis API
Backend/app/routers/analysis.py - Recipe API
Backend/app/routers/recipes.py - NSE market client · Normalizes external NSE market responses.
Backend/app/services/nse_client.py - Market models
Backend/app/models/market.py - Analysis orchestrator · Coordinates analysis, RAG, safety, and workflows.
Backend/app/services/orchestrator.py - Recipe engine
Backend/app/services/recipe_engine.py - Notifications
Backend/app/services/notifications.py
AI & Quant Engine
- Quant data engine · Computes option-chain signals and trading logic.
Backend/ai_brain/data_engine.py - Agent core
Backend/ai_brain/agent/agent_core.py - Agent tool registry
Backend/ai_brain/agent/tool_registry.py - Alert engine
Backend/ai_brain/agent/alert_engine.py - LLM server
Backend/ai_brain/llm_server.py
Clients
- Browser extension
Backend/extension/src/main.jsx - Trader workspace UI
New UI/src/App.tsx - Intraday extension
intraday-extension/src/services/api.ts
Other components
- Firebase
Backend/app/services/firebase.py - NSE
Connections 22
- Browser extension → FastAPI application: API calls
- Trader workspace UI → FastAPI application: API calls
- Intraday extension → FastAPI application: API calls
- FastAPI application → Auth & request controls: applies
- Auth & request controls → Firebase: verifies identity
- FastAPI application → Market API: serves
- FastAPI application → Analysis API: serves
- FastAPI application → Recipe API: serves
- Market API → NSE market client: fetches
- NSE market client → NSE: acquires data
- NSE market client → Market models: maps to
- Market models → Quant data engine: feeds
- Analysis API → Analysis orchestrator: runs
- Analysis orchestrator → Quant data engine: executes analysis
- Analysis orchestrator → Agent core: delegates AI tasks
- Agent core → LLM server: uses
- Agent core → Agent tool registry: invokes tools
- Agent tool registry → Quant data engine: analysis tools
- Agent tool registry → Alert engine: alert tools
- Alert engine → Notifications: triggers
- Recipe API → Recipe engine: manages flows
- Recipe engine → Analysis orchestrator: executes workflows