diff --git a/03-records/decisions/homelab-3tier-architecture-and-provenance.md b/03-records/decisions/homelab-3tier-architecture-and-provenance.md index 6b3b18c..40376ee 100644 --- a/03-records/decisions/homelab-3tier-architecture-and-provenance.md +++ b/03-records/decisions/homelab-3tier-architecture-and-provenance.md @@ -13,98 +13,99 @@ tags: - kiss --- -# Architectural Decision Record: Homelab 3-Tier Architecture & Deployment Provenance Model +# Homelab 3-Tier Architecture & Deployment Provenance Model -## 1. Context & Problem Statement +## Context and Problem Statement The `roadtotech.me` homelab operates as a dedicated NixOS appliance hosting self-hosted productivity services and personal backend engineering projects. In early iterations (v1 through v3): -1. **Application & Deployment Coupling**: In-house applications (e.g., `doc2site`, `bitetrack`) co-located application source trees, test suites, and Dockerfiles with host-specific Traefik routing labels, bridge network names, and host path mounts inside individual Git repositories in `~/Sites/`. -2. **Repository Inflation**: Off-the-shelf applications (e.g., `jellyfin`, `stirling`) required full standalone Git repositories merely to store a 20-line `docker-compose.yml` and an `app.yaml` manifest. -3. **Ambiguous Freshness**: Local Git status checks in `~/Sites/` could only report if deployment files had uncommitted local edits or diverged from their origin tracking branch; they could not determine whether running containers were built from the latest upstream application source code. -4. **Risk of Orchestrator Sprawl**: The growth of operational scripts (`appctl`, webhooks) risked adding secondary distributed systems (brokers, queues, databases) around basic container deployments. -A solid architectural boundary is required to decouple application development from deployment configuration, establish verifiable provenance, and strictly enforce the **KISS ("Keep It Simple, Stupid")** principle. +1. **Application & Deployment Coupling**: In-house applications (`doc2site`, `bitetrack`) co-located application source trees with host-specific Traefik labels, Docker bridge networks, and host path mounts inside individual Git repositories in `~/Sites/`. +2. **Repository Inflation**: Off-the-shelf applications (`jellyfin`, `stirling`) required entire standalone Git repositories simply to store a minimal Compose file and manifest. +3. **Ambiguous Freshness**: Local Git status checks in `~/Sites/` could only report if deployment descriptors had uncommitted edits, never whether running containers matched current upstream application source code. +4. **Orchestrator Sprawl Risk**: Scaling operational scripts threatened to introduce secondary distributed infrastructure (queues, databases, brokers) around basic container deployments. ---- +How should we structure application code, deployment configuration, and platform orchestration to maintain strict separation of concerns, verifiable provenance, and KISS operations? -## 2. Decision +## Decision Drivers -We formally adopt the **3-Tier Architecture, Two-Axis Provenance Model, and Linear Control Path** as the canonical architectural baseline for the homelab. +* **Clean Separation of Concerns**: In-house software projects must be developable, testable, and publishable independently of private Homelab infrastructure. +* **Workload Simplicity**: Off-the-shelf applications should not incur standalone repository overhead. +* **Verifiable Provenance**: Operators must be able to independently verify deployment configuration freshness versus upstream software code freshness. +* **KISS Primitives & Minimal Control Paths**: Operational reconciliation must remain bounded, deterministic, and linear without distributed brokers, queues, or deployment databases. +* **Filesystem State Hygiene**: Mutable runtime data must never reside inside version-controlled Git trees. -### A. Redefining KISS: Fewest Independent Concepts & Control Paths -In systems design, KISS does not mean the fewest files or single-repository shortcuts. The monolithic single-repo model pushed fundamentally orthogonal concerns together. +## Considered Options -True simplicity is achieved by defining a small, bounded set of **seven platform primitives** where each boundary has a single unambiguous owner: +* **Option 1: Monolithic / Single-Repo Deployment (Status Quo v1–v3)** — Co-locate application code, Dockerfiles, Compose files, and mutable runtime state inside a single Git repository per application. +* **Option 2: Miniature Cloud Platform** — Introduce message brokers (RabbitMQ/Redis), a Postgres deployment database, multi-environment controllers, and asynchronous rollback daemons. +* **Option 3: Bounded 3-Tier Platform with OCI Provenance Labels & Linear Control Path** — Decouple Software, Deployment, and Platform tiers; connect them via OCI image artifacts carrying source revision labels and content-addressed digests; enforce linear deployment reconciliation and isolated host state roots. -| Primitive | Epistemic Role | Operational Responsibility | -| :--- | :--- | :--- | -| **Software Repository** | Source | Application code, unit tests, `Dockerfile`, CI workflows. Zero Homelab coupling. | -| **CI Engine (Gitea Actions)** | Build | Compiles code, runs tests, injects `org.opencontainers.image.revision`, publishes OCI images. | -| **OCI Container Image** | Artifact | Immutable intermediate build product and provenance object linking commit SHA to image digest. | -| **Sites Catalog (`~/Sites`)** | Desired Deployment | Environment-specific manifests (`app.yaml`) and Compose definitions (`docker-compose.yml`). | -| **GitOps Dispatcher** | Ingress & Admission | HMAC webhook authentication, Core registry admission control, and deployment serialization. | -| **`appctl` Engine** | Inspection & Reconciliation | Manifest parsing, two-axis inspection, and declarative deployment reconciliation (`appctl update`). | -| **Core Appliance (`~/Core`)** | Platform & Runtime | Declarative NixOS host, edge ingress (Traefik), Docker API proxy, SSO (Authelia/LLDAP), and shared capabilities (Stalwart). | +## Decision Outcome -### B. 3-Tier Separation of Concerns -1. **Tier 1: Software Layer (Application Repositories)**: In-house software projects live in standalone Git repositories on Gitea/GitHub, completely decoupled from Homelab deployment configuration. -2. **Intermediate Artifacts**: The OCI container image is treated as an intermediate build product / provenance artifact carrying `org.opencontainers.image.revision`, linking source commit to container digest. -3. **Tier 2: Deployment Layer (Sites Workload Plane)**: `~/Sites/*` catalog owning environment-specific `app.yaml` manifests and `docker-compose.yml` stacks. -4. **Tier 3: Platform Layer (Homelab Core Appliance)**: NixOS host, edge primitives (Traefik, socket-proxy, Authelia, LLDAP), shared platform capabilities (Stalwart), and controllers (`appctl`, GitOps receiver). +Chosen option: **Option 3: Bounded 3-Tier Platform with OCI Provenance Labels & Linear Control Path**, because it addresses the identified coupling and provenance problems while retaining a bounded operational control path. -### C. Two Workload Deployment Classes -1. **Class A: Source-Backed Workloads**: Declare a `source:` block in `app.yaml` (`type: git`, canonical `url:`, and `ref:`). Freshness inspects upstream Git refs against container image revision labels. -2. **Class B: Image-Only Workloads**: Omit `source:` entirely. Deployment freshness relies solely on container registry image tags and digests. +### Summary of Architectural Commitments -### D. Two Operational Inspection Axes with Three Revision Identities -To eliminate ambiguity between operational checks and concrete ledger facts: -* **Two Operational Inspection Axes**: - 1. *Deployment Configuration Axis*: Local `~/Sites/` Git checkout status (`git status`, `git rev-list HEAD...@{u}`). - 2. *Software Provenance Axis*: Upstream source ref vs. deployed container image revision (`org.opencontainers.image.revision`). -* **Three Independent Revision Identities**: - 1. `deployment_config_revision`: Sites Git commit SHA. - 2. `source_revision`: Upstream application source Git commit SHA. - 3. `artifact_digest`: Immutable OCI registry SHA256 digest extracted from container `RepoDigests`. +1. **3-Tier Separation of Concerns**: + * **Software Layer (Application Repositories)**: Standalone Git repositories on Gitea/GitHub owning application code, tests, Dockerfiles, and CI workflows. Zero Homelab coupling. + * **Intermediate Artifacts**: OCI container images produced by CI act as provenance objects; the immutable identity of the deployed artifact is its OCI digest, with source commit provenance carried via the `org.opencontainers.image.revision` label. + * **Deployment Layer (Sites Workload Plane)**: Declarative catalog in `~/Sites/*` owning environment-specific `app.yaml` manifests and Compose definitions. + * **Platform Layer (Homelab Core Appliance)**: NixOS appliance (`~/Core`) owning edge routing, SSO, shared capabilities, and operational controllers (`appctl`, GitOps receiver). +2. **Two Workload Deployment Classes**: + * *Class A (Source-Backed)*: Declares explicit upstream `source:` pointer (canonical Git URL and ref); tracks upstream Git revisions against container image labels. + * *Class B (Image-Only)*: Omits `source:`; deployment freshness relies strictly on container registry image tags and digests. +3. **Decoupled Deployment Configuration & Software Provenance**: + * Distinguishes local deployment checkout state (`Sites/`) from upstream software provenance (`source.url` vs. deployed container). + * Mandates that deployment configuration, upstream source provenance, and container artifact identity must be independently observable (with exact schema fields defined in the implementation plan). +4. **Minimal Linear Reconciliation Path**: + * The deployment lifecycle remains strictly linear: + $$\text{Source Push} \longrightarrow \text{CI Build} \longrightarrow \text{GitOps Ingress} \longrightarrow \text{appctl update} \longrightarrow \text{Compose Up}$$ + * `appctl update` operates purely as a local, deterministic deployment reconciliation primitive. All secondary message queues, brokers, and deployment databases are strictly rejected. +5. **Isolated Host State Root**: + * Mutable application runtime state (databases, caches, uploads) is decoupled from version-controlled directories and provisioned under `~/var/lib/homelab//`. -### E. Minimal Linear Control Path (Anti-Sprawl Guardrail) -The deployment lifecycle is strictly linear: -$$\text{Source Push} \longrightarrow \text{CI Build} \longrightarrow \text{GitOps Ingress} \longrightarrow \text{appctl update} \longrightarrow \text{Compose Up}$$ +## Pros and Cons of the Options -The platform **strictly rejects** introducing secondary orchestration systems, message brokers (e.g. RabbitMQ/Redis), queues, deployment databases, or dynamic rollback daemons around `appctl`. `appctl update` operates purely as a local, deterministic deployment reconciliation primitive. +### Option 1: Monolithic / Single-Repo Deployment -### F. Persistent State Root Isolation -Mutable application state (databases, upload caches, runtime media) is strictly decoupled from version-controlled directories and provisioned under `~/var/lib/homelab//`. +* Good, because it is familiar and requires only one Git repository per custom app. +* Bad, because host-specific configuration leaks into application source code, preventing reuse or open-sourcing. +* Bad, because off-the-shelf tools require empty "wrapper" repositories. +* Bad, because a single commit SHA conflates software revisions with deployment descriptor edits. +* Bad, because mutable state co-located in `Sites//data` risks accidental commits and creates dirty Git trees. -### G. Degraded Remote Revision Inspection -Ancestry analysis across remote repositories without local clones is explicitly downgraded to commit equality checks via `git ls-remote` (bounded by a 10-second timeout, gated behind `appctl list --fetch` or `appctl info`). +### Option 2: Miniature Cloud Platform ---- +* Good, because it mirrors enterprise Kubernetes / ArgoCD continuous deployment capabilities. +* Bad, because running distributed brokers, queues, and databases on a single home appliance creates massive operational overhead and resource footprint. +* Bad, because it introduces complex failure modes and violates the KISS principle. -## 3. Options Considered & Trade-Offs +### Option 3: Bounded 3-Tier Platform with OCI Provenance Labels -| Option | Architecture Model | Pros | Cons | Verdict | -| :--- | :--- | :--- | :--- | :--- | -| **Model A: Monolithic Deployment Repos (v1–v3)** | Keep Compose and deployment config co-located in application Git repos. Single Git SHA. | Single repo per custom app. Familiar workflow. | Host config leaks into app code; cannot support off-the-shelf apps cleanly; ambiguous revision truth. | **Rejected** | -| **Model B: Miniature Cloud Platform** | Introduce message queues (RabbitMQ/Redis), Postgres deployment database, multi-environment controllers, rollback workers. | Replicates enterprise Kubernetes/ArgoCD workflows. | Extreme accidental complexity; excessive RAM/CPU footprint on single appliance; high operational maintenance. Violates KISS. | **Rejected** | -| **Model C: Bounded 3-Tier Platform (v4)** | Decoupled tiers, OCI provenance metadata, linear control path, filesystem state root, single manifest parser, two inspection axes. | Clean separation; testable domain models; clear ownership; minimal control paths; zero VPS costs; demonstrates systems design thinking. | Requires two Git repositories for custom apps (source repository + Sites catalog entry). | **Accepted** | +* Good, because in-house software is completely decoupled from homelab infrastructure and can be open-sourced cleanly. +* Good, because off-the-shelf software incurs zero repository overhead. +* Good, because deployment inspection resolves both configuration status and code provenance unambiguously. +* Good, because runtime state is cleanly separated into `~/var/lib/homelab//`. +* Good, because it maintains the fewest independent concepts and control paths (KISS). +* Bad, because custom in-house applications require managing two Git repositories (source repository and Sites catalog entry). +* Bad, because verifying remote revisions without local clones is restricted to commit equality (`git ls-remote`), foregoing ahead/behind commit distance counts. ---- +## Consequences -## 4. Consequences +### Positive Consequences -### Positive -* **Decoupled Application Lifecycle**: Custom backend projects can be developed, tested, and shared independently of the private homelab infrastructure. -* **Precise Deployment Truth**: Operators and automation tools can independently verify whether deployment configuration, upstream source code, or container images are out of date. -* **Clean Filesystem Contracts**: Desired configuration in `~/Sites` remains purely declarative; runtime state lives exclusively under `~/var/lib/homelab/`. -* **Bounded Operational Surface**: Eliminates orchestrator sprawl by restricting reconciliation to a single deterministic primitive (`appctl update`). +* **Independent Software Lifecycle**: In-house applications (`bitetrack`, `doc2site`) can be shared, tested, or migrated without exposing homelab secrets, domain routing, or bridge networks. +* **Precise Diagnostic Truth**: Operators and automation tools can independently determine whether a deployment configuration changed, a new image was published, or upstream source code was updated. +* **Clean State Boundaries**: Git repositories in `~/Sites` contain only declarative manifests and compose files; databases and runtime media live exclusively in dedicated host state roots. +* **Operational Restraint**: Eliminates orchestrator sprawl by keeping reconciliation linear, synchronous, and local. -### Negative / Trade-offs -* **Dual Repositories for In-House Workloads**: Updating in-house applications requires pushing to the source repository to build an artifact, followed by updating the Sites catalog when pinning explicit tags or SHAs. -* **No Ahead/Behind Counts for Remote Sources**: `git ls-remote` determines commit equality but cannot calculate commit distance without cloning the repository graph. +### Negative Consequences & Accepted Trade-offs ---- +* **Dual Repositories for In-House Applications**: Deploying a change to an in-house app requires pushing code to CI, followed by updating or pinning the Sites catalog when tag/SHA pinning is desired. +* **Commit Equality Without Ancestry Graph**: Remote Git inspection confirms whether the running container matches the upstream ref HEAD, but cannot report commit distance without performing a full source clone. -## 5. References & Successors -* **Authoritative Roadmap & Execution Plan**: [`01-plans/homelab/architecture-consolidation-roadmap-v4.md`](../../01-plans/homelab/architecture-consolidation-roadmap-v4.md) -* **Engine Modernization Plan**: [`01-plans/homelab/appctl/appctl-engine-v2-refactoring.md`](../../01-plans/homelab/appctl/appctl-engine-v2-refactoring.md) -* **Homelab Core Project Hub**: [`06-projects/homelab/README.md`](../../06-projects/homelab/README.md) +## More Information + +* **Informing Discussion & Rationale**: [`02-discussions/homelab/architecture-migration-v3-to-v4.md`](../../02-discussions/homelab/architecture-migration-v3-to-v4.md) +* **Governed Implementation Roadmap**: [`01-plans/homelab/consolidation/architecture-consolidation-roadmap-v4.md`](../../01-plans/homelab/consolidation/architecture-consolidation-roadmap-v4.md) +* **Project Hub**: [`06-projects/homelab/README.md`](../../06-projects/homelab/README.md)