### 👑 Chalesh Baz — Telegram Mini App Trivia Game
**Chalesh Baz** is a full-featured, interactive trivia and quiz game built natively for the **Telegram Mini App (TMA)** ecosystem. It allows players to participate in engaging knowledge battles right inside Telegram without downloading or installing any external app.
---
### 🎮 Gameplay Mechanics
* **6-Round Turn-based Duels:** Matches consist of 6 rounds (18 questions total). Players take turns picking categories from 3 randomized choices (Sports, Cinema, History, Tech, General Knowledge, etc.).
* **Asynchronous Gameplay:** Opponents do not need to be online at the same time. Once you complete your turn, the Telegram bot automatically dispatches an alert notifying your opponent that it is their turn.
* **Real-time Group Challenges:** Host simultaneous live quiz tournaments in Telegram groups with live scoreboards updated question by question.
* **AI Training Opponent:** Instant practice matches against a smart bot without risking rating trophies.
---
### 💡 Lifelines & Gamification
* **In-game Lifelines:** 50:50 (eliminates 2 wrong options), Second Chance, and Audience Poll percentages using in-game coins.
* **Question Factory:** Players submit custom 4-option trivia questions with explanations, earning coin rewards upon community review approval.
* **Energy, Currency & Leaderboards:** Automatic energy refills over time, daily login streaks, and global rankings based on trophies.
The Problem
Traditional mobile trivia games face significant friction points:
1. **Mandatory App Installations:** Users hesitate to download large applications from app stores for casual games.
2. **Scheduling Friction for Synchronous Play:** Requiring both players to be online at the exact same moment leads to high drop-off rates.
3. **Content Stagnation:** Without community creation mechanics, question banks quickly become repetitive.
4. **Synchronization in Live Group Contests:** Handling synchronized timers and fair question reveals across many players in groups is vulnerable to client-side manipulation.
The Solution
### 🌟 Implemented Solution in Chalesh Baz:
* **Telegram Mini App Native Experience:** Instant loading within Telegram with cryptographic verification of user authenticity via `initData` without passwords.
* **Asynchronous Turn-based Engine:** Full persistence of round state, paired with intelligent Telegram bot alerts when it's the opponent's turn (48-hour expiration).
* **Question Factory & Moderator Workflows:** End-to-end question design portal for players with approval dashboards and coin rewards.
* **Server-governed Real-time Sockets:** Authoritative server-side timers and event pipelines ensuring anti-cheat fairness in simultaneous group tournaments.
System Flow & Architecture
Structured as a clean modular Monorepo:
1. **Shared Package:** Universal TypeScript definitions, Socket.io events, and shared validation schemas between frontend and backend.
2. **Backend Server (NestJS + Prisma):** Modular architecture handling HMAC Telegram authentication, JWT issuance, duel game engine, question moderation, and Telegraf bot integrations.
3. **Mini App Client (React + Vite + TailwindCSS):** Ultra-responsive Telegram client featuring Framer Motion micro-animations and sound effects.
4. **Data & Cache (PostgreSQL 16 & Redis 7):** Persistent transactional storage with Prisma ORM and high-speed in-memory state caching.
Technical Challenges & Solutions
Secure Passwordless Authentication via Telegram WebApp Data
Challenge
Verifying the authenticity of incoming Telegram user identity without requiring classic usernames/passwords or exposing secrets.
Solution
Engineered strict cryptographic validation of the initData query string using HMAC-SHA256 with the bot token secret, issuing scoped JWTs for authenticated sessions.
Impact: Zero-friction, instant login with 100% protection against payload tampering and impersonation.
Asynchronous Match Orchestration & Fair Answer Hiding
Challenge
Preventing answer leakage while opponents play at different times, and enforcing server-authoritative answer timers.
Solution
Calculated round timers server-side, masked opponent answer states until both players answered, and scheduled proactive Telegram bot alerts upon turn handover.
Impact: Uncompromising competitive integrity and significantly higher player retention via timely bot notifications.
Low-latency Group Contests Without Database Bottlenecks
Challenge
Managing real-time lobby signups and simultaneous question answering for dozens of players without overloading relational storage.
Solution
Implemented Socket.io with timeline-driven state computed from the start timestamp, caching live states in Redis and generating leaderboards on the fly.
Impact: Zero-lag live competitive experience and instant leaderboard calculations.
Results & Metrics
• Complete implementation of 6-round duel mechanics and group trivia within Telegram Mini App.
• Sub-second frictionless authentication via Telegram HMAC-SHA256 cryptographic handshake.
• Server-authoritative anti-cheat gameplay preventing client-side clock tampering and answer inspection.
• Comprehensive gamification including regenerating energy, leaderboards, daily streaks, and Question Factory.
• Full Telegram bot synergy with automatic turn reminders and social viral referral deep links.