System Context Diagram¶
c4.diagrams.system_context.SystemContextDiagram ¶
Bases: Diagram
Represents a C4 System Context Diagram.
Source code in c4/diagrams/system_context.py
32 33 34 35 36 37 | |
__init__ ¶
__init__(
title: str | None = None,
default_renderer: BaseRenderer[Diagram] | None = None,
render_options: RenderOptions | None = None,
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str | None
|
Optional title to label the diagram. |
None
|
default_renderer
|
BaseRenderer[Diagram] | None
|
Optional default renderer to use for rendering. |
None
|
render_options
|
RenderOptions | None
|
Optional renderer-specific options. |
None
|
Source code in c4/diagrams/core/diagram.py
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 | |
ordered_elements
property
¶
ordered_elements: list[BaseDiagramElement]
Return diagram items in their order of definition.
The sequence can include C4 elements, relationships, boundaries, and backend-owned statements that affect declaration-order rendering.
relationships
property
¶
relationships: list[Relationship]
Returns all relationships defined in the diagram.
get_element_by_alias ¶
get_element_by_alias(alias: str) -> Element | None
Return the element with the given alias.
Source code in c4/diagrams/core/diagram.py
174 175 176 | |
get_elements_by_label ¶
get_elements_by_label(label: str) -> list[Element]
Return all elements that share the given label.
Source code in c4/diagrams/core/diagram.py
178 179 180 | |
generate_alias ¶
generate_alias(
label: str,
alias: str | None = None,
fallback_prefix: str | None = None,
) -> str
Generate a unique alias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Source label used to derive the alias when |
required |
alias
|
str | None
|
Optional explicit alias. If provided, it must be unique. |
None
|
fallback_prefix
|
str | None
|
Prefix to use when the label cannot produce a valid alias. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A unique alias string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If alias already exists. |
Source code in c4/diagrams/core/diagram.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
__enter__ ¶
__enter__() -> Self
Enter the diagram context.
Automatically sets this diagram as the current active diagram.
Returns:
| Type | Description |
|---|---|
Self
|
The current instance. |
Source code in c4/diagrams/core/diagram.py
82 83 84 85 86 87 88 89 90 91 92 | |
__exit__ ¶
__exit__(
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> None
Exit the diagram context and clear the current diagram.
Source code in c4/diagrams/core/diagram.py
94 95 96 97 98 99 100 101 102 103 | |
as_plantuml ¶
as_plantuml(**kwargs: Any) -> str
Render the diagram using the built-in PlantUML renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Optional keyword arguments passed to the PlantUML renderer. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The rendered PlantUML code. |
Source code in c4/diagrams/core/diagram.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
as_mermaid ¶
as_mermaid(**kwargs: Any) -> str
Render the diagram using the built-in Mermaid renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Optional keyword arguments passed to the Mermaid renderer. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The rendered Mermaid code. |
Source code in c4/diagrams/core/diagram.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
render ¶
render(
renderer: BaseRenderer[Diagram] | None = None,
) -> str
Render the diagram to a string using the given or default renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
renderer
|
BaseRenderer[Diagram] | None
|
Optional renderer to override the default. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The rendered diagram output. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no renderer is provided and no default renderer is set. |
Source code in c4/diagrams/core/diagram.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
save ¶
save(
path: str | Path,
renderer: BaseRenderer[Diagram] | None = None,
) -> None
Render and save the diagram to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Target path to save the rendered output. |
required |
renderer
|
BaseRenderer[Diagram] | None
|
Optional renderer to override the default. |
None
|
Source code in c4/diagrams/core/diagram.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
save_as_plantuml ¶
save_as_plantuml(path: str | Path, **kwargs: Any) -> None
Render and save the diagram using the PlantUML renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Target file path. |
required |
**kwargs
|
Any
|
Optional kwargs passed to the PlantUML renderer. |
{}
|
Source code in c4/diagrams/core/diagram.py
364 365 366 367 368 369 370 371 372 373 374 375 | |
save_as_mermaid ¶
save_as_mermaid(path: str | Path, **kwargs: Any) -> None
Render and save the diagram using the Mermaid renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Target file path. |
required |
**kwargs
|
Any
|
Optional kwargs passed to the Mermaid renderer. |
{}
|
Source code in c4/diagrams/core/diagram.py
377 378 379 380 381 382 383 384 385 386 387 388 | |
render_options
property
writable
¶
render_options: RenderOptions | None
Return rendering options for the diagram.
set_render_options ¶
set_render_options(
*,
plantuml: Maybe[PlantUMLRenderOptions] = MISSING,
mermaid: Maybe[MermaidRenderOptions] = MISSING,
) -> Self
Patch renderer-specific options for this diagram.
Omitted renderer keys are left unchanged. Passing None clears that
renderer's diagram-level defaults.
Source code in c4/diagrams/core/diagram.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
c4.diagrams.system_context.SystemLandscapeDiagram ¶
Bases: Diagram
Represents a C4 System Landscape Diagram.
Source code in c4/diagrams/system_context.py
40 41 42 43 44 45 | |
__init__ ¶
__init__(
title: str | None = None,
default_renderer: BaseRenderer[Diagram] | None = None,
render_options: RenderOptions | None = None,
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str | None
|
Optional title to label the diagram. |
None
|
default_renderer
|
BaseRenderer[Diagram] | None
|
Optional default renderer to use for rendering. |
None
|
render_options
|
RenderOptions | None
|
Optional renderer-specific options. |
None
|
Source code in c4/diagrams/core/diagram.py
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 | |
ordered_elements
property
¶
ordered_elements: list[BaseDiagramElement]
Return diagram items in their order of definition.
The sequence can include C4 elements, relationships, boundaries, and backend-owned statements that affect declaration-order rendering.
relationships
property
¶
relationships: list[Relationship]
Returns all relationships defined in the diagram.
get_element_by_alias ¶
get_element_by_alias(alias: str) -> Element | None
Return the element with the given alias.
Source code in c4/diagrams/core/diagram.py
174 175 176 | |
get_elements_by_label ¶
get_elements_by_label(label: str) -> list[Element]
Return all elements that share the given label.
Source code in c4/diagrams/core/diagram.py
178 179 180 | |
generate_alias ¶
generate_alias(
label: str,
alias: str | None = None,
fallback_prefix: str | None = None,
) -> str
Generate a unique alias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Source label used to derive the alias when |
required |
alias
|
str | None
|
Optional explicit alias. If provided, it must be unique. |
None
|
fallback_prefix
|
str | None
|
Prefix to use when the label cannot produce a valid alias. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A unique alias string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If alias already exists. |
Source code in c4/diagrams/core/diagram.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
__enter__ ¶
__enter__() -> Self
Enter the diagram context.
Automatically sets this diagram as the current active diagram.
Returns:
| Type | Description |
|---|---|
Self
|
The current instance. |
Source code in c4/diagrams/core/diagram.py
82 83 84 85 86 87 88 89 90 91 92 | |
__exit__ ¶
__exit__(
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> None
Exit the diagram context and clear the current diagram.
Source code in c4/diagrams/core/diagram.py
94 95 96 97 98 99 100 101 102 103 | |
as_plantuml ¶
as_plantuml(**kwargs: Any) -> str
Render the diagram using the built-in PlantUML renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Optional keyword arguments passed to the PlantUML renderer. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The rendered PlantUML code. |
Source code in c4/diagrams/core/diagram.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
as_mermaid ¶
as_mermaid(**kwargs: Any) -> str
Render the diagram using the built-in Mermaid renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Optional keyword arguments passed to the Mermaid renderer. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The rendered Mermaid code. |
Source code in c4/diagrams/core/diagram.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
render ¶
render(
renderer: BaseRenderer[Diagram] | None = None,
) -> str
Render the diagram to a string using the given or default renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
renderer
|
BaseRenderer[Diagram] | None
|
Optional renderer to override the default. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The rendered diagram output. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no renderer is provided and no default renderer is set. |
Source code in c4/diagrams/core/diagram.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
save ¶
save(
path: str | Path,
renderer: BaseRenderer[Diagram] | None = None,
) -> None
Render and save the diagram to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Target path to save the rendered output. |
required |
renderer
|
BaseRenderer[Diagram] | None
|
Optional renderer to override the default. |
None
|
Source code in c4/diagrams/core/diagram.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
save_as_plantuml ¶
save_as_plantuml(path: str | Path, **kwargs: Any) -> None
Render and save the diagram using the PlantUML renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Target file path. |
required |
**kwargs
|
Any
|
Optional kwargs passed to the PlantUML renderer. |
{}
|
Source code in c4/diagrams/core/diagram.py
364 365 366 367 368 369 370 371 372 373 374 375 | |
save_as_mermaid ¶
save_as_mermaid(path: str | Path, **kwargs: Any) -> None
Render and save the diagram using the Mermaid renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Target file path. |
required |
**kwargs
|
Any
|
Optional kwargs passed to the Mermaid renderer. |
{}
|
Source code in c4/diagrams/core/diagram.py
377 378 379 380 381 382 383 384 385 386 387 388 | |
render_options
property
writable
¶
render_options: RenderOptions | None
Return rendering options for the diagram.
set_render_options ¶
set_render_options(
*,
plantuml: Maybe[PlantUMLRenderOptions] = MISSING,
mermaid: Maybe[MermaidRenderOptions] = MISSING,
) -> Self
Patch renderer-specific options for this diagram.
Omitted renderer keys are left unchanged. Passing None clears that
renderer's diagram-level defaults.
Source code in c4/diagrams/core/diagram.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
c4.diagrams.system_context.Person ¶
Bases: Element
Represents a person (actor) interacting with the system.
__init__ ¶
__init__(
label: Required[str] = REQUIRED,
description: str | None = None,
extensions: ElementExtensions | None = None,
plantuml: PersonExtensions | None = None,
alias: Maybe[str] = MISSING,
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
Required[str]
|
Display name for the person. Required. |
REQUIRED
|
description
|
str | None
|
Optional description text. |
None
|
extensions
|
ElementExtensions | None
|
Backend-specific extension data. |
None
|
plantuml
|
PersonExtensions | None
|
PlantUML-specific extension data. |
None
|
alias
|
Maybe[str]
|
Unique identifier for the person. If not provided, it is autogenerated from the label. |
MISSING
|
set_property_header ¶
set_property_header(*args: str) -> Self
Sets the column headers for the element's property table.
This must be called either before adding any property rows, or the header length must match the number of values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
str
|
Column names to use as the property header. |
()
|
Returns:
| Type | Description |
|---|---|
Self
|
The updated diagram element. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If header length does not match the number of values. |
without_property_header ¶
without_property_header() -> Self
Disables the rendering of the header row in the property table.
Returns:
| Type | Description |
|---|---|
Self
|
The updated diagram element. |
add_property ¶
add_property(*args: str) -> Self
Adds a row to the property table.
The number of arguments must match the number of header columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
str
|
Values for each column in the property row. |
()
|
Returns:
| Type | Description |
|---|---|
Self
|
The updated diagram element. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of values does not match the header length. |
c4.diagrams.system_context.PersonExt ¶
c4.diagrams.system_context.System ¶
Bases: Element
Represents a software system in the C4 model.
__init__ ¶
__init__(
label: Required[str] = REQUIRED,
description: str | None = None,
extensions: ElementExtensions | None = None,
plantuml: SystemExtensions | None = None,
alias: Maybe[str] = MISSING,
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
Required[str]
|
Display name for the system. Required. |
REQUIRED
|
description
|
str | None
|
Optional description for the system. |
None
|
extensions
|
ElementExtensions | None
|
Backend-specific extension data. |
None
|
plantuml
|
SystemExtensions | None
|
PlantUML-specific extension data. |
None
|
alias
|
Maybe[str]
|
Unique identifier for the system. If not provided, it is autogenerated from the label. |
MISSING
|
set_property_header ¶
set_property_header(*args: str) -> Self
Sets the column headers for the element's property table.
This must be called either before adding any property rows, or the header length must match the number of values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
str
|
Column names to use as the property header. |
()
|
Returns:
| Type | Description |
|---|---|
Self
|
The updated diagram element. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If header length does not match the number of values. |
without_property_header ¶
without_property_header() -> Self
Disables the rendering of the header row in the property table.
Returns:
| Type | Description |
|---|---|
Self
|
The updated diagram element. |
add_property ¶
add_property(*args: str) -> Self
Adds a row to the property table.
The number of arguments must match the number of header columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
str
|
Values for each column in the property row. |
()
|
Returns:
| Type | Description |
|---|---|
Self
|
The updated diagram element. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of values does not match the header length. |
c4.diagrams.system_context.SystemExt ¶
c4.diagrams.system_context.SystemDb ¶
Bases: Element
Represents a system database (storage-centric system) in the C4 model.
__init__ ¶
__init__(
label: Required[str] = REQUIRED,
description: str | None = None,
extensions: ElementExtensions | None = None,
plantuml: SystemStorageExtensions | None = None,
alias: Maybe[str] = MISSING,
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
Required[str]
|
Display name for the system database. Required. |
REQUIRED
|
description
|
str | None
|
Optional description text. |
None
|
extensions
|
ElementExtensions | None
|
Backend-specific extension data. |
None
|
plantuml
|
SystemStorageExtensions | None
|
PlantUML-specific extension data. |
None
|
alias
|
Maybe[str]
|
Unique identifier for the system database. If not provided, it is autogenerated from the label. |
MISSING
|
c4.diagrams.system_context.SystemQueue ¶
Bases: Element
Represents a message queue or streaming system in the C4 model.
__init__ ¶
__init__(
label: Required[str] = REQUIRED,
description: str | None = None,
extensions: ElementExtensions | None = None,
plantuml: SystemStorageExtensions | None = None,
alias: Maybe[str] = MISSING,
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
Required[str]
|
Display name for the system queue. Required. |
REQUIRED
|
description
|
str | None
|
Optional description text. |
None
|
extensions
|
ElementExtensions | None
|
Backend-specific extension data. |
None
|
plantuml
|
SystemStorageExtensions | None
|
PlantUML-specific extension data. |
None
|
alias
|
Maybe[str]
|
Unique identifier for the system queue. If not provided, it is autogenerated from the label. |
MISSING
|
c4.diagrams.system_context.SystemQueueExt ¶
c4.diagrams.system_context.SystemBoundary ¶
Bases: Boundary
Represents the boundary around a specific system.
Used to group containers or components that belong to a single system.
__init__ ¶
__init__(
label: Required[str] = REQUIRED,
description: str | None = None,
extensions: ElementExtensions | None = None,
plantuml: BoundaryExtensions | None = None,
mermaid: BoundaryExtensions | None = None,
alias: Maybe[str] = MISSING,
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
Required[str]
|
Display name for the boundary. Required. |
REQUIRED
|
description
|
str | None
|
Optional description. |
None
|
extensions
|
ElementExtensions | None
|
Backend-specific extension data. |
None
|
plantuml
|
BoundaryExtensions | None
|
PlantUML-specific extension data. |
None
|
mermaid
|
BoundaryExtensions | None
|
Mermaid-specific extension data. |
None
|
alias
|
Maybe[str]
|
Unique identifier for the boundary. If not provided, it is autogenerated from the label. |
MISSING
|
c4.diagrams.system_context.EnterpriseBoundary ¶
Bases: Boundary
Represents an enterprise boundary in a system landscape or context diagram.
Used to group systems and actors that belong to the same organizational unit.
__init__ ¶
__init__(
label: Required[str] = REQUIRED,
description: str | None = None,
extensions: ElementExtensions | None = None,
plantuml: BoundaryExtensions | None = None,
mermaid: BoundaryExtensions | None = None,
alias: Maybe[str] = MISSING,
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
Required[str]
|
Display name for the boundary. Required. |
REQUIRED
|
description
|
str | None
|
Optional description. |
None
|
extensions
|
ElementExtensions | None
|
Backend-specific extension data. |
None
|
plantuml
|
BoundaryExtensions | None
|
PlantUML-specific extension data. |
None
|
mermaid
|
BoundaryExtensions | None
|
Mermaid-specific extension data. |
None
|
alias
|
Maybe[str]
|
Unique identifier for the boundary. If not provided, it is autogenerated from the label. |
MISSING
|
set_property_header ¶
set_property_header(*args: str) -> Self
Sets the column headers for the element's property table.
This must be called either before adding any property rows, or the header length must match the number of values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
str
|
Column names to use as the property header. |
()
|
Returns:
| Type | Description |
|---|---|
Self
|
The updated diagram element. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If header length does not match the number of values. |
without_property_header ¶
without_property_header() -> Self
Disables the rendering of the header row in the property table.
Returns:
| Type | Description |
|---|---|
Self
|
The updated diagram element. |
add_property ¶
add_property(*args: str) -> Self
Adds a row to the property table.
The number of arguments must match the number of header columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
str
|
Values for each column in the property row. |
()
|
Returns:
| Type | Description |
|---|---|
Self
|
The updated diagram element. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of values does not match the header length. |