What is a Player?
The Player is a core domain aggregate in the Blackjack API that represents a user who can participate in games. Players are automatically created or retrieved when starting a new game, and their statistics are tracked over time.Player Aggregate Structure
The Player domain model is immutable and contains the following attributes:Player Attributes
Unique identifier for the player (UUID format)
The player’s display name (1-30 characters, trimmed)
Number of games won by the player (non-negative)
Number of games lost by the player (non-negative)
Calculated as
wins - losses, used for ranking playersPlayer Creation
Players are created automatically when you start a new game. The system follows a “find or create” pattern:- When you POST to
/game/newwith a player name, the system checks if a player with that name already exists - If the player exists, it’s retrieved and used for the game
- If not, a new player is created with 0 wins and 0 losses
Player Statistics
Player statistics are automatically updated when games conclude:- Wins are incremented when the player beats the dealer
- Losses are incremented when the dealer wins or the player busts
- Score is calculated as
wins - lossesand is used for ranking
Statistics are updated in real-time when a game ends, either through a STAND move or a bust.
Immutability Pattern
The Player aggregate follows an immutable design pattern. Methods likeregisterWin(), registerLoss(), and rename() return new Player instances rather than modifying the existing one:
- Thread safety
- Predictable behavior
- Easier debugging and testing
- Alignment with functional programming principles
Related Endpoints
Change Player Name
Update a player’s display name
View Rankings
See all players ranked by score