Skip to content

feat(c4): add @c4 system level + system-context diagram - #8

Open
nightscape wants to merge 1 commit into
GitSmart86:mainfrom
nightscape:feat/c4-system-level
Open

nightscape wants to merge 1 commit into
GitSmart86:mainfrom
nightscape:feat/c4-system-level

Conversation

@nightscape

Copy link
Copy Markdown

What

Adds the top of the C4 model. C4Level previously had only Container / Component / Unknown — no way to declare the system in focus or the external systems it talks to.

  • archidoc-types: C4Level::System (+ 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). The container diagram now renders system nodes as System_Ext() so container→system arrows resolve.
  • CLI render plantuml emits the context diagram alongside container/component.

Example

//! @c4 system
//! @c4 uses vault "Reads/writes org files" "filesystem"
//! @c4 uses peers "Syncs CRDT updates" "QUIC"
//!
//! The application in focus.

c4-context.puml with System(...) nodes and Rel(...) arrows between them.

Notes

Independent of the other branches (no file overlap beyond the C4Level enum and the render dispatcher). Test added covering all four levels.

🤖 Generated with Claude Code

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds first-class support for @c4 system annotations and uses them to generate a C4 system-context diagram and improve container diagram rendering when containers relate to external systems.

Changes:

  • Introduces C4Level::System and updates string formatting/serialization expectations.
  • Updates Rust adapter parsing to recognize @c4 system and adds tests for all C4 levels.
  • Adds PlantUML generation for a new c4-context.puml diagram and renders system nodes in the container diagram; wires the new generator into the CLI.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
core/archidoc-types/src/ir.rs Adds System to the C4 level enum and display mapping.
core/archidoc-engine/src/plantuml.rs Generates system-context diagram; renders system externals in container diagram.
core/archidoc-cli/src/main.rs Calls the new context diagram generator in PlantUML rendering flow.
adapters/archidoc-rust/src/parser.rs Parses @c4 system and adds a test covering all level markers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +105 to +115
let mut rel_defs = String::new();
for dir in &systems {
let from_id = to_puml_id(&dir.path);
for rel in &dir.relationships {
let to_id = to_puml_id(&rel.target);
rel_defs.push_str(&format!(
"Rel({}, {}, \"{}\", \"{}\")\n",
from_id, to_id, rel.label, rel.protocol
));
}
}
Comment on lines +34 to +42
for dir in systems_of(ir) {
let id = to_puml_id(&dir.path);
let name = to_title_case(&dir.name);
let desc = dir.description.as_deref().unwrap_or("");
system_defs.push_str(&format!(
"System_Ext({}, \"{}\", \"{}\")\n",
id, name, desc
));
}
Comment on lines +76 to +81
fn systems_of(ir: &ArchitectureIR) -> Vec<&DirNode> {
ir.annotated_dirs()
.into_iter()
.filter(|d| d.c4_level == Some(C4Level::System))
.collect()
}
Comment on lines +99 to +102
system_defs.push_str(&format!(
"System({}, \"{}\", \"{}\")\n",
id, name, desc
));
Comment on lines +110 to +113
rel_defs.push_str(&format!(
"Rel({}, {}, \"{}\", \"{}\")\n",
from_id, to_id, rel.label, rel.protocol
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants