SuperAPI AI Directory

flowchart-generator

Security & auditing

View repository

Updated 10-16 01:38

About this skill

Flowchart Generator Skill

Creator: nigo | WeChat Official Account: 逆行的狗

A professional internal control and audit flowchart generation tool, used to convert business process descriptions into standard swimlane flowcharts.

Applicable Scenarios

Activate when users encounter the following needs:

  • Audit and finance fields: Draw fund processes, procurement processes, reimbursement processes, approval processes
  • Internal control documents: Business process diagrams, control activity diagrams, SOP flowcharts
  • System design: Business process analysis, data flow diagrams, system integration diagrams
  • Process standardization: Visualization of oral/textual descriptions

Trigger Keywords:

  • Flowchart, swimlane diagram, approval process, reimbursement process, procurement process
  • Drawing, visualization, drawing processes, generating charts
  • Internal control, SOP, workflow, business process
  • draw.io, process documentation, process design

Core Features

1. Flowchart Generation

Automatically generate standard swimlane flowcharts, including:

  • Swimlane division: Automatically group by responsible department/role
  • Node types: Processing nodes, decision nodes, start/end
  • Connector labels: Branch conditions (yes/no), process paths
  • Output documents: Automatically label documents/vouchers produced by nodes

Built-in Themes:

  • "Internal Control Setup" theme: light blue title bar + white background with black border + red start/end
  • Supports custom styles and themes

2. Node Data Structure

The engine receives structured node data in the following format:

nodes_data = [
    {
        "id": "1",                       # 唯一标识
        "step": "提交付款申请\n(附单据)", # 步骤描述(\n 换行)
        "type": "process",               # process=矩形 | decision=菱形
        "swimlane_role": "采购部",        # 泳道(部门名)
        "node_role": "采购经办",          # 节点内角色标签
        "output_docs": "请款单",          # 输出文档(可选)
        "next_steps": [                  # 下游节点
            {"id": "2", "condition": ""}  # condition 空=普通流转
        ]
    },
    {
        "id": "2",
        "step": "金额>2000?",
        "type": "decision",
        "swimlane_role": "财务部",
        "node_role": "财务经理",
        "output_docs": "",
        "next_steps": [
            {"id": "3", "condition": "是"},
            {"id": "4", "condition": "否"}
        ]
    },
    {
        "id": "5",
        "step": "登记账簿",
        "type": "process",
        "swimlane_role": "财务部",
        "node_role": "会计",
        "output_docs": "",
        "next_steps": []  # 空列表=流程终点
    }
]

Parsing Rules:

  • Swimlanes: Extract department names from the description (Finance Department, Procurement Department, General Manager, etc.)
  • Decision nodes: Contain keywords such as "whether/judge/greater than/match"
  • Start/end: Automatically generated, no need to add manually
  • Branch conditions: Decision nodes must be labeled with conditions (yes/no, etc.)

3. Output Formats

  • .drawio: Editable XML format, supports subsequent modifications
  • .png: High-definition image, scale=2.0 is the recommended value
  • .svg: Vector graphic, lossless scaling
  • .vsdx: Visio format, requires draw.io v26.0.16 (see notes below)

4. Style Customization

from engine import StyleManager

sm = StyleManager(theme_name="governance")

# 临时覆盖样式(不影响主题文件)
sm.override({
    'colors': {
        'decision': {'fill': '#FFA500'}  # 判断节点橙色
    },
    'edges': {
        'dashed_for_negative': True  # 否分支虚线
    }
})

5. Theme Management

# 列出所有主题
sm.list_themes()

# 查看主题详情
sm.get_theme_info("governance")

# 保存自定义主题
sm.save_as_theme(
    name="我的主题",
    description="橙色判断节点,虚线否分支"
)

# 加载自定义主题
sm.load_theme("我的主题")

Workflow

用户描述 → AI 解析为节点数据 → 选择导出格式 → 引擎生成 .drawio → 渲染导出

Format Selection:

  • .drawio: Editable source file (always generated)
  • .png: High-definition image (optional)
  • .svg: Vector graphic (optional)
  • .vsdx: Visio format (optional, requires a compatible version)

