Skip to content
André Borchert edited this page Aug 23, 2026 · 3 revisions

The Mod Engine

Design stage. Nothing here is implemented.

One Swift binary handles all three Minecraft servers and the website. Swift 6.3.3, running on Debian.

Process model

One engine process, not one per version. v1 ran three Swift services on three loopback ports, each scoped to a single Minecraft version, and paid for it three times over: three systemd units to maintain, three API endpoints for Caddy to route between, three copies of every fix, and no place to put logic that spans versions.

The engine instead holds all versions in one process:

pummelchen-engine serve --config /etc/pummelchen/engine.toml
  • One loopback HTTP API on 127.0.0.1:8787, serving every version.
  • One reconciliation loop, iterating the version table.
  • One conflict-test scheduler, so concurrency is bounded globally rather than per version.
  • One connection to the state database, one mod store, one conflict graph.

Caddy proxies /api/* to that single port. Adding a Minecraft version changes no Caddy configuration and creates no new service.

The Minecraft servers themselves stay under systemd — they are long-lived JVMs that must survive an engine restart, and systemd is better at that than the engine would be. The engine generates and manages those units rather than requiring them to be hand-written; see Adding a Version.

Command surface

A single binary with subcommands, so operational actions are discoverable and scriptable:

Command Purpose
serve Run the daemon: API, reconciliation loop, supervision
version add Provision a new Minecraft version end to end
version promote Move the live role to another version
version retire Stop and archive a version
sync Force an immediate sheet reconcile
resolve Resolve pinned files for one version
propose Build a candidate modset and print its digest
validate Run a conflict test against a digest
bisect Localize a failure in a delta
deploy Deploy a validated digest, subject to the live gate
rollback Return a version to its previous digest
status What is running, deployed, pending

Everything the daemon does automatically must also be runnable by hand. v1's operator CLI was its most useful property and is worth keeping.

Dependencies

Deliberately small. Every dependency is a thing that can break a Debian build.

Need Package Notes
CLI parsing swift-argument-parser Apple, stable
HTTP server Hummingbird NIO-based, far lighter than Vapor for a loopback API
HTTP client async-http-client Modrinth, CurseForge, Sheets, NeoForge Maven
Database GRDB.swift Mature SQLite layer with real migrations
Zip entry reading ZIPFoundation Pure Swift; reads one entry from a jar without extracting
TOML parsing TOMLDecoder For META-INF/neoforge.mods.toml
JWT RS256 JWTKit Google service-account assertions
Hashing swift-crypto SHA-256 for the content store
Server List Ping hand-rolled on NIO ~100 lines of varint framing; no dependency justified

Not DuckDB. v1 embedded it through a C shim and paid for it in build fragility on every machine. The data here is small and write-frequent, which is the workload DuckDB is worst at. SQLite via GRDB is the right tool and removes a native linkage from the build.

Build with --static-swift-stdlib so deployment is a single binary with no Swift runtime to install alongside it.

Concurrency

Swift 6 strict concurrency is on. The v1 code leaned on @unchecked Sendable to get a hand-rolled socket server past the compiler; that escape hatch should not be reached for here.

The natural decomposition is actors around the mutable state:

  • an actor owning the state database connection
  • an actor owning the test-session pool and its concurrency cap
  • an actor per supervised Minecraft server
  • the HTTP API as stateless handlers reading through those actors

Long-running work — downloads, boots, bisection rounds — belongs in structured concurrency with explicit cancellation, so a preempted or superseded run actually stops rather than finishing invisibly.

Configuration

One file, /etc/pummelchen/engine.toml, holding only what cannot be derived:

api_listen        = "127.0.0.1:8787"
state_db          = "/var/minecraftai/shared/state.db"
store_dir         = "/var/minecraftai/shared/store"
versions_root     = "/var/minecraftai"
site_root         = "/var/minecraftai/web/site/public"
max_test_sessions = 2
minecraft_port_range = [25565, 25599]

[sheets]
spreadsheet_id      = "1vgUZC2iymSG4PQIZOSowAXGq-gxrggP9syOwoijrzJk"
service_account_key = "/etc/pummelchen/google-service-account.json"
poll_interval       = "10m"

No Minecraft version appears in this file. Versions live in the database, because they are data that changes. See Adding a Version.

Secrets — the service-account key, the CurseForge API key — are files referenced by path, owner-read-only, never inline and never passed as command-line arguments where a process listing would expose them. That rule is inherited from v1's client identity contract and remains correct.

API surface

Read-only, unauthenticated, loopback-bound. Everything it exposes is already public.

Endpoint Returns
GET /api/v1/versions Every version with role, state, player count, uptime
GET /api/v1/versions/{version}/mods Deployed mod list: name, category, source URL
GET /api/v1/ping 204, with Server-Timing

Version paths are derived from the version table, so a new version appears in the API the moment its row exists.

v1 had an authentication asymmetry — client endpoints required a bearer token while control endpoints did not, contradicting its own written contract. Keeping this API strictly read-only avoids reintroducing that class of bug: there is no privileged operation to leave accidentally unguarded. Operator actions belong on the CLI, which is reachable only by someone already on the host.

Clone this wiki locally