Specification
Specifies the purpose, input/output formats, algorithms, and limitations of a tool that converts Excalidraw JSON to PlantUML diagrams.
What this file does
Specifies the purpose, input/output formats, algorithms, and limitations of a tool that converts Excalidraw JSON to PlantUML diagrams.
When to use it
- Understand the conversion pipeline before contributing code
- Evaluate whether the tool fits your diagramming workflow
- Review algorithm trade-offs for spatial relationship detection
- Plan error handling or edge case coverage
Assumes this stack
Specification
This document describes what diacea does, its use cases, input/output formats, algorithms, and limitations.
Purpose
diacea converts Excalidraw JSON exports to PlantUML diagrams, enabling:
- Version control of diagrams as text files
- Automated diagram generation
- Integration with documentation pipelines
- Conversion between visual and text-based diagram formats
High-Level Use Cases
Use Case 1: Convert Simple Excalidraw Diagram to PlantUML
Input: Excalidraw JSON with rectangles, text labels, and arrows
Process:
- Parse Excalidraw JSON structure
- Convert absolute coordinates to relative relationships
- Generate PlantUML syntax
Output: PlantUML .puml file
Example:
- Input: Excalidraw diagram with nested rectangles and connecting arrows
- Output: PlantUML diagram with container relationships and connections
Use Case 2: Generate C4 Architecture Diagrams
Input: Excalidraw diagram with system boundaries, containers, and people
Process:
- Detect system boundaries (large rectangles or specific text patterns)
- Identify containers within boundaries
- Map people (diamond shapes) to Person elements
- Generate C4-PlantUML format
Output: C4-PlantUML diagram
Example:
- Input: Excalidraw diagram showing AWS Cloud, EKS cluster, and services
- Output: C4 Component diagram with System_Boundary, Container, and Person elements
Use Case 3: Batch Conversion
Input: Multiple Excalidraw JSON files
Process: Process each file through the conversion pipeline
Output: Multiple PlantUML files
Input Format
Excalidraw JSON Structure
{
"type": "excalidraw/clipboard",
"elements": [
{
"id": "unique-id",
"type": "rectangle" | "text" | "arrow" | "ellipse" | "diamond",
"x": 0.0,
"y": 0.0,
"width": 100.0,
"height": 100.0,
"text": "Label text",
"points": [[x1, y1], [x2, y2]], // For arrows
"boundElements": [...],
"startBinding": {...},
"endBinding": {...},
...
}
],
"files": {}
}
Key Element Types
- rectangle: Boxes, containers, system boundaries
- text: Labels, standalone text elements
- arrow: Connections between elements
- ellipse: Often used for databases
- diamond: Often used for people/users
Output Format
Relative Format (Current)
The Python algorithms currently output a relative format:
[
{
"id": "rect-id",
"type": "rectangle",
"label": "Container Name",
"parent": "parent-rect-id" # Empty string if no parent
},
{
"id": "arrow-id",
"type": "arrow",
"label": "",
"from": "source-id",
"to": "target-id"
}
]
PlantUML Format (Planned)
@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Component.puml
LAYOUT_WITH_LEGEND()
System_Boundary(Element_abc123, "System Name") {
Container(Element_def456, "Container Name")
}
Rel(Element_def456, Element_ghi789, "Label")
@enduml
Algorithms
1. Imperative Approach (convert_to_relative)
Strategy: Sequential processing with explicit loops
Steps:
- Sort rectangles by area (largest first)
- For each rectangle:
- Find contained text for label
- Find smallest containing rectangle for parent
- For each arrow:
- Find nearest rectangles to start/end points
- Create relationship
Complexity: O(n²) for rectangle containment checks
Best For: Simple diagrams, easy to understand
2. Rule-Based Approach (rule_based_approach)
Strategy: Apply rules in order
Similar to: Imperative but with clearer rule separation
Best For: When rules need to be easily modifiable
3. CSP Solver (csp_solver)
Strategy: Constraint Satisfaction Problem formulation
Constraints:
- Each text label can only be used once
- Parent must be a containing rectangle
- All rectangles must have valid parents
Best For: Complex diagrams with ambiguous relationships
Limitations: May not find solutions for all inputs
4. QuadTree Approach (quadtree_approach)
Strategy: Spatial indexing with QuadTree
Steps:
- Build QuadTree from all elements
- Query QuadTree for spatial relationships
- Process rectangles and arrows using spatial queries
Complexity: O(n log n) average case
Best For: Large diagrams with many elements
5. Graph-Based Approach (graph_based_approach)
Strategy: NetworkX directed graph representation
Steps:
- Create graph with all elements as nodes
- Add edges for containment relationships
- Add edges for text containment
- Add edges for arrows
- Generate output from graph structure
Best For: Complex relationships, graph analysis
Advantages: Can leverage graph algorithms for analysis
Error Handling
Current Limitations
- No Input Validation: Assumes valid Excalidraw JSON structure
- No Error Messages: Fails silently or with Python exceptions
- Missing Elements: May fail if required fields are missing
- Invalid Coordinates: No bounds checking
Planned Error Handling
- JSON Validation: Verify Excalidraw JSON structure
- Element Validation: Check required fields for each element type
- Coordinate Validation: Ensure coordinates are within reasonable bounds
- Clear Error Messages: User-friendly error messages with context
- Graceful Degradation: Continue processing when possible, report issues
Known Limitations
Spatial Detection
- Overlapping Rectangles: May incorrectly identify parent-child relationships
- Arrow Endpoints: May not correctly identify target if arrow doesn't bind to element
- Text Positioning: Text must be clearly within rectangle bounds
- Nested Boundaries: Deep nesting may not be detected correctly
Element Support
- Limited Shapes: Currently focuses on rectangles, arrows, and text
- No Images: Image elements are not supported
- No Groups: Grouped elements are not handled specially
- No Frames: Frame elements are ignored
Output Format
- No PlantUML Generation: Currently only outputs relative format
- No C4 Support: C4-PlantUML format not yet implemented in Python
- No Styling: Visual styling from Excalidraw is lost
- No Layout: PlantUML layout is auto-generated, not preserved from Excalidraw
Edge Cases
Case 1: Empty Diagram
Input: Excalidraw JSON with no elements
Expected: Empty relative format array []
Status: Should be handled gracefully
Case 2: Orphaned Text
Input: Text element not contained in any rectangle
Expected: Text is ignored or becomes a note
Status: Currently ignored in relative format
Case 3: Arrow Without Binding
Input: Arrow with no startBinding or endBinding
Expected: Use point coordinates to find nearest elements
Status: Handled by find_nearest_rectangle() function
Case 4: Multiple Text Elements in Rectangle
Input: Rectangle containing multiple text elements
Expected: Use first text found or largest text
Status: Currently uses first text found
Case 5: Circular Containment
Input: Rectangles that contain each other (shouldn't happen but possible)
Expected: Detect and report error, or use size to determine hierarchy
Status: Not currently detected
Case 6: Arrow to Text Element
Input: Arrow pointing to a text element instead of rectangle
Expected: Find rectangle containing the text, or skip the relationship
Status: Currently may create invalid relationships
Performance Considerations
- Small Diagrams (< 50 elements): All algorithms perform well
- Medium Diagrams (50-200 elements): Graph-based and QuadTree approaches preferred
- Large Diagrams (> 200 elements): QuadTree or optimized graph approach recommended
Future Enhancements
- Bidirectional Conversion: PlantUML to Excalidraw
- Additional Formats: Mermaid, Graphviz, etc.
- Layout Preservation: Maintain visual layout in text format
- Styling Support: Preserve colors, line styles, etc.
- Interactive Mode: Preview conversion before saving
- Batch Processing: Convert multiple files at once
- Validation Mode: Check diagram validity without conversion
What's inside
10 sections covering purpose, 3 use cases, input/output formats, 5 algorithms, error handling, limitations, 6 edge cases, performance, and future enhancements.
Change this for your project
- Replace
KyleKing/diaceawith your own repository name - Replace
https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Component.pumlwith your PlantUML include URL - Replace
convert_to_relativewith your actual function name if different
Where it goes
Keep in docs/ or alongside the feature. Agents read it to implement against a defined contract.
Worth borrowing
- Documenting multiple algorithmic approaches with trade-offs for the same problem
- Structuring edge cases as explicit test scenarios with expected behavior and status
- Separating current limitations from planned improvements to guide roadmap
Related Documents
GPU Selection Guide for Large Language Models (LLMs)
Guides GPU selection for LLM inference, fine-tuning, and training by mapping model sizes, precision levels, and budgets to VRAM requirements.
Community AI Agent Skills Discovery Sources
Catalogs 50+ platforms, repositories, directories, and communities for discovering and sharing AI agent skills across multiple coding tools.
ReleaseKit - Technical Requirements Document
Specifies a Go library and CLI for release automation with conventional commit parsing, validation checks, and workflow orchestration.
api_llm Specification
Defines a workspace of thin HTTP API clients for major LLM providers with no abstraction layer and explicit developer control.