# amit0rana/betteroptionstrading architecture

> Architecture diagram of the GitHub repository amit0rana/betteroptionstrading, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amit0rana/betteroptionstrading
- Repository: https://github.com/amit0rana/betteroptionstrading

## Overview

This repository provides browser userscripts that add trading workflows and interface features to Zerodha Kite and several other market platforms. For the main betterKite workflow, a user opens Kite, configures settings, and the script initializes before wiring page interactions to features such as holdings, positions, P&L, and order controls. Separate scripts target Upstox, Sensibull, NSE India, Sharekhan, and other sites. The graph preserves documented product branches; some feature-to-orchestrator links are dashed because the excerpts do not show those calls.

Main entry points: [`src/main.js`](https://github.com/amit0rana/betteroptionstrading/blob/master/src/main.js) (Event wiring), [`src/bootstrap/01-init.js`](https://github.com/amit0rana/betteroptionstrading/blob/master/src/bootstrap/01-init.js) (Bootstrap), [`src/features/31-positions.js`](https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/31-positions.js) (Positions), [`betterKite.user.js`](https://github.com/amit0rana/betteroptionstrading/blob/master/betterKite.user.js) (Kite userscript)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Kite startup"]
  node_kite_script["Kite userscript<br/>[betterKite.user.js]"]
  node_bootstrap["Bootstrap<br/>[01-init.js]"]
  node_main["Event wiring<br/>[main.js]"]
end

subgraph group_core["Shared core"]
  node_settings["Settings<br/>[13-settings.js]"]
  node_stored_data["Stored trading data<br/>[14-stored-data.js]"]
  node_constants["Trading constants<br/>[10-constants.js]"]
  node_dom_paths["DOM paths<br/>[11-dom-paths.js]"]
  node_utils["Utilities<br/>[12-utils.js]"]
  node_margin_api["Margin API<br/>[15-margin-api.js]"]
  node_row_objects["Row objects<br/>[16-row-objects.js]"]
end

subgraph group_trading["Trading features"]
  node_holdings["Holdings<br/>[30-holdings.js]"]
  node_positions["Positions<br/>[31-positions.js]"]
  node_watchlist["Watchlist<br/>[33-watchlist.js]"]
  node_pnl["P&amp;L<br/>[34-pnl.js]"]
  node_margin_saving["Margin saving"]
  node_context_menu["Context menu<br/>[36-context-menu.js]"]
  node_order_bump["Order adjustments<br/>[38-order-bump.js]"]
  node_order_window["Order window<br/>[41-order-window.js]"]
  node_order_send["Order sending<br/>[42-order-send.js]"]
end

subgraph group_platforms["Other platform scripts"]
  node_other_scripts["Other platform scripts"]
  node_upstox["Upstox"]
  node_sensibull["Sensibull"]
  node_nse["NSE India<br/>[betterNSE.user.js]"]
  node_sharekhan["Sharekhan"]
  node_oipulse["Oipulse"]
  node_stocks_dev["Stocks Developer"]
  node_trading_economics["Trading Economics"]
end

node_kite_user(("Kite user"))

node_kite_user -->|"opens Kite"| node_kite_script
node_kite_script -.->|"initializes via"| node_bootstrap
node_bootstrap -.->|"waits for settings"| node_settings
node_bootstrap -.->|"starts after init"| node_main
node_main -.->|"reads settings"| node_settings
node_main -.->|"wires interactions"| node_holdings
node_main -.->|"wires interactions"| node_positions
node_main -.->|"wires interactions"| node_watchlist
node_main -.->|"wires interactions"| node_pnl
node_main -.->|"wires interactions"| node_margin_saving
node_main -.->|"wires interactions"| node_context_menu
node_main -.->|"wires interactions"| node_order_bump
node_main -.->|"wires interactions"| node_order_window
node_main -.->|"wires interactions"| node_order_send
node_holdings -.->|"uses persisted data"| node_stored_data
node_positions -->|"uses strategies"| node_stored_data
node_positions -.->|"reads position rows"| node_row_objects
node_margin_saving -.->|"uses margin calculations"| node_margin_api
node_order_bump -.->|"adjusts pending orders"| node_order_send
node_other_scripts -->|"includes"| node_upstox
node_other_scripts -->|"includes"| node_sensibull
node_other_scripts -->|"includes"| node_nse
node_other_scripts -->|"also targets"| node_sharekhan
node_other_scripts -->|"also targets"| node_oipulse
node_other_scripts -->|"also targets"| node_stocks_dev
node_other_scripts -->|"also targets"| node_trading_economics

click node_kite_script "https://github.com/amit0rana/betteroptionstrading/blob/master/betterKite.user.js"
click node_bootstrap "https://github.com/amit0rana/betteroptionstrading/blob/master/src/bootstrap/01-init.js"
click node_main "https://github.com/amit0rana/betteroptionstrading/blob/master/src/main.js"
click node_settings "https://github.com/amit0rana/betteroptionstrading/blob/master/src/core/13-settings.js"
click node_stored_data "https://github.com/amit0rana/betteroptionstrading/blob/master/src/core/14-stored-data.js"
click node_constants "https://github.com/amit0rana/betteroptionstrading/blob/master/src/core/10-constants.js"
click node_dom_paths "https://github.com/amit0rana/betteroptionstrading/blob/master/src/core/11-dom-paths.js"
click node_utils "https://github.com/amit0rana/betteroptionstrading/blob/master/src/core/12-utils.js"
click node_margin_api "https://github.com/amit0rana/betteroptionstrading/blob/master/src/core/15-margin-api.js"
click node_row_objects "https://github.com/amit0rana/betteroptionstrading/blob/master/src/core/16-row-objects.js"
click node_holdings "https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/30-holdings.js"
click node_positions "https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/31-positions.js"
click node_watchlist "https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/33-watchlist.js"
click node_pnl "https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/34-pnl.js"
click node_margin_saving "https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/35-margin-saving.js"
click node_context_menu "https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/36-context-menu.js"
click node_order_bump "https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/38-order-bump.js"
click node_order_window "https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/41-order-window.js"
click node_order_send "https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/42-order-send.js"
click node_upstox "https://github.com/amit0rana/betteroptionstrading/blob/master/betterUpstox.user.js"
click node_sensibull "https://github.com/amit0rana/betteroptionstrading/blob/master/betterSensibull.user.js"
click node_nse "https://github.com/amit0rana/betteroptionstrading/blob/master/betterNSE.user.js"
click node_sharekhan "https://github.com/amit0rana/betteroptionstrading/blob/master/betterSharekhan.user.js"
click node_oipulse "https://github.com/amit0rana/betteroptionstrading/blob/master/betterOipulse.user.js"
click node_stocks_dev "https://github.com/amit0rana/betteroptionstrading/blob/master/betterStocksDeveloper.user.js"
click node_trading_economics "https://github.com/amit0rana/betteroptionstrading/blob/master/betterTradingeconomics.user.js"

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_kite_script,node_bootstrap,node_main,node_kite_user toneBlue
class node_settings,node_stored_data,node_constants,node_dom_paths,node_utils,node_margin_api,node_row_objects toneAmber
class node_holdings,node_positions,node_watchlist,node_pnl,node_margin_saving,node_context_menu,node_order_bump,node_order_window,node_order_send toneMint
class node_other_scripts,node_upstox,node_sensibull,node_nse,node_sharekhan,node_oipulse,node_stocks_dev,node_trading_economics toneRose
```

## Components

### Kite startup

- [Kite userscript](https://github.com/amit0rana/betteroptionstrading/blob/master/betterKite.user.js): `betterKite.user.js`
- [Bootstrap](https://github.com/amit0rana/betteroptionstrading/blob/master/src/bootstrap/01-init.js): `src/bootstrap/01-init.js`
- [Event wiring](https://github.com/amit0rana/betteroptionstrading/blob/master/src/main.js): `src/main.js`

### Shared core

- [Settings](https://github.com/amit0rana/betteroptionstrading/blob/master/src/core/13-settings.js): `src/core/13-settings.js`
- [Stored trading data](https://github.com/amit0rana/betteroptionstrading/blob/master/src/core/14-stored-data.js): `src/core/14-stored-data.js`
- [Trading constants](https://github.com/amit0rana/betteroptionstrading/blob/master/src/core/10-constants.js): `src/core/10-constants.js`
- [DOM paths](https://github.com/amit0rana/betteroptionstrading/blob/master/src/core/11-dom-paths.js): `src/core/11-dom-paths.js`
- [Utilities](https://github.com/amit0rana/betteroptionstrading/blob/master/src/core/12-utils.js): `src/core/12-utils.js`
- [Margin API](https://github.com/amit0rana/betteroptionstrading/blob/master/src/core/15-margin-api.js): `src/core/15-margin-api.js`
- [Row objects](https://github.com/amit0rana/betteroptionstrading/blob/master/src/core/16-row-objects.js): `src/core/16-row-objects.js`

### Trading features

- [Holdings](https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/30-holdings.js): `src/features/30-holdings.js`
- [Positions](https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/31-positions.js): `src/features/31-positions.js`
- [Watchlist](https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/33-watchlist.js): `src/features/33-watchlist.js`
- [P&L](https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/34-pnl.js): `src/features/34-pnl.js`
- [Margin saving](https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/35-margin-saving.js): `src/features/35-margin-saving.js`
- [Context menu](https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/36-context-menu.js): `src/features/36-context-menu.js`
- [Order adjustments](https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/38-order-bump.js): `src/features/38-order-bump.js`
- [Order window](https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/41-order-window.js): `src/features/41-order-window.js`
- [Order sending](https://github.com/amit0rana/betteroptionstrading/blob/master/src/features/42-order-send.js): `src/features/42-order-send.js`

### Other platform scripts

- **Other platform scripts**
- [Upstox](https://github.com/amit0rana/betteroptionstrading/blob/master/betterUpstox.user.js): `betterUpstox.user.js`
- [Sensibull](https://github.com/amit0rana/betteroptionstrading/blob/master/betterSensibull.user.js): `betterSensibull.user.js`
- [NSE India](https://github.com/amit0rana/betteroptionstrading/blob/master/betterNSE.user.js): `betterNSE.user.js`
- [Sharekhan](https://github.com/amit0rana/betteroptionstrading/blob/master/betterSharekhan.user.js): `betterSharekhan.user.js`
- [Oipulse](https://github.com/amit0rana/betteroptionstrading/blob/master/betterOipulse.user.js): `betterOipulse.user.js`
- [Stocks Developer](https://github.com/amit0rana/betteroptionstrading/blob/master/betterStocksDeveloper.user.js): `betterStocksDeveloper.user.js`
- [Trading Economics](https://github.com/amit0rana/betteroptionstrading/blob/master/betterTradingeconomics.user.js): `betterTradingeconomics.user.js`

### Other components

- **Kite user**

## Connections

- Kite user → Kite userscript: opens Kite (evidence: `betterKite.user.js`)
- Kite userscript → Bootstrap: initializes via
- Bootstrap → Settings: waits for settings
- Bootstrap → Event wiring: starts after init
- Event wiring → Settings: reads settings
- Event wiring → Holdings: wires interactions
- Event wiring → Positions: wires interactions
- Event wiring → Watchlist: wires interactions
- Event wiring → P&L: wires interactions
- Event wiring → Margin saving: wires interactions
- Event wiring → Context menu: wires interactions
- Event wiring → Order adjustments: wires interactions
- Event wiring → Order window: wires interactions
- Event wiring → Order sending: wires interactions
- Holdings → Stored trading data: uses persisted data
- Positions → Stored trading data: uses strategies (evidence: `src/features/31-positions.js`)
- Positions → Row objects: reads position rows
- Margin saving → Margin API: uses margin calculations
- Order adjustments → Order sending: adjusts pending orders
- Other platform scripts → Upstox: includes (evidence: `README.md`)
- Other platform scripts → Sensibull: includes (evidence: `README.md`)
- Other platform scripts → NSE India: includes (evidence: `README.md`)
- Other platform scripts → Sharekhan: also targets (evidence: `betterSharekhan.user.js`)
- Other platform scripts → Oipulse: also targets (evidence: `betterOipulse.user.js`)
- Other platform scripts → Stocks Developer: also targets (evidence: `betterStocksDeveloper.user.js`)
- Other platform scripts → Trading Economics: also targets (evidence: `betterTradingeconomics.user.js`)
