|
| 1 | +--- |
| 2 | +applyTo: "**/*.{likec4,c4}" |
| 3 | +--- |
| 4 | + |
| 5 | +# LikeC4 DSL Instructions (architecture-as-code diagrams) 📐 |
| 6 | + |
| 7 | +These instructions define the engineering approach for authoring **LikeC4 architecture-as-code** files. |
| 8 | + |
| 9 | +They must remain applicable to: |
| 10 | + |
| 11 | +- C4 model definitions (system context, container, component diagrams) |
| 12 | +- Specification blocks (element kinds, relationship kinds, styles) |
| 13 | +- View definitions and layout |
| 14 | +- Multi-file workspace models |
| 15 | + |
| 16 | +They are **non-negotiable** unless an exception is explicitly documented (with rationale and expiry) in an ADR/decision record. |
| 17 | + |
| 18 | +**Cross-references.** For architecture documentation standards, see [architecture-baseline.include.md](./includes/architecture-baseline.include.md). For the C4 model generation prompt, see [architecture.05-c4-model.prompt.md](../prompts/architecture.05-c4-model.prompt.md). This file focuses exclusively on LikeC4 DSL patterns and validation. |
| 19 | + |
| 20 | +**Identifier scheme.** Every normative rule carries a unique tag in the form `[LC4-<prefix>-NNN]`, where the prefix maps to the containing section (for example `QR` for Quick Reference, `OP` for Operating Principles, `SYN` for Syntax, `VAL` for Validation, `STY` for Style). Use these identifiers when referencing, planning, or validating requirements. |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## 0. Quick reference (apply first) 🧠 |
| 25 | + |
| 26 | +This section exists so humans and AI assistants can reliably apply the most important rules even when context is tight. |
| 27 | + |
| 28 | +- [LC4-QR-001] **Element syntax**: use `identifier = kind 'Title'` — identifier first, then `=`, then kind. |
| 29 | +- [LC4-QR-002] **Never mix forms**: `kind identifier = 'Title'` is INVALID and silently drops the element. |
| 30 | +- [LC4-QR-003] **Validate after generation**: use LikeC4 MCP tools to confirm all elements parsed correctly. |
| 31 | +- [LC4-QR-004] **Specification first**: declare every element kind in `specification {}` before using it in `model {}`. |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +## 1. Operating principles 🧭 |
| 36 | + |
| 37 | +These principles extend [constitution.md §3](../../.specify/memory/constitution.md#3-core-principles-non-negotiable). |
| 38 | + |
| 39 | +- [LC4-OP-001] Treat the **specification as the source of truth** for the architecture model. If a system, container, or component is not evidenced in the codebase, it does not belong in the diagram. |
| 40 | +- [LC4-OP-002] Prefer **small, incremental updates** over full model rewrites. |
| 41 | +- [LC4-OP-003] Design for **determinism**: the same model source must produce the same diagrams. |
| 42 | +- [LC4-OP-004] **Validate every change** using LikeC4 MCP tools — the tooling fails silently on syntax errors. |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +## 2. Element declaration syntax 🧩 |
| 47 | + |
| 48 | +LikeC4 supports two forms for declaring elements. Mixing them causes silent parse failures. |
| 49 | + |
| 50 | +### Valid forms |
| 51 | + |
| 52 | +```likec4 |
| 53 | +// Form A — identifier-first with = (PREFERRED) |
| 54 | +customer = actor 'Customer' { |
| 55 | + description 'End user of the system' |
| 56 | +} |
| 57 | +
|
| 58 | +// Form B — kind-first WITHOUT = (alternative) |
| 59 | +actor customer 'Customer' { |
| 60 | + description 'End user of the system' |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +### Invalid form (common mistake) |
| 65 | + |
| 66 | +```likec4 |
| 67 | +// WRONG — kind-first WITH = sign |
| 68 | +// This silently fails: the element is dropped without error |
| 69 | +actor customer = 'Customer' { |
| 70 | + description 'End user of the system' |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +- [LC4-SYN-001] Prefer Form A (`identifier = kind 'Title'`) for consistency. |
| 75 | +- [LC4-SYN-002] Never combine kind-first ordering with the `=` sign. |
| 76 | +- [LC4-SYN-003] Apply the same rule to nested elements (containers, components) — the syntax is identical at every nesting level. |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | +## 3. Specification block 📋 |
| 81 | + |
| 82 | +- [LC4-SYN-010] Declare all element kinds in `specification {}` before referencing them in `model {}`. |
| 83 | +- [LC4-SYN-011] Declare custom styles (e.g. `shape person` for actors) inside the kind's `style {}` block within the specification. |
| 84 | + |
| 85 | +```likec4 |
| 86 | +specification { |
| 87 | + element actor { |
| 88 | + style { |
| 89 | + shape person |
| 90 | + } |
| 91 | + } |
| 92 | + element system |
| 93 | + element container |
| 94 | + element component |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +--- |
| 99 | + |
| 100 | +## 4. Views 🖼️ |
| 101 | + |
| 102 | +- [LC4-SYN-020] Use `view name { include * }` for top-level views showing all elements. |
| 103 | +- [LC4-SYN-021] Use `view name of element { include * }` to scope a view to a specific element's children. |
| 104 | +- [LC4-SYN-022] List included elements as comma-separated values: `include a, b, c`. |
| 105 | + |
| 106 | +```likec4 |
| 107 | +views { |
| 108 | + view index { |
| 109 | + title 'System Context' |
| 110 | + include * |
| 111 | + } |
| 112 | +
|
| 113 | + view containers of mySystem { |
| 114 | + title 'Container Diagram' |
| 115 | + include *, externalUser, externalDep |
| 116 | + } |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +--- |
| 121 | + |
| 122 | +## 5. Relationships 🔗 |
| 123 | + |
| 124 | +- [LC4-SYN-030] Use `source -> target 'label'` for relationships. |
| 125 | +- [LC4-SYN-031] Inside an element body, use `-> target 'label'` (implicit source is the enclosing element). |
| 126 | +- [LC4-SYN-032] Use fully qualified names for cross-boundary references: `system.container.component`. |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +## 6. Validation ✅ |
| 131 | + |
| 132 | +LikeC4 fails silently on syntax errors — invalid elements are dropped without diagnostics. |
| 133 | + |
| 134 | +- [LC4-VAL-001] After generating or editing a `.likec4` file, use `mcp_likec4_read-project-summary` to verify the element count matches expectations. |
| 135 | +- [LC4-VAL-002] Use `mcp_likec4_read-view` to confirm each view contains the expected nodes and edges. |
| 136 | +- [LC4-VAL-003] If the element count is lower than expected, check for the invalid `kind identifier = 'Title'` pattern first — it is the most common cause. |
| 137 | + |
| 138 | +--- |
| 139 | + |
| 140 | +## 7. File conventions 📁 |
| 141 | + |
| 142 | +- [LC4-STY-001] Use the `.likec4` extension for LikeC4 source files (`.c4` also works but `.likec4` is unambiguous). |
| 143 | +- [LC4-STY-002] Place architecture diagrams under `docs/architecture/`. |
| 144 | +- [LC4-STY-003] Use a single `workspace.likec4` file for small projects; split into multiple files for larger models. |
| 145 | +- [LC4-STY-004] Add a comment header with inputs and evidence pointers at the top of each file. |
| 146 | + |
| 147 | +--- |
| 148 | + |
| 149 | +> **Version**: 1.0.0 |
| 150 | +> **Last Amended**: 2026-04-27 |
0 commit comments