homegames-common 1.5.3 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docker-helper.js +2 -1
- package/docs/ARCHITECTURE.md +173 -0
- package/docs/DATA-MODEL.md +115 -0
- package/docs/FLOWS.md +125 -0
- package/docs/INFRA.md +111 -0
- package/docs/OPERATIONS.md +121 -0
- package/docs/SYSTEM.md +118 -0
- package/docs/squishjs-game-authoring.md +895 -0
- package/game-loader.js +2 -0
- package/game-session-manager.js +28 -3
- package/game-session.js +26 -1
- package/index.js +18 -1
- package/package.json +1 -1
package/docs/SYSTEM.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Homegames — System Brain Dump (start here)
|
|
2
|
+
|
|
3
|
+
> If you're reading this to take over or understand Homegames end-to-end, this is
|
|
4
|
+
> the front door. It's deliberately a complete "if I got hit by a bus" dump. The
|
|
5
|
+
> sibling docs in this folder go deeper:
|
|
6
|
+
>
|
|
7
|
+
> - **ARCHITECTURE.md** — every component, what it does, how they connect
|
|
8
|
+
> - **FLOWS.md** — end-to-end traces (play, author+publish, signup, moderation, AI edit)
|
|
9
|
+
> - **DATA-MODEL.md** — MongoDB collections, Forgejo repos, the asset store, identity
|
|
10
|
+
> - **INFRA.md** — what physically runs where, domains, secrets inventory
|
|
11
|
+
> - **OPERATIONS.md** — deploy/update/restart, logs, backups, failure playbook
|
|
12
|
+
> - **squishjs-game-authoring.md** — the contract for writing games (also fed to the LLM)
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## What Homegames is
|
|
17
|
+
|
|
18
|
+
Homegames is a platform for **making and playing simple multiplayer games in the
|
|
19
|
+
browser with as little friction as possible.** No installs to play, a free
|
|
20
|
+
in-browser studio to build, one click to publish to a public catalog.
|
|
21
|
+
|
|
22
|
+
It started as an experiment: *could a server drive what a browser renders purely
|
|
23
|
+
by sending drawing instructions over a WebSocket?* That worked, and it grew into
|
|
24
|
+
a whole product — a serialization format (squish), a game runtime, a renderer, a
|
|
25
|
+
catalog, an in-browser code studio, an asset pipeline, and an LLM that can write
|
|
26
|
+
games for you. The guiding principle throughout is **minimum friction** for both
|
|
27
|
+
players (nothing to install) and developers (build, share, done).
|
|
28
|
+
|
|
29
|
+
Originally it was **self-hosted** (run the server at home, play on your LAN, and
|
|
30
|
+
optionally expose it to the internet through a relay). It is now also — and
|
|
31
|
+
primarily — offered as a **free hosted service at homegames.io**, so people can
|
|
32
|
+
use it without running anything themselves. (The self-host relay,
|
|
33
|
+
`homegames.link` / `public.homegames.link`, was a working experiment but is not
|
|
34
|
+
actively maintained; see INFRA.md.)
|
|
35
|
+
|
|
36
|
+
A second guiding principle is **operational simplicity**: the entire backend runs
|
|
37
|
+
on a **single EC2 host** on purpose, so that anyone can stand up their own
|
|
38
|
+
Homegames without orchestrating a fleet. (The one planned split is pulling the
|
|
39
|
+
game-session runtime onto its own host for scalability — see INFRA.md.)
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## The 30,000-ft picture
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
Players' browsers Developers' browsers
|
|
47
|
+
│ │
|
|
48
|
+
│ HTTPS (site, static) │ HTTPS (studio UI + REST)
|
|
49
|
+
▼ ▼
|
|
50
|
+
┌──────────────────┐ ┌──────────────────────────────┐
|
|
51
|
+
│ homegames.io │ │ api.homegames.io (the API) │
|
|
52
|
+
│ S3 + CloudFront │ │ ── on ONE EC2 host: ── │
|
|
53
|
+
│ (static site + │ │ • API (Node) │
|
|
54
|
+
│ studio + client) │ │ • MongoDB │
|
|
55
|
+
└──────────────────┘ │ • RabbitMQ │
|
|
56
|
+
│ WebSocket (game frames) │ • Forgejo (git for games) │
|
|
57
|
+
▼ │ • homegames-core + Docker │
|
|
58
|
+
┌──────────────────┐ │ (each live game session │
|
|
59
|
+
│ game session │◄───────────────│ runs in a container) │
|
|
60
|
+
│ (homegames-core │ spawns │ • API worker (publish │
|
|
61
|
+
│ in a container) │ │ validation; NSFW is │
|
|
62
|
+
└──────────────────┘ │ in-process in the API) │
|
|
63
|
+
└──────────────────────────────┘
|
|
64
|
+
▲
|
|
65
|
+
│ pulls jobs from RabbitMQ
|
|
66
|
+
│ (LLM "AI edit" requests)
|
|
67
|
+
┌────────────────────────┐
|
|
68
|
+
│ LLM worker (MLX) │
|
|
69
|
+
│ Joseph's Mac Studio │
|
|
70
|
+
│ (Apple Silicon, at home)│
|
|
71
|
+
└────────────────────────┘
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Everything except the website (S3/CloudFront) and the LLM worker (a Mac Studio)
|
|
75
|
+
runs on that **single EC2 instance**.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## The repos and what each is
|
|
80
|
+
|
|
81
|
+
| Repo | Role |
|
|
82
|
+
|------|------|
|
|
83
|
+
| **squish** (`squishjs` on npm) | The serialization format + game node types + `Game`/`ViewableGame` base classes. The shared contract between server and client. Published as many pinned versions (`squish-135`, `squish-138`, `squish-140`, …) so old games keep working. |
|
|
84
|
+
| **homegames-common** | Shared library used across the backend: game loading (`game-loader`), the Docker runner + per-session manager (`docker-helper`, `game-session-manager`), config/util, and **this documentation** (single source of truth, incl. the authoring guide). |
|
|
85
|
+
| **homegames-core** | The game-session server. Loads a published game, runs it, squishes its scene graph, and streams frames to connected browsers over WebSocket. Each live session runs in a Docker container (`docker/` holds the runner image + `validate.js`). |
|
|
86
|
+
| **homegames-client** | The browser rendering engine: connects over WebSocket, unsquishes frames, draws to a `<canvas>`, captures input, manages assets. Bundled and served to players. |
|
|
87
|
+
| **homegames-web** | A tiny static server for the self-host path (serves the client bundle + a config). Largely superseded by homegames.io for the hosted service. |
|
|
88
|
+
| **homegamesio** | The public website (`homegames.io`): landing pages, the **catalog**, the **play** page, the **Studio** (in-browser game editor), the **Admin** moderation console, and the password-reset/verify pages. Served from S3+CloudFront; `app.js` is the Node origin for HTML routes. |
|
|
89
|
+
| **api** | The backend REST API (`api.homegames.io`): auth (signup/login/email-verify/reset), the Studio backend (Forgejo-backed editing + publish requests), the catalog, asset upload (+ **in-process NSFW classification**), admin endpoints, and the **publish-validation worker** (`worker.js`). |
|
|
90
|
+
| **worker** | The **LLM worker** that processes Studio "AI edit" requests. A Node parent (`index.js`) pulls jobs from RabbitMQ and drives a long-lived Python **MLX** model server (`llm/model_server.py`). Runs on the Mac Studio. |
|
|
91
|
+
|
|
92
|
+
External services on the host: **MongoDB** (all app data), **RabbitMQ** (job
|
|
93
|
+
queues), **Forgejo** (a self-hosted GitHub-like git server — every game's source
|
|
94
|
+
lives in a Forgejo repo).
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Bus-factor essentials (the absolute must-knows)
|
|
99
|
+
|
|
100
|
+
1. **One EC2 host runs almost everything** (API, Mongo, RabbitMQ, Forgejo,
|
|
101
|
+
homegames-core+Docker, the API worker) via **systemd services**; logs are in
|
|
102
|
+
**journalctl**. See OPERATIONS.md.
|
|
103
|
+
2. **The website is static** (S3 + CloudFront), deployed with `homegamesio/deploy.sh`.
|
|
104
|
+
3. **The LLM worker is a Mac Studio at home** that pulls from the EC2's RabbitMQ.
|
|
105
|
+
If it's off, "AI edit" in the Studio just doesn't process — nothing else breaks.
|
|
106
|
+
4. **Game source lives in Forgejo**, one repo per game, owned by the user's
|
|
107
|
+
*internal id* (not their display name). MongoDB holds metadata + which commit
|
|
108
|
+
is published. See DATA-MODEL.md.
|
|
109
|
+
5. **Publishing = running untrusted code.** A submitted game is AST-scanned and
|
|
110
|
+
run in a locked-down Docker container before it's allowed to publish. The
|
|
111
|
+
live containment and the validation gate are in `homegames-common/docker-helper.js`
|
|
112
|
+
and `api/worker.js` + `api/ast-scanner.js`. Read `homegames-core/../security_notes.md`
|
|
113
|
+
before scaling this up.
|
|
114
|
+
6. **squish is versioned and pinned.** A game declares `squishVersion`; the server
|
|
115
|
+
squishes with that version and the client unsquishes with the matching one.
|
|
116
|
+
Never break an old squish version — publish a new one.
|
|
117
|
+
7. **Secrets** (JWT, Forgejo webhook + user-password derivation, LLM worker, AWS,
|
|
118
|
+
SES, Mongo) are inventoried in INFRA.md.
|