# fmmagalhaes/random-reminder-telegram-bot architecture

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

- Interactive diagram: https://gitdiagram.com/fmmagalhaes/random-reminder-telegram-bot
- Repository: https://github.com/fmmagalhaes/random-reminder-telegram-bot

## Overview

This is a Telegram bot for collecting chat text and sending stored messages back as random reminders, either on demand or on a per-chat schedule. Users can also start or stop reminders, inspect stored messages, and delete one or all messages. The runtime registers Telegram command and text handlers, while a periodic job checks active chats against saved cron expressions. Message and chat configuration state is persisted locally in JSON. The source excerpts show these main flows; relationships for the documented commands and local storage are grounded in the README where applicable.

Main entry points: [`src/bot.py`](https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/bot.py) (Bot entrypoint), [`src/storage/chat_repository.py`](https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/storage/chat_repository.py) (Chat repository), [`src/handlers/command_handlers.py`](https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/handlers/command_handlers.py) (Command handlers), [`src/handlers/schedule_handlers.py`](https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/handlers/schedule_handlers.py) (Schedule conversation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot runtime"]
  node_bot["Bot entrypoint<br/>[bot.py]"]
end

subgraph group_handlers["Chat handlers"]
  node_commands["Command handlers"]
  node_messages["Text handler"]
end

subgraph group_scheduling["Scheduling"]
  node_schedule_handler["Schedule conversation"]
  node_time["Cron trigger check<br/>[time_utils.py]"]
end

subgraph group_support["Shared support"]
  node_auth["Authorization wrapper<br/>[auth_wrapper.py]"]
  node_reminder["Reminder sender<br/>[reminder_utils.py]"]
  node_logger["Logging<br/>[logger.py]"]
end

subgraph group_persistence["Persistence"]
  node_repository["Chat repository<br/>[chat_repository.py]"]
  node_json_store[("Local JSON state<br/>[chat_repository.py]")]
end

node_user(("Chat user"))
node_telegram["Telegram platform"]
node_cron_parser["Natural-language cron parser"]

node_user -->|"sends messages"| node_telegram
node_telegram -->|"delivers updates"| node_bot
node_bot -->|"registers commands"| node_commands
node_bot -->|"registers text handler"| node_messages
node_bot -->|"registers conversation"| node_schedule_handler
node_commands -->|"guards commands"| node_auth
node_messages -->|"guards messages"| node_auth
node_schedule_handler -->|"guards schedule actions"| node_auth
node_messages -->|"stores text"| node_repository
node_commands -->|"manages chat data"| node_repository
node_commands -->|"requests reminder"| node_reminder
node_schedule_handler -->|"saves schedule"| node_repository
node_schedule_handler -->|"parses schedule text"| node_cron_parser
node_bot -->|"reads chat schedules"| node_repository
node_bot -->|"checks trigger time"| node_time
node_bot -->|"sends due reminder"| node_reminder
node_reminder -->|"selects random message"| node_repository
node_reminder -->|"sends reminder"| node_telegram
node_repository -->|"reads and writes"| node_json_store
node_repository -->|"logs storage errors"| node_logger
node_auth -->|"logs access"| node_logger
node_bot -->|"configures logging"| node_logger

click node_bot "https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/bot.py"
click node_commands "https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/handlers/command_handlers.py"
click node_messages "https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/handlers/message_handlers.py"
click node_schedule_handler "https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/handlers/schedule_handlers.py"
click node_auth "https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/helpers/auth_wrapper.py"
click node_reminder "https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/helpers/reminder_utils.py"
click node_time "https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/helpers/time_utils.py"
click node_logger "https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/helpers/logger.py"
click node_repository "https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/storage/chat_repository.py"
click node_json_store "https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/storage/chat_repository.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,node_user toneBlue
class node_commands,node_messages toneAmber
class node_schedule_handler,node_time toneMint
class node_auth,node_reminder,node_logger toneRose
class node_repository,node_json_store,node_telegram,node_cron_parser toneIndigo
```

## Components

### Bot runtime

- [Bot entrypoint](https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/bot.py): `src/bot.py`

### Chat handlers

- [Command handlers](https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/handlers/command_handlers.py): `src/handlers/command_handlers.py`
- [Text handler](https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/handlers/message_handlers.py): `src/handlers/message_handlers.py`

### Scheduling

- [Schedule conversation](https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/handlers/schedule_handlers.py): `src/handlers/schedule_handlers.py`
- [Cron trigger check](https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/helpers/time_utils.py): `src/helpers/time_utils.py`

### Shared support

- [Authorization wrapper](https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/helpers/auth_wrapper.py): `src/helpers/auth_wrapper.py`
- [Reminder sender](https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/helpers/reminder_utils.py): `src/helpers/reminder_utils.py`
- [Logging](https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/helpers/logger.py): `src/helpers/logger.py`

### Persistence

- [Chat repository](https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/storage/chat_repository.py): `src/storage/chat_repository.py`
- [Local JSON state](https://github.com/fmmagalhaes/random-reminder-telegram-bot/blob/main/src/storage/chat_repository.py): `src/storage/chat_repository.py`

### Other components

- **Chat user**
- **Telegram platform**
- **Natural-language cron parser**

## Connections

- Chat user → Telegram platform: sends messages (evidence: `README.md`)
- Telegram platform → Bot entrypoint: delivers updates (evidence: `src/bot.py`)
- Bot entrypoint → Command handlers: registers commands (evidence: `src/bot.py`)
- Bot entrypoint → Text handler: registers text handler (evidence: `src/bot.py`)
- Bot entrypoint → Schedule conversation: registers conversation (evidence: `src/bot.py`)
- Command handlers → Authorization wrapper: guards commands (evidence: `src/handlers/command_handlers.py`)
- Text handler → Authorization wrapper: guards messages (evidence: `src/handlers/message_handlers.py`)
- Schedule conversation → Authorization wrapper: guards schedule actions (evidence: `src/handlers/schedule_handlers.py`)
- Text handler → Chat repository: stores text (evidence: `src/handlers/message_handlers.py`)
- Command handlers → Chat repository: manages chat data (evidence: `src/handlers/command_handlers.py`)
- Command handlers → Reminder sender: requests reminder (evidence: `src/handlers/command_handlers.py`)
- Schedule conversation → Chat repository: saves schedule (evidence: `src/handlers/schedule_handlers.py`)
- Schedule conversation → Natural-language cron parser: parses schedule text (evidence: `src/handlers/schedule_handlers.py`)
- Bot entrypoint → Chat repository: reads chat schedules (evidence: `src/bot.py`)
- Bot entrypoint → Cron trigger check: checks trigger time (evidence: `src/bot.py`)
- Bot entrypoint → Reminder sender: sends due reminder (evidence: `src/bot.py`)
- Reminder sender → Chat repository: selects random message (evidence: `src/helpers/reminder_utils.py`)
- Reminder sender → Telegram platform: sends reminder (evidence: `src/helpers/reminder_utils.py`)
- Chat repository → Local JSON state: reads and writes (evidence: `src/storage/chat_repository.py`)
- Chat repository → Logging: logs storage errors (evidence: `src/storage/chat_repository.py`)
- Authorization wrapper → Logging: logs access (evidence: `src/helpers/auth_wrapper.py`)
- Bot entrypoint → Logging: configures logging (evidence: `src/bot.py`)
