Skip to content

Commit 6a71807

Browse files
committed
feat(docs): added architecture diagram and added documentation
1 parent 336d1d6 commit 6a71807

File tree

3 files changed

+66
-20
lines changed

3 files changed

+66
-20
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# for local development if not using docker-compose to star the backend services
22

3+
# check versions of locally installed tools
34
check:
45
@docker -v; echo
56
@docker-compose -v; echo

README.md

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,49 @@
11
# Redis Light, Green Light
22

3-
This project is an online multiplayer implementation of the game "Red Light, Green Light" using Python, Javascript and Redis. This is my submission for the 2022 [Redis Hackathon on DEV](https://dev.to/devteam/announcing-the-redis-hackathon-on-dev-3248)
3+
This project is an online, multiplayer implementation of "Red Light, Green Light" from Squid Game built with Python, Javascript and Redis. This is my submission for the 2022 [Redis Hackathon on DEV](https://dev.to/devteam/announcing-the-redis-hackathon-on-dev-3248)!
44

55
### Gameplay
66

77
![Redis Light, Green Light Gameplay](/images/gameplay.png)
88

9-
### Game event log
9+
### Game event log built with redis streams
1010

1111
![Redis Stream data](/images/events.png)
1212

13+
### Architecture Overview
14+
15+
![Project Architecture Diagram](/images/rlgl.drawio.png)
16+
17+
## Code Overview with `cloc` (count lines of code)
18+
19+
```
20+
make cloc
21+
22+
github.com/AlDanial/cloc v 1.94 T=0.03 s (1102.7 files/s, 67098.7 lines/s)
23+
-------------------------------------------------------------------------------
24+
Language files blank comment code
25+
-------------------------------------------------------------------------------
26+
Vuejs Component 13 104 14 528
27+
Python 3 178 104 410
28+
Markdown 5 139 0 272
29+
YAML 3 10 0 83
30+
make 1 10 2 34
31+
SVG 2 0 0 22
32+
TypeScript 1 1 1 22
33+
CSS 1 4 0 18
34+
JavaScript 1 0 1 18
35+
Text 2 0 0 13
36+
Dockerfile 1 8 0 12
37+
-------------------------------------------------------------------------------
38+
SUM: 33 454 122 1432
39+
-------------------------------------------------------------------------------
40+
```
41+
1342
# Overview video
1443

1544
Here's a short video that explains the project and how it uses Redis:
1645

17-
[![Embed your YouTube video](https://i.ytimg.com/vi/vyxdC1qK4NE/maxresdefault.jpg)](https://www.youtube.com/watch?v=vyxdC1qK4NE)
46+
[[ Coming soon ]]
1847

1948
## How it works
2049

@@ -61,17 +90,17 @@ There are **eight** types of events that can happen in the lifecycle of a game:
6190

6291
```py
6392
class EventType:
64-
CREATED = "created"
65-
LIGHT = "light"
66-
JOIN = "join"
67-
MOVE = "move"
68-
WIN = "win"
69-
DIE = "die"
70-
LEAVE = "leave"
71-
END = "end"
93+
CREATED = "created" # new game room is created
94+
LIGHT = "light" # the light color is updated
95+
JOIN = "join" # player joins a room
96+
MOVE = "move" # player moves successfully when the light is green
97+
WIN = "win" # player wins by moving 100 steps
98+
DIE = "die" # player tries to move when the light is read
99+
LEAVE = "leave" # player leaves or is disconnected from the game
100+
END = "end" # game ends because there are no more players in the room
72101
```
73102

74-
I use streams as append-only logs to persist very action that happens during the course of a game. Here are some examples of how I store game event data in streams:
103+
I use streams as append-only logs to persist very action that happens during the course of a game. Each event in the stream has an `event` property that stores one of the `EventType`s listed above. Here are some examples of how I store game event data in streams:
75104

76105
**Record a room creation event**
77106

@@ -115,9 +144,13 @@ To display all events for a given room, the `XRANGE` command is used to fetch al
115144
events = om_redis_conn.xrange(f"stream:room:{room}", min="-", max="+")
116145
```
117146

147+
### Indirect usage of Redis
148+
149+
In addition to storing temporary game state and append-only event logs, Redis also supports the application as a message broker for the celery worker and scheduler, and it supports the SocketIO as a message queue which is required when there are multiple servers process (Flask, celery, celerybeat). Main application data is stored on DB index `0`, and these other services use other DB indexes for isolation and separation of concerns to the extent that it makes sense.
150+
118151
## How to run it locally?
119152

120-
Running the application in a local development environment involves starting the web client and also starting multiple backend services. Backend services can be brought up using a `docker-compose.yml` file or they can be started by running commands in Python virtual environment.
153+
Running the application in a local development environment involves starting the web client and also starting multiple backend services. Backend services can be brought up using a `docker-compose.yml` file or they can be started by running commands in a Python virtual environment.
121154

122155
### Prerequisites
123156

@@ -129,11 +162,25 @@ To run the backend locally with docker and docker-compose you will need:
129162

130163
- docker 20.10.14+
131164
- docker-compose 1.29.2
132-
- Python 3.9 (if not using docker)
165+
- Python 3.9+ (if not using docker)
133166

134-
Recommended:
167+
Run the following command to check your local versions:
135168

136-
- Redis Insights
169+
```
170+
make check
171+
```
172+
173+
It should show something like:
174+
175+
```
176+
Docker version 20.10.14, build a224086
177+
178+
docker-compose version 1.29.2, build 5becea4c
179+
180+
Python 3.10.2
181+
182+
Node v16.16.0
183+
```
137184

138185
### Local installation
139186

@@ -179,6 +226,8 @@ Next you can start the three services in different windows. Before starting each
179226
source .env/bin/activate
180227
```
181228

229+
For advanced usage, please see the [`Makefile`](/Makefile) which has some helpful targets for starting different parts of the application (redis-stack, backend services and client).
230+
182231
**Start the Flask API server**
183232

184233
```
@@ -252,7 +301,3 @@ Configuration ->
252301
Before starting `celerybeat`, make sure that you have deleted a file called `celerybeat-schedule.db`.
253302

254303
The client runs on `http://localhost:3000`. It makes API and websocket connections with the backend which runs on `http://localhost:8000`.
255-
256-
## Deployment
257-
258-
To make deploys work, you need to create free account on [Redis Cloud](https://redis.info/try-free-dev-to)

images/rlgl.drawio.png

943 KB
Loading

0 commit comments

Comments
 (0)