MindClash

Real-time, AI-moderated multiplayer debate platform with autonomous judging, ELO ranking, and a spectator betting economy.

React 18ViteTailwind CSSFramer MotionSocket.ioNode.jsExpress.jsMongoDBRedisOpenAI APIJWT

Problem

Online debates lack structure, unbiased judging, and real-time engagement — they devolve into shouting matches with no accountability or fair scoring.

Solution

Built a real-time debate platform where OpenAI (gpt-4o-mini) acts as an autonomous arbiter, migrating from per-message API calls to a batched end-of-match analysis pipeline for optimized token usage, with a mathematical fallback heuristic if the API is unavailable.

Impact

Ships a full competitive loop: matchmaking, live WebSocket rooms, anonymous aliasing for anti-bias voting, ELO-based tier progression, and an XP-based spectator betting marketplace.

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 findOneAndUpdate operations with strict status checks prevent race conditions when multiple users submit final arguments simultaneously.
  • Secure Connection Lifecycles: A dynamic React AuthContext monitors localStorage JWTs — 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 (Rounds containing arrays of Messages) minimize reads so the entire game state can be injected into the OpenAI prompt in a single query. TTL indexes on the Notification model auto-purge 30-day-old documents at the storage layer, removing the need for CRON jobs.