# kaguya2021/kaguya2_0_bot architecture

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

- Interactive diagram: https://gitdiagram.com/kaguya2021/kaguya2_0_bot
- Repository: https://github.com/kaguya2021/kaguya2_0_bot

## Overview

Kaguya is a Telegram bot for configurable automatic replies, managed through commands and inline settings. Users configure reply text, schedules, reply mode, timer mode and an allowed account; the bot processes incoming business messages and can also support admin user management and broadcasts. The runtime entry point exposes an Express webhook for Telegram and sets that webhook on startup. Bot handlers use the database module for persistent user settings, pauses and error logs. The excerpt is partial, so unshown handler-to-feature relationships are omitted; the README provides no additional capability evidence.

Main entry points: [`bot.js`](https://github.com/kaguya2021/kaguya2_0_bot/blob/main/bot.js) (Bot handlers), [`index.js`](https://github.com/kaguya2021/kaguya2_0_bot/blob/main/index.js) (Webhook server), [`database.js`](https://github.com/kaguya2021/kaguya2_0_bot/blob/main/database.js) (Database operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot runtime"]
  node_entry["Webhook server<br/>[index.js]"]
  node_bot["Bot handlers<br/>[bot.js]"]
end

subgraph group_features["Reply management"]
  node_reply_config["Reply configuration<br/>[bot.js]"]
  node_reply_processing["Auto-reply processing<br/>[bot.js]"]
  node_settings["Account settings<br/>[bot.js]"]
  node_admin["Admin commands<br/>[bot.js]"]
end

subgraph group_persistence["Persistence"]
  node_db_api["Database operations<br/>[database.js]"]
  node_postgres[("Postgres database")]
end

node_user(("Telegram user"))
node_telegram{{"Telegram API"}}

node_user -->|"sends messages"| node_telegram
node_telegram -->|"delivers webhook"| node_entry
node_entry -->|"dispatches updates"| node_bot
node_user -->|"uses commands"| node_bot
node_bot -->|"sends replies"| node_telegram
node_bot -->|"handles settings"| node_reply_config
node_bot -->|"handles messages"| node_reply_processing
node_bot -->|"handles account options"| node_settings
node_bot -->|"handles admin actions"| node_admin
node_bot -->|"calls"| node_db_api
node_db_api -->|"queries"| node_postgres
node_entry -->|"sets webhook"| node_telegram

click node_entry "https://github.com/kaguya2021/kaguya2_0_bot/blob/main/index.js"
click node_bot "https://github.com/kaguya2021/kaguya2_0_bot/blob/main/bot.js"
click node_reply_config "https://github.com/kaguya2021/kaguya2_0_bot/blob/main/bot.js"
click node_reply_processing "https://github.com/kaguya2021/kaguya2_0_bot/blob/main/bot.js"
click node_settings "https://github.com/kaguya2021/kaguya2_0_bot/blob/main/bot.js"
click node_admin "https://github.com/kaguya2021/kaguya2_0_bot/blob/main/bot.js"
click node_db_api "https://github.com/kaguya2021/kaguya2_0_bot/blob/main/database.js"

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_entry,node_bot,node_user toneBlue
class node_reply_config,node_reply_processing,node_settings,node_admin toneAmber
class node_db_api,node_postgres,node_telegram toneMint
```

## Components

### Bot runtime

- [Webhook server](https://github.com/kaguya2021/kaguya2_0_bot/blob/main/index.js): `index.js`
- [Bot handlers](https://github.com/kaguya2021/kaguya2_0_bot/blob/main/bot.js): `bot.js`

### Reply management

- [Reply configuration](https://github.com/kaguya2021/kaguya2_0_bot/blob/main/bot.js): `bot.js`
- [Auto-reply processing](https://github.com/kaguya2021/kaguya2_0_bot/blob/main/bot.js): `bot.js`
- [Account settings](https://github.com/kaguya2021/kaguya2_0_bot/blob/main/bot.js): `bot.js`
- [Admin commands](https://github.com/kaguya2021/kaguya2_0_bot/blob/main/bot.js): `bot.js`

### Persistence

- [Database operations](https://github.com/kaguya2021/kaguya2_0_bot/blob/main/database.js): `database.js`
- **Postgres database**

### Other components

- **Telegram user**
- **Telegram API**

## Connections

- Telegram user → Telegram API: sends messages
- Telegram API → Webhook server: delivers webhook (evidence: `index.js`)
- Webhook server → Bot handlers: dispatches updates (evidence: `index.js`)
- Telegram user → Bot handlers: uses commands (evidence: `bot.js`)
- Bot handlers → Telegram API: sends replies (evidence: `bot.js`)
- Bot handlers → Reply configuration: handles settings (evidence: `bot.js`)
- Bot handlers → Auto-reply processing: handles messages (evidence: `bot.js`)
- Bot handlers → Account settings: handles account options (evidence: `bot.js`)
- Bot handlers → Admin commands: handles admin actions (evidence: `bot.js`)
- Bot handlers → Database operations: calls (evidence: `bot.js`)
- Database operations → Postgres database: queries (evidence: `database.js`)
- Webhook server → Telegram API: sets webhook (evidence: `index.js`)
