The multiplayer game system provides real-time online checkers gameplay with invitation management, spectating capabilities, and social integration. The system supports both friend-to-friend games and open invitations for casual matchmaking.
🧪 BETA STATUS: The multiplayer system is currently in beta with known synchronization issues. See Known Issues section for details.
- Friend Invitations: Direct invitations to friends with personalized messages
- Open Invitations: Shareable links for casual matchmaking
- Game Configuration: Choose variants, time controls, and player colors
- Real-time Status: Live invitation tracking with expiration timers
- Real-time Moves: Synchronized game state across all clients
- Turn Management: Enforced turn order with move validation
- Conflict Resolution: Automatic handling of simultaneous move attempts
- Connection Recovery: Automatic reconnection and state synchronization
- Live Viewing: Watch ongoing games in real-time
- Move History: Review past moves and game progression
- Player Information: View player profiles and ratings
- Chat Integration: Spectator chat during games
Location: src/app/(checkers)/_components/game/GameInviteScreen.tsx
Main invitation workflow component that handles the complete game setup process.
Features:
- Multi-step invitation wizard (player selection → game configuration → waiting room)
- URL parameter handling for pre-selected friends
- Game variant selection (American, International, Brazilian, Canadian)
- Time control configuration with preset options
- Real-time invitation status updates
Props:
preselectedFriendId?: string- Pre-select a friend by IDpreselectedUsername?: string- Pre-select a friend by username
Usage:
<GameInviteScreen
preselectedFriendId="user123"
preselectedUsername="john_doe"
/>File: src/app/(checkers)/_components/game/PlayerSelectionCard.tsx
Friend selection interface with search and filtering capabilities.
Features:
- Toggle between "Specific Friend" and "Anyone" (shareable link) modes
- Friend search with real-time filtering
- Visual friend selector with avatars and user info
- Integration with existing friends API
- Selection summary with status badges
Props:
selectedFriend: string | null- Currently selected friend IDonFriendChange: (friendId: string | null) => void- Selection callbackshowInviteButton?: boolean- Whether to show invite button
File: src/app/(checkers)/_components/game/InviteStatusPanel.tsx
Real-time invitation status tracking and management.
Features:
- Live invitation status updates (Pending/Accepted/Declined/Expired)
- Countdown timer with progress bar
- Friend information display
- Cancel invitation functionality
- Responsive status indicators with appropriate colors and icons
- Mock implementation ready for real-time polling
Props:
inviteId: string- Invitation identifierselectedFriendId: string | null- Friend who was invitedonGameReady: (gameId: string) => void- Game start callbackonInviteExpired?: () => void- Expiration callback
File: src/components/game/ShareableInviteDialog.tsx
Dialog for sharing invitation links with QR codes and social media integration.
Features:
- Copy-to-clipboard functionality with visual feedback
- QR code generation using QR-Server API
- Social media sharing buttons (WhatsApp, Email, SMS)
- Native Web Share API support when available
- Tabbed interface for link sharing vs QR code
- Privacy notice about link expiration
Props:
open: boolean- Dialog visibility stateonOpenChange: (open: boolean) => void- Dialog state callbackinviteId: string- Invitation identifier for URL generation
Route: /game/online
Query Parameters:
friendId- Pre-select friend by user IDusername- Pre-select friend by username
Example URLs:
/game/online?friendId=user123- Pre-select specific friend/game/online?username=john_doe- Pre-select friend by username
Expected Route: /game/invite/[inviteId]
Purpose: Allow guests to redeem invitations without accounts
The following API endpoints need to be implemented by Working Group 1:
input: {
inviteeId: string | null; // null for shareable links
gameConfig: {
boardVariant: "american" | "brazilian" | "international" | "canadian";
timeControl: TimeControl | null;
playerColor: "red" | "black";
}
}
output: {
inviteId: string;
expiresAt: Date;
}input: { inviteId: string }
output: {
status: 'PENDING' | 'ACCEPTED' | 'DECLINED' | 'EXPIRED';
expiresAt: Date;
gameId: string | null; // Present when accepted
host: UserInfo;
invitee?: UserInfo; // For direct invitations
}input: {
inviteId: string;
}
output: {
success: boolean;
}The components expect real-time updates via the unified EventContext for:
- Invitation status changes
- Game readiness notifications
- Connection status updates
The multiplayer system uses multiple channels for real-time updates:
- Game State Updates - Real-time move synchronization via EventContext
- Invitation Status - Invitation acceptance/decline via notification events
- Connection Status - Player connection monitoring
create- Create new game invitationgetStatus- Get current invitation statuscancel- Cancel pending invitationaccept- Accept received invitationdecline- Decline received invitation
join- Join an existing gamemakeMove- Submit a move with validationgetGameState- Retrieve current game stateresign- Resign from gamerequestDraw- Request/respond to draw offers
The system supports guest players through:
- Guest Session Management - Temporary accounts for non-registered users
- Invitation Redemption - Direct game joining via shareable links
- Post-game Conversion - Account creation flow after guest games
- Move Conflicts: Simultaneous moves may cause temporary desync
- Connection Recovery: Some edge cases require manual page refresh
- State Validation: Occasional discrepancies between client and server state
- Turn Timer Sync: Minor timing differences across clients
- Large Game History: Games with 100+ moves may load slowly
- Concurrent Games: Performance degrades with 10+ simultaneous games
- Memory Leaks: Long gaming sessions may require page refresh
- Safari Mobile: Drag-and-drop occasionally fails on iOS Safari
- Firefox: Event connections may timeout more frequently
- WebKit: Some animation artifacts on older WebKit versions
Decision: Hybrid Event System + Optimistic Updates
- Unified Event System for authoritative game state broadcasts
- Optimistic Updates for immediate UI feedback
- Conflict Resolution through server-side validation and rollback
Trade-offs:
- ✅ Low latency user experience
- ✅ Scales better than WebSocket polling
- ❌ Complex conflict resolution logic
- ❌ Potential temporary desync states
Decision: Distributed State with Central Authority
- Client State: Local game representation for immediate updates
- Server State: Authoritative game state with move validation
- Sync Mechanism: Periodic reconciliation and conflict detection
Design Patterns:
- Event Sourcing: All moves stored as immutable events
- CQRS: Separate read/write models for game state
- Optimistic Concurrency: Version-based conflict detection
Decision: Token-based Invitations with Expiration
- Unique Tokens: Cryptographically secure invitation identifiers
- Flexible Recipients: Support both friend and guest invitations
- Time-bounded: Automatic expiration to prevent stale invitations
Benefits:
- Secure sharing without exposing user IDs
- Supports guest players without accounts
- Prevents invitation abuse through expiration
Decision: Read-only Event Streams with Permission Gates
- Channel-based Events: Spectator-specific event channels
- Permission System: View access based on game visibility settings
- Minimal State: Spectators receive move events, not full game state
Planned Implementation:
- Real-time move broadcasting to spectator clients
- Spectator count tracking and display
- Optional spectator chat with moderation
- Indexed Queries: Strategic indexing for game lookups and move history
- Connection Pooling: Efficient database connection management
- Query Optimization: Minimized N+1 queries with proper relations
- Component Memoization: React.memo for expensive renders
- State Batching: Grouped state updates to prevent excessive renders
- Lazy Loading: Code splitting for invitation and game components
- Event Heartbeats: Efficient connection monitoring
- Differential Updates: Only broadcast changed game state
- Compression: Gzip compression for move data
- Error Boundary Coverage: Inconsistent error handling across components
- Test Coverage: Integration tests needed for multiplayer flows
- Type Safety: Some any types in event handling
- Performance Monitoring: Need metrics for sync latency and conflicts
- State Machine: Formal state machine for game flow management
- Event Bus: Centralized event system for loose coupling
- Service Layer: Abstraction layer for game logic
- Caching Strategy: Redis integration for session management
- Game Completion Rate: Percentage of started games that finish
- Sync Conflict Frequency: Rate of move conflicts requiring resolution
- Connection Stability: Event connection disconnection and reconnection rates
- Invitation Conversion: Rate of sent invitations that result in games
- Move validation failures
- Event connection errors
- State synchronization conflicts
- Client-server state mismatches
This architectural documentation reflects the current implementation status and planned improvements for the multiplayer checkers system.