How fuiz/game works
Project Type and Purpose
• Fuiz is a backend server written in Rust (evidenced by Cargo.toml, Cargo.lock, and the use of Cargo).
• Its purpose is to host live quizzes. Clients can create games, check if a game is active, and join games via a WebSocket connection.
• The README highlights key API endpoints:
– POST /add to create a new game.
– GET /alive/:gameid to check if a game is active.
– GET /watch/:gameid to join a game via WebSocket.
• This clearly indicates a networked, real-time application serving quiz content.
File Structure for Architectural Clues
• The src directory contains multiple Rust source files and modules such as:
– A main “lib.rs” file, which likely contains the core application logic.
– Dedicated modules for various quiz functionalities: “game.rs”, “session.rs”, “teams.rs”, “leaderboard.rs”, “names.rs”, and “watcher.rs”.
– A subdirectory “src/fuiz” contains additional modules like “config.rs”, “media.rs”, “multiple_choice.rs”, “order.rs”, and “type_answer.rs”, suggesting specialized components for quiz configuration and questions.
• The structure shows a modular design with logical grouping for aspects such as configuration, game logic, and user interaction (teams, sessions, etc.).
Main Components
a. Client Interaction Layer:
– HTTP API Endpoints:
• POST /add (for game creation)
• GET /alive/:gameid (for checking game status)
– WebSocket Endpoint (GET /watch/:gameid):
• Represents the real-time client connection for participating in quizzes.
b. Core Engine / Game Manager:
– Central module managing the lifecycle of a quiz game.
– Coordinates between configuration (from fuiz/config.rs), game logic (from game.rs and associated modules like multiple_choice, order, type_answer), and session handling.
c. Supporting Modules:
– Session Management (session.rs): likely responsible for tracking active quiz sessions.
– Team Handling (teams.rs): manages groupings or teams within a quiz.
– Leaderboard (leaderboard.rs): aggregates and displays quiz results and rankings.
– Watcher (watcher.rs): possibly monitors live quiz events or handles cleanup, reconnections, etc.
– Miscellaneous utilities (names.rs, game_id.rs, etc.) provided for managing identifiers and auxiliary data.
d. Configuration:
– Module(s) under fuiz, especially config.rs, load and validate game configurations (with artifacts like config.toml also in the project root).
e. External Communication:
– Client devices’ interactions via HTTP and WebSocket, which should be depicted as external components interfacing with the backend engine.
Relationships and Data Flow
• Clients send an HTTP POST to /add to create a new game. The request passes through a HTTP server layer (entrypoint) to the Game Manager, which uses configuration and options to instantiate a quiz game.
• When a client checks for game activity, the HTTP GET request to /alive/:gameid routes naturally to the Game Manager to fetch the status.
• For joining the game, clients initiate a WebSocket connection via GET /watch/:gameid. The WebSocket handler (possibly within the “watcher” module) binds the client to the game session and facilitates real-time communication.
• Core modules communicate internally:
– The Game Manager interacts with session, leaderboard, teams, and various fuiz sub-modules to manage game logic.
– Utility modules like game_id and names help maintain unique game sessions and identity information.
Architectural Patterns and Design Principles
• Modular Design: The code is organized into multiple modules, each handling a specific concern.
• Separation of Concerns: There is a clear division between API handling (HTTP/WebSocket endpoints) and game logic (the engine and supporting modules).
• Extensibility: The fuiz submodules (like multiple choice, ordering, and type answer) indicate that the design is meant to support various quiz question types.
• Real-time Communication: The integration of a WebSocket mechanism shows the system’s focus on interactive, live engagement.