1+ ---
2+ description: Enforce modular architecture, clean separation, and reusable logic for AI Telegram bot
3+ globs: ["**/*.go"]
4+ alwaysApply: true
5+ ---
6+
7+ # 🧱 Modular AI Telegram Bot Architecture Rules
18
2- # Modular AI Telegram Bot Architecture Rules
9+ This rule enforces best practices for building scalable, testable, and clean modular architecture in the SaveMessage Telegram bot project.
10+
11+ ---
312
413## ✅ 1. Functional Isolation
514
6- Each key behavior should be implemented as a **dedicated function** with a single purpose :
15+ Each core behavior must be a **dedicated function** with a single responsibility :
716
8- - `DeleteMessage(chatID, messageID)`
9- - `RequestTopicName(chatID, originalMessageID)`
10- - `CreateNewTopic(chatID, topicName)`
11- - `SuggestCategories(messageText) -> []string`
12- - `MoveMessageToTopic(originalMsgID, targetTopicID)`
17+ - `DeleteMessage(chatID, messageID)`
18+ - `RequestTopicName(chatID, originalMessageID)`
19+ - `CreateNewTopic(chatID, topicName)`
20+ - `SuggestCategories(messageText) -> []string`
21+ - `MoveMessageToTopic(originalMsgID, targetTopicID)`
1322- `SendEditPrompt(originalMsgID)`
1423
15- All these functions should be reusable, predictable, and independently testable.
24+ These functions should be:
25+ - Predictable
26+ - Testable
27+ - Reusable
28+ - Free of side-effects outside their domain
1629
17- ## ✅ 2. Handler Separation by User Flow
18-
19- Create **separate handlers** for user paths such as:
30+ ---
2031
21- - Selecting an existing folder from suggestions
22- → `HandleExistingTopicSelection()`
32+ ## ✅ 2. Handler Separation by User Flow
2333
24- - Choosing to create a new folder from AI suggestion
25- → `HandleNewTopicCreationRequest()`
34+ Each user journey must have its own **handler function**:
2635
27- - Typing the topic name after being prompted
28- → `HandleNewTopicNameEntry()`
36+ | User Action | Handler Function |
37+ |------------------------------------------|------------------------------------|
38+ | Select an existing folder | `HandleExistingTopicSelection()` |
39+ | Create new folder from AI suggestion | `HandleNewTopicCreationRequest()` |
40+ | Enter name for new folder | `HandleNewTopicNameEntry()` |
41+ | Edit a saved message | `HandleEditRequest()` |
2942
30- - Editing a message by sending `Edit:[ID] new text`
31- → `HandleEditRequest()`
43+ This ensures logic remains traceable and modular.
3244
33- This keeps business logic traceable, debuggable, and scalable.
45+ ---
3446
3547## ✅ 3. Command/Event Routing
3648
37- Set up a router or dispatcher to route incoming updates:
49+ Use a **central dispatcher** or router to route updates based on context :
3850
3951```go
4052func HandleUpdate(update tgbotapi.Update) {
@@ -53,21 +65,34 @@ func HandleUpdate(update tgbotapi.Update) {
5365}
5466```
5567
68+ This isolates behavior from parsing logic and avoids duplication.
69+
70+ ---
71+
5672## ✅ 4. Architecture Goals
5773
58- - Respect clean architecture / separation of concerns
59- - Use clear package boundaries: handlers/, services/, ai/, utils/
60- - All messages, callbacks, and responses should go through a central dispatcher
61- - All business logic should be inside small, focused services
62- - No logic inside main.go except setup
74+ Maintain clean architectural principles:
75+
76+ - All logic should live in one of: `handlers/`, `services/`, `ai/`, or `utils/`
77+ - `main.go` should only handle setup, wiring, and server start
78+ - Keep message-handling logic out of `main.go`
79+ - Centralize all routing and command parsing
80+
81+ ---
6382
6483## 🧪 Additional Notes
6584
66- - Always use logging for every handler entry and exit
67- - Future-proof the code for new interaction types (search, tagging, etc.)
68- - No hard-coded text: use constants or i18n struct
69- - No message or user data should be saved in storage (privacy-first)
70- description:
71- globs:
72- alwaysApply: false
85+ - Always log handler **entry and exit**
86+ - Prepare services to be **mocked** for testing
87+ - Future-proof for features like:
88+ - Search
89+ - Tagging
90+ - Reactions
91+ - Avoid hardcoded text — use constants or i18n
92+ - Respect user privacy:
93+ - Do not store message content or personal data
94+ - Only store minimal user metadata if needed (e.g., roles, pro status)
95+
7396---
97+
98+ 🏁 Following these rules will ensure a modular, scalable, and robust bot architecture that’s AI-ready and privacy-first.
0 commit comments