feat(c4): relationship validation + @c4 system + @c4 code levels - #1
Closed
nightscape wants to merge 3 commits into
Closed
nightscape wants to merge 3 commits into
nightscape wants to merge 3 commits into
Conversation
Add a workspace-native dependency source and a `ir check-deps` CLI command that diffs declared `@c4 uses` arrows against the real crate→crate graph. - adapters/archidoc-rust/cargo_metadata.rs: workspace_import_graph() reads `cargo metadata --no-deps` (no external tooling, unlike the cargo-modules path) into the existing ImportGraph; validate_ir_relationships() diffs a compiled IR's relationships against it, reusing RelationshipWarning. - archidoc ir check-deps <ir> --manifest-dir <dir> [--ignore N] [--strict]: reports `missing` (real dep, no @C4 uses — prints paste-ready line) and `stale` (declared @C4 uses, no real dep). --strict exits 1 for CI. - Revives the previously dead validate_relationships/ImportGraph machinery by giving it a tool-free, crate-level edge source and a CLI entry point. - workspace-hack ignored by default. 3 unit tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds the top of the C4 model (previously C4Level had only Container/ Component/Unknown — no way to declare the system in focus or external systems). - archidoc-types: C4Level::System variant (+ Display "system"). - archidoc-rust: extract_c4_level() parses `@c4 system`. - archidoc-engine/plantuml: generate_context() renders one System() per `@c4 system` node plus its `@c4 uses` relationships → c4-context.puml (emitted only when a system node exists). Container diagram now renders system nodes as System_Ext() so container→system arrows resolve. - CLI render plantuml emits the context diagram alongside container/component. - Tests: extract_c4_level covers all four levels. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a new CLI workflow to validate compiled IR @c4 uses relationships against the actual Rust workspace crate dependency graph derived from cargo metadata, enabling detection of missing and stale dependency arrows without relying on external tooling.
Changes:
- Introduces
archidoc ir check-depsinarchidoc-clito compare IR relationships vs workspace crate deps, with--ignoreand--strictsupport. - Adds a new
archidoc_rust::cargo_metadatamodule that builds anImportGraphfromcargo metadataand diffs it against IR relationships. - Adds
serde_jsonas a dependency ofarchidoc-rustto parsecargo metadataoutput.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| core/archidoc-cli/src/main.rs | Adds the ir check-deps subcommand and prints drift output / exit codes. |
| adapters/archidoc-rust/src/cargo_metadata.rs | New implementation to build crate-level dependency graph from cargo metadata and validate IR relationships. |
| adapters/archidoc-rust/src/lib.rs | Exposes the new cargo_metadata module publicly. |
| adapters/archidoc-rust/Cargo.toml | Adds serde_json dependency needed for parsing cargo metadata JSON. |
| Cargo.lock | Lockfile update reflecting the new dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+79
to
+82
| let to = match dep["name"].as_str() { | ||
| Some(n) if members.contains(n) && n != from => n.to_string(), | ||
| _ => continue, | ||
| }; |
Comment on lines
+117
to
+127
| let declared: HashSet<String> = dir | ||
| .relationships | ||
| .iter() | ||
| .map(|r| r.target.clone()) | ||
| .filter(|t| !ignore.contains(t)) | ||
| .collect(); | ||
| let actual: HashSet<String> = graph | ||
| .get_dependencies(&crate_name) | ||
| .into_iter() | ||
| .filter(|t| !ignore.contains(t)) | ||
| .collect(); |
Comment on lines
14
to
18
| //! | `promote.rs` | -- | Auto-promote planned to verified | planned | | ||
| //! | `cargo_modules.rs` | -- | cargo-modules integration (optional) | planned | | ||
|
|
||
| pub mod cargo_metadata; | ||
| pub mod cargo_modules; |
Comment on lines
+271
to
+273
| /// Examples: | ||
| /// archidoc ir check-deps _context/current.json --manifest-dir crates | ||
| /// archidoc ir check-deps _context/current.json --manifest-dir . --strict |
Completes the C4 model downward. Item-level `@c4 code` doc markers turn a curated set of load-bearing types into code-level nodes under their component — the rust adapter previously parsed only module `//!` docs. - archidoc-types: CodeElement on ModuleDoc + ir::CodeElement on DirNode (serde-default; existing IR JSON stays valid). - archidoc-rust/parser: extract_code_elements() uses syn to find struct/enum/trait/fn items whose doc contains `@c4 code`; captures kind, description, and `@c4 uses` relationships. Unmarked items are ignored (curated, not a dump). - archidoc-rust/walker: aggregates a module's code elements from its directory's source files onto the component's ModuleDoc. - archidoc-engine: ir_builder propagates code_elements; plantuml generate_code() renders c4-code.puml (Component per element, kind as the tech tag, intra-component `@c4 uses` resolved to qualified ids). Emitted only when a code element exists. - Tests: extract_code_elements curation + typing + relationships. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Owner
Author
|
Superseded by three focused PRs against upstream GitSmart86/archidoc: GitSmart86#7 (relationship validation), GitSmart86#8 (@C4 system), GitSmart86#9 (@C4 code). dev will octo-merge those branches. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three independent enhancements that make
@c4richer and keep its diagrams honest. Each is a separate commit and could be split into its own PR on request.1.
ir check-deps— validate@c4 usesagainst real crate depsValidates the
@c4 usesarrows in a compiled IR against the real crate→crate graph fromcargo metadata(no extra tooling).Reports missing (real dep, no arrow — prints a paste-ready
@c4 usesline) and stale (declared arrow, no real dep).--strictexits 1 (CI gate).workspace-hackignored by default.This revives the previously dead
cargo_modules.rsmachinery (ImportGraph/validate_relationships/detect_orphans— never CLI-wired, and dependent on the externalcargo-modulestool) by giving it a workspace-native, tool-free, crate-level edge source and a CLI entry point.2.
@c4 systemlevel — system-context diagramC4Levelhad onlyContainer/Component/Unknown— no way to declare the system in focus or external systems. AddsC4Level::System, parses@c4 system, and rendersc4-context.puml(oneSystem()per node + its@c4 usesarrows). Container diagram now renders system nodes asSystem_Ext()so container→system arrows resolve.3.
@c4 codelevel — code diagramCompletes C4 downward. Item-level
@c4 codedoc markers onstruct/enum/trait/fn(parsed viasyn— the adapter previously read only module//!docs) become curated code-level nodes under their component. Unmarked items are ignored (curated, not a dump). Rendersc4-code.puml; intra-component@c4 usesresolve to qualified ids.Notes
devfeature branches (no file overlap); based ondevonly for a clean diff. Portable to upstreammain.serde-default, so existing IR JSON stays valid.polyglot_detection_testfailures ondevare unrelated.🤖 Generated with Claude Code