Case Study
Project Case Study
Challenges, solutions, outcomes, technical highlights, architecture, and project scale.
⚡
Challenges
1. Managing two different environments (Django web + Aiogram Telegram bot) in a single project.
2. Passwordless user authentication using Telegram ID.
3. Broadcasting messages to many Telegram users while respecting rate limits.
4. Integrating a CustomUser model with Django's authentication system.
5. Managing multilingual requests and storing 4-language data in the database.
6. Coordinating async Telegram bot execution with sync Django execution.
💡
Solutions
1. Using Aiogram for bot management and Django for the admin panel.
2. Identifying users by unique telegram_id instead of username/password.
3. Sending messages in a separate thread with a 60-second interval per send to prevent blocking.
4. Building CustomUser by inheriting from AbstractUser and adding Telegram-specific fields.
5. Storing multilingual content in separate fields (title_en, title_ar, title_tr, etc.).
6. Using sync_to_async to call Django ORM in the async bot environment.
📚
Outcomes
- Reduced customer response time from days to hours.
- Unified management of all user requests in a single panel.
- Ability to broadcast messages to all users with one click.
- Automatic user registration through the Telegram bot without forms.
- Support for 4 languages (Persian, English, Arabic, Turkish) for project content.
🔧
Technical Highlights
- Using FSM (Finite State Machine) in Aiogram for user registration flow.
- Implementing a custom permission system (IsSuperUser) to restrict access.
- Converting Gregorian dates to Jalali using the persiantools library.
- Secure file upload management with unique timestamp-based naming.
- Using AJAX to edit channel links without page refresh.
- SOCKS5 proxy support for connecting to Telegram in restricted environments.
🏗️
Architecture
The project is built on Django's MVT architecture and consists of three main apps:
1. crm: User management, consultation, investment, traders, and channel links.
2. telegram_bot: Telegram bot implementation with Aiogram and FSM management.
3. payments: Payment module (under development).
Communication between the bot and the panel is through a shared database (SQLite/MySQL). The bot runs in a separate thread when runserver starts.
📐
Project Scale
The project is designed at the level of a medium-sized application with potential to scale to a large one. It currently uses SQLite, which is suitable for development and testing and can be upgraded to MySQL or PostgreSQL for production.