Overview
MindClash is a highly scalable, real-time web application for hosting structured debates. Version 2.0 migrated the core arbitration engine to OpenAI (gpt-4o-mini) and heavily optimized API latency through batched LLM processing.
Core Features
- Real-Time Debate Engine: Socket.io "Rooms" isolate high-frequency events (timer ticks, live chat, argument submissions) to relevant participants, drastically reducing server bandwidth. The Node.js server is the authoritative source of truth for game state, preventing client-side manipulation of timers or round progression.
- Autonomous AI Arbiter: Migrated from per-message API calls to a batched analysis pipeline — the server compiles the entire debate transcript and sends it to OpenAI in a single call at the end of the match. The LLM is constrained via strict system prompts to return a nested JSON object with the winner, mathematical scores (0-100), fact-checking flags, and personalized feedback.
- Whisper Mode: Before submitting a turn, users can ask the AI to evaluate their draft in real-time, returning counter-points and structural tips.
- Smart Fallback Heuristics: A purely mathematical scoring algorithm (vocabulary diversity, sentence length, structural effort) seamlessly takes over if the OpenAI API experiences downtime or rate limits, guaranteeing 100% debate completion.
- Anonymous Mode & Anti-Bias: Users can toggle anonymity — the backend generates a unique alias via a randomized adjective/noun matrix, then securely maps it back to the master User schema post-match to update XP and ELO without exposing identity during the live event.
- Progression Economy: Dynamic ELO tiers (Novice → Debater → Skilled → Master → Legend), spectator XP betting with dynamic odds calculation, and a marketplace for avatars and profile themes.
Architecture Notes
- Concurrency Safety: Atomic MongoDB
findOneAndUpdateoperations with strict status checks prevent race conditions when multiple users submit final arguments simultaneously. - Secure Connection Lifecycles: A dynamic React
AuthContextmonitorslocalStorageJWTs — if a user logs out or switches accounts in another tab, the system tears down the stale socket connection and re-authenticates immediately, eliminating token-leakage vulnerabilities. - Database Design: Nested schemas (
Roundscontaining arrays ofMessages) minimize reads so the entire game state can be injected into the OpenAI prompt in a single query. TTL indexes on theNotificationmodel auto-purge 30-day-old documents at the storage layer, removing the need for CRON jobs.