How hxtnv/fuseball works
Project Type & Purpose
• This is a full-stack multiplayer game. The client is a modern React-based web application that handles the UI, including game overlays and p5.js sketches for the game rendering.
• The server implements the core game logic using WebSockets for real-time multiplayer communication, lobby management, game loop updates and even OAuth (with providers like Discord and Google) for account creation.
• Other features include in-game chat and news feeds, with planned improvements for leaderboards and tournament modes.
Main Components
• Client Side:
• UI Components: Organized into common (button, input, skeleton, switcher), domain-specific (footer, navbar, news, player preview), modals (disconnected, game-loader, sign-in), and lobby components.
• Context & Hooks: Managing game and WebSocket states, modal functionalities, and utility hooks for mobile and horizontal view support.
• Server Side:
• WebSocket Server & Game Loop: Located in “server/src/websocket-server.ts” and “server/src/lib/game-loop.ts” along with a series of helper functions and a dedicated “lobby-manager” for managing player lobbies (e.g., creation, updates, state management, player movement).
• OAuth and Authentication: The “server/src/features/oauth” subdirectory shows integrations with Discord and Google for authentication.
• REST & Other Business Logic: Additional features like news handling and self-profile functions.
• Data Management: Use of Prisma (in “server/prisma/schema.prisma”) for modeling database interactions and a logger and utility functions for supporting operations.
Relationships & Interactions
• Client ↔ Server:
• Bi-directional communication via WebSockets that facilitates real-time game state updates, in-game chat, and lobby interactions.
• REST API endpoints that might be used for account creation/authentication or fetching news.
• In the server, detail the flow:
• Incoming WebSocket messages are handled by dedicated handlers (connection-handler, message-handler).
• The game loop and lobby manager coordinate game ticks, update player positions, verify scoring (goal detection), and manage chats.
• Authentication flows through the OAuth modules and associated helper functions.
• Additionally, the client’s use of context providers (e.g., game.context, websocket.context) should be shown as a layer managing state and communication between UI components and the networking layer.
Architectural Patterns and Technologies
• Component-based architecture for the client leveraging React and Vite for the build.
• Separation between presentation (UI components/layout) and domain logic (game state and interaction hooks).
• Real-time bi-directional communication via a custom WebSocket server on the backend.
• Use of modern TypeScript throughout both client and server enhances type safety and maintainability.