You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| `from.id` / `to.id` | Full canonical ID strings |
66
68
| `dep.type` | Dependency type (`import`, `call`, etc.) |
@@ -154,9 +156,36 @@ rule:
154
156
suggestion: Access infrastructure through application services instead
155
157
```
156
158
159
+
## kind vs within
160
+
161
+
In v2 schemas with nested containers, there's an important distinction:
162
+
163
+
| Field | Meaning | Example |
164
+
|-------|---------|---------|
165
+
| `kind` | Immediate container's kind | `module` for code in `billing-service.invoice-module` |
166
+
| `within` | Top-level container's kind | `service` for any code inside `billing-service` |
167
+
168
+
**When to use each:**
169
+
170
+
- Use **`kind`** when you want to match the specific container type (e.g., "only code directly in a module")
171
+
- Use **`within`** when you want to match anything inside a service hierarchy (e.g., "any code belonging to a service, including nested modules")
172
+
173
+
**Example:** Code at `services/billing/domain/invoice/model/invoice.py` inside `billing-service.invoice-module`:
174
+
175
+
```
176
+
billing-service (kind: service)
177
+
└── invoice-module (kind: module)
178
+
└── invoice.py ← this file
179
+
```
180
+
181
+
| Field | Value |
182
+
|-------|-------|
183
+
| `kind` | `module` (immediate container) |
184
+
| `within` | `service` (top-level container) |
185
+
157
186
## Example: Cross-Service Rules (v2)
158
187
159
-
These rules use v2-only fields (`from.service`, `to.service`, `from.kind`, `to.kind`):
188
+
These rules use v2-only fields (`from.service`, `to.service`, `from.kind`, `to.kind`, `from.within`, `to.within`):
160
189
161
190
```yaml
162
191
# Forbid cross-service domain dependencies
@@ -172,7 +201,7 @@ rule:
172
201
- from.layer == domain
173
202
message: Domain code must not depend on another service
174
203
175
-
# Libraries must not depend on services
204
+
# Libraries must not depend on services (using 'within' for nested containers)
176
205
rule:
177
206
id: library-no-service-deps
178
207
name: Libraries must be independent of services
@@ -181,7 +210,13 @@ rule:
181
210
action: forbid
182
211
when:
183
212
all:
184
-
- from.kind == library
185
-
- to.kind == service
213
+
- from.within == library
214
+
- to.within == service
186
215
message: Library code must not import service code
216
+
suggestion: Move shared code to a library or create a proper API contract
187
217
```
218
+
219
+
!!! note "Why use `within` instead of `kind`?"
220
+
Using `to.kind == service` would NOT match code inside nested modules like `billing-service.invoice-module`, because the immediate container's kind is `module`, not `service`.
221
+
222
+
Using `to.within == service` matches ANY code inside a service hierarchy, including nested modules.
-`from.layer` / `to.layer` — standard layer constraints
29
29
30
+
### `kind` vs `within`
31
+
32
+
For nested containers, there's an important distinction:
33
+
34
+
| Field | Meaning | Example |
35
+
|-------|---------|---------|
36
+
|`kind`| Immediate container's kind |`module` for code in `invoice-module`|
37
+
|`within`| Top-level container's kind |`service` for any code inside `billing-service`|
38
+
39
+
**Why use `within`?** Using `to.kind == service` would NOT match code inside nested modules (like `invoice-module`), because the immediate kind is `module`. Using `to.within == service` matches ANY code inside the service hierarchy.
0 commit comments