Repository navigation
Architecture
MinecraftAI manages the lifecycle of a large, versioned Minecraft/NeoForge mod pack across a Debian server and macOS clients. Its primary architectural goal is to turn potentially unsafe manual operations—mod discovery, compatibility selection, package mutation, client repair, release publication, and world maintenance—into validated, repeatable workflows with checksums and DuckDB audit state.
Modrinth / CurseForge / NeoForged / Java sources
|
| metadata and artifacts
v
Operator ------> MCPummelchenModServer CLI/API <------ systemd timer
| | | |
| | +--> Minecraft process + RCON
| |
| +----------> DuckDB
|
+--> immutable releases + public release tree
|
v
Caddy edge
website / API / static downloads
|
v
macOS app + sync/watch helper
local Minecraft dir + client DuckDB
The system is deliberately split between control/metadata traffic and large immutable downloads. The Swift API handles control, status, reports, and operational data. Caddy serves large release files under /downloads/.
Server App/caddy/Caddyfile and PummelchenRoutes.caddy define:
- HTTP listeners redirecting to HTTPS.
- Caddy-managed TLS 1.2/1.3 certificates for the IPv4 and IPv6 hostnames.
- HTTP/1.1, HTTP/2, and HTTP/3/QUIC.
-
/api/26.1.2/,/api/26.2/, and/api/26.3/proxying to ports 8787, 8788, and 8789, plus unversioned/api/compatibility routing to 8787. - A 256 KiB request-body limit for proxied API requests.
- Operational JSON aliases such as
/live-stats.json,/update-activity.json,/neoforge-version.json,/release-health.json, and/server-versions.jsonmapped to Swift endpoints. - No-store/no-cache behavior for current-release pointers and operational data.
- Immutable caching for versioned release directories and short caching for mutable download aliases.
- Sensitive database, backup, temporary, and soak-report filename denial.
- Static website delivery from the runtime
site/publictree.
The edge is a trust boundary: browser/client traffic is public; the Swift server is expected to remain locally bound behind Caddy.
The tracked deployment uses one isolated Swift service per Minecraft version:
| Unit | Project root | Loopback API |
|---|---|---|
MCPummelchenModServer_26.1.2.service |
/var/minecraftai/26.1.2/runtime |
127.0.0.1:8787 |
MCPummelchenModServer_26.2.service |
/var/minecraftai/26.2/runtime |
127.0.0.1:8788 |
MCPummelchenModServer_26.3.service |
/var/minecraftai/26.3/runtime |
127.0.0.1:8789 |
The services are root-owned because they may supervise Minecraft processes and install local firewall rules. Hardening includes NoNewPrivileges, PrivateTmp, ProtectHome, ProtectSystem=full, RestrictSUIDSGID, and constrained ReadWritePaths. KillMode=process is significant: the service's Minecraft child process behavior is intentionally different from a conventional control-group kill.
When PUMMELCHEN_MINECRAFT_AUTOSTART and required environment values are present, MinecraftLiveServerSupervisor:
- Validates the runtime directory and executable command.
- Installs IPv4/IPv6 firewall rules that reject non-local RCON traffic.
- Checks whether the Minecraft TCP port is already open.
- Starts the Minecraft process and logs stdout/stderr.
- Optionally starts a watchdog.
- Uses RCON to probe the server thread.
- Restarts the process after a configured failure threshold.
This creates a privilege and availability boundary. Changes to process ownership, firewall execution, watchdog timing, RCON handling, or systemd kill semantics require deployment-owner review.
MCPummelchenModUpdateScan.timer runs daily. The corresponding oneshot service:
- Stops the Swift server service.
- Acquires an
flocklock. - Runs a dedicated 26.1.2
mod-update-scanagainst the 26.1.2 DuckDB. - Enables project-data seeding and source-link discovery with configured throttles.
- Restarts the Swift server in
ExecStopPost.
The design aims to give the write-heavy scanner exclusive DuckDB write access while preserving intended Minecraft process behavior through the service boundary.
Sources/MCPummelchenModServer/main.swift is the operator-facing composition root. It owns:
- CLI usage and option parsing.
- Command dispatch.
- Construction of pipeline configurations.
- The local socket-based HTTP listener.
- Optional supervisor startup.
- Process exit/error formatting.
Business logic should generally live in MCPummelchenModServerCore, not grow indefinitely in the command router.
The local HTTP server parses requests into HTTPRequest and delegates to MCPummelchenModServerAPI.response(for:). The API core:
- normalizes request paths;
- routes by
(method, path); - validates payload size and contracts;
- delegates persistence to
ServerClientReportStoreandControlEventStore; - delegates metrics to
LiveStatsProvider; - reads current release/manifest files;
- queries DuckDB for website/reporting payloads;
- maps typed failures to HTTP status codes.
The route switch is explicit rather than framework-driven, which makes the core file the authoritative API inventory.
The API owns the source of truth for:
- live stats;
- server-supported versions;
- merged/server/client mod inventory;
- failed/banned mod status;
- release history;
- update activity;
- NeoForge version metadata;
- release health;
- client health.
The website must display an unavailable state if these APIs fail. Static JSON fallbacks are intentionally prohibited because they can present stale operational state.
The shared package is the compatibility layer between server, client, tests, and release tooling.
CurrentRelease carries:
- release ID and timestamps;
- status, Minecraft version, loader version, server key;
- manifest, client ZIP, MRPACK, and optional DMG URLs/checksums;
- notes.
CurrentReleaseValidator enforces:
- valid release identifier;
- required fields;
- relative, release-scoped URLs;
- no parent traversal, backslashes, or empty path segments;
- expected file extensions/suffixes;
- paired DMG URL/SHA fields;
- SHA256 syntax;
- stable DMG alias preference.
This contract is consumed by the server API, release pipeline, client sync, and self-update logic. Any field change is cross-package and must be versioned/tested as a contract change.
The manifest is a five-column UTF-8 TSV:
section name size_bytes sha256:<hex> url_path
Allowed sections are mods, resourcepacks, shaderpacks, and tools. The parser enforces:
- exactly five columns;
- known section;
- plain non-hidden filename;
- non-negative size;
- SHA256 marker and 64-hex value;
- release-scoped URL;
- URL suffix matching section and filename;
- no duplicate
(section, name)entries.
APIModels.swift defines client registration/status/inventory/diagnostics/default reports, health summaries, acknowledgements, control event types, create requests, event batches, and acknowledgements. Changing JSON coding keys or optionality requires checking both the API handlers and client channel.
-
SafePathconstrains writes to a root. -
SHA256Hasherhashes source and downloaded files. -
FileInventoryrecords and verifies managed files. -
ContractValidationcentralizes input constraints.
These are security controls, not incidental helpers.
The macOS application is an AppKit application hosting SwiftUI content. ClientStatusModel owns:
- server URL and current snapshot;
- refresh/sync/force-update state;
- startup auto-sync decision;
- control watcher task;
- endpoint latency refresh task;
- retry after Minecraft closes.
The UI provides:
- server/client release status;
- endpoint health and latency;
- managed-default health;
- Sync Now;
- Force Update;
- Refresh;
- editable server URL.
A POSIX file lock prevents multiple application instances; a second launch activates the existing app.
pummelchen-client-sync exposes:
-
sync: run one synchronization and print a machine/human-readable summary; -
watch: poll control events and trigger syncs.
The CLI explicitly rejects a token value passed as --client-api-token, reducing exposure through process listings. Optional credentials come from environment, Info.plist, or a private bundle resource.
start
|
+-- Minecraft running and no override? --> fail/record/report
|
+-- prepare directories
+-- fetch & validate current release
+-- fetch & parse manifest
+-- remove stale previously managed files
+-- first install? quarantine unmanaged files
+-- for each entry:
| existing file valid? -> verified
| else download -> verify -> atomic replace
+-- install/verify Java and NeoForge as configured
+-- apply defaults (full first install; server entries later)
+-- write release marker + local manifest
+-- record local DuckDB status/inventory
+-- optional server reports
+-- evaluate/stage app self-update
v
result
The failure path records a local failed sync result and attempts optional reporting before rethrowing.
This distinction is an invariant:
- First install: quarantine unmanaged managed-section files, sync every manifest section, apply all managed defaults, inspect/report defaults and full inventory.
- Later sync: synchronize managed mods while preserving already-present non-mod content and unrelated player settings; apply server entries rather than resetting all defaults.
Changes that collapse this distinction risk data loss or preference resets.
JavaRuntimeManager uses a pinned Temurin arm64 macOS JDK archive with a pinned SHA256. It checks bundled/cache/download locations, verifies the archive, extracts to a managed directory, runs java -version, removes stale managed runtime versions, and writes a marker.
ClientSupportedVersionsResolver fetches the version list from the server, validates uniqueness and presence of a live version, caches it locally, then falls back to bundled defaults only when server/cache resolution fails. NeoForgeClientInstaller prefers server-provided installer name/URL/SHA metadata and uses pinned fallback requirements when needed.
The client treats current-release DMG metadata as the application-update contract. Self-update code downloads and verifies the DMG, mounts it read-only, validates the app bundle and helper/native library, stages replacement, exits, installs the new app, and relaunches. This path handles executable code and must retain checksum/signature/bundle validation.
operator/API creates event
-> control.control_events
-> client GET /api/v1/control/events?client_id=...
-> ClientControlWatcher interprets type
-> optional jitter + ClientSyncEngine.sync(force: true)
-> client POST acknowledgement
-> control.control_acks
Global events have no target client; targeted events include a client ID. Pending query excludes already acknowledged events.
Immediate sync types:
release_availablesync_requireddefaults_changedclient_sync_requested
Informational types:
server_messageserver_restart_noticehealth_update
Control payloads are capped at 16 KiB and cannot contain download URL/file references. Large downloads always go through the release/download channel.
When reporting is enabled and a client token is available, the client sends:
- sync/status report;
- managed-file inventory;
- defaults inspection/repair events;
- diagnostics where applicable.
conflicting: server routes currently accept these endpoints without invoking the former authorization guard, while ClientSyncEngine.report still skips all report uploads when no token is present. This asymmetry should be resolved by an explicit security decision, not an opportunistic code cleanup.
source URL / optional local artifact
-> provider resolver (Modrinth or CurseForge)
-> required dependency graph (bounded)
-> JAR metadata inspection / side classification
-> copy to server and/or client package
-> optional metadata range patch
-> persist mod source rows
-> smoke check
-> optional macOS DMG build
-> release pipeline
-> optional activation
The pipeline's dry-run mode resolves/classifies without copying or creating a release.
ModUpdateScanner:
- Ensures needed runtime tables/columns exist.
- Optionally seeds from project release manifests.
- Seeds missing target-version candidates from the live baseline for staging versions.
- Optionally discovers missing redundant provider links.
- Creates a scan row.
- Loads source records for the selected version.
- Applies fetch throttling.
- Checks official APIs/pages or generic source HTML.
- Classifies results, including Cloudflare blocking.
- Persists per-source result, failure status, progress, and completed summary.
Provider behavior is differentiated: NeoForge, Modrinth, CurseForge, and generic web sources do not have identical loader/version rules.
Documented discovery order:
- Modrinth/CurseForge APIs.
- Direct provider-site HTML search.
- Google results filtered to accepted provider URLs.
Discovery is capped at two searches per second and recorded in DuckDB. A discovered link remains evidence, not deployment authorization.
ModUpdateApplyPipeline:
- Load live/staging targets.
- Load latest completed scan candidates.
- If priority candidates exist, apply only that protected/priority set first.
- Verify package readiness.
- Group candidates by artifact URL.
- Download and inspect the artifact.
- Remove replaced files from applicable server/client locations.
- Copy and patch the replacement.
- Update source rows.
- Smoke-check the version package.
- Build DMG for the live version when available.
- Create release; activate only a configured live target, otherwise stage.
- Record update activity.
DuckDB core.minecraft_server_versions and related views are the source of truth for supported versions, status, is_live, server address, sort order, loader version, and NeoForge installer metadata.
registered target version + registered reference version
-> scan target with live/project seeding
-> query accepted reference-version mods/files
-> create/ensure target package sections
-> use target-specific scanned artifact where available
-> otherwise copy validated baseline file
-> preserve Priority Mod/Admin Locked state
-> copy client shaders/resourcepacks/tools/datapacks
-> optional apply pipeline and release
A staging version may have compatibility candidates without being a deployed install. Code and reporting must maintain that distinction.
A release contains, at minimum:
<release-id>/
├── CHANGELOG.md
├── metadata.json
├── manifests/
│ ├── server-files.tsv
│ └── client-package.tsv
├── server-files/
│ ├── mods/
│ └── server-datapacks/
├── client-package/
├── artifacts/
│ ├── version-scoped client ZIP + checksum
│ ├── version-scoped MRPACK + checksum
│ └── optional versioned DMG + checksum + soak report
├── db/
└── public/
├── current-release.json
├── client-sync-manifest.tsv
└── client-files/
The exact copied DB/public structure is owned by SwiftReleasePipeline; verify current implementation before adding fields.
The release pipeline:
- rejects an existing release directory;
- copies server and client package content;
- generates manifests and hashes;
- rebuilds client distribution artifacts;
- validates required ZIP/MRPACK;
- validates optional DMG and soak report;
- writes deterministic metadata/current-release content;
- builds public release files;
- persists release state;
- validates the completed release.
Activation:
- publishes the release public tree to Caddy downloads;
- always writes version-scoped current-release files;
- writes versioned download aliases for the activated version and writes global current-release JSON/text only if DuckDB marks that version live;
- updates active release rows/events;
- prunes old release storage using configured retention;
- performs configured cleanup and service restart.
A staging release must never overwrite the global client pointer.
On macOS the builder:
- Builds release binaries for the app and sync helper.
- Creates the app bundle layout.
- Optionally writes the private bootstrap resource with mode
0600. - Builds the icon.
- Locates and embeds
libduckdb.dylib. - Patches install names and rpaths.
- Writes Info.plist with client/release metadata.
- Lints and ad-hoc signs the app/native binaries.
- Verifies signatures.
- Optionally tests the public-edge control path.
- Creates and hashes the versioned DMG.
- Optionally runs the headless live soak.
The production contract requires proof tied to the exact DMG and release ID. The acceptance run covers:
- app installation from the DMG;
- signature/helper/DuckDB validation;
- managed Java and NeoForge;
- full manifest sync and checksum verification;
- managed defaults;
- exactly one server entry;
- live server login;
- at least 60 seconds connected;
- no fatal logs or crash reports.
The release pipeline rejects missing, stale, mismatched, too-short, or failed proof.
pummelchen-duckdb migrate:
- discovers numeric-prefix
.sqlfiles; - rejects duplicate numeric versions;
- initializes
core.schema_migrations; - skips applied versions;
- computes migration checksums;
- applies each migration transactionally;
- records version/name/time/checksum.
The server, client, and helper use DuckDBDatabase through the native C API. Normal runtime code should not shell out to the DuckDB CLI.
Reporting views decouple website/API consumers from operational table layout. Health checks verify required reporting fields and print table/schema/database/settings summaries. Parquet export/verify covers a known list of reporting views and records audit rows.
The scheduled scan stops the API service to avoid write contention. Future changes involving concurrent writers should be treated as an architectural change and tested against DuckDB locking/transaction behavior.
The tracked website is static HTML/CSS/JS, but its operational content is dynamic. index.html includes:
- live system/server statistics and charts;
- server-version cards;
- release/download actions;
- mod/update tables;
- operator guidance;
- links to release and failed-mod pages.
Tabulator is loaded from a CDN for data-grid rendering. The site theme is in tracked assets. API field changes can break JavaScript rendering even when server tests pass; inspect the page consumer.
World reset is a durable job with database/audit state and a planned versus executed result.
- validate configuration;
- resolve active world name/path;
- enumerate required datapacks;
- compute pregeneration chunks/segments;
- return a plan without service/filesystem mutation.
- require confirmation;
- validate native service control;
- persist requested/running state;
- stop service;
- back up active world;
- update server properties;
- install/verify required datapacks;
- start service and wait for RCON;
- apply safety gamerules;
- pregenerate using forceload segments;
- verify forceload cleanup;
- optionally delete backup;
- persist completed/failed result.
Failure handling persists a failed job and rethrows. Never simplify this to ad-hoc directory deletion.
| Boundary | Primary controls | Main risks |
|---|---|---|
| Internet → Caddy | TLS, local proxy target, body limit, cache/security headers | public exposure, stale/cache leakage, route misconfiguration |
| Caddy → Swift API | localhost binding and proxy rules | accidentally exposing local service or bypassing headers |
| API → DuckDB/files | validators, safe paths, payload limits, typed stores | injection/path traversal, corrupt operational state |
| Release source → public downloads | immutable layout, SHA256, validation, live-only aliases | malicious/corrupt client files, wrong live version |
| Client download → filesystem | manifest validation, hash/size, temp + atomic replace | arbitrary file write, partial/corrupt install |
| DMG → executable app | hash, mount/bundle/signature/helper/native validation | executable replacement compromise |
| systemd root → Minecraft/RCON/firewall | hardening, local RCON firewall, explicit env config | privilege misuse, service outage, secret leakage |
| Operator → world reset/release/DB | dry-run, explicit confirmation, immutable releases, migrations | irreversible data loss or live outage |
See Security for the detailed checklist.
Current route code leaves control-event creation, polling, and acknowledgement outside the bearer authorization guard. Client registration and report endpoints do call requireAuthorized, and the client only attempts reports when a token is available. The client identity contract still describes authenticated control traffic, so the control channel remains inconsistent with the intended trust model.
A future fix must explicitly decide:
- which endpoints are public, operator-only, or client-authenticated;
- whether client ID alone has any trust meaning;
- token enrollment/rotation/revocation model;
- whether Caddy contributes access control;
- migration/compatibility behavior for existing clients;
- updated status mode semantics and tests/docs.
The repo defines desired service/configuration and retains backup artifacts, but it does not prove:
- deployed unit/config versions;
- current certificates/DNS/firewall;
- live DuckDB schema/data consistency;
- exact current mod/provider responses;
- available disk space and runtime artifacts;
- account state for live soak.
Treat these as operator-observed facts, not repository facts.
Server App/MCPummelchenModServer/Sources/MCPummelchenModServer/main.swiftServer App/MCPummelchenModServer/Sources/MCPummelchenModServerCore/MCPummelchenModServerCore.swiftServer App/MCPummelchenModServer/Sources/MCPummelchenModServerCore/ControlEventStore.swiftServer App/MCPummelchenModServer/Sources/MCPummelchenModServerCore/ModAddPipeline.swiftServer App/MCPummelchenModServer/Sources/MCPummelchenModServerCore/ModUpdateScanner.swiftServer App/MCPummelchenModServer/Sources/MCPummelchenModServerCore/ModUpdateApplyPipeline.swiftServer App/MCPummelchenModServer/Sources/MCPummelchenModServerCore/ServerVersionBootstrapPipeline.swiftServer App/MCPummelchenModServer/Sources/MCPummelchenModServerCore/SwiftReleasePipeline.swiftServer App/MCPummelchenModServer/Sources/MCPummelchenModServerCore/ClientDMGBuilder.swiftServer App/MCPummelchenModServer/Sources/MCPummelchenModServerCore/SwiftWorldResetPipeline.swiftServer App/MCPummelchenModServer/Sources/MCPummelchenModServerCore/MinecraftLiveServerSupervisor.swiftClient App/MCPummelchenModClient/Sources/MCPummelchenModClientCore/ClientSyncEngine.swiftClient App/MCPummelchenModClient/Sources/MCPummelchenModClientCore/ClientControlWatcher.swiftClient App/MCPummelchenModClient/Sources/MCPummelchenModClientCore/JavaRuntimeManager.swiftClient App/MCPummelchenModClient/Sources/MCPummelchenModClientCore/NeoForgeClientInstaller.swiftServer App/MCPummelchenModShared/Sources/MCPummelchenModShared/CurrentRelease.swiftServer App/MCPummelchenModShared/Sources/MCPummelchenModShared/ClientSyncManifest.swiftServer App/MCPummelchenModShared/Sources/MCPummelchenModShared/APIModels.swiftServer App/Database/duckdb/README.mdServer App/Docs/contracts/PRODUCTION_CONTRACTS.mdServer App/caddy/CaddyfileServer App/systemd/MCPummelchenModServer_26.1.2.serviceServer App/systemd/MCPummelchenModServer_26.2.serviceServer App/systemd/MCPummelchenModServer_26.3.serviceServer App/systemd/MCPummelchenModUpdateScan.service
Design stage — not implemented
Design
Validation
Trust
Interfaces
Operations
Project
Reference