Skip to content

incryptomax/clicker-miniapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Telegram Clicker Mini App

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.

🎬 Demo

Watch the application in action: Demo Video

🎯 Overview

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.

Key Features

  • 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

πŸ—οΈ Architecture

Microservices Design

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Telegram Bot  β”‚    β”‚   Web App       β”‚    β”‚   API Gateway   β”‚
β”‚   (NestJS)      │◄──►│   (React)       │◄──►│   (NestJS)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β”‚                       β”‚                       β”‚
         β–Ό                       β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Redis Cache   β”‚    β”‚   PostgreSQL    β”‚    β”‚   Worker Queue  β”‚
β”‚   (Sessions)    β”‚    β”‚   (Persistent)  β”‚    β”‚   (Background) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Service Responsibilities

  • 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

πŸ› οΈ Technology Stack

Backend

  • 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

Frontend

  • Framework: React 18 with TypeScript
  • Build Tool: Vite
  • State Management: Zustand
  • Styling: CSS-in-JS with styled-components
  • Telegram Integration: Telegram WebApp API

Infrastructure

  • Containerization: Docker & Docker Compose
  • Reverse Proxy: Nginx
  • CI/CD: GitHub Actions
  • Monitoring: Health checks, structured logging
  • Security: Vulnerability scanning with Trivy

Telegram Integration

  • Bot Framework: Telegraf
  • Web App: Telegram WebApp API
  • Authentication: Telegram initData validation
  • UI Components: Inline keyboards, callback queries

πŸš€ Quick Start

Prerequisites

  • Docker & Docker Compose
  • Node.js 18+ (for local development)
  • Telegram Bot Token
  • PostgreSQL 15+
  • Redis 7+

Environment Setup

  1. Clone the repository

    git clone https://github.com/your-username/telegram-clicker-miniapp.git
    cd telegram-clicker-miniapp
  2. Configure environment variables

    cp .env.example .env
    # Edit .env with your configuration
  3. Start the application

    docker-compose up -d
  4. Initialize database

    docker-compose exec api npx prisma migrate dev

Environment Variables

# 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

πŸ“Š Performance & Scalability

Current Capacity

  • Users: 100,000+ total users
  • Concurrent: 5,000+ active sessions
  • Throughput: 50 clicks/second per user
  • Response Time: <100ms average

Scaling Strategies

Horizontal Scaling

# docker-compose.scale.yml
services:
  api:
    deploy:
      replicas: 3
  bot:
    deploy:
      replicas: 2
  worker:
    deploy:
      replicas: 4

Database Optimization

  • Read Replicas: Separate read/write operations
  • Connection Pooling: Optimized connection management
  • Indexing: Strategic database indexes
  • Partitioning: User data partitioning by region

Caching Strategy

  • Redis Clusters: Distributed caching
  • CDN Integration: Static asset delivery
  • Edge Computing: Regional data centers

Monitoring & Observability

  • Metrics: Prometheus + Grafana
  • Logging: Structured logging with correlation IDs
  • Tracing: Distributed tracing with OpenTelemetry
  • Alerts: Real-time alerting system

πŸ”§ Development

Local Development

  1. Start services

    docker-compose -f docker-compose.yml up -d
  2. Run migrations

    docker-compose exec api npx prisma migrate dev
  3. Seed database

    docker-compose exec api npx prisma db seed

Testing

# Run all tests
npm test

# Run specific service tests
cd services/api && npm test
cd services/bot && npm test

Code Quality

  • Linting: ESLint + Prettier
  • Type Checking: TypeScript strict mode
  • Testing: Jest + Supertest
  • Security: Automated vulnerability scanning

πŸš€ Deployment

Production Deployment

  1. Build images

    docker-compose -f docker-compose.prod.yml build
  2. Deploy to production

    docker-compose -f docker-compose.prod.yml up -d
  3. Run migrations

    docker-compose -f docker-compose.prod.yml exec api npx prisma migrate deploy

Kubernetes Deployment

# 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

πŸ“ˆ Monitoring & Analytics

Health Checks

  • Liveness: Service availability
  • Readiness: Service readiness
  • Startup: Service startup time

Metrics

  • Performance: Response times, throughput
  • Business: User engagement, click rates
  • Infrastructure: Resource utilization

Logging

  • Structured Logging: JSON format with correlation IDs
  • Log Levels: DEBUG, INFO, WARN, ERROR
  • Log Aggregation: Centralized logging system

πŸ”’ Security

Authentication & Authorization

  • Telegram Validation: Secure initData verification
  • Rate Limiting: Per-user and global limits
  • Input Validation: Comprehensive data validation

Data Protection

  • Encryption: Data encryption at rest and in transit
  • Privacy: GDPR-compliant data handling
  • Audit Logging: Comprehensive audit trails

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow TypeScript best practices
  • Write comprehensive tests
  • Update documentation
  • Follow conventional commit messages

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • 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

About

A high-performance, scalable clicker game built as a Telegram Mini App with microservices architecture.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors