-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc4-annotations-schema.yaml
More file actions
282 lines (250 loc) · 10.1 KB
/
Copy pathc4-annotations-schema.yaml
File metadata and controls
282 lines (250 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# =============================================================================
# C4 Literate Python Annotation Schema
# =============================================================================
#
# This schema defines the C4 model annotations that can be embedded in
# Python docstrings and comments. The tangler extracts these annotations
# and generates Structurizr DSL for creating architecture diagrams.
#
# Version: 0.9.0
# Date: 2025-01-21
# =============================================================================
schema_version: "0.9.0"
schema_type: "c4-literate-annotations"
# -----------------------------------------------------------------------------
# Annotation Definitions
# -----------------------------------------------------------------------------
annotations:
# ===========================================================================
# STRUCTURE ANNOTATIONS (What elements exist)
# ===========================================================================
"@c4-container":
name: "@c4-container"
placement: [module]
required_attributes:
- "@c4-technology"
- "@c4-description"
optional_attributes:
- "@c4-responsibilities"
format: "Name of the container"
description: >
Declares that this module represents a C4 container (deployable
unit like a web application, database, mobile app, etc.)
examples:
- "@c4-container: API Application"
- "@c4-container: Database Layer"
- "@c4-container: Message Queue"
notes: >
Containers are the high-level building blocks of your system.
Each container is separately deployable and typically runs in
its own process space.
"@c4-component":
name: "@c4-component"
placement: [module, class]
required_attributes:
- "@c4-technology"
optional_attributes:
- "@c4-description"
format: "Name of the component"
description: >
Declares that this module or class represents a C4 component
(a grouping of related functionality within a container)
examples:
- "@c4-component: Data Validation Layer"
- "@c4-component: API Request Handler"
- "@c4-component: Authentication Service"
notes: >
Components are the major structural elements within a container.
They represent groupings of related functionality.
parent_container_assignment: >
Components are automatically assigned to containers based on
filepath. If a component and container are in the same file,
the component is nested inside that container. Otherwise, the
component is assigned to the first available container.
See docs/ADR-001-component-assignment.md for details.
# ===========================================================================
# ATTRIBUTE ANNOTATIONS (Properties of elements)
# ===========================================================================
"@c4-technology":
name: "@c4-technology"
placement: [module, class, function]
format: "Technology stack description"
description: >
Describes the technology or tech stack used to implement this
element
examples:
- "@c4-technology: Python 3.12, FastAPI 0.104"
- "@c4-technology: SQLAlchemy 2.0, SQLite 3"
- "@c4-technology: Pydantic 2.0"
notes: >
Be specific about versions when relevant for documentation
purposes.
"@c4-description":
name: "@c4-description"
placement: [module, class, function]
format: "Brief description (1-2 sentences recommended)"
description: >
Provides a brief description of what this element does or
represents
examples:
- "@c4-description: REST API providing CRUD operations for notes"
- "@c4-description: Validates and serializes request/response data"
notes: >
Keep descriptions concise and focused on the primary
responsibility. Detailed explanations belong in the surrounding
prose documentation.
"@c4-responsibilities":
name: "@c4-responsibilities"
placement: [module, class]
format: "Bullet list of responsibilities (one per line, indented)"
description: "Lists the key responsibilities of this element"
examples:
- |
@c4-responsibilities:
- Accept and validate HTTP requests
- Route requests to handlers
- Transform responses to JSON
notes: >
Each responsibility should be a brief action phrase. Typically
3-7 items.
# ===========================================================================
# RELATIONSHIP ANNOTATIONS (How elements interact)
# ===========================================================================
"@c4-uses":
name: "@c4-uses"
placement: [module, class]
format: 'Target - "Description" - "Technology"'
description: >
Declares that this element depends on or uses another container
or component
examples:
- '@c4-uses: Database Layer (app.database) - "Manages note persistence" - "SQLAlchemy ORM"'
- '@c4-uses: Data Models (app.models) - "Validates requests" - "Pydantic"'
notes: >
The three parts are: (1) Target name with optional module path
in parens, (2) Action description in quotes, (3) Technology/
protocol in quotes.
"@c4-used-by":
name: "@c4-used-by"
placement: [module, class]
format: 'Source - "Description" - "Technology"'
description: >
Declares that this element is used by another container or
component (inverse of @c4-uses)
examples:
- '@c4-used-by: API Application (app.main) - "Requests database sessions" - "SQLAlchemy ORM"'
notes: >
Use this for documenting reverse dependencies when the
relationship is important to understand from this element's
perspective.
"@c4-used-by-person":
name: "@c4-used-by-person"
placement: [module, class]
format: 'Person name - "Description" - "Technology/Protocol"'
description: >
Declares that this element is used by an external actor (person
or external system acting as a user)
examples:
- '@c4-used-by-person: API Consumer - "Creates and manages notes" - "HTTPS/JSON"'
- '@c4-used-by-person: System Administrator - "Monitors health" - "HTTPS"'
notes: >
Persons represent human actors or external systems that interact
with your system from the outside.
"@c4-operation":
name: "@c4-operation"
placement: [function]
format: "Operation name (typically function name)"
description: >
Declares that this function represents a significant operation
within a component
examples:
- "@c4-operation: create_note"
- "@c4-operation: authenticate_user"
notes: >
Operations are the finest level of detail, showing key functions
within components. Only annotate significant operations, not
every function.
"@c4-calls":
name: "@c4-calls"
placement: [function]
format: 'Target - "Description"'
description: >
Declares that this operation calls another component or container
examples:
- '@c4-calls: Database Layer - "Persists new note"'
- '@c4-calls: Authentication Service - "Validates token"'
notes: >
Use this to show data flow and interactions at the operation
level. Two-part format: Target and action description.
"@c4-relationship":
name: "@c4-relationship"
placement: [module, class, function]
format: "Generic relationship declaration"
description: >
Generic relationship annotation for advanced use cases not
covered by @c4-uses/@c4-calls
examples:
- "@c4-relationship: Initializes Database Container on startup"
notes: >
Use specific annotations (@c4-uses, @c4-calls) when possible.
This is for special cases.
# -----------------------------------------------------------------------------
# Validation Rules
# -----------------------------------------------------------------------------
validation_rules:
container_requirements:
description: >
A module with @c4-container must have @c4-technology and
@c4-description
required:
- "@c4-technology"
- "@c4-description"
component_requirements:
description: >
A module or class with @c4-component must have @c4-technology
required:
- "@c4-technology"
relationship_format:
description: >
Relationship annotations must follow the specified format with
proper quoting
pattern: '^.+ - ".+" - ".+"$'
# -----------------------------------------------------------------------------
# Best Practices
# -----------------------------------------------------------------------------
best_practices:
placement: >
Place container declarations at module level, component
declarations at module or class level, operation declarations
at function level
naming: >
Use clear, consistent names that match your architecture
documentation
descriptions: >
Keep descriptions concise (1-2 sentences). Use surrounding prose
for detailed explanations
relationships: >
Document relationships from the perspective of the element being
annotated
consistency: >
Use consistent terminology across all annotations in your codebase
# -----------------------------------------------------------------------------
# Future Extensions (Planned)
# -----------------------------------------------------------------------------
future_extensions:
planned:
- "@c4-software-system: For declaring system context"
- "@c4-person: For declaring external actors"
- "@c4-database: For declaring data stores"
- "@c4-external-system: For declaring external dependencies"
- "@c4-deployment-node: For deployment context"
- "@c4-security-zone: For security boundaries"
- "@c4-parent-container: For explicit component-to-container assignment"
# -----------------------------------------------------------------------------
# References
# -----------------------------------------------------------------------------
references:
c4_model: "https://c4model.com/"
structurizr_dsl: "https://github.com/structurizr/dsl"
repository: "https://github.com/yourusername/c4-literate-python"
adr_component_assignment: "docs/ADR-001-component-assignment.md"