Skip to content

[Audit][Round 2][Umbrella] A++ Architecture & Maintainability Roadmap #839

Description

@MichaelFisher1997

Goal

Drive ZigCraft from current B+/A− across SOLID & maintainability to A++ across the board. This is the Round 2 umbrella — successor to #776 (Round 1, M1–M21 + m1–m6, all closed) and parallel to #834 (production-readiness / CI / tooling, still open).

Round 1 closed the worst seams (split lod_mesh.zig, killed src/engine/ dead tree, extracted LightingEngine/LpvGridBuilder, dispatcher at RenderSystem.init, comptime generator registry, role interfaces, etc.). Round 2 picks up the debt that either survived Round 1 or was introduced/exposed by it.

The audit re-ran 5 parallel deep-dives (RHI abstraction, world-lod God-objects, dependency graph, error handling/tests, readability) against current dev. Every finding below cites a file:line verified at HEAD.

Round 2 scorecard (current state)

Principle Round 1 close Round 2 finding Worst area
SRP Weak → Adequate Adequate lod_manager.zig (2,715 LOC, ~10 concerns) — new God object exposed by Round 1's lod_mesh.zig split
OCP Weak → Strong Strong Residual: adding a new RHI interface still touches rhi.zig in 5 places
LSP Adequate Weak lpv_backend.zig:13 still downcasts rhi.ptr*VulkanContext; ComputePipeline/ComputeBuffer still raw u64
ISP Adequate → Strong Strong 19 segregated I*Context vtables; RenderContext re-bundles 7 of them (35 pub fn)
DIP Weak → Adequate Adequate One minor leak: world-runtime/world.zig:42,54 imports 2 POD structs from engine-ui
Test coverage n/a Bimodal engine-rhi 0 tests / 263 pub fn · game-ui 0 tests / 108 pub fn · world-runtime ratio 0.08
Readability n/a B+ 0 std.log leaks · 4 TODOs total · build.zig:build 668 LOC · pub-fn docs at 14.6%

Scope & method


P1 — Architectural (highest leverage)

Goal: kill the remaining God-object and close the LSP/DIP gap that prevents a hypothetical second GPU backend.

P2 — Contracts & error discipline

Goal: remove shotgun-surgery signatures and silent failures that mask real bugs.

P3 — Test coverage (the bimodal problem)

Goal: lift D/F-grade modules to A/B. Half the codebase is exemplary (math 4.00, world-core 2.33, meshing 2.09); the other half is dangerously thin.

P4 — Hygiene & docs

Goal: alignment between AGENTS.md and the code; doc coverage target ≥ 40%.


Suggested wave order

Wave Items Why first
1 #841, #840 LODManager is the only file that is genuinely hard to reason about today; #841 unblocks safe extraction in #840
2 #844, #842 RHI contract hardening; #844 (tests) should land before #842 (refactor) so the seam is guarded
3 #846, #848, #850, #843 Independent, low-risk, parallelizable
4 #845, #847 Test coverage; benefits from #840/#841 landing first (smaller units are easier to test)
5 #849, #851, #852 Hygiene; can land anytime but best after structural churn settles

Strengths to preserve (do not regress)

Round 1 left these in excellent shape — Round 2 must not break them:

  • Composition root (src/game/app.zig) — textbook manual constructor injection with errdefer
  • Worker-thread RHI isolation — zero RHI/Vulkan calls on workers; chunk pin()/unpin() discipline
  • No dependency cycles — clean 10-layer acyclic DAG (one trivial leak addressed in [R2-7][P2] Fix world-runtime → engine-ui DIP leak (move 2 POD structs to world-core) #850)
  • engine-rhi imports no Vulkan headers — true abstract layer for the dominant resource/render surface
  • RenderGraph.addPass() OCP — purely additive pass extension, execute() is 14 lines
  • Logging facade — 0 std.log leaks across 93K LOC
  • TODO hygiene — 4 markers total, zero FIXME/HACK/XXX
  • Leaf modules (lod_geometry, lod_ingest, lod_scheduler, meshing *_mesher) — pure, lock-free, single-shape

Constraints

  • Use existing architecture (RHI vtables, job tokens, LODGPUBridge, role interfaces) — no parallel systems.
  • Small reviewable PRs targeting dev; conventional commits (refactor:, feat:, test:, docs:); never push to dev directly.
  • Preserve current gameplay/rendering behavior except where a sub-issue explicitly changes it.
  • All build/test commands wrapped in nix develop --command.
  • Verification baseline for every PR: nix develop --command zig build test (includes shader validation); rendering-touching PRs also run headless crash/screenshot/benchmark skill checks with -Dskip-present.
  • P1 RHI work must keep the existing Vulkan path green end-to-end.

Key risks

Out of scope (covered elsewhere)

Subissue index

# Title Phase Risk
#840 Decompose LODManager God-object P1 HIGH
#841 Encapsulate LODMesh/LODChunk P1 MEDIUM
#842 Resolve residual RHI native-handle leak P1 HIGH
#844 Add engine-rhi unit-test contract suite P1 LOW
#846 Bundle updateGlobalUniforms into struct P2 LOW
#848 Replace worldgen catch unreachable P2 MEDIUM
#850 Fix world-runtime → engine-ui DIP leak P2 TRIVIAL
#843 Surface silent save/mutation errors P2 MEDIUM
#845 Add game-ui test coverage P3 LOW
#847 Add world-runtime test coverage P3 LOW
#849 Fix AGENTS.md function-casing rule P4 TRIVIAL
#851 Decompose build.zig:build P4 LOW
#852 Raise pub-API /// doc coverage P4 LOW

Metadata

Metadata

Assignees

No one assigned

    Labels

    automated-auditIssues found by automated opencode audit scansbugSomething isn't workingdocumentationImprovements or additions to documentationengineenhancementNew feature or requestgamehotfixworld

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions