# deshwalmahesh/nse-stock-scanner architecture

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

- Interactive diagram: https://gitdiagram.com/deshwalmahesh/nse-stock-scanner
- Repository: https://github.com/deshwalmahesh/nse-stock-scanner

## Overview

1. **Overall shape**
   - This is a **local, notebook-driven stock analysis toolkit**, not a deployed service.
   - The primary user entry point is **`Tutorial.ipynb`**, which orchestrates code in `helpers/`.
   - Execution is done in a **Python/Jupyter kernel** with file-based inputs and outputs.

2. **Main orchestration boundary**
   - The notebook layer is the “UI” of the project: users run cells to fetch data, scan stocks, plot charts, backtest, and inspect results.
   - The reusable business logic lives in the **`helpers/` package**, so the notebook stays relatively thin and interactive.

3. **Data acquisition subsystem**
   - `helpers/nse_data.py` is the main boundary for **NSE market data access**.
   - The repo supports both **historical data** and **live data**, with README emphasis on multiple intraday intervals.
   - `helpers/online_brokers.py` suggests a separate adapter layer for broker/platform connectivity rather than mixing it into strategy code.

4. **Local market data store**
   - The `data/` directory contains a large set of **per-stock CSV files**, one file per NSE symbol with date-stamped historical records.
   - `data.json` appears to act as a **metadata/config index** for the dataset.
   - This means the system can run largely **offline against cached market history**, while live feeds are an add-on path.

5. **Strategy and signal engine**
   - `helpers/investing.py`, `helpers/intraday.py`, and `helpers/FnO.py` partition the logic by trading style:
     - **Swing / investing-style screening**
     - **Intraday scanning**
     - **Futures & options support**
   - The README’s supported indicators and setups indicate the engine computes signals from price series, indicator values, and pattern checks.

6. **Technical analysis layer**
   - `helpers/candlestick.py` handles **candlestick pattern recognition**.
   - `helpers/stock_analyser.py` likely ties together indicators, filters, and ranking logic for the stock scanner.
   - The project’s outputs are not just raw indicators; they are **actionable candidate lists** based on combined technical conditions.

7. **Risk and trade planning**
   - `helpers/risk_management.py` is a distinct subsystem for **entry, stop-loss, target, and position sizing logic**.
   - This is important architecturally because the scanner does not only “find stocks”; it also emits a **trade plan** and risk-aware recommendation.
   - The README also references expected change, risk appetite, and budget-based filtering, which are part of this boundary.

8. **Backtesting subsystem**
   - `helpers/backtest.py` provides the simulation layer for validating strategies on historical data.
   - README mentions built-in backtests for **CCI, MACD, RSI, Stochastic, and Moving Average** strategies.
   - Architecturally, this is a separate consumer of the same historical data and indicator pipeline used by the live scanner.

9. **Visualization and reporting**
   - `helpers/plotting.py` is the chart/report boundary for turning time series into visual analysis.
   - `helpers/journal_handler.py` supports **trade journaling and post-trade analysis**, likely reading/writing spreadsheet-like records.
   - These modules sit at the output end of the pipeline: they don’t decide signals, they present and record them.

10. **Market structure / intraday context**
   - `helpers/experimental/trading_alerts.py` and related experimental modules suggest support for **market mood, alerts, and sentiment-like context**.
   - The README’s “market mood” features imply this project can combine stock-level scans with broader **sector/index context** for intraday decisions.
   - This is a higher-level aggregation layer above single-symbol analysis.

11. **Experimental boundary**
   - `helpers/experimental/psychology.py`, `risk_management.py`, `strategies_signals.py`, and `trading_alerts.py` are clearly separated from the main stable helpers.
   - They represent **R&D / extension code**, not the core runtime path.
   - For a diagram, treat them as optional satellite modules feeding ideas or alerts into the core scanner, not as mandatory dependencies.

12. **Repository content that is not runtime**
   - `ebooks/` is reference material, not part of the execution flow.
   - `.ipynb_checkpoints/` and `__pycache__` are development artifacts.
   - `requirements.txt` defines the Python dependency boundary for local setup.

13. **End-to-end data flow**
   - The typical flow is: **market data source or CSV cache → helper modules compute indicators/patterns → scanner ranks candidates → plotting/reporting shows results → journal/backtest validates or records outcomes**.
   - Broker integration, if used, is an optional branch off the analysis path rather than the center of the system.

14. **What to diagram as the core architecture**
   - Draw the project as a **local analytical engine** with these main boxes:
     - Notebook orchestrator
     - NSE/live data ingestion
     - Local CSV/historical store
     - Indicator/strategy engine
     - Risk management
     - Backtesting
     - Visualization/journaling
     - Optional broker/alert integrations
   - The key architectural idea is that **the same historical/live price data feeds multiple consumers**: screening, charting, backtesting, and journaling.

