8. Store: a repository per aggregate
- [E] One repository per aggregate (planet, fleet, player, guild, …)
instead of the single
Storeclass. The SQLite transaction ofrunActionis the unit of work.Ctxcarries the repositories. - [E] The aggregates are cut by game object (owner, 2026-11-13, #117): players and accounts; planets with buildings, ships, defense and queues; fleets; reports; guilds; invitations and admin data. The exact cut follows the code in the pull request.
- [E] Tests use SQLite in memory, no hand-written fakes.
- [E] Decisions after the first build attempt (owner, 2026-11-13, #117):
- Scope: the methods of
Storeplus the aggregates of the cut that lived outside it, guilds (guilds.ts) and admin data (audit, moderation, settings). Achievements, push, passkeys, account security, error log, news and diagnostics stay raw SQL throughctx.db; follow-up issues move them. Storebecomes a thin facade: it composes the repositories and keeps every former method name, plusdbandtx. It is used only by tests,e2e/seed.ts,cli.tsandserver.ts; the store, migration and E2E-seed tests stay unchanged.- [E] Changed for #481, not built yet (owner, 2026-11-28): the
wrappers of the former method names move to
src/test; the core ofStore(repos,db,tx) stays in production forserver.ts,cli.tsandgame/context.ts. Ctxhas flat fields:players,planets,fleets,reports,guilds,invitations,admin, plustx(fn)anddbfor the SQL not moved yet.- Short method names per aggregate, for example
planets.get(id),planets.home(uid),planets.ofOwner(uid),planets.all(),planets.save(p),fleets.due(now). - The cut: players and accounts take users, user research, sessions,
passkeys, passkey challenges and account tokens; admin data takes
settings (universe), audit events, suspensions, player activity and
error events; planets also take
usedSize. - Tests:
ctx.store.xis rewritten mechanically to the repositories, no assertion changed; the existing extra transactions stay, throughctx.tx; SQL that moves into a repository loses its own transaction to the caller; one test file per repository against SQLite in memory. - Every statement moves verbatim: the same text and parameter order, no
rewrite, no optimisation, no new index. One exception, same text and
parameter:
DELETE FROM guild_members WHERE user_id = ?stood three times inguilds.tsand is now the one methodguilds.removeMember.
- Scope: the methods of
- [E] Built with #117:
src/server/db/repos/holds one file per aggregate, each a typed interface (Players,Planets,Fleets,Reports,Guilds,Invitations,Admin) and its better-sqlite3 class;repositories(db)inindex.tsbuilds them on one connection,rows.tsmaps rows.createCtx(store)spreadsstore.reposintoCtxwithdbandtx. No repository callstransaction: therunActiontransaction stays the unit of work, and the other existing transactions (audit, activity, account security, news, push, achievements, account deletion, arrivals, registration) stay where they were. The game logic of guilds, round, audit and moderation stays in its file; only the SQL moved. Players and admin data hold sessions, audit and moderation SQL, so they are security files of the mutation standard (90 %); so are the invitations, whose tokens decide who may register (owner, 2026-11-13). Still raw throughctx.db:achievements.ts,push-store.ts,web-push.ts,passkeys.ts,account-security.ts,error-log.ts,error-export.ts,news.ts,diagnostics.ts,delete-account.ts,game/admin.ts(new round), theUPDATE usersofauth.tsand the health check ofhttp/app.ts.