# codetradesalgo-cmyk/dhan-api-tradingview-webhook-python architecture

> Architecture diagram of the GitHub repository codetradesalgo-cmyk/dhan-api-tradingview-webhook-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/codetradesalgo-cmyk/dhan-api-tradingview-webhook-python
- Repository: https://github.com/codetradesalgo-cmyk/dhan-api-tradingview-webhook-python

## Overview

This repository is a FastAPI webhook engine that accepts TradingView trade alerts, resolves symbols to cached Dhan security tokens, records order state in SQLite, submits orders asynchronously to Dhan, and returns the resulting status. The graph follows the handler’s actual calls and separates lookup, ledger, and broker execution. The token master is a hardcoded demonstration dataset in the sampled source; the README’s production options resolver is an external premium module, not included here.

Main entry points: [`app.py`](https://github.com/codetradesalgo-cmyk/dhan-api-tradingview-webhook-python/blob/main/app.py) (Webhook handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingress["Webhook ingress"]
  node_webhook["Webhook handler<br/>[app.py]"]
end

subgraph group_routing["Token routing"]
  node_token_manager["Token manager<br/>[app.py]"]
  node_numpy_cache["NumPy token cache<br/>[app.py]"]
end

subgraph group_execution["Order execution"]
  node_ledger[("SQLite trade ledger<br/>[app.py]")]
  node_order_sender["Dhan order sender<br/>[app.py]"]
end

node_tradingview(("TradingView alerts"))
node_dhan["Dhan API"]
node_caller(("Webhook client"))

node_tradingview -->|"posts alert"| node_webhook
node_webhook -->|"resolves symbol"| node_token_manager
node_token_manager -->|"looks up token"| node_numpy_cache
node_webhook -->|"records pending"| node_ledger
node_webhook -->|"submits order"| node_order_sender
node_order_sender -->|"posts order"| node_dhan
node_webhook -->|"updates status"| node_ledger
node_webhook -->|"returns status"| node_caller

click node_webhook "https://github.com/codetradesalgo-cmyk/dhan-api-tradingview-webhook-python/blob/main/app.py"
click node_token_manager "https://github.com/codetradesalgo-cmyk/dhan-api-tradingview-webhook-python/blob/main/app.py"
click node_numpy_cache "https://github.com/codetradesalgo-cmyk/dhan-api-tradingview-webhook-python/blob/main/app.py"
click node_ledger "https://github.com/codetradesalgo-cmyk/dhan-api-tradingview-webhook-python/blob/main/app.py"
click node_order_sender "https://github.com/codetradesalgo-cmyk/dhan-api-tradingview-webhook-python/blob/main/app.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_webhook,node_tradingview,node_caller toneBlue
class node_token_manager,node_numpy_cache toneAmber
class node_ledger,node_order_sender,node_dhan toneMint
```

## Components

### Webhook ingress

- [Webhook handler](https://github.com/codetradesalgo-cmyk/dhan-api-tradingview-webhook-python/blob/main/app.py): `app.py`

### Token routing

- [Token manager](https://github.com/codetradesalgo-cmyk/dhan-api-tradingview-webhook-python/blob/main/app.py): `app.py`
- [NumPy token cache](https://github.com/codetradesalgo-cmyk/dhan-api-tradingview-webhook-python/blob/main/app.py): `app.py`

### Order execution

- [SQLite trade ledger](https://github.com/codetradesalgo-cmyk/dhan-api-tradingview-webhook-python/blob/main/app.py): `app.py`
- [Dhan order sender](https://github.com/codetradesalgo-cmyk/dhan-api-tradingview-webhook-python/blob/main/app.py): `app.py`

### Other components

- **TradingView alerts**
- **Dhan API**
- **Webhook client**

## Connections

- TradingView alerts → Webhook handler: posts alert (evidence: `README.md`)
- Webhook handler → Token manager: resolves symbol (evidence: `app.py`)
- Token manager → NumPy token cache: looks up token (evidence: `app.py`)
- Webhook handler → SQLite trade ledger: records pending (evidence: `app.py`)
- Webhook handler → Dhan order sender: submits order (evidence: `app.py`)
- Dhan order sender → Dhan API: posts order (evidence: `app.py`)
- Webhook handler → SQLite trade ledger: updates status (evidence: `app.py`)
- Webhook handler → Webhook client: returns status (evidence: `app.py`)
