-
Notifications
You must be signed in to change notification settings - Fork 1
Application Fundamentals
Cards is built on an event based architecture using node.js for the backend and extensive use of JavaScript on the frontend. The application framework that we use for the backend is express.js. The module we use to synchronize our backend and client frontends so that we can maintain the games in realtime is now.js.
The express.js module is used to initialize the application server, building views with ejs templates, handling errors that occur during http requests, and parsing any parameters that are sent in request bodies. It is also used to route requests, but since the vast majority of the application's functionality is handled through data synchronizations with now.js, there are a very small number of endpoints to route.
This is where the magic happens. The now.js module allows us to set properties on an object that is shared in realtime between all frontend clients and the backend. It also allows us to call functions on said object that are also executed in realtime between the frontend and backend. Pretty much all of the data transfer and actionable items will occur through the use of now.js.
In order to interact with only the frontend clients that are playing a specific game, we utilize the groups functionality in now.js. Each game is considered its own group, so our backend can call functions that impact only the clients associated with one particular game.
It is fairly easy to get confused with a realtime architecture like this, but keeping these two points in mind should help you keep focussed:
- Any time a single player performs some action in a game, the frontend makes a call to the backend.
- Any time an action needs to be performed on more than one player, the backend makes a call to the frontend.