Technical documentation for developers and contributors
BitMshauri is built with a modular, scalable architecture designed for reliability and maintainability:
Core programming language
Lightweight database
Messaging platform
AI-powered Q&A
git clone https://github.com/MWANGAZA-LAB/bitmshauri-bot.git
cd bitmshauri-bot-3
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
# Edit .env with your bot token and API keys
python setup.py
python app/enhanced_telegram_bot.py
Use the --debug
flag when running the bot for detailed logging and development features.
bitmshauri-bot-3/
├── app/
│ ├── __init__.py
│ ├── enhanced_telegram_bot.py # Main bot entry point
│ ├── database.py # Database models
│ ├── enhanced_database.py # Enhanced database operations
│ ├── routes.py # Web routes (future)
│ └── bot/
│ ├── __init__.py
│ ├── telegram_bot.py # Core bot functionality
│ ├── price_api.py # Price fetching
│ ├── content_swahili.py # Swahili content
│ └── audio_tts.py # Text-to-speech
├── app/services/
│ ├── calculator.py # Price calculator
│ ├── community.py # Group features
│ ├── content_manager.py # Content management
│ ├── enhanced_audio.py # Audio processing
│ ├── multi_language.py # Language handling
│ ├── price_service.py # Price services
│ └── progress_tracker.py # User progress
├── app/utils/
│ ├── logger.py # Logging utilities
│ └── rate_limiter.py # Rate limiting
├── docs/ # Documentation
├── tests/ # Test suite
├── requirements.txt # Python dependencies
├── config.py # Configuration
├── main.py # Alternative entry point
└── setup.py # Setup script
The main bot handler manages incoming messages and routes them to appropriate services:
Handles currency conversions and price calculations
app/services/calculator.py
Manages study groups and community features
app/services/community.py
Handles educational content and lessons
app/services/content_manager.py
Language detection and translation
app/services/multi_language.py
The database layer provides data persistence and user management:
CREATE TABLE users (
id INTEGER PRIMARY KEY,
telegram_id INTEGER UNIQUE NOT NULL,
username TEXT,
first_name TEXT,
last_name TEXT,
language TEXT DEFAULT 'en',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
last_active TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
progress_data TEXT, -- JSON string
preferences TEXT -- JSON string
);
CREATE TABLE lessons (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
content TEXT NOT NULL,
language TEXT NOT NULL,
difficulty INTEGER DEFAULT 1,
category TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE user_progress (
id INTEGER PRIMARY KEY,
user_id INTEGER,
lesson_id INTEGER,
completed BOOLEAN DEFAULT FALSE,
score INTEGER,
completed_at TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (lesson_id) REFERENCES lessons(id)
);
CREATE TABLE study_groups (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
description TEXT,
creator_id INTEGER,
max_members INTEGER DEFAULT 50,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (creator_id) REFERENCES users(id)
);
Primary messaging platform
Cryptocurrency price data
AI-powered Q&A system
The bot implements intelligent rate limiting to prevent abuse:
Comprehensive testing ensures reliability and quality:
Test individual components and functions
python -m pytest tests/unit/
Test component interactions
python -m pytest tests/integration/
Test complete user workflows
python -m pytest tests/e2e/
python -m pytest
python -m pytest --cov=app
python -m pytest tests/test_calculator.py
Deploy the bot to production using various platforms:
TELEGRAM_BOT_TOKEN
Your Telegram bot token from @BotFather
OPENAI_API_KEY
OpenAI API key for AI features
DATABASE_PATH
Path to SQLite database file
LOG_LEVEL
Logging level (DEBUG, INFO, WARNING, ERROR)
We welcome contributions from the community! Here's how to get started:
Create your own fork of the project on GitHub
git checkout -b feature/your-feature-name
Implement your feature or fix with proper testing
python -m pytest
Create a PR with a clear description of your changes