--- name: plantuml-diagramming description: Apply when writing or editing PlantUML (.puml, .plantuml, .pu) files or when generating diagrams from text descriptions. Covers diagram type selection, syntax conventions, modern styling, preprocessing, audience-aware abstraction levels, and common anti-patterns. Project conventions always override these defaults. --- # PlantUML Diagramming Match the project's existing conventions. When uncertain, check for existing `.puml` files to infer the local style -- naming, layout direction, theme usage, and abstraction level. Check for shared includes (`!include`) or a project theme file. These defaults apply only when the project has no established convention. ## Never rules These are unconditional. They prevent broken or unreadable diagrams regardless of project style. - **Never omit `@startuml`/`@enduml` delimiters** -- PlantUML silently fails or produces garbage without them. Every `.puml` file must start with `@startuml` and end with `@enduml` (or the equivalent for the diagram type: `@startmindmap`/`@endmindmap`, `@startgantt`/`@endgantt`, etc.). - **Never use cryptic abbreviations or internal codenames as labels** -- use plain English that any team member understands. `AuthSvc` means nothing to a product manager; `Authentication Service` does. Labels are for humans, not compilers. - **Never create diagrams with more than ~15 elements without grouping/nesting** -- overcrowded diagrams defeat the purpose. Use `package`, `rectangle`, `node`, `cloud`, or `together` to group related elements. If you cannot group meaningfully, split into multiple diagrams. - **Never use legacy `skinparam` when ` actor Customer participant "Order Service" as OS ... @enduml ``` ### Built-in themes PlantUML ships with themes. Use `!theme` to apply one: ```plantuml @startuml !theme cerulean title Themed Diagram ... @enduml ``` Common themes: `cerulean`, `plain`, `sketchy-outline`, `aws-orange`, `mars`, `minty`. Preview themes before committing to one. ### Color formats - Named colors: `Red`, `LightBlue`, `DarkGreen` - Hex: `#FF5733`, `#2196F3` - Gradients: `#White/#LightBlue` (top to bottom) ### Layout direction Default is top-to-bottom. For wide diagrams with many horizontal relationships: ```plantuml left to right direction ``` Add this immediately after `@startuml` (before any elements). ## Preprocessing ### !include Split large diagrams or share common definitions across files: ```plantuml !include common/styles.puml !include common/actors.puml ``` Use relative paths. Keep shared definitions (themes, common participants, standard styles) in a `common/` or `shared/` directory. ### !procedure Reusable diagram fragments: ```plantuml !procedure $service($name, $alias) participant "$name" as $alias !endprocedure $service("Order Service", OS) $service("Payment Service", PS) ``` ### !function Reusable computed values: ```plantuml !function $endpoint($service, $path) !return $service + " " + $path !endfunction ``` ### Variables ```plantuml !$primary_color = "#1565C0" !$secondary_color = "#2E7D32" ``` ### Conditionals and loops ```plantuml !if (%getenv("DETAIL_LEVEL") == "high") class Order { - id: UUID - status: OrderStatus + addItem(product: Product, qty: int) } !else rectangle "Order Service" !endif !$i = 0 !while ($i < 3) node "Worker $i" !$i = $i + 1 !endwhile ``` ## Anti-patterns - **Overcrowded diagrams without grouping** -- more than ~15 ungrouped elements makes the diagram unreadable. Split or group. - **Technical jargon in business-level diagrams** -- `POST /api/v2/orders` belongs in API docs, not in a diagram for stakeholders. Use "Creates order" instead. - **Mixing styling approaches** -- combining inline colors (`#Red`), `skinparam`, and `