Skip to content

FLT-379 first slice: plan v2 (Clahadore, WT-8b9a, 2026-11-04)

Supersedes v1 in the same folder. v1 was attacked by CedricFocus (REJECT), Jenny, SusieFranny, Gronktayvius General, Gronktayvius Red Team (each APPROVE WITH CONDITIONS). All five pick model option B and new private repo andrewjonesdev-tools/forge-architecture. Those are settled.

Goal

Diagrams generated from code, kept in git, gate fails when stale. Done when adding a service makes it appear with no hand edit (screenshot receipt) on a real repo, and the gate is shown failing on a stale diagram. Out of scope: LikeC4, Rete.js, two-way editing, Theia, GrapesJS, Puck, UI and MCP surfaces (named follow-ups).

What a green gate means (stated in the docs and stamped on each diagram)

Green = committed artifacts equal this generator's output for the declared sources, and the semantics below are tested against expected models authored from the real sources by a different model family than the implementer (no human has checked them). It does NOT mean the picture is the whole system, a runtime call graph, or an exposure map. Each diagram carries a fixed stamp: sources that ran, relationship kinds shown, "derived subset, not a runtime or security map".

Model (immutable records, C#, no external model library)

ArchitectureModel { SchemaVersion, SystemName, Elements[], Relationships[] }. Committed JSON Schema for version 1. Unknown or newer SchemaVersion = exit 2. Older committed version = exit 1, regenerate. Element { Id, Kind, Name, Technology?, ParentId?, Origin }. Kinds: Person, ExternalSystem, SoftwareSystem, Boundary, Container, DataStore, Library, DeploymentNode. Library replaces C4 Component deliberately: a .NET library is a build unit that can be shared by several executables, not a runtime component owned by one container. ParentId = logical containment only. Legal parents: Boundary or Container or DataStore -> SoftwareSystem or Boundary; DeploymentNode -> Boundary. Library has none. Missing parent, illegal parent kind, containment cycle, duplicate ID, dangling relationship = exit 2. Relationship { FromId, ToId, Kind, Label?, Origin }, key (FromId, ToId, Kind, Label, Origin), duplicate key = exit 2. Kinds, never merged: BuildDependency (ProjectReference), StartupDependency (Compose depends_on), InfrastructureReference (Terraform reference or depends_on), Declared (overlay; drawn dashed). Deployment placement is not modeled in this slice (cross-source link, follow-up). SystemName comes from required config, never folder name. ID preimage: length-prefixed sourceKind, canonical path, logical name. Canonical path: repo-relative, / separators, NFC, resolved to exact on-disk casing, no . or ... SHA-256 only, never GetHashCode. A rename is delete plus add, and exit 1 output says so. Serialization: System.Text.Json with fixed property order, nulls omitted, UTF-8 no BOM, LF, trailing newline, StringComparer.Ordinal total order on Id and on the relationship key.

Views (projection rules in Core, each tested)

  • C1 c1-context: SoftwareSystem plus declared Person and ExternalSystem, Declared relationships only. Only hand-declared parts; says so in stamp.
  • C2 c2-containers: Boundary, Container, DataStore. StartupDependency edges as is. Container-to-Container build edges lifted through Library chains, labelled "build dependency (via N libraries)".
  • c3-<slug> per Container with at least one Library: the Container plus transitive closure of Library via BuildDependency. Same Library may appear in several. Title says "build dependencies", not "components", because that is what the source proves.
  • deployment: DeploymentNode and DataStore from Terraform source, InfrastructureReference edges. Only if the source is configured.

Mapping table

| Source fact | Model | | Exe (OutputType Exe/WinExe), or SDK Microsoft.NET.Sdk.Web/Worker | Container | | Otherwise, OutputType Library or SDK default | Library | | IsTestProject=true or direct PackageReference to Microsoft.NET.Test.Sdk, xunit, xunit.v3, NUnit, MSTest, TUnit | excluded. xunit.v3 tests are Exe, so Exe plus test signal = test. Web or Worker SDK plus test signal = exit 2. Name alone never excludes: a *.Tests project with no signal is drawn | | ProjectReference | BuildDependency | | Compose file | Boundary (stack name from config) | | Service | DataStore if image matches table, else Container. Technology = image repository | | Compose depends_on list or mapping form | StartupDependency | | cdk.tf.json resource.<type>.<name> | closed table: DeploymentNode, DataStore, Ignored. Unknown type = exit 2 naming the type; config resourceTypes may classify it | | Terraform ${type.name...} or depends_on resolving to a known resource | InfrastructureReference | | config declared | Person, ExternalSystem, Declared relationships. Origin=declared. Same label rules | | config projectOverrides by path | complete replacement of what XML cannot decide: kind plus full references, or excluded. Origin marks it declared |

Data-store image table: exact match on repository last segment, or full name for multi-segment products. postgres, postgresql, postgis, pgvector, mysql, mariadb, mssql/server, redis, valkey, mongo, mongodb, elasticsearch, opensearch, clickhouse, cassandra, couchdb, neo4j, qdrant, minio, kafka, rabbitmq, nats. No suffix or substring match. Unknown stays Container with repository visible.

Solution source: restricted XML subset, no MSBuild evaluation

Evaluating untrusted csproj runs Exec and UsingTask, and makes Kind depend on the machine's SDK. So: the contract is the unconditional, declared topology. Handles <Project Sdk=...> and <Sdk Name=...>; .slnx and .sln; nearest Directory.Build.props only, parents only if explicitly imported in that file via the standard GetPathOfFileAbove form, otherwise exit 2. Topology-bearing facts are exactly: Sdk, OutputType, IsTestProject, ProjectReference, and PackageReference to a test-signal package. They are read from the csproj and from the nearest props, including items, since props can add any of them. Exit 2 (path and line, never line text) when any topology-bearing fact is outside the subset: Condition on it or on its parent group; $(...) in its value; any PackageReference whose identity is computed or conditional, whatever the package, because it cannot be ruled out as a test signal; or any non-SDK <Import> in a csproj or in the props, because the imported file could supply any of them. The only escape is a complete override: projectOverrides by path must state both kind and the full references list, or excluded: true. A partial override is exit 2. An overridden project is not parsed for topology, and origin marks every resulting element and edge declared, so the picture shows what a human asserted. Corpus measured before landing: fleet-mission-control, forge-approvals, usage-governor; every exit 2 listed in the decision record. XML: DtdProcessing.Prohibit, XmlResolver = null, no XInclude.

Compose source

Explicit file list in config (FLT-394 manifest.json is uncommitted; adopt later). YamlDotNet representation model only, no Deserializer. Reads ONLY service names, image, build presence, depends_on. Never environment, command, secrets, labels, networks, ports. Image parse: strip @digest, then :tag only after final /, so localhost:5000/x:1 stays right. Digest bump does not stale the diagram. Exit 2: extends, include, second YAML document, custom tags, merge keys, more than 100 aliases, unexpected shapes. include support is a named follow-up; config can list included files directly.

Terraform-JSON source (cdktn seam)

Reads a configured cdk.tf.json synth snapshot. Never runs cdktn, terraform or a provider; proves diagram = snapshot, not diagram = live cloud. Top-level module = exit 2 this slice. Resource bodies are traversed: string leaves tested against a strict regex for references, depends_on read, the string then discarded; no value is retained, logged or put in diagnostics. A canary fixture proves it. Reference resolution: resolve against ALL resources in the file, including Ignored. Both ends retained = edge. An end that is Ignored = edge omitted on purpose, and the per-diagram stamp counts omitted edges. A data. reference = omitted, also counted. A reference to a managed type and name that is not in the file = exit 2, because it is unresolved rather than intentionally omitted. The real-synth oracle covers an edge to an Ignored resource. Rejected from a seat: a synth hash in model.json, because every attribute change would stale the diagram. Security resources are Ignored and the stamp says this is not an exposure map. Stub status, observed: FLT-374 is not on main, and real synth of V4VStack at bef1b71 gives a 370-byte file with no resource key, so no real repo can wire this yet. That output is kept as a verbatim fixture and must give exit 2 (zero elements). Resource shape comes from the same real engine (Io.Cdktn 0.25.0, jsii) running a scratch stack with generic TerraformResources and real tokens, so bytes are producer-made and topology is authored for the test; the docs say that plainly. Plus an end-to-end CLI run on that output.

Output

docs/architecture/ is wholly tool-owned: model.json, <view>.d2, <view>.svg, README.md (generated text alternative: img tags plus tables of elements and relationships, never inlined SVG, and the readable diff). Filenames are slugs matching ^[a-z0-9_-]+$, never raw names. Generate writes to a staging dir, validates all, then replaces; obsolete managed files go; a crash cannot mix generations. .gitattributes: model.json, *.d2, README.md text eol=lf; *.svg -text. Conflict rule in docs: never hand-merge, run generate.

Pinned D2

v0.9.0, MPL-2.0, subprocess only, binary not committed. tools/d2.pin.json: URL, length, SHA-256 per platform. windows-amd64 tarball 5f63b643de8f5a6dfb922d172e1b5496e4caf47497c33c4427cf1127f28c340f, linux-amd64 tarball 5669ddc46b99e942cc96078f4a4e36d5e62103348f4c05179ede27802fdd87a9, plus SHA-256 of each extracted binary. Authoritative render env: Windows amd64 on home-ci, Linux checked by a representative-fixture receipt including long and non-ASCII labels. Every launch: explicit --d2 path or FORGE_ARCH_D2, no PATH lookup; hash that exact file against the pin, mismatch = exit 2. UseShellExecute=false, CreateNoWindow, ArgumentList, constant flags --layout=dagre --theme=0 --pad=100 --sketch=false --timeout <n> --omit-version=false, fixed input.d2 in a private temp dir, cleared environment with only the minimum OS vars (no D2_*, no tokens), stdout and stderr drained asynchronously, timeout kills process tree. D2 errors contain absolute paths, so they are mapped to a fixed message, never echoed.

Trust boundary: files from any scanned repo are hostile

  • One rooted opener for every read and write. Canonicalize; reject UNC, \\?\, device names, drive-absolute, .., before any file API; walk each segment from root rejecting reparse points. Applies to discovered paths: solution entries, ProjectReference, props, compose files, tf file.
  • D2 allowlist writer: only identifiers, quoted labels, edges, blocks, fixed style keys for shape and dashed. Grammar test locks that. IDs: slug + _ + first 12 hex of SHA-256 of model ID; collision = exit 2.
  • Label rule, verified by experiment on real v0.9.0: $ in a double-quoted label breaks compile ("substitutions must begin on {"), and \$, \\, \" escaping renders ${vars.x}, @evil.d2, icon: https://..., ...@spread, <script> all as inert text, HTML-escaped in SVG. Writer escapes \, ", $. Reject Unicode Cc and Cf. Same rule for overlay and config strings.
  • Post-render SVG check via XML reader: DOCTYPE, script, foreignObject, on* attributes, any href that is not #fragment, any external URL in attributes = exit 2. Text content is not matched, since escaped text may contain those words; <style> with embedded font data URIs is expected and allowed. Network denial during render is not enforced in this slice: emitted D2 has no URL position, and this is recorded as a residual.
  • Caps exit 2: 1 MiB per csproj/props/solution/compose, 32 MiB cdk.tf.json, JSON depth 64, 2000 elements, 10000 relationships.
  • Fixtures: real compose files only after a secret scan; canary fixtures for each producer with CANARY_FLT379_*; asserted absent from model.json, every .d2, .svg, README.md and all diagnostics. Proof copy of greatroom tree is never pushed, and deleted after.
  • Docs say SVG is viewed via <img>, never inline. Viewer CSP is a follow-up for the UI slice.

Gate and CLI

Core library; thin CLI forge-arch generate|check --config architecture.json --d2 <path>. Config: versioned, discriminated sources, unknown property = exit 2. check regenerates in memory, compares every managed file byte for byte, and flags extra or missing files. Exit 0 fresh. Exit 1 stale: names added, removed, changed elements and relationships, or names the artifact that was hand-edited. Exit 2 cannot run. CI treats 1 and 2 as failure. Extra or missing managed files are exit 1; any unowned file, subdirectory or link in the output directory is exit 2. Anti-vacuous rules: a configured source with zero elements = exit 2. A source with more than one element and zero relationships = exit 2 unless allowNoRelationships. Unreferenced source scan: .sln, .slnx, *compose*.y*ml, cdk.tf.json in the repo not in sources or ignorePaths = exit 2.

Tests (each able to fail)

  • Semantic oracle: for each verbatim fixture an expected element and edge list (expected/*.txt) written by Clahadore by reading the real source, before the implementer's code exists, and write-locked against the implementer (a different model family). Not human-checked: Andrew or Shereeba remain the human oracle. Asserted on the object model before serialization. Includes negatives: vikunja db is DataStore and not in Container set; test project absent; shared Library appears in both C3 views; vikunja-init depends-on shape. A mutated classifier must fail these while staying self-consistent; prove via Stryker with break above 0 on Core, covering jail, emitter, spawn wrapper, exit map.
  • Fixtures verbatim with origin comment: vikunja compose, real slnx and csprojs from forge-approvals, real cdk.tf.json synth, real D2 output.
  • Parser edge fixtures: both <Sdk> forms, conditional refs, conditional IsTestProject, conditional test package, computed PackageReference identity ($(TestPackage)), ProjectReference via props, non-SDK Import, partial override, complete override, shared library, service removal, list and mapping depends_on, registry host with port, module address, indexed reference.
  • Hostile: UNC path in .sln asserts opener never called; DOCTYPE canary; junction mid-path; .. in slug source; alias bomb; payload labels through all four sources compiled with real D2.
  • Determinism: shuffled input same bytes; two runs same bytes; no drive letter or temp prefix in any output; D2 real and pinned in CI, no skip.
  • Gate: stale, hand-edited SVG, hand-edited model, missing file, extra file, wrong binary hash, source gone, unreferenced source. Each asserts exit code by driving CLI Main.
  • CI churn 5x, zero-tests rejection.

CI

home-ci Windows self-hosted runners. permissions: contents: read, actions pinned to SHAs, no continue-on-error, $LASTEXITCODE propagated, ErrorActionPreference trap handled. Failing jobs: build -warnaserror, test, Stryker, d2 download verify, dogfood forge-arch check, gitleaks, Semgrep plus custom rules (Process.Start(string), XmlResolver, DtdProcessing.Parse, YamlDotNet Deserializer), dependency advisory scan. CODEOWNERS on pin and workflows; branch protection if the org plan allows it, otherwise say so. Dogfood config lists only sources that exist in this repo.

Executable checks

  1. dotnet build -warnaserror exit 0. 2. Oracle tests green. 3. Real D2 test green on Windows CI. 4. Gate exit-code matrix. 5. Smoke outside the system: built exe by hand on a private clone of a real repo. 6. Smoke inside: CI green on branch tip, and a throwaway commit adding a project without regenerating gives red CI with named diff. Receipt binds to commit.

Proof on a real repo

  • Private clone of fleet-mission-control: generate, add an Exe project with a ProjectReference, check exit 1 naming it, generate, box and edge appear, expected list updated. Before and after screenshots.
  • Scratch git repo holding a copy of real local-stacks/greatroom (sibling owns the source; no edits to it; never pushed): add a service to vikunja compose, check exit 1, generate, box appears.
  • End-to-end CLI on real FLT-374 synth snapshot.
  • forge-arch check on forge-architecture itself in CI, plus the red-CI stale commit.

Work split

Jenny (gemini-4-argon-high) writes it, Susie fallback; meters: Cedric weekly 21%, Muse 2% window / 10% weekly, Gemini GREEN, Grok unknown. Clahadore routes, writes the expected oracle lists, reviews, decides. Worktree forge-architecture-wt-WT-8b9a-FLT379, branch wt/WT-8b9a/FLT-379. Then /council-code-review, green CI, land.

Not covered

UI and MCP surfaces, LikeC4, drift badges (G10), Rete parity (G4), cross-source links and deployment placement, runtime calls, wiring app repos, Compose include and extends, Terraform modules, Structurizr DSL export, viewer CSP, network denial during render.