Box of Cards V1

The original: a story-telling card game on a deliberately overkill Kubernetes / Redis / RabbitMQ stack — built to learn the tech, not because the game needed it. Part of the Box of Cards work.

TS · Kubernetes · Docker · Google Cloud · React · NodeJs · Express · Digital Ocean · Firebase · GitHub Actions · Redis · RabbitMQ · Websockets · Redux · MaterialUi · Webpack · Jest · ImageKit

A long time ago

Landing page

This is the original landing page. A lot has been done since. See V2 and V3 for newer changes.

Choose Decks

Deck selection

The Host can decide to use one or combine multiple decks for the new session.

Create Decks

Deck editor

The Player can create his own decks and test them directly. Sentences contain Answer placeholders using '_'. Answers can have dropdown values by adding them comma separated into square brackets [one, two].

Multiplayer Lobby

Multiplayer lobby

Public games can be joined and seen by anyone. I admit I am lazy when choosing names for testing.

Game Lobby

Game lobby

The host may set the Game settings in the Game Lobby. He also has to approve players wanting to join. Once all players are ready the game may begin.

Game

Active game

Based on the settings a sentence is chosen and Players submit their Answers for voting. In this case they may submit up to two Answers. There already played a round and thus have a completed Card in their history at the top.

Overengineered to the limit

I started this project as I wanted to try out lots of new technologies. All of this could have been done in an express server on a Raspberry Pi. But a wise person once said: Give a man a fish and he eats for a day. Give a man a Fishing-Boat-Industry and he will never see a fish again.

Components

Architecture

A Node.js server would have been sufficient. I chose a Kubernetes cluster of microservices instead — each of which does exactly one job.

Web Client

Providing Web-client

The Web-Client is being compiled and then served by an express Server. The express Server is run inside a docker container. And the docker container is deployed using a kubernetes deployment. Lastly a domain points towards a load-balancer service which points to the express server.

Backend

Backend architecture

Three services which handle the games multiplayer logic. The MultiplayerLobby serves available GameLobbies. The GameLobby handles, well.... the Games lobby. Once the host clicks the start button inside the GameLobby all players migrate onto a Game Server.

Redis Cluster

Redis architecture

Redis is being used to cache data which is required across those backend services. For example it stores which player is assigned to which Game or GameLobby. This avoids players being in multiple games or being unable to reconnect.

One Broker, Two Protocols

RabbitMq architecture

The broker loosely couples client sessions and backend services, which is what enables scaling. Browsers speak WebStomp over websockets; the express services speak AMQP — the broker translates between the two.

Google Cloud

Google Cloud authentication

Why on earth do I also use a google cloud additionally to kubernetes? Well my initial plan was to use firebase to manage gamestate but my calculations resulted in ... bankruptcy. I still use google cloud functions to manage authentications and store decks though. No need to implement authentication by myself. Cloud Functions are realllly fun.

My Cluster Overview

Cluster overview in terminal

These are all the services and config files of my running cluster, though some persistent volumes are not being displayed. There is only one pod of each service as I am running on the cheapest Node plan available. Why the restarts? The Broker takes some time to get up and I have yet to add readiness probes.

Digital Ocean Dashboard

Cluster overview in Digital Ocean

Nothing fancy, just my cluster and the two load-balancers pointing at it. One for fetching the web client and one for accessing the broker for multiplayer interaction. Why can't this be one loadbalancer? Well I tried quite some stuff but due to port requirements across services it won't work.

Tech Stacks

What libraries did I use? Did I use libraries? Let's find out!

Web App

Web-client architecture

Most of the content is in the Client, thus I use some frontend libraries to make it look nice. Material Ui as a solid design base, React for reusable components and Redux to manage states globally. Typescript to avoid the javascript hell, webpack to make the build more compact and docker to deploy. Imagekit.io is compatible with React and allows the outsourcing of images into the cloud, thus reducing load time. The server is just one file to serve it all and proxy some requests to the Google Cloud.

Backend Services

Backend services architecture

These services all share the same core components. The green boxes are npm packages that github worfklows create from my other repositories. Other than that I use jest for unit testing. The broker package lets those services talk to the RabbitMq broker. Types allow for consistent sending and receiving of data. TestData and MockProvider are dev dependencies to avoid redundancy in unit tests. Then there is CheckAlive which just checks whether a player is still connected. And lastly my wrapper for Redis interaction GameRedis.

Backend Packages

Backend packages

This is the tech stack of my packages. The Broker supports RabbitMq with stomp.js via websockets and AMQP via CloudAMQP. The GameRedis uses my more generic RedisClient package, which uses packages for redis cluster interaction. All those other packages are just the core.

Google Cloud Functions

Google Cloud packages

