# chaku84/algo-trade-public architecture

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

- Interactive diagram: https://gitdiagram.com/chaku84/algo-trade-public
- Repository: https://github.com/chaku84/algo-trade-public

## Overview

This repository is an automated trading application: scheduled workers refresh market prices, evaluate trades, and apply entry and exit rules, with Django-backed trade state and broker integrations. A separate bundled TA-Lib C library supplies technical-analysis functions and a metadata-oriented abstract API. The README documents the main worker workflow; source-index references and excerpts support selected internal links. Many Django routes, task definitions, and broker paths were not sampled, so their wiring is shown only where documented or directly referenced.

Main entry points: [`trading_django/trading/kite_manager.py`](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/kite_manager.py) (Kite trade loop), [`trading_django/trading/models.py`](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/models.py) (Trade records), [`trading_django/trading/tasks.py`](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/tasks.py) (Worker tasks), [`trading_django/trading/dhan_manager.py`](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/dhan_manager.py) (Dhan trade manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Trading runtime"]
  node_django_api["Django API<br/>[views.py]"]
  node_celery_tasks["Worker tasks<br/>[tasks.py]"]
  node_scheduler["Task scheduler"]
  node_kite_manager["Kite trade loop<br/>[kite_manager.py]"]
end

subgraph group_trade["Trade lifecycle"]
  node_entry_rules["Entry rules<br/>[entry.py]"]
  node_exit_rules["Exit rules<br/>[exit.py]"]
  node_specialized_strategies["Specialized strategies"]
  node_trade_models[("Trade records<br/>[models.py]")]
  node_redis_queue["Redis trade queue"]
end

subgraph group_integrations["Market integrations"]
  node_tick_updater["Kite tick updater"]
  node_dhan_manager["Dhan trade manager<br/>[dhan_manager.py]"]
  node_broker_adapters["Broker adapters"]
  node_instrument_catalog["Instrument catalog<br/>[instruments.py]"]
  node_notifications["Notifications and OTP"]
  node_gmail_service["Gmail OTP service<br/>[gmail.py]"]
end

subgraph group_analytics["TA-Lib analytics"]
  node_ta_functions["Indicator functions"]
  node_ta_abstract["Abstract function API<br/>[ta_abstract.c]"]
  node_ta_metadata["Function metadata"]
  node_ta_common["Common runtime"]
end

node_operator(("Operator"))
node_market_brokers(("Broker services"))

node_operator -.->|"requests"| node_django_api
node_django_api -->|"starts workers"| node_celery_tasks
node_celery_tasks -->|"starts updates"| node_tick_updater
node_celery_tasks -->|"starts trading"| node_kite_manager
node_tick_updater -->|"receives ticks"| node_market_brokers
node_tick_updater -->|"updates prices"| node_redis_queue
node_kite_manager -->|"reads prices"| node_redis_queue
node_kite_manager -->|"dispatches entries"| node_entry_rules
node_kite_manager -->|"dispatches exits"| node_exit_rules
node_kite_manager -->|"dispatches variants"| node_specialized_strategies
node_kite_manager -->|"evaluates trades"| node_trade_models
node_entry_rules -->|"records entry"| node_trade_models
node_exit_rules -->|"records exit"| node_trade_models
node_kite_manager -.->|"places orders"| node_market_brokers
node_dhan_manager -->|"uses Dhan API"| node_market_brokers
node_dhan_manager -.->|"manages trades"| node_trade_models
node_dhan_manager -->|"uses queue"| node_redis_queue
node_kite_manager -->|"loads instruments"| node_instrument_catalog
node_broker_adapters -.->|"connects brokers"| node_market_brokers
node_scheduler -.->|"schedules workers"| node_celery_tasks
node_notifications -->|"reads trade state"| node_trade_models
node_notifications -->|"uses market guide"| node_gmail_service
node_ta_abstract -.->|"accesses metadata"| node_ta_metadata
node_ta_abstract -.->|"exposes functions"| node_ta_functions
node_ta_functions -.->|"uses common runtime"| node_ta_common

click node_django_api "https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/views.py"
click node_celery_tasks "https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/tasks.py"
click node_scheduler "https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/scheduler_manager.py"
click node_kite_manager "https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/kite_manager.py"
click node_tick_updater "https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/kite_tick_updater.py"
click node_dhan_manager "https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/dhan_manager.py"
click node_broker_adapters "https://github.com/chaku84/algo-trade-public/tree/main/trading_django/trading/brokers"
click node_instrument_catalog "https://github.com/chaku84/algo-trade-public/blob/main/trading_django/strategies/instruments.py"
click node_entry_rules "https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/strategies/entry.py"
click node_exit_rules "https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/strategies/exit.py"
click node_specialized_strategies "https://github.com/chaku84/algo-trade-public/tree/main/trading_django/trading/strategies"
click node_trade_models "https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/models.py"
click node_redis_queue "https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/strategies/rolling_redis_queue.py"
click node_notifications "https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/telegram_manager.py"
click node_gmail_service "https://github.com/chaku84/algo-trade-public/blob/main/trading_django/tips/gmail.py"
click node_ta_functions "https://github.com/chaku84/algo-trade-public/tree/main/ta-lib/src/ta_func"
click node_ta_abstract "https://github.com/chaku84/algo-trade-public/blob/main/ta-lib/src/ta_abstract/ta_abstract.c"
click node_ta_metadata "https://github.com/chaku84/algo-trade-public/tree/main/ta-lib/src/ta_abstract/tables"
click node_ta_common "https://github.com/chaku84/algo-trade-public/tree/main/ta-lib/src/ta_common"

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_django_api,node_celery_tasks,node_scheduler,node_kite_manager toneBlue
class node_entry_rules,node_exit_rules,node_specialized_strategies,node_trade_models,node_redis_queue toneAmber
class node_tick_updater,node_dhan_manager,node_broker_adapters,node_instrument_catalog,node_notifications,node_gmail_service toneMint
class node_ta_functions,node_ta_abstract,node_ta_metadata,node_ta_common toneRose
class node_operator,node_market_brokers toneIndigo
```

## Components

### Trading runtime

- [Django API](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/views.py): `trading_django/trading/views.py`
- [Worker tasks](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/tasks.py): `trading_django/trading/tasks.py`
- [Task scheduler](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/scheduler_manager.py): `trading_django/trading/scheduler_manager.py`
- [Kite trade loop](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/kite_manager.py): `trading_django/trading/kite_manager.py`

### Trade lifecycle

- [Entry rules](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/strategies/entry.py): `trading_django/trading/strategies/entry.py`
- [Exit rules](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/strategies/exit.py): `trading_django/trading/strategies/exit.py`
- [Specialized strategies](https://github.com/chaku84/algo-trade-public/tree/main/trading_django/trading/strategies): `trading_django/trading/strategies`
- [Trade records](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/models.py): `trading_django/trading/models.py`
- [Redis trade queue](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/strategies/rolling_redis_queue.py): `trading_django/trading/strategies/rolling_redis_queue.py`

### Market integrations

- [Kite tick updater](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/kite_tick_updater.py): `trading_django/trading/kite_tick_updater.py`
- [Dhan trade manager](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/dhan_manager.py): `trading_django/trading/dhan_manager.py`
- [Broker adapters](https://github.com/chaku84/algo-trade-public/tree/main/trading_django/trading/brokers): `trading_django/trading/brokers`
- [Instrument catalog](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/strategies/instruments.py): `trading_django/strategies/instruments.py`
- [Notifications and OTP](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/trading/telegram_manager.py): `trading_django/trading/telegram_manager.py`
- [Gmail OTP service](https://github.com/chaku84/algo-trade-public/blob/main/trading_django/tips/gmail.py): `trading_django/tips/gmail.py`

### TA-Lib analytics

- [Indicator functions](https://github.com/chaku84/algo-trade-public/tree/main/ta-lib/src/ta_func): `ta-lib/src/ta_func`
- [Abstract function API](https://github.com/chaku84/algo-trade-public/blob/main/ta-lib/src/ta_abstract/ta_abstract.c): `ta-lib/src/ta_abstract/ta_abstract.c`
- [Function metadata](https://github.com/chaku84/algo-trade-public/tree/main/ta-lib/src/ta_abstract/tables): `ta-lib/src/ta_abstract/tables`
- [Common runtime](https://github.com/chaku84/algo-trade-public/tree/main/ta-lib/src/ta_common): `ta-lib/src/ta_common`

### Other components

- **Operator**
- **Broker services**

## Connections

- Operator → Django API: requests
- Django API → Worker tasks: starts workers
- Worker tasks → Kite tick updater: starts updates
- Worker tasks → Kite trade loop: starts trading
- Kite tick updater → Broker services: receives ticks
- Kite tick updater → Redis trade queue: updates prices
- Kite trade loop → Redis trade queue: reads prices (evidence: `trading_django/trading/kite_manager.py`)
- Kite trade loop → Entry rules: dispatches entries (evidence: `trading_django/trading/kite_manager.py`)
- Kite trade loop → Exit rules: dispatches exits (evidence: `trading_django/trading/kite_manager.py`)
- Kite trade loop → Specialized strategies: dispatches variants (evidence: `trading_django/trading/kite_manager.py`)
- Kite trade loop → Trade records: evaluates trades (evidence: `trading_django/trading/kite_manager.py`)
- Entry rules → Trade records: records entry
- Exit rules → Trade records: records exit
- Kite trade loop → Broker services: places orders
- Dhan trade manager → Broker services: uses Dhan API (evidence: `trading_django/trading/dhan_manager.py`)
- Dhan trade manager → Trade records: manages trades (evidence: `trading_django/trading/dhan_manager.py`)
- Dhan trade manager → Redis trade queue: uses queue (evidence: `trading_django/trading/dhan_manager.py`)
- Kite trade loop → Instrument catalog: loads instruments (evidence: `trading_django/trading/kite_manager.py`)
- Broker adapters → Broker services: connects brokers
- Task scheduler → Worker tasks: schedules workers
- Notifications and OTP → Trade records: reads trade state (evidence: `trading_django/trading/telegram_manager.py`)
- Notifications and OTP → Gmail OTP service: uses market guide (evidence: `trading_django/trading/telegram_manager.py`)
- Abstract function API → Function metadata: accesses metadata
- Abstract function API → Indicator functions: exposes functions
- Indicator functions → Common runtime: uses common runtime
