By Houdaifa Drahm
A real-time game needs more than a browser that can draw a puck. Two players must be authenticated, matched, assigned sides, and kept in sync even when their network connections behave differently. A match also needs a clear ending, a record for history, and a deployment that supports WebSocket connections.
This guide starts with one two-player air hockey match and grows it into a full-stack application. It uses NETPONG as a source-code reference while describing a design you can build and test independently.
Why NestJS fits this application
NestJS gives the HTTP API, the WebSocket gateway, and the game service explicit places to live. A controller handles HTTP requests, a gateway receives or sends socket events, and an injectable service owns application logic. Modules declare which providers they own and which dependencies they import. The main benefit is that game rules can be tested through a service without needing a real socket or browser.…