# nageshmadaram/sterling-v2 architecture

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

- Interactive diagram: https://gitdiagram.com/nageshmadaram/sterling-v2
- Repository: https://github.com/nageshmadaram/sterling-v2

## Overview

Sterling is a live Indian-derivatives trading platform with web and mobile terminals backed by a FastAPI service. The principal workflow runs from a trader’s strategy screen through a backend scan and safety checks to broker order execution, with positions, fills, and activity persisted for operator review. The README documents four live strategies, Kite/TrueData market feeds, backtesting/replay, simulation, and Telegram alerts. Sampled code confirms the Kite Engine UI/API and tick-stream paths; other strategy and integration links below are limited to README-documented relationships.

Main entry points: [`backend/app/engines/sterling_kite_engine/engine.py`](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/engines/sterling_kite_engine/engine.py) (Strategy scanning), [`frontend/src/components/kite/SterlingKiteEnginePane.tsx`](https://github.com/nageshmadaram/sterling-v2/blob/main/frontend/src/components/kite/SterlingKiteEnginePane.tsx) (Web terminal), [`backend/app/services/exchanges/kite/ticker_manager.py`](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/services/exchanges/kite/ticker_manager.py) (Market data feeds), [`backend/app/api/v1/endpoints/kite_engine.py`](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/api/v1/endpoints/kite_engine.py) (Kite Engine API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Trader clients"]
  node_web["Web terminal"]
  node_mobile["Mobile terminal<br/>[index.tsx]"]
  node_engine_hook["Engine API hook"]
end

subgraph group_market["Market and strategies"]
  node_signals["Strategy scanning<br/>[engine.py]"]
  node_supertrend["SuperTrend strategy"]
  node_snapback["Snapback strategy"]
  node_gamma["Gamma Unwind"]
  node_price_rules["Price Rules<br/>[price_rules.py]"]
  node_market_data["Market data feeds<br/>[ticker_manager.py]"]
  node_research["Backtest and replay<br/>[unified_engine.py]"]
end

subgraph group_trading["Trading operations"]
  node_kite_api["Kite Engine API<br/>[kite_engine.py]"]
  node_risk["Risk controls<br/>[engine.py]"]
  node_execution["Order execution"]
  node_positions["Positions and fills"]
  node_simulation["Simulation workspace"]
end

subgraph group_platform["Platform services"]
  node_api["FastAPI API<br/>[main.py]"]
  node_persistence[("Trading persistence<br/>[db.py]")]
  node_accounts["Kite accounts<br/>[accounts.py]"]
  node_operators["Operators and users<br/>[auth.py]"]
  node_telegram["Telegram alerts"]
  node_stream["Live tick stream<br/>[stream.py]"]
end

node_trader(("Trader"))
node_truedata["TrueData"]
node_kite["Zerodha Kite"]

node_trader -->|"uses"| node_web
node_trader -->|"uses"| node_mobile
node_web -->|"requests"| node_engine_hook
node_engine_hook -->|"calls"| node_kite_api
node_api -->|"routes"| node_kite_api
node_kite_api -->|"invokes"| node_signals
node_market_data -->|"publishes ticks"| node_stream
node_kite -->|"supplies feed"| node_market_data
node_truedata -->|"supplies feed"| node_market_data
node_signals -->|"scans"| node_supertrend
node_signals -->|"scans"| node_snapback
node_signals -->|"scans"| node_gamma
node_signals -->|"scans"| node_price_rules
node_signals -->|"checks safety"| node_risk
node_risk -->|"authorizes"| node_execution
node_execution -->|"places orders"| node_kite
node_execution -->|"updates fills"| node_positions
node_positions -->|"persists"| node_persistence
node_web -->|"requests replay"| node_research
node_web -->|"uses workspace"| node_simulation
node_kite_api -->|"reads accounts"| node_accounts
node_trader -->|"manages users"| node_operators
node_positions -->|"sends alerts"| node_telegram
node_market_data -->|"streams updates"| node_web

click node_web "https://github.com/nageshmadaram/sterling-v2/blob/main/frontend/src/components/kite/SterlingKiteEnginePane.tsx"
click node_mobile "https://github.com/nageshmadaram/sterling-v2/blob/main/mobile/app/(tabs)/index.tsx"
click node_api "https://github.com/nageshmadaram/sterling-v2/blob/main/backend/main.py"
click node_kite_api "https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/api/v1/endpoints/kite_engine.py"
click node_engine_hook "https://github.com/nageshmadaram/sterling-v2/blob/main/frontend/src/hooks/useSterlingKiteEngine.ts"
click node_signals "https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/engines/sterling_kite_engine/engine.py"
click node_supertrend "https://github.com/nageshmadaram/sterling-v2/tree/main/backend/app/engines/sterling_kite_engine"
click node_snapback "https://github.com/nageshmadaram/sterling-v2/tree/main/backend/app/engines/snapback"
click node_gamma "https://github.com/nageshmadaram/sterling-v2/tree/main/backend/app/engines/gamma_move"
click node_price_rules "https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/api/v1/endpoints/price_rules.py"
click node_market_data "https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/services/exchanges/kite/ticker_manager.py"
click node_risk "https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/engines/risk/engine.py"
click node_execution "https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/services/execution_service.py"
click node_positions "https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/services/canonical_fill_reconciliation.py"
click node_persistence "https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/services/db.py"
click node_simulation "https://github.com/nageshmadaram/sterling-v2/tree/main/backend/app/services/simulation"
click node_research "https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/engines/backtest/unified_engine.py"
click node_accounts "https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/services/exchanges/kite/accounts.py"
click node_operators "https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/api/v1/endpoints/auth.py"
click node_telegram "https://github.com/nageshmadaram/sterling-v2/tree/main/backend/app/services"
click node_stream "https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/api/v1/endpoints/stream.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_web,node_mobile,node_engine_hook toneBlue
class node_signals,node_supertrend,node_snapback,node_gamma,node_price_rules,node_market_data,node_research toneAmber
class node_kite_api,node_risk,node_execution,node_positions,node_simulation toneMint
class node_api,node_persistence,node_accounts,node_operators,node_telegram,node_stream toneRose
class node_trader,node_truedata,node_kite toneIndigo
```

## Components

### Trader clients

- [Web terminal](https://github.com/nageshmadaram/sterling-v2/blob/main/frontend/src/components/kite/SterlingKiteEnginePane.tsx): `frontend/src/components/kite/SterlingKiteEnginePane.tsx`
- [Mobile terminal](https://github.com/nageshmadaram/sterling-v2/blob/main/mobile/app/(tabs)/index.tsx): `mobile/app/(tabs)/index.tsx`
- [Engine API hook](https://github.com/nageshmadaram/sterling-v2/blob/main/frontend/src/hooks/useSterlingKiteEngine.ts): `frontend/src/hooks/useSterlingKiteEngine.ts`

### Market and strategies

- [Strategy scanning](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/engines/sterling_kite_engine/engine.py): `backend/app/engines/sterling_kite_engine/engine.py`
- [SuperTrend strategy](https://github.com/nageshmadaram/sterling-v2/tree/main/backend/app/engines/sterling_kite_engine): `backend/app/engines/sterling_kite_engine`
- [Snapback strategy](https://github.com/nageshmadaram/sterling-v2/tree/main/backend/app/engines/snapback): `backend/app/engines/snapback`
- [Gamma Unwind](https://github.com/nageshmadaram/sterling-v2/tree/main/backend/app/engines/gamma_move): `backend/app/engines/gamma_move`
- [Price Rules](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/api/v1/endpoints/price_rules.py): `backend/app/api/v1/endpoints/price_rules.py`
- [Market data feeds](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/services/exchanges/kite/ticker_manager.py): `backend/app/services/exchanges/kite/ticker_manager.py`
- [Backtest and replay](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/engines/backtest/unified_engine.py): `backend/app/engines/backtest/unified_engine.py`

### Trading operations

- [Kite Engine API](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/api/v1/endpoints/kite_engine.py): `backend/app/api/v1/endpoints/kite_engine.py`
- [Risk controls](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/engines/risk/engine.py): `backend/app/engines/risk/engine.py`
- [Order execution](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/services/execution_service.py): `backend/app/services/execution_service.py`
- [Positions and fills](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/services/canonical_fill_reconciliation.py): `backend/app/services/canonical_fill_reconciliation.py`
- [Simulation workspace](https://github.com/nageshmadaram/sterling-v2/tree/main/backend/app/services/simulation): `backend/app/services/simulation`

### Platform services

- [FastAPI API](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/main.py): `backend/main.py`
- [Trading persistence](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/services/db.py): `backend/app/services/db.py`
- [Kite accounts](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/services/exchanges/kite/accounts.py): `backend/app/services/exchanges/kite/accounts.py`
- [Operators and users](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/api/v1/endpoints/auth.py): `backend/app/api/v1/endpoints/auth.py`
- [Telegram alerts](https://github.com/nageshmadaram/sterling-v2/tree/main/backend/app/services): `backend/app/services`
- [Live tick stream](https://github.com/nageshmadaram/sterling-v2/blob/main/backend/app/api/v1/endpoints/stream.py): `backend/app/api/v1/endpoints/stream.py`

### Other components

- **Trader**
- **TrueData**
- **Zerodha Kite**

## Connections

- Trader → Web terminal: uses (evidence: `README.md`)
- Trader → Mobile terminal: uses (evidence: `README.md`)
- Web terminal → Engine API hook: requests (evidence: `frontend/src/components/kite/SterlingKiteEnginePane.tsx`)
- Engine API hook → Kite Engine API: calls (evidence: `frontend/src/hooks/useSterlingKiteEngine.ts`)
- FastAPI API → Kite Engine API: routes (evidence: `backend/main.py`)
- Kite Engine API → Strategy scanning: invokes (evidence: `backend/app/api/v1/endpoints/kite_engine.py`)
- Market data feeds → Live tick stream: publishes ticks (evidence: `backend/app/services/exchanges/kite/ticker_manager.py`)
- Zerodha Kite → Market data feeds: supplies feed (evidence: `README.md`)
- TrueData → Market data feeds: supplies feed (evidence: `README.md`)
- Strategy scanning → SuperTrend strategy: scans (evidence: `README.md`)
- Strategy scanning → Snapback strategy: scans (evidence: `README.md`)
- Strategy scanning → Gamma Unwind: scans (evidence: `README.md`)
- Strategy scanning → Price Rules: scans (evidence: `README.md`)
- Strategy scanning → Risk controls: checks safety (evidence: `README.md`)
- Risk controls → Order execution: authorizes (evidence: `README.md`)
- Order execution → Zerodha Kite: places orders (evidence: `README.md`)
- Order execution → Positions and fills: updates fills (evidence: `README.md`)
- Positions and fills → Trading persistence: persists (evidence: `backend/app/services/db.py`)
- Web terminal → Backtest and replay: requests replay (evidence: `README.md`)
- Web terminal → Simulation workspace: uses workspace (evidence: `README.md`)
- Kite Engine API → Kite accounts: reads accounts (evidence: `backend/app/api/v1/endpoints/kite_engine.py`)
- Trader → Operators and users: manages users (evidence: `README.md`)
- Positions and fills → Telegram alerts: sends alerts (evidence: `README.md`)
- Market data feeds → Web terminal: streams updates (evidence: `backend/app/services/exchanges/kite/ticker_manager.py`)
