> **Sole engineer on the rebuild, engaged by DDB Canada while Head of Technology at DDB New Zealand** · January to May 2021
> Source: https://www.simonbetton.com/case-studies/geminai-rising.md (markdown only; there is no HTML page for this document).
> Index of case studies: https://www.simonbetton.com/case-studies/index.md

# Case study: GeminAI Rising

## Quick facts

|  |  |
| --- | --- |
| Role | Sole engineer on the 2021 rebuild of the host |
| Employer at the time | DDB New Zealand, as Head of Technology; the work was for DDB Canada, whose Edmonton office made the product |
| Client | Alberta Health Services, Tobacco, Vaping, and Cannabis Program |
| Product | GeminAI Rising, a cooperative online game for grade 7 to 9 classrooms, live at [geminairising.ca](https://geminairising.ca) |
| Timeline | January to May 2021; the rebuilt host was live before I left DDB New Zealand in May 2021 |
| Stack | AdonisJS 4 (HTTP and WebSocket in one process, Lucid ORM, Shield, JWT auth), React, Webpack, SQL via Lucid |

## What the product is

GeminAI Rising is a game a class plays together. The teacher runs it from a computer on a projector or SMART Board, which AHS calls the gameboard. Students sit in groups of three or four around one Chromebook, tablet, or laptop per group. Story video plays on the board, each group's device prompts when a challenge starts, results come back to the board, and the class works through five episodes: Awakening, Choices, Perception, Creation, and Revolution. AHS pairs each episode with a lesson on one social competency (coping, decision-making, critical thinking, problem-solving, self-concept), on the stated basis that substance prevention works better by building those skills than by delivering health information.

DDB Canada's Edmonton office created it with animation and audio partners, and it won an Applied Arts award in the website category in 2020. The story, art, video, UX, and lesson content are theirs and AHS's. The platform underneath is what I rebuilt in 2021.

## The problem I was handed

By the time I was involved, the product had launched: an Express application with a live teacher dashboard. DDB Canada's brief to me was to tidy the code and fix the bugs. My assessment after reading it was that the build was roughly 90 per cent complete, unstable, and hard to maintain because a series of contractors had each added their piece without anyone owning the whole path from teacher login to a group's device staying in sync.

The code volume was not the hard part. The runtime was.

Two audiences share one session with almost no setup time. The teacher registers and creates a class; the students never create anything. They open the site, choose Player, and type a short code the teacher reads out. If joining takes longer than that, the period goes to IT instead of the episode.

The session is stateful and lives on a projector. When a challenge starts, every group's device has to prompt at the same time; when the timer ends, results return to the board; then an outcome video plays and the next chapter arms. A device that sleeps, drops Wi-Fi, or opens a second tab has to be able to come back without turning into a second team.

The users are minors on shared hardware in a public-health programme, so a teacher dashboard that could be framed by another page, or a student session that leaked between groups on the same device, would matter more than on a consumer site.

The content is fixed in shape and loose in schedule: five episodes that any grade 7 to 9 class can run in any order, repeat, or stop after a disruption, so progress belongs to the class, not to a child.

## The decision: rebuild the host, keep the screens

Three options were on the table.

Patch in place. Fastest for the first fortnight. It leaves every implicit contract between screens, auth, and sockets exactly where it was, and the bugs I was hired to fix lived in those contracts rather than in any one screen.

Rewrite everything. Throws away React screens that already expressed the classroom routine and were not where the problems were.

Rebuild the host and migrate the screens. Start a fresh server, define the data model around the classroom's nouns, put IO in a service layer, and bring the presentational React across one screen at a time, cleaning each as it moved.

I chose the third and did it alone. The trade-offs I accepted: the first weeks were slower than a patch would have been; a fresh host can reintroduce bugs the old one had already fixed; and for the duration I was the only person who knew the system, with no second engineer to review it. I took the last one deliberately, because handoffs were how the first build had got into trouble. The mitigation was to stay inside the framework's standard project layout, so the next engineer would be reading AdonisJS documentation rather than my head.

## How the rebuilt host is shaped

Several of the nouns below (a spoken game code, no student accounts, team labels, a class dashboard) already existed in the 2020 product, but they were buggy and mostly broken. What I decided was how they were modelled, secured, and connected so that they worked.

One process, one application origin. AdonisJS boots the HTTP server and the WebSocket server together. The API and the socket path sit on the same host that serves the pages, and cross-origin requests are refused. Media is the deliberate exception: the build injects an asset base URL into both JavaScript and Sass so video, audio, and art load from object storage in AWS's Canadian region rather than from the application, which leaves a school proxy with two hostnames to allow and the Node process serving only HTML, JSON, and sockets.

A schema that reads like the teacher guide. Teachers are users, with an admin flag and the school postal code the registration form asks for. A class has a name and a student count. Episodes are five reference rows. A game is one class playing one episode, identified by a short public code. A player is one group in one game, with a UUID, a team name drawn from a fixed NATO list (Alpha through Lima), and a JSON document for whatever the current chapter needs to remember, so a change to a puzzle does not need a migration. Students appear nowhere in the users table, and progress is tracked against the class.

A code you can say aloud and cannot predict. Each game's code is generated with Hashids using a fresh random salt per save, at least six characters, with a unique constraint on the column. It cannot be predicted from the class id, so knowing one code tells you nothing about the next. The teacher guide calls it the game ID and tells teachers it appears in green.

JWT for teachers, a code for students. The authenticator is JWT over a Bearer header; the user API sits behind the auth middleware and the registration validator normalises email and enforces uniqueness. A student's only credential is the game code, so there is no student password to reset, phish, or leave behind on a shared Chromebook. The teacher's token lives in localStorage, which was the SPA convention in 2021 and is the XSS trade-off I would not make again.

One channel per game. Socket clients subscribe to a channel named for their game, so a device only hears the session it joined. I left the framework's heartbeat defaults in place (a 30 second server interval with three missed beats before a drop, and a 25 second client ping with three attempts) and did not tune them. AHS's teacher guide tells teachers to disable sleep mode, which suggests device sleep, rather than heartbeat timing, was the disconnect classrooms actually hit.

Browser protections left on. Adonis Shield ships with frame denial, content-type sniffing disabled, and a CSRF token cookie marked SameSite with a two-hour life, and I kept those defaults rather than turning them off to make the SPA easier. Frame denial is the one that matters here: the gameboard is an authenticated teacher page on a projector. I left the Content Security Policy empty, which I would not do again.

Build and frontend. Webpack compiles the React with path aliases for shared components, services, and styles. The scaffold had separate admin and player JavaScript entries plus a global stylesheet entry, an admin route table with lazily loaded screens, a React Query provider, and a user context. The screens came across from the previous build one at a time. The production build serves one shared JavaScript bundle to both surfaces and splits only the stylesheets by surface, so the per-surface JavaScript split did not survive to deployment.

## What shipped and how it is used

I shipped the rebuilt host before leaving DDB New Zealand in May 2021, and it is the host that runs at geminairising.ca today: an AdonisJS application behind nginx and CloudFront, with Shield's frame denial and two-hour SameSite CSRF cookie on every response, serving media from AWS object storage in Canada.

AHS published its grade 7 to 9 teacher resource on 10 February 2022. Its setup steps follow the model above: register on Admin with an email, password, and school postal code; add a class with a name and student count; read the green game ID to the room; students choose Player and enter the ID until the device reports it is connected; the teacher checks that the connected-device count under the class name matches the room. Its troubleshooting page describes the reconnect behaviour: a dropped device reloads and re-enters the game ID, and if that happens mid-challenge it waits for the next one; a rebooted teacher machine logs back in and starts a new session of the interrupted challenge while students re-sync. That reconnect behaviour was intended in the 2020 product and did not work reliably; the rebuild is what made it hold.

The programme was still being taught to teachers in 2026. "GeminAI Rising: Play, Connect, Empower" ran at the North Central Teachers' Convention on 5 February 2026, presented by Primary Care Alberta, and at the PDTCA convention in Calgary on 20 February 2026, with attendees asked to bring a tablet, Chromebook, or laptop to play. The AHS teacher-resources page still links the guide.

I do not have classroom counts, session volumes, uptime, or before-and-after bug figures. The outcome I can defend is that the host I built is the one still running, five years on, under a programme its client is still promoting.

## What I would do differently

Put the teacher session in an httpOnly, SameSite cookie instead of localStorage. Ship a real Content Security Policy. Write the reconnect behaviour down as a state machine before the first pilot and test it: join during video, join during a challenge, join after results, second tab, device sleep. AHS ended up writing that state machine for teachers in the troubleshooting page; it should have existed for the code first. Tune the socket heartbeats from classroom data rather than leaving defaults. Keep the per-surface JavaScript split through to production. And write the rebuild decision down on day one, with what I kept, what I discarded, and why patching would have failed, so the next engineer inherits the reasoning and not just the result.

## Technologies and standards

| Layer | Choices |
| --- | --- |
| Runtime | Node.js, AdonisJS 4 with HTTP and WebSocket servers in one process, Edge-rendered HTML shells, Lucid ORM with Knex migrations |
| Data | SQL through Lucid (SQLite locally, MySQL seeders); users, tokens, classes, episodes, games, players; JSON column for per-chapter team state |
| Identity | JWT Bearer tokens for teachers, bcrypt password hashing, UUID v4 for teams, Hashids game codes with a unique constraint, no student accounts |
| Real-time | One WebSocket channel per game on a dedicated upgrade path; framework default heartbeats |
| Security | Same-origin API with CORS refused, Adonis Shield defaults kept (frame denial, nosniff, CSRF with a two-hour SameSite cookie) |
| Frontend and build | React, Webpack with path aliases and a build-time asset base URL injected into JavaScript and Sass, Axios service layer, media on AWS object storage in Canada |
| Classroom | Chrome as the browser AHS instructs teachers to use, one device per group of three or four, NATO team labels, class as the unit of progress |
