a
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
---
|
||||
name: architecture-diagram
|
||||
description: Generate beautiful dark-themed system architecture diagrams as standalone HTML/SVG files. ⚠️ IMPORTANT - This skill consumes AI tokens and should ONLY be used when explicitly requested. For most diagram needs, use Mermaid syntax or ASCII art instead (no token cost).
|
||||
---
|
||||
|
||||
# Architecture Diagram Generator
|
||||
|
||||
生成精美的深色主题系统架构图(独立 HTML/SVG 文件)。
|
||||
|
||||
## ⚠️ 使用警告
|
||||
|
||||
**本 skill 消耗 AI token(DeepSeek/Moonshot),除非明确要求,否则不要使用。**
|
||||
|
||||
### 优先使用以下免费方式:
|
||||
|
||||
1. **Mermaid 文本**(推荐)
|
||||
```markdown
|
||||
```mermaid
|
||||
flowchart TD
|
||||
A[前端] --> B[后端]
|
||||
B --> C[(数据库)]
|
||||
```
|
||||
```
|
||||
|
||||
2. **ASCII 艺术**(极简场景)
|
||||
```
|
||||
+--------+ +--------+ +--------+
|
||||
| 前端 | --> | 后端 | --> | 数据库 |
|
||||
+--------+ +--------+ +--------+
|
||||
```
|
||||
|
||||
### 何时使用本 skill:
|
||||
|
||||
- ✅ 明确要求"精美架构图"、"专业可视化"、"深色主题"
|
||||
- ✅ 需要导出独立 HTML 文件(给客户展示)
|
||||
- ✅ 需要截图用于小红书/公众号/技术分享
|
||||
- ✅ 复杂架构,Mermaid/ASCII 无法表达
|
||||
|
||||
## 工作方式
|
||||
|
||||
1. 接收用户描述(系统组件、关系、类型)
|
||||
2. 调用 AI API(DeepSeek/Moonshot)生成 SVG 代码
|
||||
3. 嵌入模板生成独立 HTML 文件
|
||||
4. 返回文件路径
|
||||
|
||||
## 设计系统
|
||||
|
||||
### 配色方案
|
||||
|
||||
| 组件类型 | 填充色 | 边框色 |
|
||||
|---------|--------|--------|
|
||||
| 前端 | `rgba(8, 51, 68, 0.4)` | `#22d3ee` (青色) |
|
||||
| 后端 | `rgba(6, 78, 59, 0.4)` | `#34d399` (绿色) |
|
||||
| 数据库 | `rgba(76, 29, 149, 0.4)` | `#a78bfa` (紫色) |
|
||||
| 云服务 | `rgba(120, 53, 15, 0.3)` | `#fbbf24` (琥珀色) |
|
||||
| 安全 | `rgba(136, 19, 55, 0.4)` | `#fb7185` (玫瑰色) |
|
||||
| 消息队列 | `rgba(251, 146, 60, 0.3)` | `#fb923c` (橙色) |
|
||||
| 通用/外部 | `rgba(30, 41, 59, 0.5)` | `#94a3b8` (灰色) |
|
||||
|
||||
### 视觉规范
|
||||
|
||||
- **背景**: `#020617` (深蓝黑) + 网格图案
|
||||
- **字体**: JetBrains Mono (技术感等宽字体)
|
||||
- **组件**: 圆角矩形,半透明填充,1.5px 边框
|
||||
- **连线**: 灰色箭头,层级在组件下方
|
||||
- **图例**: 放置在边界框外部
|
||||
|
||||
## 使用方法
|
||||
|
||||
```
|
||||
用户: "画 fumamxCRM 的架构图,要求精美的深色主题"
|
||||
→ 使用本 skill
|
||||
|
||||
用户: "fumamxCRM 有哪些表?"
|
||||
→ 不使用本 skill,直接回答
|
||||
|
||||
用户: "画个简单的流程图"
|
||||
→ 优先使用 Mermaid
|
||||
```
|
||||
|
||||
## 输出格式
|
||||
|
||||
生成自包含的 HTML 文件:
|
||||
- 内嵌 CSS(无外部样式表,除 Google Fonts)
|
||||
- 内联 SVG(无外部图片)
|
||||
- 无 JavaScript(纯 CSS 动画)
|
||||
- 可直接在浏览器打开
|
||||
|
||||
## Token 成本
|
||||
|
||||
| 复杂度 | 预估 Token | 费用(DeepSeek) |
|
||||
|--------|-----------|-----------------|
|
||||
| 简单(3-5组件) | ~2K | ¥0.003 |
|
||||
| 中等(6-10组件) | ~4K | ¥0.006 |
|
||||
| 复杂(10+组件) | ~8K+ | ¥0.012+ |
|
||||
|
||||
## 参考
|
||||
|
||||
基于 https://github.com/Cocoon-AI/architecture-diagram-generator 移植,适配 DeepSeek/Moonshot API。
|
||||
@@ -0,0 +1,204 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{PROJECT_NAME}} 架构图</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
background: #020617;
|
||||
min-height: 100vh;
|
||||
padding: 2rem;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.header {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.header-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.pulse-dot {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
background: #22d3ee;
|
||||
border-radius: 50%;
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.5; }
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.025em;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
color: #94a3b8;
|
||||
font-size: 0.875rem;
|
||||
margin-left: 1.75rem;
|
||||
}
|
||||
|
||||
.diagram-container {
|
||||
background: rgba(15, 23, 42, 0.5);
|
||||
border-radius: 1rem;
|
||||
border: 1px solid #1e293b;
|
||||
padding: 1.5rem;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
svg {
|
||||
width: 100%;
|
||||
min-width: 900px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.cards {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: 1rem;
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: rgba(15, 23, 42, 0.5);
|
||||
border-radius: 0.75rem;
|
||||
border: 1px solid #1e293b;
|
||||
padding: 1.25rem;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.card-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.card-dot.frontend { background: #22d3ee; }
|
||||
.card-dot.backend { background: #34d399; }
|
||||
.card-dot.database { background: #a78bfa; }
|
||||
|
||||
.card h3 {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
color: #e2e8f0;
|
||||
}
|
||||
|
||||
.card ul {
|
||||
list-style: none;
|
||||
font-size: 0.75rem;
|
||||
color: #94a3b8;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.card li::before {
|
||||
content: "• ";
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 2rem;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid #1e293b;
|
||||
font-size: 0.75rem;
|
||||
color: #64748b;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<div class="header-row">
|
||||
<div class="pulse-dot"></div>
|
||||
<h1>{{PROJECT_NAME}}</h1>
|
||||
</div>
|
||||
<div class="subtitle">系统架构图</div>
|
||||
</div>
|
||||
|
||||
<div class="diagram-container">
|
||||
<svg viewBox="0 0 1000 600" xmlns="http://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<pattern id="grid" width="40" height="40" patternUnits="userSpaceOnUse">
|
||||
<path d="M 40 0 L 0 0 0 40" fill="none" stroke="#1e293b" stroke-width="0.5"/>
|
||||
</pattern>
|
||||
<marker id="arrowhead" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
|
||||
<polygon points="0 0, 10 3.5, 0 7" fill="#64748b" />
|
||||
</marker>
|
||||
</defs>
|
||||
|
||||
<!-- 背景网格 -->
|
||||
<rect width="1000" height="600" fill="url(#grid)"/>
|
||||
|
||||
<!-- 在此插入生成的 SVG 内容 -->
|
||||
{{SVG_CONTENT}}
|
||||
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="cards">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<div class="card-dot frontend"></div>
|
||||
<h3>前端组件</h3>
|
||||
</div>
|
||||
<ul>
|
||||
{{FRONTEND_ITEMS}}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<div class="card-dot backend"></div>
|
||||
<h3>后端服务</h3>
|
||||
</div>
|
||||
<ul>
|
||||
{{BACKEND_ITEMS}}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<div class="card-dot database"></div>
|
||||
<h3>数据存储</h3>
|
||||
</div>
|
||||
<ul>
|
||||
{{DATABASE_ITEMS}}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
生成时间: {{TIMESTAMP}} | {{PROJECT_NAME}} Architecture Diagram
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,195 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Architecture Diagram Generator
|
||||
生成精美的深色主题系统架构图
|
||||
|
||||
⚠️ 本脚本消耗 AI token,请确保用户明确要求使用
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import re
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
try:
|
||||
from openai import OpenAI
|
||||
except ImportError:
|
||||
print("Error: openai package not installed")
|
||||
sys.exit(1)
|
||||
|
||||
# 配置
|
||||
SKILL_DIR = Path(__file__).parent
|
||||
TEMPLATE_PATH = SKILL_DIR / "assets" / "template.html"
|
||||
OUTPUT_DIR = Path("/tmp/architecture-diagrams")
|
||||
|
||||
# 配色方案
|
||||
COLORS = {
|
||||
"frontend": ("rgba(8, 51, 68, 0.4)", "#22d3ee"),
|
||||
"backend": ("rgba(6, 78, 59, 0.4)", "#34d399"),
|
||||
"database": ("rgba(76, 29, 149, 0.4)", "#a78bfa"),
|
||||
"cloud": ("rgba(120, 53, 15, 0.3)", "#fbbf24"),
|
||||
"security": ("rgba(136, 19, 55, 0.4)", "#fb7185"),
|
||||
"message": ("rgba(251, 146, 60, 0.3)", "#fb923c"),
|
||||
"generic": ("rgba(30, 41, 59, 0.5)", "#94a3b8"),
|
||||
}
|
||||
|
||||
|
||||
def get_api_client():
|
||||
"""获取 API 客户端(优先 DeepSeek,备选 Moonshot)"""
|
||||
# 优先使用 DeepSeek
|
||||
api_key = os.getenv("DEEPSEEK_API_KEY")
|
||||
if api_key:
|
||||
return OpenAI(api_key=api_key, base_url="https://api.deepseek.com")
|
||||
|
||||
# 备选 Moonshot
|
||||
api_key = os.getenv("MOONSHOT_API_KEY")
|
||||
if api_key:
|
||||
return OpenAI(api_key=api_key, base_url="https://api.moonshot.cn/v1")
|
||||
|
||||
raise ValueError("未找到 DEEPSEEK_API_KEY 或 MOONSHOT_API_KEY")
|
||||
|
||||
|
||||
def build_prompt(project_name: str, description: str, components: list) -> str:
|
||||
"""构建生成 SVG 的 prompt"""
|
||||
|
||||
components_str = "\n".join([
|
||||
f"- {c['name']}: {c['type']} - {c.get('description', '')}"
|
||||
for c in components
|
||||
])
|
||||
|
||||
return f"""你是一个专业的架构图设计师。请根据以下系统描述,生成 SVG 代码。
|
||||
|
||||
项目: {project_name}
|
||||
描述: {description}
|
||||
|
||||
组件列表:
|
||||
{components_str}
|
||||
|
||||
要求:
|
||||
1. 生成完整的 SVG 代码,可直接嵌入 HTML
|
||||
2. 使用深色主题,背景透明(由外部容器控制)
|
||||
3. 组件类型对应的配色:
|
||||
- frontend: 填充 rgba(8, 51, 68, 0.4), 边框 #22d3ee (青色)
|
||||
- backend: 填充 rgba(6, 78, 59, 0.4), 边框 #34d399 (绿色)
|
||||
- database: 填充 rgba(76, 29, 149, 0.4), 边框 #a78bfa (紫色)
|
||||
- cloud: 填充 rgba(120, 53, 15, 0.3), 边框 #fbbf24 (琥珀色)
|
||||
- security: 填充 rgba(136, 19, 55, 0.4), 边框 #fb7185 (玫瑰色)
|
||||
- message: 填充 rgba(251, 146, 60, 0.3), 边框 #fb923c (橙色)
|
||||
- generic: 填充 rgba(30, 41, 59, 0.5), 边框 #94a3b8 (灰色)
|
||||
|
||||
4. 组件使用圆角矩形 (rx="6"),半透明填充,1.5px 边框
|
||||
5. 组件之间用灰色箭头连接 (#64748b),箭头使用 marker
|
||||
6. 组件标签使用白色文字,字号 11px,居中
|
||||
7. 组件大小约 120x60px,间距合理避免重叠
|
||||
8. 图例放在右下角,说明各颜色代表的组件类型
|
||||
|
||||
只返回 SVG 代码,不要返回其他内容。SVG 的 viewBox 应该是 "0 0 900 500" 左右。
|
||||
"""
|
||||
|
||||
|
||||
def generate_svg(prompt: str) -> str:
|
||||
"""调用 AI API 生成 SVG"""
|
||||
client = get_api_client()
|
||||
|
||||
response = client.chat.completions.create(
|
||||
model="deepseek-chat", # 或 moonshot 模型
|
||||
messages=[
|
||||
{"role": "system", "content": "你是一个专业的架构图 SVG 生成器。只输出 SVG 代码,不输出任何解释。"},
|
||||
{"role": "user", "content": prompt}
|
||||
],
|
||||
temperature=0.3,
|
||||
max_tokens=4000
|
||||
)
|
||||
|
||||
return response.choices[0].message.content
|
||||
|
||||
|
||||
def extract_svg_code(content: str) -> str:
|
||||
"""从 AI 响应中提取 SVG 代码"""
|
||||
# 尝试提取 <svg> 标签内容
|
||||
svg_match = re.search(r'<svg[^>]*>.*?</svg>', content, re.DOTALL)
|
||||
if svg_match:
|
||||
return svg_match.group(0)
|
||||
|
||||
# 如果没有标签,可能是纯 SVG 路径
|
||||
if '<' in content and '>' in content:
|
||||
return f'<svg viewBox="0 0 900 500" xmlns="http://www.w3.org/2000/svg">{content}</svg>'
|
||||
|
||||
return content
|
||||
|
||||
|
||||
def generate_diagram(
|
||||
project_name: str,
|
||||
description: str,
|
||||
components: list,
|
||||
output_path: Optional[str] = None
|
||||
) -> str:
|
||||
"""
|
||||
生成架构图
|
||||
|
||||
Args:
|
||||
project_name: 项目名称
|
||||
description: 项目描述
|
||||
components: 组件列表,每项包含 name, type, description
|
||||
output_path: 输出路径,默认保存到 /tmp/architecture-diagrams/
|
||||
|
||||
Returns:
|
||||
生成的 HTML 文件路径
|
||||
"""
|
||||
# 确保输出目录存在
|
||||
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# 生成文件名
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
safe_name = re.sub(r'[^\w\-]', '_', project_name.lower())
|
||||
|
||||
if output_path is None:
|
||||
output_path = OUTPUT_DIR / f"{safe_name}_{timestamp}.html"
|
||||
else:
|
||||
output_path = Path(output_path)
|
||||
|
||||
# 读取模板
|
||||
template = TEMPLATE_PATH.read_text(encoding='utf-8')
|
||||
|
||||
# 构建 prompt 并生成 SVG
|
||||
prompt = build_prompt(project_name, description, components)
|
||||
svg_content = generate_svg(prompt)
|
||||
svg_content = extract_svg_code(svg_content)
|
||||
|
||||
# 生成卡片内容
|
||||
frontend_items = [f"<li>{c['name']}</li>" for c in components if c['type'] == 'frontend']
|
||||
backend_items = [f"<li>{c['name']}</li>" for c in components if c['type'] == 'backend']
|
||||
database_items = [f"<li>{c['name']}</li>" for c in components if c['type'] == 'database']
|
||||
|
||||
# 填充模板
|
||||
html = template.replace("{{PROJECT_NAME}}", project_name)
|
||||
html = html.replace("{{SVG_CONTENT}}", svg_content)
|
||||
html = html.replace("{{FRONTEND_ITEMS}}", "\n".join(frontend_items) if frontend_items else "<li>无</li>")
|
||||
html = html.replace("{{BACKEND_ITEMS}}", "\n".join(backend_items) if backend_items else "<li>无</li>")
|
||||
html = html.replace("{{DATABASE_ITEMS}}", "\n".join(database_items) if database_items else "<li>无</li>")
|
||||
html = html.replace("{{TIMESTAMP}}", datetime.now().strftime("%Y-%m-%d %H:%M"))
|
||||
|
||||
# 保存
|
||||
output_path.write_text(html, encoding='utf-8')
|
||||
|
||||
return str(output_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 测试用例
|
||||
test_components = [
|
||||
{"name": "React 前端", "type": "frontend", "description": "用户界面"},
|
||||
{"name": "FastAPI", "type": "backend", "description": "API 服务"},
|
||||
{"name": "SQLite", "type": "database", "description": "数据存储"},
|
||||
{"name": "Redis", "type": "database", "description": "缓存"},
|
||||
]
|
||||
|
||||
result = generate_diagram(
|
||||
project_name="Test Project",
|
||||
description="一个简单的测试项目",
|
||||
components=test_components
|
||||
)
|
||||
print(f"Generated: {result}")
|
||||
Reference in New Issue
Block a user