What the player experiences, what the implementation actually owns, and where production responsibilities would begin.
01
Game background
Rock Paper Scissors is a simultaneous-choice game with a cyclic dominance rule: each move beats one move and loses to another. The backend challenge is generating the house move after player commitment, resolving the pair deterministically, and keeping session statistics consistent.
02
How the game works
Choose a virtual stake and commit Rock, Paper, or Scissors.
The backend generates an unbiased house move.
The engine resolves win, tie, or loss from the two moves.
The service applies the explicit multiplier and returns balance and session statistics.
03
Backend architecture
A NestJS session service owns virtual balance, bet, history, and one RockPaperScissorsGame per UUID. The game generates the house move, resolves the round, updates statistics, and returns state in one synchronous service boundary.
Presentation, input, accessibility, and demo-credit display.
REST API
Request validation and routing into one isolated game session.
Game Session
Ephemeral configuration and the previous authoritative result.
Game Engine / RNG
Outcome generation, game rules, win evaluation, and result contracts.
Session Balance
Demo-only balance and recent-round statistics.
05
Critical engineering decisions
Generate the house move only after the player command reaches the server.
Keep the rule matrix deterministic and separate from random move generation.
Return the complete updated state after each round.
Label balance ownership as a demo session concern rather than a production wallet.
06
Failure handling
An unknown sessionId is rejected without playing a round.
A client disconnect after the response is committed may leave the browser uncertain; the current state endpoint can restore session state.
A duplicate play request can create another round because command idempotency is not implemented.
Session expiry removes history and virtual balance from process memory.
07
Fairness / RNG
The house move uses backend cryptographic random bytes across three choices. The implementation is server-authoritative and statistically testable, but not provably fair or independently certified.