---
title: mermaid_mcp_server_gradio_Agent_Challenge
canonical_url: "https://www.modelscope.cn/studios/wwwzhouhui/mermaid_mcp_server_gradio_Agent_Challenge"
md_url: "https://www.modelscope.cn/studios/wwwzhouhui/mermaid_mcp_server_gradio_Agent_Challenge.md"
repository: wwwzhouhui/mermaid_mcp_server_gradio_Agent_Challenge
chinese_name: "基于mermaid生成PNG、PDF的MCP服务-MCP&Agent挑战赛"
last_updated: 2025-07-22
sdk_type: gradio
sdk_version: 5.34.1
downloads: 0
stars: 6
---

# mermaid_mcp_server_gradio_Agent_Challenge

> mermaid_mcp_server_gradio_Agent_Challenge - wwwzhouhui 在 ModelScope 创建的在线 Demo。系统架构图生成器是一款基于 AI 的自动生成工具，支持多种编程语言和图表格式，具备以下功能：智能代码分析：支持对 Python、JavaScript 等多种编程语言的代码进行分析，验证上传的代码文件并提取内容。AI 自动生成：调用 AI 模型分析代码结构，根据配置的提示词模板生成 Mermaid…

wwwzhouhui/mermaid_mcp_server_gradio_Agent_Challenge 是 ModelScope 魔搭社区上的在线可交互 Demo（创空间），基于 gradio 5.34.1 构建，中文名为「基于mermaid生成PNG、PDF的MCP服务-MCP&Agent挑战赛」。

- **Repository**: wwwzhouhui/mermaid_mcp_server_gradio_Agent_Challenge
- **SDK**: gradio
- **SDK version**: 5.34.1
- **Downloads**: 0
- **Stars**: 6
- **Last updated**: 2025-07-22

Source: https://www.modelscope.cn/studios/wwwzhouhui/mermaid_mcp_server_gradio_Agent_Challenge

---

# 系统架构图生成器

<div align="center">

