# ujan0009/telegrampricealertbot architecture

> Architecture diagram of the GitHub repository ujan0009/telegrampricealertbot, 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/ujan0009/telegrampricealertbot
- Repository: https://github.com/ujan0009/telegrampricealertbot

## Overview

CryptoPriceBot lets Telegram users check cryptocurrency prices and create threshold alerts. Telegram command handlers validate requests, resolve coin shortcuts, fetch USD prices from CoinGecko, and reply to users. Alert requests are held in memory and checked every 60 seconds; triggered alerts are sent through Telegram. A small Flask endpoint reports that the bot is alive, started alongside polling. The source is a single-file application, so several distinct responsibilities share main.py; omitted portions limit detail about alert triggering and command behavior.

Main entry points: [`main.py`](https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py) (Bot runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_bot["Telegram bot"]
  node_bot_runtime["Bot runtime<br/>[main.py]"]
  node_commands["Command handlers<br/>[main.py]"]
end

subgraph group_pricing["Price lookup"]
  node_coin_mapping["Coin mapping<br/>[main.py]"]
  node_price_fetch["Price fetch<br/>[main.py]"]
end

subgraph group_alerts["Price alerts"]
  node_alert_state[("Alert state<br/>[main.py]")]
  node_alert_checker["Alert checker<br/>[main.py]"]
end

subgraph group_uptime["Uptime endpoint"]
  node_flask_endpoint["Alive endpoint<br/>[main.py]"]
  node_flask_server["Flask server<br/>[main.py]"]
end

node_user(("Telegram user"))
node_telegram{{"Telegram platform"}}
node_coingecko{{"CoinGecko API"}}

node_user -->|"sends commands"| node_telegram
node_telegram -->|"delivers updates"| node_bot_runtime
node_bot_runtime -->|"dispatches commands"| node_commands
node_commands -->|"sends replies"| node_telegram
node_commands -->|"fetches prices"| node_price_fetch
node_price_fetch -->|"resolves symbol"| node_coin_mapping
node_price_fetch -->|"requests price"| node_coingecko
node_commands -->|"stores alerts"| node_alert_state
node_bot_runtime -->|"schedules checks"| node_alert_checker
node_alert_checker -->|"reads alerts"| node_alert_state
node_alert_checker -->|"checks prices"| node_price_fetch
node_alert_checker -->|"sends notifications"| node_telegram
node_bot_runtime -->|"starts server"| node_flask_server
node_flask_server -->|"serves route"| node_flask_endpoint

click node_bot_runtime "https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py"
click node_commands "https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py"
click node_coin_mapping "https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py"
click node_price_fetch "https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py"
click node_alert_state "https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py"
click node_alert_checker "https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py"
click node_flask_endpoint "https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py"
click node_flask_server "https://github.com/ujan0009/telegrampricealertbot/blob/main/main.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_bot_runtime,node_commands,node_user toneBlue
class node_coin_mapping,node_price_fetch toneAmber
class node_alert_state,node_alert_checker,node_coingecko toneMint
class node_flask_endpoint,node_flask_server toneRose
class node_telegram toneIndigo
```

## Components

### Telegram bot

- [Bot runtime](https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py): `main.py`
- [Command handlers](https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py): `main.py`

### Price lookup

- [Coin mapping](https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py): `main.py`
- [Price fetch](https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py): `main.py`

### Price alerts

- [Alert state](https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py): `main.py`
- [Alert checker](https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py): `main.py`

### Uptime endpoint

- [Alive endpoint](https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py): `main.py`
- [Flask server](https://github.com/ujan0009/telegrampricealertbot/blob/main/main.py): `main.py`

### Other components

- **Telegram user**
- **Telegram platform**
- **CoinGecko API**

## Connections

- Telegram user → Telegram platform: sends commands
- Telegram platform → Bot runtime: delivers updates
- Bot runtime → Command handlers: dispatches commands (evidence: `main.py`)
- Command handlers → Telegram platform: sends replies (evidence: `main.py`)
- Command handlers → Price fetch: fetches prices (evidence: `main.py`)
- Price fetch → Coin mapping: resolves symbol (evidence: `main.py`)
- Price fetch → CoinGecko API: requests price (evidence: `main.py`)
- Command handlers → Alert state: stores alerts (evidence: `main.py`)
- Bot runtime → Alert checker: schedules checks (evidence: `main.py`)
- Alert checker → Alert state: reads alerts (evidence: `main.py`)
- Alert checker → Price fetch: checks prices (evidence: `main.py`)
- Alert checker → Telegram platform: sends notifications (evidence: `main.py`)
- Bot runtime → Flask server: starts server (evidence: `main.py`)
- Flask server → Alive endpoint: serves route (evidence: `main.py`)