Default format: .drawio + .png (if the user has not selected any format)

Quick Start

Interaction Flow

  1. Parse user description: Convert natural language into structured node data
  2. Format selection: Ask the user which formats they need to export (multiple selections allowed)
  3. Generate flowchart: Generate a .drawio file
  4. Export and render: Export the corresponding format based on the user's selection

Format selection interaction

Before generating the flowchart, use the question tool to ask the user:

请选择要导出的格式:
- ✓ .drawio(可编辑源文件,始终生成)
- □ .png(高清图片)
- □ .svg(矢量图)
- □ .vsdx(Visio格式)

Default behavior: If the user does not select or cancels, export .drawio and .png by default.

Notes:

  • .drawio is always generated (editable source file)
  • .vsdx requires draw.io v26.0.16 or lower
  • Selecting multiple formats will export them one by one

Complete example

import sys
sys.path.insert(0, "/path/to/flowchart-generator")
from engine import StyleManager, FlowchartBuilder, Renderer
from pathlib import Path

# 1. 定义流程节点
nodes_data = [
    {"id": "1", "step": "提交申请", "type": "process",
     "swimlane_role": "部门A", "node_role": "申请人",
     "output_docs": "申请单", "next_steps": [{"id": "2", "condition": ""}]},
    {"id": "2", "step": "部门经理审批", "type": "process",
     "swimlane_role": "部门A", "node_role": "部门经理",
     "output_docs": "", "next_steps": [{"id": "3", "condition": ""}]},
    {"id": "3", "step": "财务审核", "type": "process",
     "swimlane_role": "财务部", "node_role": "财务",
     "output_docs": "", "next_steps": [{"id": "4", "condition": ""}]},
    {"id": "4", "step": "出纳付款", "type": "process",
     "swimlane_role": "财务部", "node_role": "出纳",
     "output_docs": "付款凭证", "next_steps": []},
]

# 2. 格式选择(默认导出 .drawio + .png)
# 实际使用时由 AI 调用 question 工具询问用户
export_formats = ['png']  # 用户选择导出 PNG

# 3. 生成 .drawio(始终生成)
sm = StyleManager(theme_name="governance")
builder = FlowchartBuilder(style_manager=sm, sheet_name="费用报销流程", nodes_data=nodes_data)
xml = builder.generate_xml_content()
drawio_path = Path("费用报销.drawio")
drawio_path.write_text(xml, encoding="utf-8")

# 4. 根据用户选择导出对应格式
renderer = Renderer()

if 'png' in export_formats:
    renderer.export_to_png(drawio_path, Path("费用报销.png"), scale=2.0)

if 'svg' in export_formats:
    renderer.export_to_svg(drawio_path, Path("费用报销.svg"))

if 'vsdx' in export_formats:
    # VSDX 需要 draw.io v26.0.16 或更低版本
    renderer.export_to_vsdx(drawio_path, Path("费用报销.vsdx"), auto_install=True)

print(f"✓ 已生成 .drawio(始终生成)")
if export_formats:
    print(f"✓ 已导出: {', '.join(export_formats)}")
else:
    print("✓ 使用默认格式: .drawio + .png")

Visio (VSDX) export instructions

Important: After draw.io v26.2.2, the official VSDX export feature has been removed.

Automatic installation (recommended)

Intelligently detect the version, and if incompatible, automatically install v26.0.16:

renderer.export_to_vsdx(
    Path("费用报销.drawio"),
    Path("费用报销.vsdx"),
    auto_install=True  # 自动安装兼容版本
)

Interaction process:

  1. Detect the current draw.io version
  2. If VSDX is supported, export directly
  3. If not supported, ask the user: "The current version is detected to not support VSDX export. Do you want to automatically install draw.io v26.0.16 (the last version that supports VSDX)? [y/n]"
  4. After the user confirms, automatically download and install
  5. After export is complete, disable automatic updates to prevent version upgrades

Supported platforms:

  • ✅ macOS (Intel + Apple Silicon)
  • ✅ Windows (x64)
  • ✅ Linux (x64 + ARM64)

