What it was
I've been into 40k for a few years now. When 11th edition came out the official app dropped support for 10th, which I still wanted to play, so I started building Dilectus. It now covers every army in both editions. You choose a faction and detachment, add units and wargear, attach Leaders to their bodyguards and put units in Transports. The rules engine checks the list as you go. At the table you can track wounds and Command Points, or link your battle with another player's using a 4-digit code. Lists work without an account too, signing in just lets you keep them across devices. BSData and Wahapedia provide the game data. The app checks for updates every morning. Hosting runs on free tiers.
Build
- The rules engine reads BSData's catalogues directly, including their constraints, modifiers and conditions. Adding an army means importing its data, there's no separate set of rules written in TypeScript for each faction. The engine runs in the browser and behind the API.
- A scheduled GitHub Actions job checks the source versions before doing an import. Most days nothing has changed and it stops there. A full rebuild needs about 2 GB of memory, so running it on an Actions runner gives it room to finish.
- An import is blocked if it contains a rule the engine doesn't understand. Otherwise an unknown condition could quietly become false and mark someone's list incorrectly. A failed import leaves the previous data live and opens a GitHub issue.
- Each edition keeps one active import in Postgres. I record the BSData commit, Wahapedia export date and hashes of my own rule fixes with it, so an older dataset can be rebuilt.
- Lists live in IndexedDB and work signed out. Better Auth handles accounts in the same Postgres database. Signing in syncs the lists, using the last change to each one.
- Battle cards use the same rules engine. A Leader's buff or an Enhancement changes the unit it applies to, rather than leaving you to remember it. Each player has their own battle record, with a match linking the shared round and victory points.
Key decisions
Battle connections
The devices are usually on the same table, often on the same Wi-Fi, sending a few kilobytes at a time. WebRTC lets them talk directly after the API introduces them. Phones that can't connect directly use Cloudflare's TURN relay. I looked at hosted realtime services too, I just didn't want another account and another dashboard for this.
Using BSData
I started with Wahapedia's CSV export and wrote the Orks list-building rules by hand. A day in I threw that away. BSData already describes the rules for all the armies, and it's what BattleScribe and New Recruit use. I needed to interpret that model properly.
CI minutes
The daily import and tests share the Actions allowance. Unit tests run on every PR, while Playwright runs on PRs with an e2e label and uses a small set of Orks and Thousand Sons data. Running a full import for every test run was using about 3 minutes before a test had even started.
Lesson learned
The database wouldn't sleep while a battle was open.the rest of it ↓fold it back up ↑
The free tiers have sent me down quite a few rabbit holes. The import outgrew a Vercel function, so it moved to GitHub Actions. Keeping every old import used too much storage, so now I keep the active one for each edition and record the source versions needed to rebuild the others. The live battles took more work. Polling every 5 seconds kept the database awake even when nobody changed anything. Most people only had one device open anyway. Now those people make no background requests, and devices sharing a battle talk directly over WebRTC. I had to deal with phones sleeping and connections surviving page reloads along the way. There's a hidden connections page for seeing what each device is doing, I wish I'd built that earlier.