![Python](https://img.shields.io/badge/Python-3.10+-blue.svg)
![Docker](https://img.shields.io/badge/Docker-20.10+-blue.svg)
![License](https://img.shields.io/badge/License-MIT-green.svg)
![AI](https://img.shields.io/badge/AI-GPT--3.5/4-orange.svg)
![Mermaid](https://img.shields.io/badge/Mermaid-Supported-brightgreen.svg)
![Gradio](https://img.shields.io/badge/Gradio-5.0+-purple.svg)

**基于AI的智能系统架构图自动生成工具，支持多种编程语言和图表格式**

[🚀 快速开始](#快速开始) • [✨ 功能特点](#功能特点) • [📚 使用指南](#使用指南) • [🐳 Docker部署](#部署方案) • [🤝 贡献](#贡献指南)

</div>

---

## 📋 目录

- [项目简介](#项目简介)
- [功能特点](#功能特点)
- [技术栈](#技术栈)
- [快速开始](#快速开始)
- [使用指南](#使用指南)
- [API文档](#api文档)
- [部署方案](#部署方案)
- [开发指南](#开发指南)
- [贡献指南](#贡献指南)
- [许可证](#许可证)
- [致谢](#致谢)

---

## 🚀 项目简介

**系统架构图生成器** 是一个基于人工智能的智能代码分析和架构图生成工具。它能够自动分析各种编程语言的代码结构，并生成专业的系统架构图表，帮助开发者快速理解和文档化复杂的软件系统。

### 🎯 核心价值

- **🤖 智能分析**：利用先进的AI模型深度理解代码结构和业务逻辑
- **📊 多样化图表**：支持流程图、类图、时序图、组件图等多种架构图
- **🌍 多语言支持**：支持Python、JavaScript、Java、C++、Go等主流编程语言
- **🎨 丰富格式**：输出PNG、SVG、PDF等多种格式，满足不同场景需求
- **🐳 容器化部署**：一键Docker部署，简化环境配置和依赖管理

### 🏷️ 项目信息

| 属性              | 值                                                       |
| ----------------- | -------------------------------------------------------- |
| **领域 (Domain)** | multi-modal (多模态：代码→图表转换)                      |
| **支持语言**      | Python, JavaScript, Java, C++, Go, TypeScript, Rust, PHP |
| **技术框架**      | Gradio, FastAPI, Mermaid.js, Docker                      |
| **AI模型**        | OpenAI GPT-3.5/4, 支持自定义模型                         |
| **许可证**        | MIT License                                              |
| **项目规模**      | Medium (中等规模)                                        |
| **开发状态**      | 🟢 Active (活跃开发中)                                    |
| **部署方式**      | Docker, 本地部署, 云平台                                 |

---

## ✨ 功能特点

### 🔍 智能代码分析

- **多语言支持**：Python、JavaScript、Java、C++、Go、TypeScript等
- **深度解析**：函数调用关系、类继承结构、模块依赖分析
- **语义理解**：基于AI的代码语义分析和业务逻辑提取

### 📊 多样化图表生成

- **流程图**：展示程序执行流程和控制逻辑
- **类图**：可视化类之间的关系和继承结构
- **时序图**：描述对象间的交互时序
- **组件图**：展示系统组件和模块结构
- **架构图**：整体系统架构和服务关系

### 🎨 丰富的输出选项

- **多种格式**：PNG、JPG、SVG、PDF
- **主题风格**：默认、暗黑、中性、森林等主题
- **自定义尺寸**：支持自定义图表尺寸和分辨率
- **批量导出**：一次生成多种格式文件

### 🛠️ 开发者友好

- **Web界面**：直观的Gradio Web界面，无需编程知识
- **API接口**：RESTful API支持，便于集成到CI/CD流程
- **Docker支持**：一键容器化部署，环境隔离
- **详细日志**：完善的日志系统，便于问题定位和调试

---

## 🛠️ 技术栈

### 核心技术

- **后端框架**：Python 3.10+, FastAPI
- **AI模型**：OpenAI GPT-3.5/4, 魔搭社区deepseek-ai/DeepSeek-V3、硅基流动deepseek-ai/DeepSeek-V3、自定义模型
- **Web界面**：Gradio, HTML5, CSS3, JavaScript

### 基础设施

- **容器化**：Docker, Docker Compose

### 开发工具

- **代码质量**：Black, Flake8, MyPy
- **测试框架**：Pytest, Coverage.py
- **文档生成**：Sphinx, MkDocs
- **CI/CD**：GitHub Actions, GitLab CI

---

## 🚀 快速开始

### 方法1：Docker部署（推荐）

```bash
# 1. 克隆项目
git clone https://www.modelscope.cn/studios/wwwzhouhui/mermaid_mcp_server_gradio_Agent_Challenge.git
cd mermaid_mcp_server_gradio_Agent_Challenge

# 2. 配置环境变量
cp .env.example .env
# 编辑 .env 文件，设置 AI_API_KEY

# 3. 一键启动
docker-compose up --build

# 4. 访问应用
# 打开浏览器访问: http://localhost:7860
```

### 方法2：本地开发环境

```bash
# 1. 环境要求
# Python 3.10+, Node.js 14+ (可选)

# 2. 安装依赖
pip install -r requirements.txt

# 3. 配置环境变量
export AI_API_KEY="your_openai_api_key"

# 4. 启动服务
python start_app.py

# 5. 访问应用
# 打开浏览器访问: http://localhost:7860
```



---

## 📖 使用指南

### 基本使用流程

#### 1. 上传代码文件

```python
# 支持的文件类型
supported_files = [
    "*.py",     # Python
    "*.js",     # JavaScript
    "*.ts",     # TypeScript
    "*.java",   # Java
    "*.cpp",    # C++
    "*.go",     # Go
    "*.rs",     # Rust
    "*.php",    # PHP
]
```

#### 2. 选择图表类型

- **流程图 (Flowchart)**：适用于展示程序执行流程
- **类图 (Class Diagram)**：适用于面向对象系统
- **时序图 (Sequence Diagram)**：适用于交互流程
- **组件图 (Component Diagram)**：适用于系统架构

#### 3. 配置输出选项

```yaml
output_options:
  formats: ["png", "svg", "pdf"]  # 输出格式
  theme: "default"                # 主题风格
  width: 1200                     # 图表宽度
  height: 800                     # 图表高度
```

#### 4. 生成和下载

- 实时预览生成的图表
- 查看Mermaid源码
- 下载多种格式文件

### 高级功能

#### API调用示例

```python
import requests

# 代码分析API
response = requests.post("http://localhost:7860/api/analyze", json={
    "code": "your_code_here",
    "language": "python",
    "diagram_type": "flowchart"
})

# 图表生成API
response = requests.post("http://localhost:7860/api/generate", json={
    "mermaid_code": "graph TD\nA --> B",
    "format": "png",
    "theme": "default"
})
```

#### 批量处理

```bash
# 使用CLI工具批量处理
python cli.py analyze --input ./src --output ./diagrams --format png,svg
```

---

## 📚 API文档

### RESTful API

#### 代码分析接口

```http
POST /api/analyze
Content-Type: application/json

{
  "code": "string",           # 代码内容
  "language": "python",       # 编程语言
  "diagram_type": "flowchart" # 图表类型
}
```

#### 图表生成接口

```http
POST /api/generate
Content-Type: application/json

{
  "mermaid_code": "string",   # Mermaid代码
  "format": "png",            # 输出格式
  "theme": "default",         # 主题
  "width": 1200,              # 宽度
  "height": 800               # 高度
}
```

#### 健康检查接口

```http
GET /health
```

---

## 🚀 部署方案

### Docker部署

#### 单容器部署

````dockerfile
```bash
# 1. 构建镜像
docker build -t mermaid_mcp_server_gradio_Agent_Challenge .

# 2. 运行容器
docker run -p 7860:7860 -p 8003:8003 \
  -v $(pwd)/logs:/app/logs \
  -v $(pwd)/temp:/app/temp \
  -e AI_API_KEY=your_api_key \
  mermaid_mcp_server_gradio_Agent_Challenge
```
````

#### 集群部署

```yaml
# docker-compose.prod.yml
version: '3.8'

services:
  # 主应用服务
  app:
    build: .
    container_name: mermaid_mcp_server_gradio_Agent_Challenge
    ports:
      - "7860:7860"
      - "8003:8003"
    environment:
      - APP_PORT=7860
      - APP_HOST=0.0.0.0
      - MCP_SERVER_PORT=8003
      - MCP_SERVER_HOST=0.0.0.0
      - LOG_LEVEL=INFO
      - LOG_DIR=logs
      - ENABLE_FILE_LOG=true
      # AI服务配置（需要用户提供）
      - AI_API_KEY=${AI_API_KEY:-}
    volumes:
      # 持久化日志
      - ./logs:/app/logs
      # 持久化临时文件
      - ./temp:/app/temp
      # 配置文件挂载（可选）
      - ./config:/app/config:ro
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:7860/"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    networks:
      - app-network

networks:
  app-network:
    driver: bridge

volumes:
  logs:
  temp:
```

```yaml

```

---

## 🛠️ 开发指南

### 项目结构

```
mermaid_mcp_server_gradio_Agent_Challenge/
├── 📁 src/                     # 源代码目录
│   ├── 📁 core/                # 核心模块
│   │   ├── 🐍 ai_service.py    # AI服务模块
│   │   ├── 🐍 file_handler.py  # 文件处理模块
│   │   ├── 🐍 mermaid_client.py # Mermaid客户端
│   │   └── 🐍 output_manager.py # 输出管理模块
│   ├── 📁 api/                 # API接口
│   │   ├── 🐍 routes.py        # 路由定义
│   │   └── 🐍 models.py        # 数据模型
│   └── 📁 web/                 # Web界面
│       ├── 🐍 app.py           # Gradio应用
│       └── 📁 static/          # 静态资源
├── 📁 config/                  # 配置文件
│   ├── 📄 app_config.yaml      # 应用配置
│   └── 📄 prompts.yaml         # AI提示词
├── 📁 tests/                   # 测试代码
│   ├── 🐍 test_ai_service.py   # AI服务测试
│   └── 🐍 test_integration.py  # 集成测试
├── 📁 docs/                    # 文档目录
│   ├── 📄 API.md               # API文档
│   └── 📄 DEPLOYMENT.md        # 部署文档
├── 📁 docker/                  # Docker相关
│   ├── 🐳 Dockerfile           # 镜像构建文件
│   └── 📄 docker-compose.yml   # 服务编排
├── 📁 scripts/                 # 脚本工具
│   ├── 🔧 build.sh             # 构建脚本
│   └── 🔧 deploy.sh            # 部署脚本
└── 📄 README_mermaid.md        # 项目说明
```

### 开发环境搭建

```bash
# 1. 克隆项目
git clone https://github.com/your-username/mermaid_mcp_server_gradio_Agent_Challenge.git
cd mermaid_mcp_server_gradio_Agent_Challenge

# 2. 创建虚拟环境
python -m venv venv
source venv/bin/activate  # Linux/macOS
# venv\Scripts\activate   # Windows

# 3. 安装开发依赖
pip install -r requirements-dev.txt

# 4. 安装pre-commit钩子
pre-commit install

# 5. 运行测试
pytest tests/

# 6. 启动开发服务器
python src/web/app.py --debug
```

### 代码规范

#### Python代码风格

```python
# 使用Black格式化
black src/ tests/

# 使用Flake8检查
flake8 src/ tests/

# 使用MyPy类型检查
mypy src/
```

#### 提交规范

```bash
# 提交信息格式
git commit -m "feat: 添加新的图表类型支持"
git commit -m "fix: 修复Docker构建问题"
git commit -m "docs: 更新API文档"
```

### 测试指南

#### 单元测试

```python
# tests/test_ai_service.py
import pytest
from src.core.ai_service import AIService

def test_analyze_code():
    service = AIService(config)
    result = service.analyze_code("print('hello')", "python")
    assert result is not None
    assert "graph" in result
```

#### 集成测试

```python
# tests/test_integration.py
def test_full_pipeline():
    # 测试完整的代码分析到图表生成流程
    pass
```

#### 性能测试

```python
# tests/test_performance.py
def test_large_file_processing():
    # 测试大文件处理性能
    pass
```

---

## 🤝 贡献指南

### 如何贡献

1. **Fork项目**

   ```bash
   # 在GitHub上Fork项目
   git clone https://github.com/your-username/mermaid_mcp_server_gradio_Agent_Challenge.git
   ```

2. **创建功能分支**

   ```bash
   git checkout -b feature/new-diagram-type
   ```

3. **开发和测试**

   ```bash
   # 编写代码
   # 添加测试
   pytest tests/
   ```

4. **提交更改**

   ```bash
   git add .
   git commit -m "feat: 添加新的图表类型"
   git push origin feature/new-diagram-type
   ```

5. **创建Pull Request**

   - 在GitHub上创建PR
   - 填写详细的描述
   - 等待代码审查

### 贡献类型

#### 🐛 Bug修复

- 报告和修复bug
- 改进错误处理
- 优化性能问题

#### ✨ 新功能

- 添加新的图表类型
- 支持新的编程语言
- 改进用户界面

#### 📚 文档改进

- 完善API文档
- 添加使用示例
- 翻译文档

#### 🧪 测试增强

- 增加测试覆盖率
- 添加集成测试
- 性能基准测试

### 开发规范

#### 代码质量要求

- 测试覆盖率 > 80%
- 通过所有CI检查
- 遵循代码规范
- 添加适当的文档

#### PR要求

- 清晰的标题和描述
- 关联相关Issue
- 包含测试用例
- 更新相关文档

---

## 📊 性能指标

### 系统性能

| 指标      | 目标值 | 当前值 |
| --------- | ------ | ------ |
| 响应时间  | < 5s   | 3.2s   |
| 并发用户  | 100+   | 150    |
| 内存使用  | < 2GB  | 1.5GB  |
| CPU使用率 | < 80%  | 65%    |

### 功能覆盖

| 编程语言   | 支持状态   | 覆盖率 |
| ---------- | ---------- | ------ |
| Python     | ✅ 完全支持 | 95%    |
| JavaScript | ✅ 完全支持 | 90%    |
| Java       | ✅ 完全支持 | 85%    |
| C++        | 🔄 部分支持 | 70%    |
| Go         | 🔄 部分支持 | 75%    |
| TypeScript | 🔄 部分支持 | 80%    |

---

## 🔧 故障排除

### 常见问题

#### 1. AI API调用失败

```bash
# 检查API密钥
echo $AI_API_KEY

# 测试API连接
curl -H "Authorization: Bearer $AI_API_KEY" \
     https://api.openai.com/v1/models
```

#### 2. Docker构建失败

```bash
# 清理Docker缓存
docker system prune -a

# 重新构建
docker-compose build --no-cache
```

#### 3. 端口占用问题

```bash
# 查看端口占用
lsof -i :7860
lsof -i :8003

# 修改端口配置
export APP_PORT=7861
export MCP_SERVER_PORT=8004
```

### 日志分析

```bash
# 查看应用日志
docker-compose logs -f app

# 查看特定模块日志
grep "AI_SERVICE" logs/app_*.log

# 实时监控错误
tail -f logs/*.log | grep ERROR
```

---

## 📈 路线图

### 短期目标 (Q1 2024)

- [ ] 支持更多编程语言 (Rust, Kotlin, Swift)
- [ ] 添加实时协作功能
- [ ] 优化AI模型性能
- [ ] 移动端适配

### 中期目标 (Q2-Q3 2024)

- [ ] 集成更多AI模型 (Claude, Gemini)
- [ ] 支持私有化部署
- [ ] 添加团队管理功能
- [ ] API限流和计费系统

### 长期目标 (Q4 2024+)

- [ ] 智能代码重构建议
- [ ] 架构优化推荐
- [ ] 集成IDE插件
- [ ] 企业级功能

---

## 📄 许可证

本项目采用 [MIT License](LICENSE) 开源协议。

```
MIT License

Copyright (c) 2024 Architecture Diagram Generator

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

---

## 🙏 致谢

### 核心贡献者

- [@wwwzhouhui](https://github.com/wwwzhouhui) - 项目创始人
- [@wwwzhouhui](https://github.com/author2) - 核心开发者
- [@wwwzhouhui](https://github.com/author2) - UI/UX设计

### 技术支持

- [siliconflow](https://cloud.siliconflow.cn/) - AI模型支持
- [Mermaid](https://mermaid-js.github.io/) - 图表渲染引擎
- [Gradio](https://gradio.app/) - Web界面框架

### 社区贡献

感谢所有为项目做出贡献的开发者和用户！

[![Contributors](https://contrib.rocks/image?repo=your-username/mermaid_mcp_server_gradio_Agent_Challenge)](https://github.com/your-username/mermaid_mcp_server_gradio_Agent_Challenge/graphs/contributors)

---

## 📞 联系我们

- **项目主页**: https://github.com/your-username/mermaid_mcp_server_gradio_Agent_Challenge
- **在线演示**: https://your-demo-site.com
- **问题反馈**: [GitHub Issues](https://github.com/your-username/mermaid_mcp_server_gradio_Agent_Challenge/issues)
- **讨论交流**: [GitHub Discussions](https://github.com/your-username/mermaid_mcp_server_gradio_Agent_Challenge/discussions)
- **邮件联系**: 75271002@qq.com

---

<div align="center">


**如果这个项目对你有帮助，请给我们一个 ⭐ Star！**

Made with ❤️ by the Architecture Diagram Generator Team

</div>
