A high-performance, scalable clicker game built as a Telegram Mini App with microservices architecture. This project demonstrates modern backend development practices, real-time data processing, and seamless Telegram integration.
Watch the application in action: Demo Video
This application implements a competitive clicker game where users compete for the highest click count. The system features real-time leaderboards, user statistics, and a responsive Telegram Mini App interface.
- Real-time Click Tracking: Instant click processing with Redis-based caching
- Dynamic Leaderboards: Top 20 players with live updates
- Telegram Integration: Native Mini App with Web App support
- User Management: Custom usernames and profile management
- Scalable Architecture: Microservices design supporting 100,000+ users
- Rate Limiting: Advanced protection against abuse
- Health Monitoring: Comprehensive health checks and monitoring
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Telegram Bot β β Web App β β API Gateway β
β (NestJS) βββββΊβ (React) βββββΊβ (NestJS) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Redis Cache β β PostgreSQL β β Worker Queue β
β (Sessions) β β (Persistent) β β (Background) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- API Service: Core business logic, data processing, rate limiting
- Bot Service: Telegram Bot API integration, user interactions
- WebApp Service: React-based Mini App interface
- Worker Service: Background processing, data synchronization
- Redis: Session management, caching, real-time data
- PostgreSQL: Persistent data storage, user profiles
- Framework: NestJS (Node.js)
- Language: TypeScript
- Database: PostgreSQL with Prisma ORM
- Cache: Redis with ioredis
- Queue: Redis-based job processing
- Validation: class-validator, class-transformer
- Security: Helmet, rate limiting, CORS
- Framework: React 18 with TypeScript
- Build Tool: Vite
- State Management: Zustand
- Styling: CSS-in-JS with styled-components
- Telegram Integration: Telegram WebApp API
- Containerization: Docker & Docker Compose
- Reverse Proxy: Nginx
- CI/CD: GitHub Actions
- Monitoring: Health checks, structured logging
- Security: Vulnerability scanning with Trivy
- Bot Framework: Telegraf
- Web App: Telegram WebApp API
- Authentication: Telegram initData validation
- UI Components: Inline keyboards, callback queries
- Docker & Docker Compose
- Node.js 18+ (for local development)
- Telegram Bot Token
- PostgreSQL 15+
- Redis 7+
-
Clone the repository
git clone https://github.com/your-username/telegram-clicker-miniapp.git cd telegram-clicker-miniapp -
Configure environment variables
cp .env.example .env # Edit .env with your configuration -
Start the application
docker-compose up -d
-
Initialize database
docker-compose exec api npx prisma migrate dev
# Database
DATABASE_URL=postgresql://postgres:password@postgres:5432/clicker_game
REDIS_URL=redis://redis:6379
# Telegram
TELEGRAM_BOT_TOKEN=your_bot_token_here
TELEGRAM_WEBHOOK_URL=https://your-domain.com
WEBAPP_URL=https://your-domain.com
# Application
NODE_ENV=production
LOG_LEVEL=info- Users: 100,000+ total users
- Concurrent: 5,000+ active sessions
- Throughput: 50 clicks/second per user
- Response Time: <100ms average
# docker-compose.scale.yml
services:
api:
deploy:
replicas: 3
bot:
deploy:
replicas: 2
worker:
deploy:
replicas: 4- Read Replicas: Separate read/write operations
- Connection Pooling: Optimized connection management
- Indexing: Strategic database indexes
- Partitioning: User data partitioning by region
- Redis Clusters: Distributed caching
- CDN Integration: Static asset delivery
- Edge Computing: Regional data centers
- Metrics: Prometheus + Grafana
- Logging: Structured logging with correlation IDs
- Tracing: Distributed tracing with OpenTelemetry
- Alerts: Real-time alerting system
-
Start services
docker-compose -f docker-compose.yml up -d
-
Run migrations
docker-compose exec api npx prisma migrate dev -
Seed database
docker-compose exec api npx prisma db seed
# Run all tests
npm test
# Run specific service tests
cd services/api && npm test
cd services/bot && npm test- Linting: ESLint + Prettier
- Type Checking: TypeScript strict mode
- Testing: Jest + Supertest
- Security: Automated vulnerability scanning
-
Build images
docker-compose -f docker-compose.prod.yml build
-
Deploy to production
docker-compose -f docker-compose.prod.yml up -d
-
Run migrations
docker-compose -f docker-compose.prod.yml exec api npx prisma migrate deploy
# k8s/deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: telegram-clicker-api
spec:
replicas: 3
selector:
matchLabels:
app: telegram-clicker-api
template:
metadata:
labels:
app: telegram-clicker-api
spec:
containers:
- name: api
image: ghcr.io/your-username/telegram-clicker-miniapp-api:latest
ports:
- containerPort: 3000
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: db-secret
key: url- Liveness: Service availability
- Readiness: Service readiness
- Startup: Service startup time
- Performance: Response times, throughput
- Business: User engagement, click rates
- Infrastructure: Resource utilization
- Structured Logging: JSON format with correlation IDs
- Log Levels: DEBUG, INFO, WARN, ERROR
- Log Aggregation: Centralized logging system
- Telegram Validation: Secure initData verification
- Rate Limiting: Per-user and global limits
- Input Validation: Comprehensive data validation
- Encryption: Data encryption at rest and in transit
- Privacy: GDPR-compliant data handling
- Audit Logging: Comprehensive audit trails
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow TypeScript best practices
- Write comprehensive tests
- Update documentation
- Follow conventional commit messages
This project is licensed under the MIT License - see the LICENSE file for details.
- Telegram Bot API team for excellent documentation
- NestJS team for the amazing framework
- React team for the powerful frontend library
- Redis team for the high-performance caching solution
Built with β€οΈ for the Telegram ecosystem