Knowledge
Search knowledge... ⌘K
Knowledge · Guidelines · go
Go Yaml To Mermaid Diagram
Generate Mermaid diagrams from YAML model files using raw map parsing and DSL string building
Metadata
go go
Description
Pattern for reading YAML model files (package.yml, entity.yml) and
auto-generating Mermaid diagram DSL. Two diagram types:
1. Class diagrams — from exports.types + exports.functions
- Types become class boxes with description annotations
- Functions assigned as methods via TypeName.MethodName prefix matching
- Standalone functions grouped into a utility class
- Dependencies rendered as dotted dependency arrows
2. Sequence diagrams — from user_stories BDD scenarios
- Actor from actor_ref, participants from package name (UI/API/SVC)
- Step routing by verb detection (Click/Navigate → UI, Call/Invoke → API)
- HTTP method extraction from expected text (GET/POST/PUT/DELETE)
- Service method resolution from affected_layers.md
- Postconditions as Mermaid notes
Key design decisions:
- Raw map[string]interface{} parsing avoids struct coupling to YAML schema
- sanitizeMermaid() escapes characters that break Mermaid syntax
- String truncation prevents oversized labels
- Only first scenario per story generates a diagram (multiple scenarios = multiple stories)