From a3fba634dadd7cded306183da3afd173c92a29f1 Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Tue, 29 Sep 2026 12:40:00 -0500 Subject: [PATCH] discussion(homelab): deepen v3 to v4 architecture migration narrative Expand historical context, operational friction analysis, and evolutionary reasoning from v1 to v4. Eliminate decision voice and align on 3-tier architecture with state root. --- .../architecture-migration-v3-to-v4.md | 117 +++++++++++------- 1 file changed, 74 insertions(+), 43 deletions(-) diff --git a/02-discussions/homelab/architecture-migration-v3-to-v4.md b/02-discussions/homelab/architecture-migration-v3-to-v4.md index 5f5cdf6..3f31b28 100644 --- a/02-discussions/homelab/architecture-migration-v3-to-v4.md +++ b/02-discussions/homelab/architecture-migration-v3-to-v4.md @@ -13,38 +13,61 @@ tags: # Architectural Discussion: Migrating from Legacy Multirepo (v3) to 3-Tier Provenance Architecture (v4) -## 1. Problem Statement +## 1. Problem Statement & Historical Context The initial architecture of the `roadtotech.me` homelab followed an intuitive multirepo pattern: - The platform host was organized under `/home/kiskaadee/Homelab`. - Core platform capabilities (NixOS, Traefik, Authelia, LLDAP) lived in `Core/`. - Every application workload lived in its own folder under `Sites//`, where each folder was an independent Git repository cloned from Gitea. -- The `appctl` CLI and the `homelab-gitops` dispatcher interacted directly with these local Git repositories: `appctl` checked Git ahead/behind counts via `git rev-list HEAD...@{u}`, and GitOps deployed changes via `git pull origin main`. +- Operational tooling (`appctl`, `homelab-gitops`) interacted directly with these local Git repositories: `appctl` checked Git ahead/behind counts via `git rev-list HEAD...@{u}`, and GitOps deployed changes via `git pull origin main`. -While minimal on paper, scaling this setup to in-house projects (`doc2site`, `bitetrack`), automated container CI (`act_runner`), and invariant testing exposed severe architectural friction across five key areas: +### Why the Original Model Looked Attractive +In the early days of the homelab, the multirepo pattern appeared minimal and elegant: +- **One Folder = One Repo**: Developers could `cd ~/Sites/my-app`, edit files, run `git commit`, and push. +- **Uniformity**: Every service looked identical to operational tools—they were all Git checkouts containing a `docker-compose.yml` and an `app.yaml`. +- **Zero Central Coordination**: Deploying a new service simply meant cloning a new Git repository into `Sites/`. -| Friction Area | Legacy / v3 Multirepo Assumption | Concrete Operational Failure | -| :--- | :--- | :--- | -| **Source Pollution** | The application repository *is* the deployment repository. | In-house software projects (`doc2site`, `bitetrack`) had to commit Homelab-specific Traefik labels, Docker bridge networks (`proxy-net`), and host path mounts directly into their source trees. The software could not be open-sourced or run elsewhere without Homelab artifacts. | -| **Repository Inflation** | Every workload requires its own dedicated Git repository. | Off-the-shelf applications (`jellyfin`, `stirling`, `snappymail`) required entire standalone Git repositories simply to store a 20-line `docker-compose.yml` and a small `app.yaml`. | -| **Semantic Ambiguity in `appctl`** | Freshness = `git rev-list HEAD...@{u}` in `Sites//.git`. | `appctl` could only answer: *"Has this deployment directory changed relative to Git?"* It could never answer whether the running container was running the latest application code, whether a Traefik label changed, or whether an upstream release was available. | -| **Git / State Conflation** | Workload mutable state lived inside `Sites//data/`. | Mutable runtime data (SQLite databases, session caches) lived directly inside the version-controlled directory tree, creating dirty Git working trees and risking accidental commits of persistent data. | -| **Coupled Build Execution** | GitOps ran `compose_build` on the deployment host. | The deployment host was responsible for pulling source and compiling software, violating least-privilege host principles and creating ambient dependency requirements on the host. | +### The Concrete Operational Failures +As the homelab matured from simple containers to in-house software development, automated CI (`act_runner`), and invariant testing, this coupled model began to break down across five critical areas: + +1. **Source Repository Pollution (`doc2site`, `bitetrack`)**: + When developing custom software like `doc2site` (a documentation generator) or `bitetrack` (a nutrition tracking API), the application source code had to live directly inside the deployment repository. This forced private Homelab-specific Traefik labels, Docker bridge network names (`proxy-net`), host bind-mount paths, and environment secrets into the application's source tree. + *The Friction*: Hosting infrastructure co-located with code made clean open-sourcing, code sharing, or isolated testing difficult without stripping Homelab configuration. + +2. **Repository Inflation (Off-the-Shelf Applications)**: + Standard third-party services like `jellyfin`, `stirling-pdf`, and `snappymail` are distributed as pre-built container images. Yet, under the multirepo model, each required a full standalone Git repository on Gitea simply to track a 20-line `docker-compose.yml` and a small `app.yaml`. Gitea became cluttered with dozens of near-empty repositories whose sole purpose was satisfying the convention that every workload directory had to be an independent Git clone. + +3. **Semantic Ambiguity in `appctl`**: + `appctl` determined whether an application was "up to date" by running `git rev-list HEAD...@{u}` inside `Sites//.git`. + *The Blind Spot*: This check could only answer: *"Has someone pushed a change to the deployment configuration files in Git?"* It could never answer: + - Is the running container executing the latest release of the application code? + - Was the container built from a commit with critical bug fixes? + - Has a new upstream image tag been published? + Operators were left with a false sense of confidence: `appctl list` would report a green "✓ Up to date" badge even when the running container was running months-old, stale code. + +4. **Conflation of Versioned Descriptors and Mutable State**: + Because `Sites/` was a Git checkout, workloads frequently stored runtime state inside `Sites//data/`. Mutable SQLite databases, session tokens, and dynamic uploads sat right inside the working tree. This dirtied the Git working tree, caused merge conflicts during automated deployments, and increased the risk of accidentally committing sensitive or volatile state to the forge. + +5. **Host-Bound Build Execution**: + Because the application repository was cloned directly onto the deployment host, the GitOps dispatcher often triggered `docker compose build` on the server itself. This required installing build tools and runtime compilers on the appliance host, consuming substantial CPU/RAM during builds and violating the principle of a hardened, minimal host appliance. --- ## 2. Context & Analysis: The KISS Principle in Systems Design -A central dilemma was evaluated: **Does migrating to v4 introduce unnecessary complexity, or does it represent true systems simplification?** +A central architectural debate emerged: **Does moving away from the single-repo pattern introduce unwarranted complexity, or does it represent true systems simplification?** -In systems engineering, KISS is not measured merely by the count of files or commands; it is measured by **minimizing uncoordinated coupling and ambiguous control loops**. +In systems engineering, KISS ("Keep It Simple, Stupid") is often misunderstood as "the fewest files" or "the fewest directories." However, shoving fundamentally different concerns into a single directory is not simplicity—it is uncoordinated coupling. -- **The Old Model was "Simple on Paper, Coupled in Practice"**: Pushing source code, deployment declarations, and runtime state into one folder looked simple, but it forced one Git commit SHA to represent three completely independent concepts. -- **The v4 Model is "Strictly Decoupled with Few Primitives"**: It establishes a clean **3-Tier Architecture** where each component has exactly one owner: - - **Software Layer**: Owns code, Dockerfiles, and tests (agnostic of Homelab). - - **Deployment Layer**: Owns environment-specific compose stacks and ingress rules (`~/Sites/*`). - - **Platform Layer**: Owns host lifecycle, edge routing, and deployment controllers (`~/Core`). - - **State Root**: Owns mutable data, isolated outside Git trees (`~/var/lib/homelab//`). +* **Legacy Multirepo: Simple on Paper, Coupled in Practice**: + Treating `Sites/` as both the software repository and the deployment declaration looked simple, but it forced a single Git commit SHA to represent three orthogonal concepts simultaneously: the software source code, the deployment environment configuration, and the runtime state. +* **3-Tier Decoupling: Modular Simplicity with Few Primitives**: + True systems simplicity is achieved by decoupling into three core tiers connected by intermediate artifacts and an isolated state boundary, where each component has exactly one clear responsibility: + - **Software Layer (Tier 1)**: Owns application code, unit tests, and Dockerfiles. Agnostic of Homelab. + - **Intermediate Artifacts**: Immutable OCI container images produced by CI, carrying cryptographic provenance (`org.opencontainers.image.revision`). + - **Deployment Layer (Tier 2)**: Owns environment manifests and Compose definitions (`~/Sites/*`). + - **Platform Layer (Tier 3)**: Owns host lifecycle, edge routing, and operational controllers (`~/Core`). + - **Persistent State Root (Filesystem Boundary)**: Owns mutable databases and caches isolated outside Git trees (`~/var/lib/homelab//`). ```mermaid flowchart TD @@ -73,36 +96,44 @@ flowchart TD --- -## 3. Options Evaluation +## 3. Evaluated Dilemmas & Rejected Alternatives -| Dimension | Option A: Retain & Patch v3 | Option B: Migrate to 3-Tier v4 (Adopted) | Analysis & Rationale | -| :--- | :--- | :--- | :--- | -| **Separation of Concerns** | Low. Software and environment configuration remain coupled. | High. Software, deployment, and platform remain completely independent. | v4 allows in-house software to be reused or published publicly without refactoring. | -| **Workload Taxonomy** | Homogeneous. Treats all apps as identical Git repositories. | Explicit. Distinguishes *Source-Backed* (custom code) from *Image-Only* (off-the-shelf). | Off-the-shelf apps (Jellyfin, Stalwart) do not need fake source repositories. | -| **Inspection Meaning** | Fragile. A "behind" Git badge could mean a doc change or a bugfix. | Accurate. Two operational inspection axes resolve deployment state vs. software provenance. | `appctl` inspects real runtime facts (`org.opencontainers.image.revision`). | -| **Control Path Complexity** | Uncontrolled. Host builds images on demand over SSH or webhook. | Bounded. Source pushes trigger CI; CI publishes image; `appctl update` reconciles deployment. | Host appliance never clones source or compiles software. | -| **State Hygiene** | Poor. Mutable data co-located with versioned files in `Sites//data`. | Clean. Runtime state provisioned strictly under `~/var/lib/homelab//`. | Prevents unversioned databases from dirtying Git trees. | +### A. The Upstream Cloning Dilemma: Ahead/Behind Counts vs. `git ls-remote` +An initial proposal explored calculating exact commit distance (e.g. `"3 commits behind upstream"`) for source-backed applications. + +* **The Problem**: Git cannot calculate commit distance or ancestry without access to the commit graph. This would require the deployment host to clone or fetch full Git histories for every in-house application. +* **Resulting Direction**: The exploration ultimately converged on rejecting local cloning on the appliance host in favor of **commit equality verification via `git ls-remote`**. + By querying `git ls-remote refs/heads/`, the host asks one crisp question: *Does the remote ref match the commit SHA stamped into the container's OCI label?* +* **The Trade-Off Rationale**: Foregoing commit distance counts eliminates repository bloat, disk overhead, and credential propagation on the deployment host, providing instant staleness detection with zero on-host git state. + +### B. The Orchestrator Sprawl Dilemma: Miniature Kubernetes vs. Linear Reconciliation +Another alternative considered was adopting a dynamic container management architecture modeled after enterprise systems (e.g. RabbitMQ/Redis event queues, a PostgreSQL deployment state store, and background rollback daemons). + +* **The Problem**: A single 24/7 home server cannot justify running complex distributed brokers just to start and stop containers. It increases memory pressure, introduces distributed state split-brain scenarios, and makes disaster recovery painful. +* **Resulting Direction**: The exploration ultimately converged on strictly bounding the control path to a **linear, deterministic chain**: + $$\text{Source Push} \longrightarrow \text{CI Build} \longrightarrow \text{GitOps Ingress} \longrightarrow \text{appctl update} \longrightarrow \text{Compose Up}$$ +* **The Trade-Off Rationale**: `appctl update` operates purely as a local reconciliation primitive. Simplicity is preserved by having zero background daemons managing deployment state. --- -## 4. Consensus & Resolutions Incorporated into v4 +## 4. What Became Possible After the Architectural Separation -The architectural migration from v3 to v4 was approved and frozen with four specific design guardrails: +| Dimension | Legacy Coupled Model (Historical Constraint) | 3-Tier Provenance Model (Engineering Motivation) | +| :--- | :--- | :--- | +| **Open Source & Code Sharing** | Hosting infrastructure co-located with code made clean open-sourcing or external sharing cumbersome. | Allows the software repository to remain free of Homelab-specific infrastructure and be tested or open-sourced independently. | +| **Off-the-Shelf Workloads** | Deploying third-party apps required creating dummy Git repositories on Gitea to satisfy the workload structure. | Workloads without custom source declare an Image-Only manifest directly in `Sites/` with zero repository overhead. | +| **Deployment Truth & Visibility** | Inspection in `appctl` was limited to local working tree status, leaving operators unaware of running container staleness relative to source. | Two operational inspection axes independently report local deployment configuration status and container code provenance. | +| **Host Appliance Hygiene** | On-host image compilation consumed appliance resources and mutable runtime data risked dirtying version-controlled directories. | Appliance runtime relies on pre-built container artifacts, with mutable state provisioned strictly under `~/var/lib/homelab//`. | -1. **Artifact as Provenance Object, Not a 4th Architectural Tier**: - The container image is treated as an intermediate build product connecting the Software Layer to the Platform Runtime, keeping the architecture strictly 3-tiered. -2. **`appctl update` Defined as Deployment Reconciliation**: - `appctl update` was explicitly protected from becoming an on-host source compiler. Its sole responsibility is: pull deployment descriptors, pull published image, recreate containers (`docker compose up -d`), verify readiness, and record the truth ledger. -3. **Downgrading `git ls-remote` to a Remote Revision Resolver**: - Rather than building a complex commit-distance/ancestry engine, `git ls-remote` simply answers: *Does the remote ref match the deployed container's SHA?* (`exact match` vs. `different revision`), strictly gated behind `--fetch`. -4. **Two Operational Axes with Three Independent Revision Identities**: - - *Operational Inspection Axes*: Deployment Configuration Status & Software Provenance Status. - - *Cryptographic Identities Recorded*: - 1. `deployment_config_revision` (Sites Git commit) - 2. `source_revision` (Upstream Git commit from OCI label) - 3. `artifact_digest` (Immutable OCI `RepoDigests` SHA256) +--- -### Successor Plans & Decisions -* **Unified Blueprint**: [`01-plans/homelab/architecture-consolidation-roadmap-v4.md`](../../01-plans/homelab/architecture-consolidation-roadmap-v4.md) +## 5. Convergence & Successors + +This exploratory inquiry resolved the tension between structural simplicity and architectural coupling: true simplicity lies in clear boundaries and minimal control paths, not monolithic folder cramming. + +The exploration converged on the three-tier provenance architecture formalized in the ADR: * **Architectural Decision Record**: [`03-records/decisions/homelab-3tier-architecture-and-provenance.md`](../../03-records/decisions/homelab-3tier-architecture-and-provenance.md) -* **Active Refactoring**: [`01-plans/homelab/appctl/appctl-engine-v2-refactoring.md`](../../01-plans/homelab/appctl/appctl-engine-v2-refactoring.md) + +The concrete technical specifications, contracts, and phased execution roadmaps (P0 through P5) are specified in the companion plan: +* **Authoritative Implementation Plan**: [`01-plans/homelab/consolidation/architecture-consolidation-roadmap-v4.md`](../../01-plans/homelab/consolidation/architecture-consolidation-roadmap-v4.md) +* **Homelab Project Hub**: [`06-projects/homelab/README.md`](../../06-projects/homelab/README.md)