MVCGen
中文 | English
一个基于 LangChain 的智能 MVC 代码生成器,支持自然语言描述生成 Web 应用代码。
MVCGen 追求智能、高效、易用,适合快速原型开发、代码生成、自动化开发等场景。
1. 特性
- 🚀 智能代码生成: 基于自然语言描述自动生成 MVC 架构代码
- 🔧 多框架支持: 支持 FastAPI、Django、Flask 等主流 Python Web 框架
- 🗄️ 数据库集成: 内置 Tortoise ORM 支持,自动生成模型和 CRUD 操作
- 📚 API 文档: 自动生成 OpenAPI/Swagger 文档
- ✨ 代码质量: 集成代码格式化、类型检查
- 🔌 可扩展性: 模块化设计,支持自定义工具和模板
- 🎯 简单易用: 快速生成 Web 应用代码
- 🔄 异步支持: 全异步架构,高性能处理
2. 安装
2.1 从源码安装
# 克隆仓库
git clone https://github.com/your-username/mvcgen.git
cd mvcgen
# 安装依赖
pip install -e .
# 开发模式安装
pip install -e ".[dev]"
2.2 开发环境
# 安装依赖
pip install -e ".[dev]"
# 运行测试
pytest
# 代码格式化
black .
# 代码检查
flake8
# 运行示例
python examples/basic_example.py
3. 快速开始
3.1 基本使用
from mvcgen import Agent
# 创建 Agent 实例
agent = Agent()
# 生成用户管理模块
result = await agent.run("创建一个用户管理系统,包含用户注册、登录、个人信息管理功能")
print(result)
3.2 数据库模型生成
from mvcgen.models import Model
# 创建用户模型
user_model = Model("User", {
"id": "int primary key",
"username": "str unique",
"email": "str unique",
"password": "str",
"created_at": "datetime"
})
# 生成 CRUD 操作
crud_code = await user_model.generate_crud()
3.3 配置环境变量
创建 .env 文件:
# OpenAI API 配置
OPENAI_API_KEY=your_openai_api_key_here
OPENAI_BASE_URL=https://api.openai.com/v1
# 数据库配置
DATABASE_URL=sqlite://./mvcgen.db
# 应用配置
DEBUG=True
HOST=0.0.0.0
PORT=8000
# 日志配置
LOG_LEVEL=INFO
4. 高级用法
4.1 自定义 Agent 配置
from mvcgen import Agent
# 自定义配置
agent = Agent(
model_name="gpt-4",
temperature=0.7,
max_tokens=2000,
system_prompt="你是一个专业的 Python 开发者..."
)
result = await agent.run("生成一个博客系统")
4.2 批量生成
# 批量生成多个模块
modules = [
"用户管理模块",
"文章管理模块",
"评论系统模块",
"标签管理模块"
]
for module in modules:
result = await agent.run(f"创建{module}")
print(f"生成 {module}: {result}")
4.3 数据库操作
from mvcgen.models import Model
# 创建记录
user_data = {"username": "john", "email": "john@example.com"}
user = await UserModel.create(user_data)
# 查询记录
users = await UserModel.get_all(filters={"username": "john"})
# 更新记录
await UserModel.update(1, {"email": "new@example.com"})
# 删除记录
await UserModel.delete(1)
5. 示例项目
5.1 博客系统
# 生成完整的博客系统
blog_system = await agent.run("""
创建一个博客系统,包含以下功能:
- 用户注册和登录
- 文章发布和编辑
- 评论系统
- 标签管理
- 搜索功能
- 管理员后台
""")
5.2 电商系统
# 生成电商系统
ecommerce = await agent.run("""
创建一个电商系统,包含:
- 商品管理
- 购物车
- 订单管理
- 支付集成
- 用户评价
- 库存管理
""")
6. 项目结构
mvcgen/
├── src/mvcgen/
│ ├── __init__.py
│ ├── agent.py # 核心 Agent 类
│ ├── models.py # 数据库模型管理
│ ├── schemas.py # 数据模型定义
│ ├── utils.py # 工具函数
│ └── dotenv.py # 环境变量管理
├── examples/ # 示例代码
├── docs/ # 文档
├── tests/ # 测试文件
├── pyproject.toml # 项目配置
├── README.md # 项目说明
└── .env.example # 环境变量示例
7. 参考框架
MVCGen 参考和对标了以下主流代码生成和 AI 开发框架:
8. 项目状态
📦 发布状态
🔄 版本信息
- 当前版本: 0.1.0
- Python 支持: 3.9+
- 许可证: MIT
- 状态: Alpha
9. 贡献指南
欢迎贡献代码!请查看我们的贡献指南:
- Fork 项目
- 创建功能分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 打开 Pull Request
10. 许可证
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
11. 相关链接
Metadata
Release files for mvcgen 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mvcgen-0.1.0.tar.gz | 20.3 kB | Without provenance | Details for mvcgen-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mvcgen-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for mvcgen-0.1.0-py3-none-any.whl |
Total release size: 33.9 kB
Release files / mvcgen-0.1.0.tar.gz
| Download URL | mvcgen-0.1.0.tar.gz |
|---|---|
| Size | 20.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
959e57a2897c16d723e9f1c05a8a10d93d7e93e095bca94fdcc29853e48a1bdf
|
|
BLAKE2b-256 checksum How to use checksums |
981ed6439c3fcb7caee0dedf2204504343fffd25fa67adaba8879913da48cd8c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / mvcgen-0.1.0-py3-none-any.whl
| Download URL | mvcgen-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ec9518375c8c25d46db870dc60436be1ff276571788ea9da33f1e8a624924a3b
|
|
BLAKE2b-256 checksum How to use checksums |
1e3fc2dc08db17b20ecc612aaa65387d2ee37638be6754c846626e14cbc4467a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for mvcgen 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.