# onekill0503/ethereum_gas_alert architecture

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

- Interactive diagram: https://gitdiagram.com/onekill0503/ethereum_gas_alert
- Repository: https://github.com/onekill0503/ethereum_gas_alert

## Overview

##### Project type and purpose
- This is a backend-focused Node.js microservice (a Telegram Bot) whose sole responsibility is to alert users when the Ethereum gas price meets a threshold.
- It has no separate “frontend,” but it integrates two external services: the Telegram Bot API and an Ethereum JSON-RPC provider.

##### File structure
Top-level files:
- .env.example – environment variables template (likely includes TELEGRAM_TOKEN, ETHEREUM_RPC_URL, GAS_THRESHOLD, etc.)
- Dockerfile – containerization of the bot
- index.js – application entry point or bootstrapper
- README.md – high-level description
- package.json – Node.js dependencies, scripts, metadata
- node_modules – installed packages
- database/alert.sqlite – persistent store for user subscriptions or last‐seen values
- backend/index.js – main bot logic (polling or webhook setup, gas-check scheduler, notification dispatch)
- backend/index.test.js – unit/integration tests for core functionality

##### README for additional insights
- The README confirms the core use case: monitor Ethereum gas price and send Telegram notifications when price ≤ user-specified threshold.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Docker Container"
        Env["Config Loader (.env)"]:::internal
        Entry["Bot Service (index.js)"]:::internal
        Core["Core Bot Logic"]:::internal
        Scheduler["Scheduler"]:::internal
        DAL["Data Access Layer"]:::internal
        DB["SQLite Database"]:::db
        RPCClient["Ethereum JSON-RPC Provider"]:::external
        TelegramClient["Telegram Bot API"]:::external
    end

    Env -->|"loads config"| Entry
    Entry -->|"bootstraps service"| Core
    Core -->|"starts polling"| Scheduler
    Scheduler -->|"getGasPrice()"| RPCClient
    RPCClient -->|"returns price"| Core
    Core -->|"evaluate thresholds"| DAL
    DAL -->|"SELECT subscriptions"| DB
    Core -->|"sendMessage()"| TelegramClient
    TelegramClient -->|"delivers message"| EndUser["Telegram User"]:::external

    TelegramClient -->|"incoming updates"| Core
    Core -->|"INSERT/DELETE subscription"| DAL
    DAL -->|"write subscriptions"| DB

    subgraph "Tests"
        TestSuite["Test Suite"]:::test
    end
    TestSuite -->|"tests logic in"| Core

    subgraph "Project Files"
        README["README.md"]:::docs
        EnvFile[".env.example"]:::docs
        DockerfileNode["Dockerfile"]:::docs
        Package["package.json"]:::docs
        NodeModules["node_modules"]:::docs
        GitIgnore[".gitignore"]:::docs
    end
    README --- Entry
    EnvFile --- Env
    DockerfileNode --- Entry
    Package --- Entry
    NodeModules --- Entry
    GitIgnore --- Entry

    click EnvFile "https://github.com/onekill0503/ethereum_gas_alert/blob/master/.env.example"
    click DockerfileNode "https://github.com/onekill0503/ethereum_gas_alert/tree/master/Dockerfile"
    click Entry "https://github.com/onekill0503/ethereum_gas_alert/blob/master/index.js"
    click Core "https://github.com/onekill0503/ethereum_gas_alert/blob/master/backend/index.js"
    click TestSuite "https://github.com/onekill0503/ethereum_gas_alert/blob/master/backend/index.test.js"
    click DB "https://github.com/onekill0503/ethereum_gas_alert/blob/master/database/alert.sqlite"
    click Package "https://github.com/onekill0503/ethereum_gas_alert/blob/master/package.json"
    click NodeModules "https://github.com/onekill0503/ethereum_gas_alert/tree/master/node_modules"
    click README "https://github.com/onekill0503/ethereum_gas_alert/blob/master/README.md"
    click GitIgnore "https://github.com/onekill0503/ethereum_gas_alert/blob/master/.gitignore"

    classDef internal fill:#D0E8FF,stroke:#333;
    classDef external fill:#DFF2BF,stroke:#333;
    classDef db fill:#FFDDAA,stroke:#333;
    classDef container fill:#EEE,stroke-dasharray:5 5;
    classDef test fill:#F0F0F0,stroke:#333;
    classDef docs fill:#EFEFEF,stroke:#333;
```