The Cloud Functions run on node.js and use a firebase package to interact with the firestore. The firestore stores decks and verification links as well as some basic account data.

RabbitMq

RabbitMq configuration

RabbitMq is configured using only kubernetes config files and has plugins so that server and client can talk with the broker.

Deployment

All of these pieces still have to become a running cluster. DevOps and pipelines to the rescue.

Github Workflow

Github Actions

Just store a git workflow file in the repository and jobs can be defined. Jobs can be dependent on one another, check out commits and even install plugins themselves. I use a job to get the package versions and check whether they have updated in the current commit. If so, rebuild docker images. If anything got rebuilt, delete stuff from my digital ocean cluster and deploy it anew. Yes my workflow talks with digital ocean! And all of this in just ~300 lines of config (without empty lines).

The Toolbox

Deployment script management

A good friend gave me a nice template for a shell-script and it made testing things so much easier. I extended it over time and it allows me to switch between my local cluster and the digital ocean cluster. If I do not want to use the github action to redeploy a pod I can just use this to redeploy all, or just a single service. I think Helm does something similar so that will be the next thing to check out. I also deployed a cluster using Terraform but found it to be overkill for this project. Yes it seems I have a limit for overengineering

Unit Tests

Successfull tests

Green numbers on a Unit Test provide one of the best feelings. There are over 400 unit tests in this project and some dozen integration tests. I still have some logical branches to be covered and the web client has no unit tests whatsoever.

Unit Test Output

Example test output

This is the output of my TimeoutHandler package. Yes I am showing this minor package because my bigger packages are not that covered but psssht!

Origins

In the following sections I will post parts of the plans and designs I made on the way. I remember my professor on Software Design repeating: 'Planning is essential. Plans are useless.'

1. Game Board

1st design of active game

I concept everything in draw.io as I found that tool to be the least annoying. The bottom left shows my first idea for a game board. It was not flexible enough for resolutions and game options.

2. Game Board

2nd design of active game

This design is more flexible and rounding makes it seem easier

First Page

1st design of landing page

This was my first page running in localhost. Hilarious what it once looked like.

Maybe use a scribble design?

2nd design of landing page

I tried really hard to make a hand drawn look possible but giving good usage feedback was just too hard. There seems to be a reason that web pages are always so clean.

Concepting Designs

Iterative design phase

In Affinity Designer I concepted several design ideas. Even though some looked really nice it was rough getting all components fitting one another.

Designing Logos

2nd logo approach

This was my second approach at a logo. I am too ashamed to show my first version and even these hands are... stolen from the wilds of the internet. I really like it but it was impossible to make a good looking icon out of it.

Designing the logo

3rd logo approach

I started watching logo concepting videos on side and found one using a box consisting of letters. I was able to adapt it using the letters B, O and C and add in some card. Really happy with the result. Things started coming together.

Designing the Game Board

3rd design of active game

I started focussing on making the ui responsive. A fixed height History at the top, a Hand at the bottom, Sentence and Info Left and a body to fill up the remaining space. I made the optional stuff like Chat, Player-List and Options hide-able. It turned out that those component headers were a nightmare in responsive design so I moved them into the components to only be displayed when they are empty.

Testing Fonts

Iterative font testing

I had some friends rate fonts for this application. They chose 4 and 11 and so I proceeded with 4 as I liked it most of them.

How many obstacles could there be?

Well I never counted but lets say curses existed! Special mentions to: scrollbars, table implementations, checking negated enums, cors, caching, caching, git being case insensitive, Google Agones, package dependency conflicts, react-router v5->v6, weird behaving cluster regions and github telling me I reached 9500 of my 2000 build minutes with a 56$ balance on my 0$ limit. It was their bug though.

Umlauts!

Font editor

In the german language there are umlauts (ä,ö, etc.) and it turns out the font I chose did not have those so.... I added them myself! I guess that is fine as I bought this font and otherwise: psssht.

Font Borders

Problematic Font Borders

The font also had some lines repeated for... reasons I guess. It was fine until I added a border which turned out weird. So I edited those out. I knew the font editor by now.

Display Settings

Display Color Offset

What is this you ask? Modern art? Yes probably. It is also the color difference of both my monitors and I was incapable to get them any closer. I decided to resolve this issue by not caring at all and moving on.

Debugging Unit Tests

Test failure

Well some error messages are at first confusing and then they get weird. I use Typescript so the types are set but when passing data along a number can still be a string even though the compiler thinks it is a number. Nananananananana Javascriiiipt

How long did this journey take?

Comedic intervention

Well I don't know but in all repositories together there are 1000 + commits. I got some nice templates though and some stuff left to cleanup What is left to be done? Quality of Life, more unit tests, login with google, etc. Ah and I somehow forgot to add a user account management... nobody needs that. I just love development <3