Skip to content

Commit 52292ab

Browse files
committed
docs: update README.md
1 parent 4c55392 commit 52292ab

2 files changed

Lines changed: 322 additions & 25 deletions

File tree

‎README.md‎

Lines changed: 322 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,356 @@
1-
# CodyColorClient
1+
# CodyColor
22

3-
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.2.15.
3+
<p align="center">
4+
<img src="docs/CodyColorComponents.jpeg" alt="CodyColor Multiplayer Component Diagram" width="640" />
5+
</p>
46

5-
## Development server
7+
[CodyColor Multiplayer](https://codycolor.codyroby.it) is an educational coding
8+
game developed by [Digit SRL](https://digit.srl), inspired by the unplugged
9+
coding method **CodyColor**. It teaches computational thinking through a
10+
multiplayer, grid-based game where players program a robot's path to reach a
11+
target — competing in real time against other players or against the bot.
12+
Learn more on the [Digit blog](https://digit.srl/codycolor-multiplayer-learn-by-having-fun/).
613

7-
To start a local development server, run:
14+
The game supports three match modes:
815

9-
```bash
10-
ng serve
16+
| Mode | Description |
17+
| --------- | -------------------------------------------------------------------- |
18+
| **Arcade** | Practice against the bot — single player, no time pressure |
19+
| **Random** | Matchmaking with random opponents on shared game rooms |
20+
| **Royale** | Battle-royale-style multi-round elimination tournament |
21+
22+
---
23+
24+
## Architecture
25+
26+
CodyColor is a full-stack real-time application with four cooperating
27+
components, all orchestrated through Docker Compose:
28+
29+
```mermaid
30+
flowchart TD
31+
Client["Client\n(Angular 21 SPA — nginx)"] -->|STOMP over WebSocket| Rabbit["RabbitMQ\n(STOMP broker)"]
32+
Rabbit -->|STOMP queues / topics| Server["Server\n(Node.js — stompjs v2)"]
33+
Server -->|SQL queries| DB[("MySQL 5.7")]
34+
Server -->|game rooms & match state| Rabbit
35+
Rabbit -->|topic broadcasts| Client
1136
```
1237

13-
Once the server is running, open your browser and navigate to `http://localhost:4200/`. The application will automatically reload whenever you modify any of the source files.
38+
1. **Client** (`client/`) — an Angular 21 single-page application using
39+
`@stomp/stompjs` to communicate with the message broker over WebSocket.
40+
Firebase Authentication handles user login. The production build runs
41+
inside an nginx container; the client's config (Firebase keys, RabbitMQ
42+
credentials, public URL) is injected at container startup via
43+
`window.__RUNTIME_CONFIG__`.
44+
45+
2. **Server** (`server/`) — a Node.js application (stompjs v2) that connects to
46+
RabbitMQ as a STOMP consumer. It manages game rooms (arcade, random, and
47+
royale), synchronizes match state between players, persists match results,
48+
user profiles, and rankings in MySQL, and enforces the game logic.
49+
50+
3. **RabbitMQ** — a STOMP-enabled message broker (`beevelop/rabbitmq-stomp`)
51+
that mediates all client ↔ server communication through named queues and
52+
topics.
53+
54+
4. **MySQL** — a relational database (`mysql:5.7`) storing users, match
55+
sessions, match participants, and scores. A phpMyAdmin container is
56+
included for inspection.
57+
58+
5. **Database Operator** (`database-operator/`) — an Alpine image bundling
59+
`mysql-client` and the schema/migration SQL files for initialising the
60+
database.
1461

15-
## Code scaffolding
62+
### Communication flow
1663

17-
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
64+
The client never talks to the server directly. Instead, both the client and
65+
the server are STOMP clients connected to the same RabbitMQ broker:
66+
67+
- The client publishes control messages to `/queue/serverControl` and
68+
subscribes to a per-session response queue.
69+
- The server subscribes to `/queue/serverControl`, processes game logic, and
70+
broadcasts state updates on shared topics (`/topic/gameRooms`,
71+
`/topic/custGameRooms`, `/topic/agaGameRooms`, `/topic/general`).
72+
73+
### Runtime configuration
74+
75+
Secrets and environment-specific values are **never baked into the build**:
76+
77+
| Value | Development | Production |
78+
| ------------------- | ---------------------------------- | ----------------------------------- |
79+
| Firebase config | `client/src/environments/environment.ts` (gitignored) | `/firebase-config.json` volume mount |
80+
| RabbitMQ credentials | `environment.ts` | `RABBIT_USERNAME` / `RABBIT_PASSWORD` env vars |
81+
| RabbitMQ WebSocket URL | `environment.ts` | `RABBIT_SOCKET_URL` env var |
82+
| Web base URL | `environment.ts` | `WEB_BASE_URL` env var |
83+
84+
In production, `client/entrypoint.sh` reads the mounted Firebase JSON and the
85+
environment variables, then writes a `runtime-config.js` file into the nginx
86+
web root. `index.html` loads it before Angular boots, making
87+
`window.__RUNTIME_CONFIG__` available to `environment.prod.ts`.
88+
89+
---
90+
91+
## Repository layout
92+
93+
```
94+
CodyColor/
95+
├── client/ # Angular 21 frontend (SPA)
96+
│ ├── src/
97+
│ │ ├── app/ # Components, pages, services
98+
│ │ │ └── services/rabbit.service.ts # STOMP connection layer
99+
│ │ └── environments/ # environment.ts (dev, gitignored) / .prod.ts
100+
│ ├── entrypoint.sh # Runtime config injection (production)
101+
│ ├── Dockerfile # Multi-stage: build → nginx
102+
│ └── nginx.conf
103+
├── server/ # Node.js backend
104+
│ ├── app.js # Entry point — message handlers & game logic
105+
│ ├── communication/ # broker.js (STOMP), database.js (MySQL), logs.js
106+
│ ├── gameRooms/ # Game room logic: random.js, custom.js, royale.js
107+
│ ├── versions.js # Required client version checks
108+
│ └── Dockerfile
109+
├── database-operator/ # Schema + migration SQL + mysql-client container
110+
│ ├── create.sql # Full initial schema
111+
│ ├── migrations/ # Incremental migrations
112+
│ ├── client.sh # mysql CLI wrapper
113+
│ └── Dockerfile
114+
├── docker-compose.yml # Production stack (Traefik, external volumes)
115+
├── docker-compose.local.yml # Local development stack (exposed ports, guest creds)
116+
├── config-template.env # Template for config.env
117+
├── firebase-config.example.json # Template for Firebase config
118+
├── Taskfile.yml # Task runner shortcuts (go-task)
119+
└── docs/ # Component diagram, database operations
120+
```
121+
122+
---
123+
124+
## Prerequisites
125+
126+
- [Docker](https://docs.docker.com/get-docker/) with the Docker Compose plugin
127+
(v2+)
128+
- [Node.js](https://nodejs.org/) 22+ and npm (for local Angular development)
129+
- [Go Task](https://taskfile.dev/) (optional — for the `task` shortcuts in
130+
`Taskfile.yml`; you can use `docker compose` directly instead)
131+
- A [Firebase](https://console.firebase.google.com/) project with
132+
Authentication enabled (for local development you can use a test project)
133+
134+
---
135+
136+
## Quick start — run locally with Docker
137+
138+
This is the fastest way to get the full stack running. It uses
139+
`docker-compose.local.yml`, which exposes RabbitMQ and MySQL on localhost with
140+
guest credentials and includes phpMyAdmin.
141+
142+
### 1. Prepare configuration files
18143

19144
```bash
20-
ng generate component component-name
145+
# Firebase config (use your own project's web config)
146+
cp firebase-config.example.json firebase-config.json
147+
148+
# Edit firebase-config.json with your Firebase project's web config keys
149+
# (apiKey, authDomain, projectId, appId, ...)
150+
151+
# Local config for the Angular dev environment
152+
cp client/src/environments/environmentTemplate.ts client/src/environments/environment.ts
153+
# Edit environment.ts — fill in your Firebase config and set:
154+
# rabbit.socketUrl: 'ws://localhost:15674/ws'
155+
# webBaseUrl: 'http://localhost:4200'
21156
```
22157

23-
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
158+
### 2. Start the infrastructure (RabbitMQ + MySQL + Server)
24159

25160
```bash
26-
ng generate --help
161+
docker compose -f docker-compose.local.yml up -d
27162
```
28163

29-
## Building
164+
This starts:
165+
166+
| Service | Port | Purpose |
167+
| ----------------- | ----- | ------------------------------- |
168+
| `rabbit` | 15674 | RabbitMQ STOMP WebSocket |
169+
| | 15672 | RabbitMQ management UI |
170+
| `database` | 3306 | MySQL |
171+
| `database-manager`| 8080 | phpMyAdmin (`root` / `root`) |
172+
| `server` | — | Node.js game server |
30173

31-
To build the project run:
174+
### 3. Initialise the database
175+
176+
The server expects the schema from `database-operator/create.sql`. Apply it
177+
via phpMyAdmin (open http://localhost:8080, log in with `root` / `root`,
178+
select the `codycolor` database, and import `database-operator/create.sql`) or
179+
with the mysql CLI:
32180

33181
```bash
34-
ng build
182+
docker compose -f docker-compose.local.yml exec database \
183+
mysql -u codycolor -pcodycolor codycolor < /docker-entrypoint-initdb.d/create.sql
35184
```
36185

37-
This will compile your project and store the build artifacts in the `dist/` directory. By default, the production build optimizes your application for performance and speed.
186+
> **Note:** If `create.sql` is not automatically loaded on first start, copy
187+
> it into the database container and run it manually:
188+
> ```bash
189+
> docker compose -f docker-compose.local.yml cp database-operator/create.sql database:/create.sql
190+
> docker compose -f docker-compose.local.yml exec database \
191+
> sh -c 'mysql -u codycolor -pcodycolor codycolor < /create.sql'
192+
> ```
193+
194+
### 4. Start the Angular dev server
38195
39-
## Running unit tests
196+
```bash
197+
cd client
198+
npm install
199+
npm start
200+
```
40201
41-
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
202+
Open http://localhost:4200 — the app will connect to the local RabbitMQ
203+
instance on port 15674 and the Node.js server will handle game logic.
204+
205+
---
206+
207+
## Quick start — full Docker stack (production-like)
208+
209+
To run everything (including the built client served by nginx) in Docker,
210+
use the production compose file. This requires an external Docker network
211+
named `web` and the `config.env` file.
212+
213+
```bash
214+
# Create the external network (only once)
215+
docker network create web
216+
217+
# Prepare production config
218+
cp config-template.env config.env
219+
# Edit config.env with your RabbitMQ credentials, MySQL credentials,
220+
# and public URLs (RABBIT_SOCKET_URL, WEB_BASE_URL)
221+
222+
# Start all services
223+
docker compose up -d website server rabbit database database-client
224+
```
225+
226+
Or use the Taskfile shortcuts (requires [Go Task](https://taskfile.dev/)):
42227

43228
```bash
44-
ng test
229+
task up # start website + server (detached)
230+
task rebuild # rebuild and recreate all services
231+
task ps # show running containers
232+
task stop # stop all services
233+
task rm # force-remove all containers
45234
```
46235

47-
## Running end-to-end tests
236+
The production stack is configured for deployment behind [Traefik 3](https://traefik.io)
237+
with automatic HTTPS and domain-based routing. See `docker-compose.yml` for the
238+
full Traefik label configuration.
239+
240+
---
48241

49-
For end-to-end (e2e) testing, run:
242+
## Local development (without Docker for the client)
243+
244+
If you only want to develop the Angular frontend while the backend services
245+
run in Docker:
50246

51247
```bash
52-
ng e2e
248+
# 1. Start infrastructure
249+
docker compose -f docker-compose.local.yml up -d rabbit database server
250+
251+
# 2. Set up the Angular dev environment
252+
cd client
253+
cp src/environments/environmentTemplate.ts src/environments/environment.ts
254+
npm install
255+
npm start # ng serve — http://localhost:4200, hot reload enabled
53256
```
54257

55-
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
258+
For the client dev environment (`environment.ts`), point the RabbitMQ
259+
WebSocket URL at the local broker:
260+
261+
```typescript
262+
export const environment = {
263+
production: false,
264+
firebaseConfig: {
265+
apiKey: '<your-firebase-apiKey>',
266+
authDomain: '<your-project>.firebaseapp.com',
267+
databaseURL: 'https://<your-project>.firebaseio.com',
268+
projectId: '<your-project>',
269+
storageBucket: '<your-project>.appspot.com',
270+
messagingSenderId: '<your-sender-id>',
271+
appId: '<your-app-id>',
272+
},
273+
rabbit: {
274+
username: 'guest',
275+
password: 'guest',
276+
vHost: '/',
277+
socketUrl: 'ws://localhost:15674/ws',
278+
},
279+
webBaseUrl: 'http://localhost:4200',
280+
};
281+
```
282+
283+
### Useful npm scripts (in `client/`)
284+
285+
| Command | Description |
286+
| ------------- | ---------------------------------------- |
287+
| `npm start` | Dev server with live reload (`ng serve`) |
288+
| `npm run build` | Production build → `dist/` |
289+
| `npm run watch` | Build + watch for changes |
290+
| `npm test` | Unit tests (Karma + Jasmine) |
291+
292+
---
293+
294+
## Deployment
295+
296+
The application is deployed at **https://codycolor.codyroby.it** behind Traefik 3.
297+
The legacy domain `codycolor.codemooc.net` is automatically redirected.
298+
299+
Production services defined in `docker-compose.yml`:
300+
301+
| Service | Description |
302+
| ------------------- | ----------------------------------------------- |
303+
| `website` | Angular client (nginx) — built from `client/` |
304+
| `server` | Node.js game server — built from `server/` |
305+
| `rabbit` | RabbitMQ STOMP broker |
306+
| `database` | MySQL 5.7 |
307+
| `database-client` | One-shot schema initializer |
308+
| `database-manager` | phpMyAdmin (web UI at `/phpmyadmin/`) |
309+
310+
### Environment variables (`config.env`)
311+
312+
See `config-template.env` for the full list:
313+
314+
| Variable | Used by | Description |
315+
| ---------------------- | --------- | ------------------------------------- |
316+
| `MYSQL_USER` | server | MySQL application user |
317+
| `MYSQL_PASSWORD` | server | MySQL application password |
318+
| `MYSQL_DATABASE` | server | MySQL database name |
319+
| `MYSQL_ROOT_PASSWORD` | database | MySQL root password |
320+
| `RABBIT_USERNAME` | website | RabbitMQ STOMP username |
321+
| `RABBIT_PASSWORD` | website | RabbitMQ STOMP password |
322+
| `RABBIT_VHOST` | website | RabbitMQ virtual host |
323+
| `RABBIT_SOCKET_URL` | website | Public WebSocket URL for STOMP |
324+
| `WEB_BASE_URL` | website | Public base URL of the application |
325+
326+
The Firebase web config is mounted as a volume (`firebase-config.json`) and
327+
injected at container startup — see `client/entrypoint.sh`.
328+
329+
---
330+
331+
## Tech stack
332+
333+
| Layer | Technology |
334+
| ----------- | ------------------------------------------------------- |
335+
| Frontend | Angular 21, TypeScript, Tailwind CSS 4, Angular Material |
336+
| Auth | Firebase Authentication (`@angular/fire`) |
337+
| Messaging | `@stomp/stompjs` (client) / `stompjs` v2 (server) |
338+
| Backend | Node.js (stompjs v2), MySQL 5.7 |
339+
| Broker | RabbitMQ with STOMP plugin (`beevelop/rabbitmq-stomp`) |
340+
| Web server | nginx (production client) |
341+
| Reverse proxy | Traefik 3 (production) |
342+
| Orchestration | Docker Compose, Taskfile |
343+
344+
---
345+
346+
## License
347+
348+
[MIT](LICENSE) — Copyright 2019 DIGIT srl.
349+
350+
## Contributors
56351

57-
## Additional Resources
352+
- [Riccardo Maldini](https://github.com/maldins46)
353+
- [Miriam Petrocchi](https://github.com/miris-mp)
354+
- [Lorenz Cuno Klopfenstein](https://github.com/LorenzCK)
58355

59-
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
356+
Developed by [Digit SRL](https://digit.srl) as part of the CodeMOOC project.

‎docs/ServerDiagram.jpeg‎

-69.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)