Manual installation

If you need to manually control the installation process:

macOS:

Windows:

Linux:

Configuration after manual installation:

# 禁用自动更新
import os
import json

config_path = Path.home() / "Library" / "Application Support" / "draw.io" / ".preferences"  # macOS
# Windows: Path(os.environ['APPDATA']) / 'draw.io' / '.preferences'
# Linux: Path.home() / '.config' / 'draw.io' / '.preferences'

config = {
    "checkForUpdates": False,
    "disableUpdate": True
}
with open(config_path, 'w') as f:
    json.dump(config, f)

VSDX export fallback strategy

If the user does not need VSDX export, you can:

  • Skip export_to_vsdx call
  • Use the latest version of draw.io (better PNG/SVG results)
  • Use the online version app.diagrams.net to manually export VSDX

Error handling

Common issues

  1. draw.io is not installed

  2. VSDX export failed

    • Error: "The exported file is not a valid VSDX format"
    • Cause: An unsupported draw.io version was used
    • Solution: Set auto_install=True or manually install v26.0.16
  3. Node data validation failed

    • Error: "Data validation warning"
    • Cause: Missing required fields or format errors
    • Solution: Check whether id, step, type, swimlane_role, and node_role are complete
  4. Export timeout

    • Error: "draw.io export timeout"
    • Cause: The flowchart is too complex or draw.io responds slowly
    • Solution: Increase the timeout parameter (default 60 seconds)

Robustness design

Platform compatibility

  • Automatically detect the operating system (Windows/macOS/Linux)
  • Automatically identify the architecture (x86/ARM)
  • Automatically find the draw.io installation path
  • Support multiple draw.io versions coexisting

Boundary handling

  • Duplicate node IDs: automatically deduplicate
  • Incorrect node order: automatically fix dependencies
  • Empty flowchart: generate a minimal usable placeholder diagram
  • Long text: automatic line wrapping or truncation
  • Chinese paths: fully supported

Version compatibility

  • VSDX export: automatically detects the version and provides a solution
  • Style compatibility: new version styles can be downgraded for compatibility
  • Theme compatibility: custom themes are compatible with built-in themes

Extensibility

Custom themes

# 保存新主题
sm.save_as_theme(
    name="审计专用",
    description="深色主题,高对比度"
)

# 加载自定义主题
sm2 = StyleManager(theme_name="审计专用")

Extend node types

To add new node types (such as subprocess, call, parallel node), you need to modify the style builder and XML generation logic in flowchart_builder.py .

Custom layout parameters

# 调整间距和尺寸
sm.override({
    'layout': {
        'y_gap': 60,  # 行间距
        'node_width': 140,  # 节点宽度
        'swimlane_width': 300  # 泳道宽度
    }
})

AI invocation process

When the user describes a business process, execute the following steps:

  1. Parse the user description, extract node data (see above for the node data structure)
  2. Call the question toolQuery format:
    question(questions=[{
        "question": "请选择要导出的格式(.drawio始终生成):",
        "header": "格式选择",
        "options": [
            {"label": ".png(高清图片)", "description": "适合插入文档,高分辨率"},
            {"label": ".svg(矢量图)", "description": "无损缩放,适合网页和打印"},
            {"label": ".vsdx(Visio格式)", "description": "需 draw.io v26.0.16,兼容 Visio 2013+"}
        ],
        "multiple": True
    }])
    
  3. Based on the user's selectionexecute the export (.drawio is always generated)
  4. After generation, read the PNG imageCheck the layout, confirm there are no issues such as collisions or out-of-bounds

Technical architecture

See references/architecture.md:

  • Engine module structure
  • Detailed explanation of the layout algorithm
  • Style system mechanism
  • Error handling strategy
  • Performance optimization suggestions

Notes

  • The built-in "Internal Control Setup" theme aligns with mainstream internal control manual specifications
  • VSDX is a Beta feature and may have compatibility issues
  • After export, please open and test it in Visio 2013+
  • Automatic installation will disable draw.io's automatic updates
  • If you encounter format errors, try simplifying the flowchart and exporting again