Skip to content
CAI
Software that uses CAICheck a score

barahouei/clean-architecture-telegram-bot

48.1

Weak · 21 September 2026

1.2k

lines of production code

Go

primary language

4

measurements over time

CAI band scale
CAI trend line
CAI lens gauges

What this system is

This system is a Go-based Telegram bot that manages user accounts and processes interactions through a modular, clean architecture. It supports multi-language interfaces in English and Farsi, handling commands, callback queries, and message routing via a service layer. The application is designed with flexible data persistence, allowing users to switch between PostgreSQL, MySQL, and MongoDB backends through centralized configuration.

Features

Add MongoDB repository implementation with auto-increment user IDs

Introduces a new MongoDB database driver and user repository within the application. The implementation connects to MongoDB using configuration parameters and provides methods to create, retrieve, and update user records. Notably, user creation now assigns an auto-incrementing ID based on the existing document count in the 'users' collection, rather than relying on MongoDB's default ObjectId generation.

repositories/mongodb · high confidence

Add MySQL database repository implementation

Users can now store application data in a MySQL database. This change introduces the MySQL-specific repository implementation, including database connection management via a factory pattern and data access methods for creating, retrieving, and updating user records.

repositories/mysql · high confidence

Add multi-language support for Telegram bot UI and logging

The bot now supports English and Persian (Farsi) for user-facing content. Inline keyboards (main menu, back button, language selection with flags) and text messages (help, user information, welcome, error) are localized based on the user's language setting. A new structured logging package using Zap is introduced, writing to both file and stdout.

pkg · high confidence

Centralized configuration for multi-database support

The application now uses a centralized configuration system that supports PostgreSQL, MySQL, and MongoDB. Users can select the active database driver via the BOT\_DB\_DRIVER environment variable, and all connection details (host, port, credentials, database name) are managed through specific environment variables for each supported database type.

configs · high confidence

Initial model definitions for user, language, and database configuration

This change introduces the foundational data models for the application. It defines the User struct with fields for ID, Telegram ID, username, name, join date, and language preference, utilizing BSON tags for MongoDB compatibility. It also adds configuration enums for Application Mode (Development/Production), supported Database types (PostgreSQL, MySQL, MongoDB) with a Stringer implementation, and User Language (English, Farsi) with a Stringer implementation.

models · high confidence

Initial project structure and documentation

The repository is initialized with a clean architecture structure for a Go-based Telegram bot, including directories for commands, configurations, handlers, logs, models, packages, repositories, and services. The main entry point has been updated to use the slog library for error logging and to execute the application via the cmd package, replacing the previous simple print statement. Additionally, a .gitignore file has been added to exclude log files and a comprehensive README.md has been created to explain the directory structure and architecture principles.

(repo-wide) · high confidence

Initial release of the Telegram bot handler and core services

This change introduces the foundational structure for the Telegram bot, adding the \handlers/bot\ package which implements the main bot loop, command processing (\/start\), callback query handling (including language selection for English and Farsi), and general message handling. It also adds the \handlers\ interface definition and integrates with new service layer components for account, message, command, and callback operations, establishing the initial user interaction flow.

handlers/bot · high confidence

Introduce CLI entry point and serve command for the Telegram bot

The application now exposes a command-line interface (using urfave/cli/v2) with a 'serve' command to start the Telegram bot. This command initializes the logging infrastructure (creating a 'logs' directory and file), loads configuration, establishes a database connection, and starts the bot service, handling graceful shutdown on interrupt signals. A 'debug' subcommand is also available to enable debug mode.

cmd · high confidence

Introduce PostgreSQL repository implementation for user management

Added a new PostgreSQL database repository that implements the core user data operations: creating new users, retrieving user details by Telegram ID, and updating a user's language preference. The implementation includes a factory function to establish and verify the database connection using context-aware methods, ensuring proper resource management and error handling for connection failures.

repositories/postgres · high confidence

Introduces application services for account management, command handling, and callback processing

This change adds the core application service layer for the Telegram bot, introducing interfaces and implementations for user account management (creating, retrieving, and updating user language preferences), command processing (specifically language selection), and callback query handling (displaying main menu, help, information, and language selection screens). These services act as the business logic layer, coordinating between the database repositories and the Telegram API to ensure user interactions are handled with the correct language context.

services · high confidence

Behavioural changes

Centralized database driver selection

The application now uses a centralized factory function to initialize the database connection, allowing users to switch between PostgreSQL, MySQL, and MongoDB backends via configuration. This change consolidates the database creation logic into a single entry point that selects the appropriate driver based on the configured database type.

repositories/database · high confidence

Dependencies

Initial dependency set for Telegram bot application

The project now includes its core Go dependencies, enabling the Telegram bot functionality and data persistence. Key libraries added include the Telegram Bot API client (v5.5.1), database drivers for MySQL (v1.7.1) and MongoDB (v1.12.0), environment configuration tools (godotenv v1.5.1, env v8.0.0), a CLI framework (urfave/cli v2.25.7), and structured logging (zap v1.24.0).

(dependencies) · high confidence

Housekeeping

Added empty bot log file

An empty log file named bot.log has been added to the repository.

logs · high confidence

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Baseline

  • First survey — no prior run to compare against. CAI 48.

Lenses

  • Code Health 99
  • Architecture 69
  • Maturity 62
  • Readiness 21
  • Security 95

Changes since last survey

  • 45 commits — 35 feature/other, 10 fixes

By area

  • (root) — 18 commits
  • cmd/commands.go — 7 commits
  • handlers/bot — 6 commits
  • repositories/postgres — 3 commits
  • configs/.env — 2 commits
  • models/user.go — 2 commits
  • pkg/logger — 2 commits
  • cmd/cli.go — 1 commit
  • models/language.go — 1 commit
  • pkg/messages — 1 commit
  • services/account — 1 commit
  • services/callback — 1 commit

Notable commits

  • fix: fix: better error handling
  • fix: fix: better logging
  • fix: fix: break on blocking the bot
  • fix: fix: change config
  • fix: fix: change context
  • fix: fix: change how to pass context
  • fix: fix: change necessary user field
  • fix: fix: exit on error
  • fix: fix: mysql env
  • fix: fix: remove Sync method from logger for similarity with other loggers
  • change: add callback service
  • change: chore: move creating new database to its own package
  • change: chore: use factory pattern for creating new database
  • change: docs: update README
  • change: feat: Add cli
  • change: feat: Add log for debug mode
  • change: feat: add /configs to README
  • change: feat: add /models to README
  • change: feat: add /pkg to README
  • change: feat: add account service
  • …and 25 more

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

Survey your own repository

barahouei/clean-architecture-telegram-bot was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.

About this page

  • The score is its most recent published measurement, taken on 21 September 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit 8993256b20a79b8f0d350b14fdd615b84e78a2ce — the exact code this score is about.
  • Scored under rubric-2026.09.15 — the same rubric and the same method as every other entry in this index.
  • Measured by watchdog.canine.dev using codehealth-analyzer preprod-28e75b8e3254.