A production-ready, full-stack Telegram Mini App template featuring real-time updates, leaderboards, and referral systems. Perfect for building viral Telegram games and interactive bots.
๐ Quick Start โข โจ Features โข ๐๏ธ Architecture โข ๐ฆ Deploy โข ๐ Documentation
A complete, battle-tested template for building Telegram Mini Apps with real-time gameplay, live leaderboards, viral referral mechanics, and a comment service for social engagement. Built with modern technologies and designed for scale.
- ๐ฎ Game Developers - Build viral clicker games, idle games, or competitive experiences
- ๐ฌ Community Builders - Create discussion platforms with nested comments
- ๐ Startup Founders - Launch your MVP in hours, not weeks
- ๐ผ Agencies - White-label template for client projects
- ๐ Learners - Study a production-grade Telegram bot architecture
โ
Production-Ready - Already deployed and tested at scale
โ
Real-Time Updates - Live leaderboards and statistics using Redis pub/sub
โ
Viral Growth - Built-in referral system with encrypted codes
โ
Comment Service - Tree-structured comments with unlimited nesting (MongoDB)
โ
One-Click Deploy - Docker and Fly.io configs included
โ
Type-Safe - Full TypeScript across frontend, backend, and bot
โ
Modern Stack - Built with Bun, React, and the latest tools
- Interactive Menus - Beautiful inline keyboard navigation
- Posts & Comments - Create posts directly from the bot
- Admin Panel - User management, broadcasting, and analytics
- Webhook Support - Production-ready webhook handling with Fly.io
- Error Handling - Graceful error recovery with Slack notifications
- Session Management - Stateful conversations and user context
- Telegram Web App API - Seamless integration with Telegram UI
- Tab Navigation - Switch between Clicker game and Posts/Comments
- Real-Time Updates - Live click counts and leaderboard updates
- Comment Threads - Tree-structured discussions with unlimited nesting
- Responsive Design - Works perfectly on mobile and desktop
- Rate Limiting - Client-side and server-side anti-cheat measures
- Combo System - Engaging gameplay mechanics
- High Performance - Built with Express and Bun for speed
- Redis Caching - Lightning-fast data access
- Batch Processing - Efficient database writes
- Security - Telegram data validation and request signing
- CORS Ready - Configured for cross-origin requests
- Live Leaderboards - Top players updated in real-time
- Global Statistics - Total clicks, active players, rankings
- Broadcaster Service - Push updates to all active users
- Session Tracking - Know who's online and where
- Referral System - Encrypted referral codes with tracking
- Display Names - Let users customize their identity
- Posts & Comments - Discussion system similar to Disqus
- Nested Replies - Unlimited comment threading
- Achievements - Track milestones and engagement
- Notifications - Keep users engaged with updates
โโโโโโโโโโโโโโโโโโโ
โ Telegram User โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โโโโโโผโโโโโ
โ Bot โ โโโโ grammY Framework
โโโโโโฌโโโโโ โข /start, /posts commands
โ โข Create posts
โโโโโโผโโโโโโโโโโโ
โ Mini App โ โโโโ React + Vite
โ (Frontend) โ โข Clicker game
โโโโโโฌโโโโโโโโโโโ โข Posts & Comments
โ
โโโโโโผโโโโโโโโโโโ
โ Backend API โ โโโโ Express + Bun
โโโโโโฌโโโโโโโโโโโ โข REST API
โ
โโโโโโผโโโโโฌโโโโโโผโโโโโฌโโโโโโโผโโโโโโโ
โ Redis โ Postgres โ MongoDB โ
โ (Cache) โ (Users) โ(Posts/Cmts) โ
โโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโโโโ
| Component | Technology | Purpose |
|---|---|---|
| Bot | grammY, TypeScript | Telegram bot framework |
| Frontend | React, Vite, TypeScript | Mini app interface |
| Backend | Express, Bun | REST API server |
| Database | PostgreSQL, Drizzle ORM | User data & clicks |
| Posts/Comments | MongoDB, Mongoose | Discussion threads |
| Cache | Redis, ioredis | Real-time updates & caching |
| Runtime | Bun | Fast JavaScript runtime |
| Deploy | Docker, Fly.io | Production deployment |
- Bun (v1.2+)
- Docker (optional)
- Telegram Bot Token
- PostgreSQL & Redis (or use Docker)
- MongoDB (local or MongoDB Atlas free tier)
# Clone the repository
git clone <your-repo-url>
cd telegram-clicker-game
# Install dependencies
bun install
cd bot && bun install && cd ..
cd backend && bun install && cd ..
cd web && bun install && cd ..
cd shared && bun install && cd ..Create .env files in each directory:
# Root .env or bot/.env
BOT_TOKEN=your_telegram_bot_token
DATABASE_URL=postgresql://admin:password@localhost:5432/databasev1
REDIS_URL=redis://localhost:6379
QUEUE_REDIS_URL=redis://localhost:6379
MONGO_URL=mongodb://localhost:27017/komi
MINI_APP_URL=http://localhost:5173
REFERRAL_CRYPTO_KEY=generate_with_openssl_rand_hex_16
REFERRAL_CRYPTO_IV=generate_with_openssl_rand_hex_8
ENABLE_WEBHOOKS=false
# backend/.env
BACKEND_PORT=4000
BOT_TOKEN=your_telegram_bot_token
DATABASE_URL=postgresql://admin:password@localhost:5432/databasev1
REDIS_URL=redis://localhost:6379
MONGO_URL=mongodb://localhost:27017/komiGenerate crypto keys:
openssl rand -hex 16 # REFERRAL_CRYPTO_KEY
openssl rand -hex 8 # REFERRAL_CRYPTO_IVMongoDB Setup:
# Option 1: Local MongoDB with Docker
docker run -d --name mongodb -p 27017:27017 mongo:7
# Option 2: MongoDB Atlas (Free tier)
# Sign up at https://www.mongodb.com/cloud/atlas
# Create free M0 cluster and get connection string
MONGO_URL=mongodb+srv://username:[email protected]/komicd bot
docker-compose up -dThis starts:
- PostgreSQL (port 5432)
- Redis (port 6379)
- MongoDB (port 27017)
- Backend API (port 4000)
- Bot
# Terminal 1: Start bot
cd bot
bun run dev
# Terminal 2: Start backend
cd backend
bun run dev
# Terminal 3: Start web app
cd web
bun run dev- Message your bot on Telegram
- Send
/startcommand - Play the clicker game: Click "๐ฎ Play Game" button
- Use comments feature: Click "๐ฌ Posts & Comments" button
- Start clicking and posting! ๐
# 1. Install Fly CLI
curl -L https://fly.io/install.sh | sh
# 2. Login
fly auth login
# 3. Run setup script
./fly-setup.sh
# 4. Deploy
./fly-deploy-all.shSee FLY_DEPLOYMENT.md for detailed instructions.
# Build bot
docker build -f bot/Dockerfile -t clicker-bot .
# Build backend
docker build -f backend/Dockerfile -t clicker-backend .
# Run with docker-compose
cd bot
docker-compose up --buildtelegram-clicker-game/
โโโ bot/ # Telegram bot
โ โโโ src/
โ โ โโโ commands/ # Bot commands (/start, /posts, /admin)
โ โ โโโ menus/ # Interactive inline keyboards
โ โ โโโ messages/ # Centralized text/labels
โ โ โโโ services/ # Business logic
โ โ โโโ plugins/ # grammY plugins
โ โ โโโ main.ts # Bot entry point
โ โโโ Dockerfile
โ
โโโ backend/ # REST API
โ โโโ src/
โ โ โโโ controllers/ # Route handlers (clicker, posts)
โ โ โโโ routes/ # Route definitions with DI
โ โ โโโ middleware/ # Express middleware (Telegram auth)
โ โ โโโ index.ts # API entry point
โ โโโ Dockerfile
โ
โโโ web/ # React Mini App
โ โโโ src/
โ โโโ components/ # UI components (Clicker, Posts, Comments)
โ โโโ hooks/ # React hooks (useClicker, usePosts)
โ โโโ App.tsx # Main app with tab navigation
โ
โโโ shared/ # Shared code
โโโ database/ # Schemas (PostgreSQL + MongoDB)
โโโ infra/database/ # DB clients (Postgres, Mongo, Redis)
โโโ repositories/ # Data access layer
โโโ services/ # Business logic
ExistingUserStart- Main menu with stats & leaderboardNewUserStart- Onboarding for new usersPostsMenu- Browse and create postsCreatePostMenu- Post creation with validationAdminPanel- Admin controlsReferrals- Referral system managementChangeDisplayName- User customization
Clicker:
POST /api/clicker/click- Record user clickGET /api/clicker/stats- Get user statistics
Posts & Comments:
POST /api/posts- Create new postGET /api/posts- List all postsGET /api/posts/:id- Get single postPOST /api/posts/:id/comments- Add commentGET /api/posts/:id/comments?tree=true- Get comment tree
UserService- User managementClickerService- Click tracking & validationLeaderboardService- Rankings & statisticsPostService- Posts & comments with tree buildingBroadcasterService- Real-time updatesNotificationService- Push notifications
Edit click values and combo logic:
// shared/services/clicker.service.ts
const CLICK_VALUE = 1;
const COMBO_THRESHOLD = 5;Modify the web app appearance:
// web/src/App.css
// web/src/components/ClickButton.cssCreate new admin features:
// bot/src/command/admin.command.ts
// bot/src/menus/AdminPanel.tsFor production, enable webhooks:
ENABLE_WEBHOOKS=true
BOT_WEBHOOK_HOST=https://your-domain.fly.dev
WEBHOOK_SECRET_TOKEN=your_secret_token- โ Telegram Data Validation - Verify all requests from Telegram
- โ Rate Limiting - Prevent click spam and abuse
- โ CORS Protection - Secure API endpoints
- โ Encrypted Referrals - Tamper-proof referral codes
- โ Environment Variables - No hardcoded secrets
- โ Input Validation - Sanitize all user inputs
- โก < 50ms API response time
- โก 1000+ concurrent users supported
- โก Redis caching for sub-millisecond reads
- โก Batch writes to minimize database load
- โก Connection pooling for optimal resource usage
We love contributions! Check out our Contributing Guide to get started.
- ๐ Report bugs
- ๐ก Suggest features
- ๐ Improve documentation
- ๐ง Submit pull requests
This project is open source and available under the MIT License.
If this template helped you, please give it a โญ on GitHub!
- ๐ฌ Telegram Support
- ๐ Report Issues
- ๐ก Feature Requests
- Clicker game with combo system
- Real-time leaderboards
- Referral system
- Posts & Comments (tree structure)
- Tab navigation in Mini App
- Edit/delete posts and comments
- Like/reaction system
- User mentions (@username)
- Rich text formatting (Markdown)
- Image attachments
- Multi-language support
- Achievement system
- Daily rewards
- Team/clan features
- Analytics dashboard
Built with:
- grammY - Telegram Bot Framework
- Bun - Fast JavaScript Runtime
- Drizzle ORM - TypeScript ORM for PostgreSQL
- Mongoose - MongoDB ODM
- Fly.io - Deployment Platform
Made with โค๏ธ for the Telegram community
Star this repo if you found it helpful!