# fabston/tradingview-webhook-bot architecture

> Architecture diagram of the GitHub repository fabston/tradingview-webhook-bot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fabston/tradingview-webhook-bot
- Repository: https://github.com/fabston/tradingview-webhook-bot

## Overview

##### Project type and purpose
- This is a lightweight, open-source backend service (microservice) whose sole responsibility is to listen for TradingView alert webhooks and fan them out to various messaging channels (Telegram, Discord, Slack, Twitter, Email).

##### File structure
- Top-level files:
- main.py – starts the Flask HTTP server and defines the `/webhook` endpoint
- handler.py – contains the core logic that validates incoming payloads, reads `config.py`, and dispatches alerts
- config.py – holds all user-editable settings (API keys, default channels on/off)
- requirements.txt – Python dependencies (Flask, python-telegram-bot, tweepy, etc.)
- Dockerfile & docker-compose.yml – containerization for deployment
- .github/workflows – CI workflows (e.g., stale‐issue handling)
- assets/ – project logo (not part of runtime)

##### Extract insights from the README
- Tech stack: Python 3.8, Flask, python-telegram-bot, tweepy, smtplib, plus HTTP-based webhooks for Slack/Discord
- Runtime: listens on port 8080 (recommended), optionally fronted by NGINX on port 80
- Deployment options: direct `python main.py`, PM2, Docker Compose

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Deployment stack
    subgraph "Deployment"
        direction TB
        dockerCompose["docker-compose.yml"]:::config
        DockerfileNode["Dockerfile"]:::config
        subgraph "Containers"
            direction TB
            nginx["NGINX Reverse Proxy"]:::internal
            flask["Flask App"]:::internal
        end
        dockerCompose --> nginx
        dockerCompose --> flask
    end

    %% Ingress
    TradingView["TradingView Alerts"]:::external
    TradingView -->|"HTTP POST"| nginx
    nginx -->|"forward /webhook"| flask

    %% Flask Application Details
    subgraph "Flask Application"
        direction TB
        main["main.py"]:::internal
        handler["handler.py"]:::internal
        configNode["config.py"]:::config
        requirements["requirements.txt"]:::config
        main -->|"/webhook"| handler
        handler -->|"read config"| configNode
    end
    flask --> main

    %% Sender Modules
    subgraph "Sender Modules"
        direction TB
        telegramMod["Telegram Client"]:::internal
        discordMod["Discord Webhook"]:::internal
        slackMod["Slack Webhook"]:::internal
        twitterMod["Twitter Client"]:::internal
        emailMod["Email Sender"]:::internal
    end

    handler --> telegramMod
    handler --> discordMod
    handler --> slackMod
    handler --> twitterMod
    handler --> emailMod

    %% External Services
    subgraph "External Services"
        direction TB
        TelegramAPI["Telegram API"]:::external
        DiscordService["Discord Service"]:::external
        SlackService["Slack Service"]:::external
        TwitterAPI["Twitter API"]:::external
        SMTPServer["SMTP Server"]:::external
    end

    telegramMod -->|"send message"| TelegramAPI
    discordMod -->|"post webhook"| DiscordService
    slackMod -->|"post webhook"| SlackService
    twitterMod -->|"tweet"| TwitterAPI
    emailMod -->|"send email"| SMTPServer

    %% CI/CD and Assets
    github[".github/workflows"]:::config
    assets["assets/"]:::config

    %% Click Events
    click main "https://github.com/fabston/tradingview-webhook-bot/blob/master/main.py"
    click handler "https://github.com/fabston/tradingview-webhook-bot/blob/master/handler.py"
    click configNode "https://github.com/fabston/tradingview-webhook-bot/blob/master/config.py"
    click requirements "https://github.com/fabston/tradingview-webhook-bot/blob/master/requirements.txt"
    click DockerfileNode "https://github.com/fabston/tradingview-webhook-bot/tree/master/Dockerfile"
    click dockerCompose "https://github.com/fabston/tradingview-webhook-bot/blob/master/docker-compose.yml"
    click github "https://github.com/fabston/tradingview-webhook-bot/tree/master/.github/workflows/"
    click assets "https://github.com/fabston/tradingview-webhook-bot/tree/master/assets/"

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef external fill:#90EE90,stroke:#333,stroke-width:1px
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:1px
```
