# fauzi-1110/bot-trading architecture

> Architecture diagram of the GitHub repository fauzi-1110/bot-trading, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fauzi-1110/bot-trading
- Repository: https://github.com/fauzi-1110/bot-trading

## Overview

This is a Telegram-based trading-game bot, described by its author as a coding exercise. Users send commands through private chat; message handling presents game actions and callback handling completes trades and other selections. The wider game includes item/coin markets, automated bots and parties, jobs/businesses, season and leaderboard functions, plus scheduled market and game-state updates. The README is brief, and excerpts are partial, so the graph includes only supported wiring; several documented command capabilities are grouped at their known handler paths.

Main entry points: [`lib/func_db.js`](https://github.com/fauzi-1110/bot-trading/blob/main/lib/func_db.js) (Database access), [`System/message.js`](https://github.com/fauzi-1110/bot-trading/blob/main/System/message.js) (Message commands), [`System/query.js`](https://github.com/fauzi-1110/bot-trading/blob/main/System/query.js) (Callback actions), [`index.js`](https://github.com/fauzi-1110/bot-trading/blob/main/index.js) (Scheduled updates)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_telegram["Telegram interface"]
  node_telegram_api["Telegram API"]
  node_entry["Bot entry<br/>[index.js]"]
  node_messages["Message commands<br/>[message.js]"]
  node_callbacks["Callback actions<br/>[query.js]"]
  node_parser["Update parser"]
end

subgraph group_gameplay["Trading gameplay"]
  node_trade["Trade actions<br/>[query.js]"]
  node_market["Market prices<br/>[func_cointem.js]"]
  node_game_rules["Game utilities<br/>[func_other.js]"]
  node_jobs_business["Jobs and shops<br/>[func_other.js]"]
  node_season["Season and rankings<br/>[func_other.js]"]
end

subgraph group_simulation["Game simulation"]
  node_bots["Bot traders<br/>[func_bot.js]"]
  node_party["Party system<br/>[func_bot.js]"]
  node_scheduler["Scheduled updates<br/>[index.js]"]
end

subgraph group_state["Persistent state"]
  node_db_access["Database access<br/>[func_db.js]"]
  node_user_store[("User records<br/>[user.json]")]
  node_global_store[("Game records<br/>[global.json]")]
end

node_user(("Player"))

node_user -->|"sends updates"| node_telegram_api
node_telegram_api -->|"delivers updates"| node_entry
node_entry -->|"registers handlers"| node_telegram_api
node_entry -->|"dispatches messages"| node_messages
node_entry -->|"dispatches callbacks"| node_callbacks
node_messages -->|"parses messages"| node_parser
node_callbacks -->|"parses callbacks"| node_parser
node_messages -->|"sends replies"| node_telegram_api
node_callbacks -->|"edits replies"| node_telegram_api
node_messages -->|"reads and writes"| node_db_access
node_callbacks -->|"reads and writes"| node_db_access
node_messages -->|"offers trades"| node_trade
node_callbacks -->|"executes trades"| node_trade
node_trade -->|"updates volumes"| node_market
node_trade -->|"uses calculations"| node_game_rules
node_messages -->|"manages bot roles"| node_bots
node_messages -->|"handles game commands"| node_jobs_business
node_callbacks -->|"handles ranking actions"| node_season
node_entry -->|"starts timer"| node_scheduler
node_scheduler -->|"updates prices"| node_market
node_scheduler -->|"updates bots"| node_bots
node_scheduler -->|"checks parties"| node_party
node_scheduler -->|"restocks shops"| node_jobs_business
node_scheduler -->|"applies daily updates"| node_db_access
node_market -->|"reads and writes"| node_db_access
node_bots -->|"reads and writes"| node_db_access
node_party -->|"reads and writes"| node_db_access
node_jobs_business -->|"reads and writes"| node_db_access
node_season -->|"reads and writes"| node_db_access
node_db_access -->|"loads and saves"| node_user_store
node_db_access -->|"loads and saves"| node_global_store

click node_entry "https://github.com/fauzi-1110/bot-trading/blob/main/index.js"
click node_messages "https://github.com/fauzi-1110/bot-trading/blob/main/System/message.js"
click node_callbacks "https://github.com/fauzi-1110/bot-trading/blob/main/System/query.js"
click node_trade "https://github.com/fauzi-1110/bot-trading/blob/main/System/query.js"
click node_market "https://github.com/fauzi-1110/bot-trading/blob/main/lib/func_cointem.js"
click node_game_rules "https://github.com/fauzi-1110/bot-trading/blob/main/lib/func_other.js"
click node_bots "https://github.com/fauzi-1110/bot-trading/blob/main/lib/func_bot.js"
click node_party "https://github.com/fauzi-1110/bot-trading/blob/main/lib/func_bot.js"
click node_jobs_business "https://github.com/fauzi-1110/bot-trading/blob/main/lib/func_other.js"
click node_season "https://github.com/fauzi-1110/bot-trading/blob/main/lib/func_other.js"
click node_scheduler "https://github.com/fauzi-1110/bot-trading/blob/main/index.js"
click node_db_access "https://github.com/fauzi-1110/bot-trading/blob/main/lib/func_db.js"
click node_user_store "https://github.com/fauzi-1110/bot-trading/blob/main/database/user.json"
click node_global_store "https://github.com/fauzi-1110/bot-trading/blob/main/database/global.json"

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_telegram_api,node_entry,node_messages,node_callbacks,node_parser toneBlue
class node_trade,node_market,node_game_rules,node_jobs_business,node_season toneAmber
class node_bots,node_party,node_scheduler toneMint
class node_db_access,node_user_store,node_global_store toneRose
class node_user toneIndigo
```

## Components

### Telegram interface

- **Telegram API**
- [Bot entry](https://github.com/fauzi-1110/bot-trading/blob/main/index.js): `index.js`
- [Message commands](https://github.com/fauzi-1110/bot-trading/blob/main/System/message.js): `System/message.js`
- [Callback actions](https://github.com/fauzi-1110/bot-trading/blob/main/System/query.js): `System/query.js`
- **Update parser**

### Trading gameplay

- [Trade actions](https://github.com/fauzi-1110/bot-trading/blob/main/System/query.js): `System/query.js`
- [Market prices](https://github.com/fauzi-1110/bot-trading/blob/main/lib/func_cointem.js): `lib/func_cointem.js`
- [Game utilities](https://github.com/fauzi-1110/bot-trading/blob/main/lib/func_other.js): `lib/func_other.js`
- [Jobs and shops](https://github.com/fauzi-1110/bot-trading/blob/main/lib/func_other.js): `lib/func_other.js`
- [Season and rankings](https://github.com/fauzi-1110/bot-trading/blob/main/lib/func_other.js): `lib/func_other.js`

### Game simulation

- [Bot traders](https://github.com/fauzi-1110/bot-trading/blob/main/lib/func_bot.js): `lib/func_bot.js`
- [Party system](https://github.com/fauzi-1110/bot-trading/blob/main/lib/func_bot.js): `lib/func_bot.js`
- [Scheduled updates](https://github.com/fauzi-1110/bot-trading/blob/main/index.js): `index.js`

### Persistent state

- [Database access](https://github.com/fauzi-1110/bot-trading/blob/main/lib/func_db.js): `lib/func_db.js`
- [User records](https://github.com/fauzi-1110/bot-trading/blob/main/database/user.json): `database/user.json`
- [Game records](https://github.com/fauzi-1110/bot-trading/blob/main/database/global.json): `database/global.json`

### Other components

- **Player**

## Connections

- Player → Telegram API: sends updates
- Telegram API → Bot entry: delivers updates
- Bot entry → Telegram API: registers handlers
- Bot entry → Message commands: dispatches messages
- Bot entry → Callback actions: dispatches callbacks
- Message commands → Update parser: parses messages
- Callback actions → Update parser: parses callbacks
- Message commands → Telegram API: sends replies
- Callback actions → Telegram API: edits replies
- Message commands → Database access: reads and writes
- Callback actions → Database access: reads and writes
- Message commands → Trade actions: offers trades
- Callback actions → Trade actions: executes trades
- Trade actions → Market prices: updates volumes
- Trade actions → Game utilities: uses calculations
- Message commands → Bot traders: manages bot roles
- Message commands → Jobs and shops: handles game commands
- Callback actions → Season and rankings: handles ranking actions
- Bot entry → Scheduled updates: starts timer
- Scheduled updates → Market prices: updates prices
- Scheduled updates → Bot traders: updates bots
- Scheduled updates → Party system: checks parties
- Scheduled updates → Jobs and shops: restocks shops
- Scheduled updates → Database access: applies daily updates
- Market prices → Database access: reads and writes
- Bot traders → Database access: reads and writes
- Party system → Database access: reads and writes
- Jobs and shops → Database access: reads and writes
- Season and rankings → Database access: reads and writes
- Database access → User records: loads and saves
- Database access → Game records: loads and saves