Main entry points: [`helpers/stock_analyser.py`](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/stock_analyser.py) (Stock analyser), [`Tutorial.ipynb`](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/Tutorial.ipynb) (Tutorial), [`helpers/risk_management.py`](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/risk_management.py) (Risk rules), [`data`](https://github.com/deshwalmahesh/nse-stock-scanner/tree/main/data) (Local cache)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Notebook layer"]
  node_n1["Tutorial<br/>notebook orchestrator<br/>[Tutorial.ipynb]"]
end

subgraph group_g2["Market data"]
  node_n2[("NSE data<br/>data access<br/>[nse_data.py]")]
  node_n3["Broker adapters<br/>integration<br/>[online_brokers.py]"]
  node_n4[("Local cache<br/>csv store")]
  node_n5["Data index<br/>metadata<br/>[data.json]"]
  node_n6["Data handler<br/>loader<br/>[datahandler.py]"]
end

subgraph group_g3["Analysis engine"]
  node_n7["Investing<br/>swing scanner<br/>[investing.py]"]
  node_n8["Intraday<br/>scan engine<br/>[intraday.py]"]
  node_n9["FnO<br/>derivatives<br/>[FnO.py]"]
  node_n10["Stock analyser<br/>ranking engine<br/>[stock_analyser.py]"]
  node_n11["Candlestick<br/>pattern analysis<br/>[candlestick.py]"]
  node_n12["Risk rules<br/>trade planning<br/>[risk_management.py]"]
  node_n16["Alerts<br/>context layer<br/>[trading_alerts.py]"]
  node_n17["Signals R&D<br/>experimental"]
  node_n18["Psychology<br/>experimental<br/>[psychology.py]"]
end

subgraph group_g4["Outputs and validation"]
  node_n13["Backtest<br/>simulation<br/>[backtest.py]"]
  node_n14["Plotting<br/>visualization<br/>[plotting.py]"]
  node_n15["Journal<br/>trade log<br/>[journal_handler.py]"]
end

node_n1 -->|"uses"| node_n6
node_n1 -->|"fetches"| node_n2
node_n1 -->|"reads"| node_n4
node_n1 -->|"plots"| node_n14
node_n1 -->|"backtests"| node_n13
node_n2 -->|"caches"| node_n4
node_n2 -.->|"optional route"| node_n3
node_n5 -->|"indexes"| node_n4
node_n6 -->|"loads"| node_n4
node_n6 -->|"resolves"| node_n5
node_n6 -->|"adapts"| node_n2
node_n7 -->|"feeds"| node_n10
node_n8 -->|"feeds"| node_n10
node_n9 -->|"feeds"| node_n10
node_n10 -->|"checks"| node_n11
node_n10 -->|"plans"| node_n12
node_n11 -->|"informs"| node_n12
node_n7 -->|"applies"| node_n12
node_n8 -->|"applies"| node_n12
node_n13 -->|"replays"| node_n4
node_n13 -->|"validates"| node_n10
node_n14 -->|"renders"| node_n10
node_n15 -->|"records"| node_n12
node_n16 -.->|"augments"| node_n8
node_n17 -.->|"proposes"| node_n10
node_n18 -.->|"influences"| node_n12

click node_n1 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/Tutorial.ipynb"
click node_n2 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/nse_data.py"
click node_n3 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/online_brokers.py"
click node_n4 "https://github.com/deshwalmahesh/nse-stock-scanner/tree/main/data"
click node_n5 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/data.json"
click node_n6 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/datahandler.py"
click node_n7 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/investing.py"
click node_n8 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/intraday.py"
click node_n9 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/FnO.py"
click node_n10 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/stock_analyser.py"
click node_n11 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/candlestick.py"
click node_n12 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/risk_management.py"
click node_n13 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/backtest.py"
click node_n14 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/plotting.py"
click node_n15 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/journal_handler.py"
click node_n16 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/experimental/trading_alerts.py"
click node_n17 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/experimental/strategies_signals.py"
click node_n18 "https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/experimental/psychology.py"

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_n1 toneBlue
class node_n2,node_n3,node_n4,node_n5,node_n6 toneAmber
class node_n7,node_n8,node_n9,node_n10,node_n11,node_n12,node_n16,node_n17,node_n18 toneMint
class node_n13,node_n14,node_n15 toneRose
```

## Components

### Notebook layer

Interactive Jupyter entry point and local execution context.

- [Tutorial](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/Tutorial.ipynb): notebook orchestrator · Primary interactive entry point for running scans, charts, backtests, and analysis cells. · `Tutorial.ipynb`

### Market data

Historical cache plus live NSE and broker adapters.

- [NSE data](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/nse_data.py): data access · Main market data boundary for historical and live NSE price retrieval. · `helpers/nse_data.py`
- [Broker adapters](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/online_brokers.py): integration · Optional connectivity layer for online broker or platform access. · `helpers/online_brokers.py`
- [Local cache](https://github.com/deshwalmahesh/nse-stock-scanner/tree/main/data): csv store · Per-symbol historical CSV archive used for offline and cached analysis. · `data`
- [Data index](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/data.json): metadata · Repository index or dataset catalog for local market files. · `data.json`
- [Data handler](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/datahandler.py): loader · Shared file and dataset handling utilities that bridge notebook and stored market data. · `helpers/datahandler.py`

### Analysis engine

Core screening, indicators, strategy, and risk logic.

- [Investing](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/investing.py): swing scanner · Swing and investing-style screening logic over price series and indicators. · `helpers/investing.py`
- [Intraday](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/intraday.py): scan engine · Intraday analysis path for shorter interval market scanning. · `helpers/intraday.py`
- [FnO](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/FnO.py): derivatives · Futures and options analysis support. · `helpers/FnO.py`
- [Stock analyser](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/stock_analyser.py): ranking engine · Combines indicator checks, filters, and candidate ranking into actionable stock picks. · `helpers/stock_analyser.py`
- [Candlestick](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/candlestick.py): pattern analysis · Candlestick pattern recognition used by the signal engine. · `helpers/candlestick.py`
- [Risk rules](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/risk_management.py): trade planning · Entry, stop-loss, target, sizing, and budget-aware trade planning logic. · `helpers/risk_management.py`
- [Alerts](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/experimental/trading_alerts.py): context layer · Market mood and trading alert support for broader intraday context. · `helpers/experimental/trading_alerts.py`
- [Signals R&D](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/experimental/strategies_signals.py): experimental · Experimental strategy and signal ideas outside the core runtime path. · `helpers/experimental/strategies_signals.py`
- [Psychology](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/experimental/psychology.py): experimental · R&D module for trader psychology and behavioral ideas. · `helpers/experimental/psychology.py`

### Outputs and validation

Charts, journals, and simulation results.

- [Backtest](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/backtest.py): simulation · Historical strategy validation over cached market data and indicator pipelines. · `helpers/backtest.py`
- [Plotting](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/plotting.py): visualization · Charting and reporting boundary for time series and analysis output. · `helpers/plotting.py`
- [Journal](https://github.com/deshwalmahesh/nse-stock-scanner/blob/main/helpers/journal_handler.py): trade log · Trade journaling and post-trade record handling. · `helpers/journal_handler.py`

## Connections

- Tutorial → Data handler: uses · Notebook cells call shared loaders and helpers.
- Tutorial → NSE data: fetches · Interactive analysis pulls market data from NSE access layer.
- Tutorial → Local cache: reads · Notebook works against local CSV history when available.
- Tutorial → Plotting: plots · Notebook renders charts and analysis views.
- Tutorial → Backtest: backtests · Notebook runs strategy validation workflows.
- NSE data → Local cache: caches · Live or historical data can be persisted into local CSV files.
- NSE data → Broker adapters: optional route · Broker connectivity extends the data acquisition path.
- Data index → Local cache: indexes · Metadata catalog describes the local dataset.
- Data handler → Local cache: loads · File handling utilities read symbol CSVs.
- Data handler → Data index: resolves · Loader can use the dataset index to locate assets.
- Data handler → NSE data: adapts · Shared handler sits between notebook code and market data access.
- Investing → Stock analyser: feeds · Investing scans feed the ranking/analyser boundary.
- Intraday → Stock analyser: feeds · Intraday scans feed candidate selection.
- FnO → Stock analyser: feeds · F&O logic contributes to stock analysis and screening.
- Stock analyser → Candlestick: checks · Stock analysis incorporates candlestick pattern recognition.
- Stock analyser → Risk rules: plans · Selected candidates are translated into trade plans and risk levels.
- Candlestick → Risk rules: informs · Pattern context can influence trade planning and stops.
- Investing → Risk rules: applies · Swing workflows use risk management before recommendations.
- Intraday → Risk rules: applies · Intraday workflows use risk management before recommendations.
- Backtest → Local cache: replays · Backtests consume historical CSV data.
- Backtest → Stock analyser: validates · Simulation validates the same signal pipeline used for screening.
- Plotting → Stock analyser: renders · Visualization presents scanner outputs and series analysis.
- Journal → Risk rules: records · Journals capture executed or recommended trade plans.
- Alerts → Intraday: augments · Alerts add market context to intraday analysis.
- Signals R&D → Stock analyser: proposes · Experimental signals can feed ideas into the core analyser.
- Psychology → Risk rules: influences · Psychology experiments relate to decision and risk framing.
