99math time based live (TBL) games server documentation

Description

TBL backend for 99math games designed to be running separate from core 99math backend and communicate with core via redis pub/sub channel messages.

TBL backend designed to be running in parallel aws beanstalk environments in multiple world regions, so each env (app) should have defined environment variable MATH99_REGION with region code (all regions codes should be defined in core app environment variable 99MATH_REGIONS).

App run completely separate from core, and there is no relations with core, could break app from working. App doesn't care about games creating and players join proccess (all this should be prepared by core) - it only care about websocket part of game.

To clarify this moment - regional TBL and CORE use same redis for pub/sub communications and if it's so happen that any of them (core or tbl) will collapse taking down redis server - other app will ger redis error/disconnect messages, and, for sure, will not work correctly, but will not crash because of this and will keep working alsmost same as before (but without communication with other apps). TBL and CORE apps are independent Elastic Beanstalk apps working in different environments, and there is no any other relations between them except redis pub/sub channels.

For authentication - single game json web token generated by core is used, passing it as query jwt param on websocket connection request. Token contains information required for game only - game region, gameCode, random "per game" generated clientId and isHost flag showing if client is game host (teacher or student). (shared/interfaces/AbstractGameClient interface)

AWS Installation

TBL application should be able to communicate with core app, but in reality - core application should have access to region redis server.

VPC preparing

AWS provide nice and secure way of cross regional resources access - VPC peering. But this way requires peered VPCs to have different CIDRs blocks. By default AWS creates "default VPC" in each reagion, but they all have same CIDR block and can't be peered together. Because of this - separate VPC in required region should be created and region resources - redis database and elastic beanstalk application should use this "not default VPC"

Currently busy CIDRs:

  1. 172.31.0.0/16 - core app VPC CIDR in eu-west-1 AWS region
  2. 10.0.0.0/16 - REGION_US tbl app CIDR in us-east-1 AWS region

Redis

Application uses redis for websockets adapter, games data storage and core channel communication.

Elastic Beanstalk Configuration

  1. Be sure to select correct VPC on env creation
  2. Configure env variables accordingly to .env.example file
  3. Be sure to define environment variable MATH99_REGION accordingly to core MATH99_REGIONS configuration
  4. Update core regional redis configuration for created region

Autodeployment

Configure bitbucket-pipelines.yml file for autodeployment into created region

Documentation

Documentation autobuilder for docs.99math.com and docs.qa.99math.com configured in bitbucket-pipelines.yml file.

Develop locally

Application is not designed to run as usual nodejs apps - it requires at minimum redis database to start without errors, and core application communication for games creation and saving. To run all such environment - docker-compose.yml file used to describe required env and run it usign docker-compose up. To add multiple regional apps to local test - docker-compose file should be edited.

Installation

# share package preparing
$ cd ../shared && npm ci && cd ../tbl

# tbl app deps
$ npm ci

Configure

  1. Create a .env file and copy the contents from .env.example

Running the app

# docker
$ docker-compose up

# If you run into a problem where a newly installed npm package isn't found in
# the container then stop and remove the node container and run the following
$ docker-compose up --build --force-recreate --no-deps

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

Currently there is no "build in" tests - use bots_class_light and bots_class repos

Documentation

Local documentation build is very ugly - you need to prepare separate folder, mix inside shared and tbl packages, take README, tsconfig.docs.json and package files into root folder and run documents build commands

# build docs into documentation dir with compodoc
$ npm run build:docs

# build docs with watch and hot reload on files change
$ npm run start:docs

results matching ""

    No results matching ""