# glavtoy/glavtoybot architecture

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

- Interactive diagram: https://gitdiagram.com/glavtoy/glavtoybot
- Repository: https://github.com/glavtoy/glavtoybot

## Overview

GlavtoyBot is a Telegram game/economy bot: users interact through bot commands to manage balances, transfer coins, play dice, upgrade businesses, and view profiles and leaderboards. Main loads account state from PostgreSQL, registers the bot, and starts scheduled business-income processing. The graph separates command handling, economy rules, account and leaderboard state, and persistence. TelegramBot is only partially excerpted, so its specific casino call is shown as unverified; no README capabilities were available.

Main entry points: [`src/TelegramBot.java`](https://github.com/glavtoy/glavtoybot/blob/master/src/TelegramBot.java) (Command handler), [`src/user/UserBase.java`](https://github.com/glavtoy/glavtoybot/blob/master/src/user/UserBase.java) (User registry), [`src/user/User.java`](https://github.com/glavtoy/glavtoybot/blob/master/src/user/User.java) (User account), [`src/Main.java`](https://github.com/glavtoy/glavtoybot/blob/master/src/Main.java) (Startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Bot entry"]
  node_main["Startup<br/>[Main.java]"]
  node_bot["Command handler<br/>[TelegramBot.java]"]
end

subgraph group_economy["Economy features"]
  node_casino["Dice odds<br/>[Casino.java]"]
  node_business["Business income<br/>[BussinessTask.java]"]
end

subgraph group_accounts["Account state"]
  node_user["User account<br/>[User.java]"]
  node_userbase["User registry<br/>[UserBase.java]"]
  node_leaderboards["Leaderboard sorting"]
end

subgraph group_storage["Persistence"]
  node_sql["SQL access<br/>[SQLUtil.java]"]
end

node_player(("Telegram player"))
node_telegram["Telegram API"]
node_postgres[("PostgreSQL")]

node_player -->|"sends commands"| node_bot
node_bot -->|"sends replies"| node_player
node_bot -->|"uses API"| node_telegram
node_main -->|"registers"| node_bot
node_main -->|"loads accounts"| node_userbase
node_main -->|"creates connection"| node_sql
node_main -->|"starts schedule"| node_business
node_bot -->|"handles accounts"| node_user
node_bot -->|"uses account data"| node_userbase
node_bot -.->|"requests game result"| node_casino
node_bot -->|"sorts rankings"| node_leaderboards
node_business -->|"iterates users"| node_userbase
node_business -->|"updates income and level"| node_user
node_userbase -->|"creates account records"| node_user
node_userbase -->|"queries accounts"| node_sql
node_userbase -->|"sorts rankings"| node_leaderboards
node_user -->|"updates registry"| node_userbase
node_user -->|"persists changes"| node_sql
node_sql -->|"executes SQL"| node_postgres

click node_main "https://github.com/glavtoy/glavtoybot/blob/master/src/Main.java"
click node_bot "https://github.com/glavtoy/glavtoybot/blob/master/src/TelegramBot.java"
click node_casino "https://github.com/glavtoy/glavtoybot/blob/master/src/casino/Casino.java"
click node_business "https://github.com/glavtoy/glavtoybot/blob/master/src/task/BussinessTask.java"
click node_user "https://github.com/glavtoy/glavtoybot/blob/master/src/user/User.java"
click node_userbase "https://github.com/glavtoy/glavtoybot/blob/master/src/user/UserBase.java"
click node_leaderboards "https://github.com/glavtoy/glavtoybot/blob/master/src/util/HashMapSorterUtil.java"
click node_sql "https://github.com/glavtoy/glavtoybot/blob/master/src/util/SQLUtil.java"

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_main,node_bot toneBlue
class node_casino,node_business,node_postgres toneAmber
class node_user,node_userbase,node_leaderboards,node_telegram toneMint
class node_sql toneRose
class node_player toneIndigo
```

## Components

### Bot entry

- [Startup](https://github.com/glavtoy/glavtoybot/blob/master/src/Main.java): `src/Main.java`
- [Command handler](https://github.com/glavtoy/glavtoybot/blob/master/src/TelegramBot.java): `src/TelegramBot.java`

### Economy features

- [Dice odds](https://github.com/glavtoy/glavtoybot/blob/master/src/casino/Casino.java): `src/casino/Casino.java`
- [Business income](https://github.com/glavtoy/glavtoybot/blob/master/src/task/BussinessTask.java): `src/task/BussinessTask.java`

### Account state

- [User account](https://github.com/glavtoy/glavtoybot/blob/master/src/user/User.java): `src/user/User.java`
- [User registry](https://github.com/glavtoy/glavtoybot/blob/master/src/user/UserBase.java): `src/user/UserBase.java`
- [Leaderboard sorting](https://github.com/glavtoy/glavtoybot/blob/master/src/util/HashMapSorterUtil.java): `src/util/HashMapSorterUtil.java`

### Persistence

- [SQL access](https://github.com/glavtoy/glavtoybot/blob/master/src/util/SQLUtil.java): `src/util/SQLUtil.java`

### Other components

- **Telegram player**
- **Telegram API**
- **PostgreSQL**

## Connections

- Telegram player → Command handler: sends commands (evidence: `src/TelegramBot.java`)
- Command handler → Telegram player: sends replies (evidence: `src/TelegramBot.java`)
- Command handler → Telegram API: uses API (evidence: `src/TelegramBot.java`)
- Startup → Command handler: registers (evidence: `src/Main.java`)
- Startup → User registry: loads accounts (evidence: `src/Main.java`)
- Startup → SQL access: creates connection (evidence: `src/Main.java`)
- Startup → Business income: starts schedule (evidence: `src/Main.java`)
- Command handler → User account: handles accounts (evidence: `src/TelegramBot.java`)
- Command handler → User registry: uses account data (evidence: `src/TelegramBot.java`)
- Command handler → Dice odds: requests game result (evidence: `src/TelegramBot.java`)
- Command handler → Leaderboard sorting: sorts rankings (evidence: `src/TelegramBot.java`)
- Business income → User registry: iterates users (evidence: `src/task/BussinessTask.java`)
- Business income → User account: updates income and level (evidence: `src/task/BussinessTask.java`)
- User registry → User account: creates account records (evidence: `src/user/UserBase.java`)
- User registry → SQL access: queries accounts (evidence: `src/user/UserBase.java`)
- User registry → Leaderboard sorting: sorts rankings (evidence: `src/user/UserBase.java`)
- User account → User registry: updates registry (evidence: `src/user/User.java`)
- User account → SQL access: persists changes (evidence: `src/user/User.java`)
- SQL access → PostgreSQL: executes SQL (evidence: `src/util/SQLUtil.java`)
