Skip to content

Commit 7fdd2ea

Browse files
committed
feat(instructions): add LikeC4 DSL guidelines and validation tips to prevent silent failures
1 parent 08fa8c2 commit 7fdd2ea

2 files changed

Lines changed: 180 additions & 3 deletions

File tree

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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

.github/prompts/architecture.05-c4-model.prompt.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ agent: agent
33
description: Produce C4 model diagrams (Context, Container, Component) in LikeC4 format (https://likec4.dev/, evidence-first, consistent naming)
44
---
55

6-
**Mandatory preparation:** read [architecture overview](../instructions/includes/architecture-baseline.include.md) instructions in full and follow strictly its rules before executing any step below.
6+
**Mandatory preparation:** read [architecture overview](../instructions/includes/architecture-baseline.include.md) and [LikeC4 DSL](../instructions/likec4.instructions.md) instructions in full and follow strictly their rules before executing any step below.
77

88
## Goal 🎯
99

@@ -191,6 +191,33 @@ Also include brief "How to view" notes (repo-local, no external claims), for exa
191191

192192
---
193193

194+
## LikeC4 pitfalls and validation ⚠️
195+
196+
These rules are derived from real debugging sessions. Follow them to avoid silent failures.
197+
198+
### Element declaration syntax
199+
200+
LikeC4 supports two declaration forms — **never mix them**:
201+
202+
| Form | Syntax | Valid? |
203+
| ---------------------------- | ----------------------------------- | ------ |
204+
| Identifier-first (preferred) | `identifier = kind 'Title' { ... }` ||
205+
| Kind-first (alternative) | `kind identifier 'Title' { ... }` ||
206+
| **Mixed (common mistake)** | `kind identifier = 'Title' { ... }` ||
207+
208+
The mixed form silently drops the element — no error, no warning. The diagram renders with missing nodes.
209+
210+
### Post-generation validation (mandatory)
211+
212+
After creating or editing any `.likec4` file:
213+
214+
1. Call `mcp_likec4_read-project-summary` and count the elements returned.
215+
2. Compare against the expected count from your model.
216+
3. If elements are missing, search for the invalid `kind identifier = 'Title'` pattern.
217+
4. Call `mcp_likec4_read-view` for each view to confirm nodes and edges.
218+
219+
---
220+
194221
## LikeC4 skeletons (use as starting points)
195222

196223
### Context skeleton
@@ -320,5 +347,5 @@ views {
320347

321348
---
322349

323-
> **Version**: 1.1.3
324-
> **Last Amended**: 2026-01-17
350+
> **Version**: 1.2.0
351+
> **Last Amended**: 2026-04-27

0 commit comments

Comments
 (0)