excalidraw-generator
npx skills add https://github.com/lexiaoyao20/excalidraw-generator --skill excalidraw-generator
Agent 安装分布
Skill 文档
Excalidraw Diagram Generator
Overview
This skill enables you to generate complete, valid .excalidraw files that users can directly open at excalidraw.com. You act as a professional diagram generation expert, creating beautiful, well-structured diagrams from user descriptions with automatic layout calculation and saving them as ready-to-use files.
Supports two visual styles:
- ä¸ä¸æ¨¡å¼ (Professional Mode): Clean, polished diagrams for technical documentation (default)
- æç»æ¨¡å¼ (Hand-drawn Mode): Sketch-style diagrams for brainstorming and informal use
Core Capabilities
You can generate these diagram types:
- Flowcharts – Process flows, decision trees, workflows
- Architecture Diagrams – System architectures, network topologies, component diagrams
- UML Diagrams – Class diagrams, sequence diagrams, use case diagrams
- Mind Maps – Hierarchical concept maps, brainstorming diagrams
Quick Start
When a user requests a diagram:
- Understand the request – Identify the diagram type and key content
- Choose style – Use ä¸ä¸æ¨¡å¼ (Professional Mode) by default; switch to hand-drawn mode only if user requests it
- Choose a template – Start from the relevant template in
assets/ - Modify elements – Adjust text, positions, colors based on requirements
- Calculate layout – Use spacing guidelines from
references/excalidraw-format.md - Save to file – Write the complete JSON to a
.excalidrawfile
Workflow
Step 1: Identify Diagram Type
Match the user’s request to a diagram type:
- Flowchart: Process flows, algorithms, decision trees, workflows
- Architecture: System designs, microservices, cloud infrastructure, databases
- UML Class: Object-oriented design, class hierarchies, relationships
- Mind Map: Brainstorming, concept hierarchies, topic exploration
Step 2: Use Templates as Foundation
Templates are located in assets/ directory:
flowchart-template.json– Start â Process â Decision flowarchitecture-template.json– Frontend â Backend â Database architectureuml-class-template.json– Class with attributes and methodsmindmap-template.json– Central topic with three branches
Template usage:
- Read the appropriate template file
- Modify element IDs, text, positions, and colors
- Add or remove elements as needed
- Ensure all IDs are unique
Step 3: Generate Elements
For detailed element specifications, consult references/excalidraw-format.md.
Key element types:
rectangle– Boxes, containers, processesellipse– Start/end nodes, databases, emphasisdiamond– Decisions, conditional branchesarrow/line– Connections, flows, relationshipstext– Labels, descriptions
Essential properties all elements need:
{
"id": "unique-id",
"type": "rectangle|ellipse|diamond|arrow|text",
"x": 100,
"y": 100,
"width": 150,
"height": 80,
"strokeColor": "#1e1e1e",
"backgroundColor": "#a5d8ff",
"fillStyle": "solid",
"strokeWidth": 2,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"angle": 0,
"groupIds": [],
"frameId": null,
"roundness": { "type": 3 },
"boundElements": [],
"updated": 1705276800000,
"link": null,
"locked": false,
"versionNonce": 123456789,
"isDeleted": false,
"seed": 987654321
}
Step 4: Calculate Layout Automatically
Spacing guidelines:
- Minimum spacing between elements: 80-100px
- Vertical flow gap (parent â child): 120px
- Horizontal spacing (siblings): 150px
- Arrow padding from element edge: 10-20px
Standard sizes:
- Small boxes: 120Ã60
- Medium boxes: 150Ã80
- Large boxes: 200Ã100
Text height calculation (CRITICAL):
textHeight = fontSize à lineHeight à numberOfLines
= fontSize à 1.25 à numberOfLines
Example:
- 1 line, fontSize 20: height = 20 Ã 1.25 Ã 1 = 25px
- 3 lines, fontSize 14: height = 14 Ã 1.25 Ã 3 = 52.5px â 53px
- 12 lines, fontSize 15: height = 15 Ã 1.25 Ã 12 = 225px
UML Class Diagram container height calculation:
containerHeight = headerHeight + dividerHeight + attributesHeight + dividerHeight + methodsHeight + padding
Where:
- headerHeight = classNameTextHeight + topPadding (typically 15px + 15px = 30px)
- dividerHeight = 0 (line element, but reserve ~10px visual space after)
- attributesHeight = fontSize à 1.25 à numberOfAttributes + 10px (bottom padding)
- methodsHeight = fontSize à 1.25 à numberOfMethods + 10px (bottom padding)
- topPadding: 15px above class name
- bottomPadding: 10px below each section
Example for a class with 12 attributes and 10 methods (fontSize 15):
- headerHeight: 20 + 15 = 35px
- attributesHeight: 15 Ã 1.25 Ã 12 + 10 = 225 + 10 = 235px
- methodsHeight: 15 Ã 1.25 Ã 10 + 10 = 187.5 + 10 â 198px
- Total: 35 + 10 + 235 + 10 + 198 = 488px (round to 500px for safety)
Layout strategies:
- Flowcharts: Top-to-bottom, centered alignment
- Architecture: Left-to-right for flow, grouped by layer
- UML Class: Use calculation formula above; ensure text doesn’t overflow container
- Mind Maps: Radial from center, balanced branches
Step 5: Style and Polish
Choose a diagram style based on context:
ä¸ä¸æ¨¡å¼ (Professional Mode) – æ¨èç¨äºææ¯ææ¡£
éç¨åºæ¯ï¼ æ¶æå¾ãUML å¾ãææ¯ææ¡£ãæ£å¼æ¼ç¤º
æ ·å¼åæ°ï¼
roughness: 0– å®å ¨å¹³æ»ï¼æ æç»ææfillStyle: "solid"– 纯è²å¡«å ï¼æåæ´æè¯»strokeWidth: 2– æ å线宽fontFamily: 2– æ£å¸¸åä½ï¼éæç»ï¼- é¢è²ä½¿ç¨æ·¡è²èæ¯ ä»¥æé«å¯è¯»æ§ï¼
- Primary:
#e7f5ff(æµ è) - Success:
#ebfbee(æµ ç»¿) - Warning:
#fff9db(æµ é») - Accent:
#f3f0ff(æµ ç´«) - Secondary:
#fff4e6(æµ æ©)
- Primary:
使¶ä½¿ç¨ï¼ é»è®¤æ¨¡å¼ï¼é¤éç¨æ·æç¡®è¦æ±æç»é£æ ¼
æç»æ¨¡å¼ (Hand-drawn Mode)
éç¨åºæ¯ï¼ åæå¤´è飿´ãå¿«éèå¾ã鿣å¼å享
æ ·å¼åæ°ï¼
roughness: 1– æç»é£æ ¼ææfillStyle: "hachure"– æçº¿çº¹çå¡«åstrokeWidth: 2– æ å线宽fontFamily: 1– æç»åä½- é¢è²ä½¿ç¨ä¸ç饱å度ï¼
- Primary:
#a5d8ff(è) - Success:
#b2f2bb(绿) - Warning:
#ffec99(é») - Error:
#ffc9c9(红) - Accent:
#d0bfff(ç´«) - Secondary:
#ffd8a8(æ©)
- Primary:
使¶ä½¿ç¨ï¼ ç¨æ·æç¡®è¦æ±”æç»é£æ ¼”ã”sketch”ã”casual” æ¶
éç¨æ ·å¼å»ºè®®ï¼
- Stroke color:
#1e1e1e(æ·±ç°ï¼æ¯çº¯é»æå) - ç®å¤´æ ç¾ä½¿ç¨å¯¹æ¯è²ï¼ç¡®ä¿å¯è¯»æ§
- ä¿æç»ä»¶é´è·ä¸è´ï¼80-100pxï¼
Step 6: Save to File
Always save the diagram directly as a .excalidraw file instead of showing JSON in a code block.
- Use the Write tool to save the complete JSON to a file
- Name the file descriptively (e.g.,
user-login-flow.excalidraw,system-architecture.excalidraw) - Save to the current working directory unless user specifies otherwise
After saving the file, provide:
- Confirmation message with the file path
- Brief description of the diagram structure
- Instructions: “Open the file at excalidraw.com using ‘Open’ â ‘Open from your computer’, or drag and drop the file into the browser”
- Any customization suggestions
Common Patterns
Pattern 1: Sequential Flow
For processes with steps A â B â C:
- Place elements vertically with 120px gaps
- Use rectangles for processes, ellipses for start/end
- Connect with arrows (type: “arrow”, endArrowhead: “arrow”)
- Center-align all elements
Pattern 2: Decision Tree
For conditional branches:
- Use diamond for decision nodes
- Branch arrows left/right or up/down
- Add text labels on arrows (“Yes”, “No”, “Success”, “Fail”)
- Rejoin paths when appropriate
Pattern 3: Hierarchical Structure
For layered architectures:
- Group elements by layer (horizontal rows)
- Use different colors per layer
- Vertical arrows show dependencies
- Maintain consistent element sizes within layers
Pattern 4: Radial Mind Map
For concept exploration:
- Central node (ellipse) in the middle
- Branch lines (type: “line”) radiate outward
- Use different colors for each main branch
- Rectangles for sub-topics
Tips for Quality Diagrams
- Unique IDs: Generate random 8-16 character IDs for each element
- Consistent spacing: Follow the spacing guidelines strictly
- Color harmony: Use the recommended color palette
- Text sizing: Match text width to container width with padding
- Arrow connections: Position arrow start/end points precisely
- Version numbers: Use random integers for versionNonce and seed
Handling Complex Requests
For large or complex diagrams:
- Start simple: Create core structure first
- Iterate: Add details progressively
- Group logically: Use visual grouping (colors, spacing)
- Limit complexity: Suggest breaking into multiple diagrams if needed
- Maintain readability: Ensure text doesn’t overlap, adequate spacing
Reference Material
- Complete format specification: See
references/excalidraw-format.md- Full element property reference
- All element types and their specific properties
- Color palette recommendations
- Detailed layout guidelines
Resources
assets/
Contains starter templates for common diagram types:
flowchart-template.json– Basic flowchart structurearchitecture-template.json– System architecture patternuml-class-template.json– UML class diagram formatmindmap-template.json– Mind map layout
references/
excalidraw-format.md– Complete Excalidraw JSON format specification, element types, properties, and examples