# iamsaisamhithreddy/tradingbot architecture

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

- Interactive diagram: https://gitdiagram.com/iamsaisamhithreddy/tradingbot
- Repository: https://github.com/iamsaisamhithreddy/tradingbot

## Overview

TradingView Alerts Bot is a self-hosted forex signal and trade-grading platform, with Telegram delivery, data collection, administration, research and charting. Its main workflow receives five-candle alerts, evaluates a pattern and target, distributes a signal, then grades trades against candle data. The README documents several capabilities whose implementation was not sampled; those links cite the README. The repository also contains a substantial Lightweight Charts library, shown as a separate charting dependency rather than as part of the PHP signal pipeline.

Main entry points: [`webhook.php`](https://github.com/iamsaisamhithreddy/tradingbot/blob/main/webhook.php) (Bot commands), [`db.php`](https://github.com/iamsaisamhithreddy/tradingbot/blob/main/db.php) (Trade predictions), [`admin_dashboard.php`](https://github.com/iamsaisamhithreddy/tradingbot/blob/main/admin_dashboard.php) (Admin panel), [`plot`](https://github.com/iamsaisamhithreddy/tradingbot/tree/main/plot) (Trade plotter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_signals["Signals and grading"]
  node_receiver["Alert receiver<br/>[receiver.php]"]
  node_rawtrades[("Raw alerts<br/>[db.php]")]
  node_pattern["Pattern engine"]
  node_predictions[("Trade predictions<br/>[db.php]")]
  node_grading["Trade grading"]
end

subgraph group_data["Market data"]
  node_candlefeed["Candle collector<br/>[add.php]"]
  node_marketdata[("Candle data")]
end

subgraph group_bot["Telegram and events"]
  node_telegrambot["Bot commands<br/>[webhook.php]"]
  node_events["Economic calendar<br/>[fetch_news.php]"]
end

subgraph group_ops["Administration"]
  node_admin["Admin panel"]
  node_ota["Firmware updates"]
end

subgraph group_research["Research and charts"]
  node_research["Trade research"]
  node_reports["Trade reports<br/>[Trade_report.php]"]
  node_plotter["Trade plotter"]
  node_livechart["Live terminal"]
  node_chartlib["Chart library<br/>[create-chart.ts]"]
  node_pdf["PDF generation<br/>[fpdf.php]"]
end

node_tradingview(("TradingView"))
node_esp(("ESP32 collector"))
node_telegram{{"Telegram"}}

node_tradingview -->|"sends alerts"| node_receiver
node_receiver -->|"stores candles"| node_rawtrades
node_rawtrades -->|"evaluates pattern"| node_pattern
node_pattern -->|"records target"| node_predictions
node_predictions -.->|"serves bot"| node_telegrambot
node_predictions -->|"grades trades"| node_grading
node_esp -->|"posts candles"| node_candlefeed
node_candlefeed -->|"updates data"| node_marketdata
node_marketdata -->|"provides candles"| node_grading
node_telegrambot -->|"sends replies"| node_telegram
node_events -.->|"supplies events"| node_telegrambot
node_admin -->|"manages updates"| node_ota
node_admin -->|"offers analytics"| node_research
node_research -->|"generates reports"| node_reports
node_plotter -.->|"uses charts"| node_chartlib
node_livechart -->|"uses charts"| node_chartlib
node_telegrambot -->|"creates PDFs"| node_pdf
node_plotter -.->|"generates PDFs"| node_pdf

click node_receiver "https://github.com/iamsaisamhithreddy/tradingbot/blob/main/receiver.php"
click node_rawtrades "https://github.com/iamsaisamhithreddy/tradingbot/blob/main/db.php"
click node_pattern "https://github.com/iamsaisamhithreddy/tradingbot/blob/main/lib_candle_algo.php"
click node_predictions "https://github.com/iamsaisamhithreddy/tradingbot/blob/main/db.php"
click node_grading "https://github.com/iamsaisamhithreddy/tradingbot/blob/main/evaluate_win_loss.php"
click node_candlefeed "https://github.com/iamsaisamhithreddy/tradingbot/blob/main/dataset/add.php"
click node_marketdata "https://github.com/iamsaisamhithreddy/tradingbot/tree/main/dataset"
click node_telegrambot "https://github.com/iamsaisamhithreddy/tradingbot/blob/main/webhook.php"
click node_events "https://github.com/iamsaisamhithreddy/tradingbot/blob/main/fetch_news.php"
click node_admin "https://github.com/iamsaisamhithreddy/tradingbot/blob/main/admin_dashboard.php"
click node_ota "https://github.com/iamsaisamhithreddy/tradingbot/tree/main/ota"
click node_research "https://github.com/iamsaisamhithreddy/tradingbot/tree/main/analysis"
click node_reports "https://github.com/iamsaisamhithreddy/tradingbot/blob/main/Trade_report.php"
click node_plotter "https://github.com/iamsaisamhithreddy/tradingbot/tree/main/plot"
click node_livechart "https://github.com/iamsaisamhithreddy/tradingbot/tree/main/livechart"
click node_chartlib "https://github.com/iamsaisamhithreddy/tradingbot/blob/main/lightweight-charts-master/src/api/create-chart.ts"
click node_pdf "https://github.com/iamsaisamhithreddy/tradingbot/blob/main/fpdf.php"

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_receiver,node_rawtrades,node_pattern,node_predictions,node_grading,node_tradingview toneBlue
class node_candlefeed,node_marketdata toneAmber
class node_telegrambot,node_events toneMint
class node_admin,node_ota toneRose
class node_research,node_reports,node_plotter,node_livechart,node_chartlib,node_pdf,node_esp,node_telegram toneIndigo
```

## Components

### Signals and grading

- [Alert receiver](https://github.com/iamsaisamhithreddy/tradingbot/blob/main/receiver.php): `receiver.php`
- [Raw alerts](https://github.com/iamsaisamhithreddy/tradingbot/blob/main/db.php): `db.php`
- [Pattern engine](https://github.com/iamsaisamhithreddy/tradingbot/blob/main/lib_candle_algo.php): `lib_candle_algo.php`
- [Trade predictions](https://github.com/iamsaisamhithreddy/tradingbot/blob/main/db.php): `db.php`
- [Trade grading](https://github.com/iamsaisamhithreddy/tradingbot/blob/main/evaluate_win_loss.php): `evaluate_win_loss.php`

### Market data

- [Candle collector](https://github.com/iamsaisamhithreddy/tradingbot/blob/main/dataset/add.php): `dataset/add.php`
- [Candle data](https://github.com/iamsaisamhithreddy/tradingbot/tree/main/dataset): `dataset`

### Telegram and events

- [Bot commands](https://github.com/iamsaisamhithreddy/tradingbot/blob/main/webhook.php): `webhook.php`
- [Economic calendar](https://github.com/iamsaisamhithreddy/tradingbot/blob/main/fetch_news.php): `fetch_news.php`

### Administration

- [Admin panel](https://github.com/iamsaisamhithreddy/tradingbot/blob/main/admin_dashboard.php): `admin_dashboard.php`
- [Firmware updates](https://github.com/iamsaisamhithreddy/tradingbot/tree/main/ota): `ota`

### Research and charts

- [Trade research](https://github.com/iamsaisamhithreddy/tradingbot/tree/main/analysis): `analysis`
- [Trade reports](https://github.com/iamsaisamhithreddy/tradingbot/blob/main/Trade_report.php): `Trade_report.php`
- [Trade plotter](https://github.com/iamsaisamhithreddy/tradingbot/tree/main/plot): `plot`
- [Live terminal](https://github.com/iamsaisamhithreddy/tradingbot/tree/main/livechart): `livechart`
- [Chart library](https://github.com/iamsaisamhithreddy/tradingbot/blob/main/lightweight-charts-master/src/api/create-chart.ts): `lightweight-charts-master/src/api/create-chart.ts`
- [PDF generation](https://github.com/iamsaisamhithreddy/tradingbot/blob/main/fpdf.php): `fpdf.php`

### Other components

- **TradingView**
- **ESP32 collector**
- **Telegram**

## Connections

- TradingView → Alert receiver: sends alerts
- Alert receiver → Raw alerts: stores candles
- Raw alerts → Pattern engine: evaluates pattern
- Pattern engine → Trade predictions: records target
- Trade predictions → Bot commands: serves bot (evidence: `webhook.php`)
- Trade predictions → Trade grading: grades trades
- ESP32 collector → Candle collector: posts candles
- Candle collector → Candle data: updates data
- Candle data → Trade grading: provides candles
- Bot commands → Telegram: sends replies (evidence: `webhook.php`)
- Economic calendar → Bot commands: supplies events
- Admin panel → Firmware updates: manages updates
- Admin panel → Trade research: offers analytics
- Trade research → Trade reports: generates reports
- Trade plotter → Chart library: uses charts
- Live terminal → Chart library: uses charts
- Bot commands → PDF generation: creates PDFs (evidence: `webhook.php`)
- Trade plotter → PDF generation: generates PDFs
