智能代码生成器,提升开发效率10倍+
Project description
AutoCode-Gen v0.2.0
🚀 智能代码生成器,提升开发效率10倍+
AutoCode-Gen 是一个自动化代码生成工具,能够根据 OpenAPI 规范或 SQL DDL 自动生成完整的、可运行的代码。
✨ 核心功能
- 🚀 API代码生成 - 从 OpenAPI 规范生成 FastAPI/Flask/Django 代码
- 🗄️ 模型生成 - 从 SQL DDL 生成 SQLAlchemy/Django ORM 模型
- 🐳 Docker配置 - 生成 Dockerfile 和 docker-compose.yml
- ☸️ K8s部署 - 生成 Kubernetes 部署配置
- 🔄 CI/CD流水线 - 生成 GitHub Actions 工作流
🚀 快速开始
安装
# 从 PyPI 安装
pip install autocode-gen
# 或者从源码安装
git clone https://github.com/yourusername/autocode-gen.git
cd autocode-gen
pip install -e .
验证安装
autocode --version
📖 使用示例
1. 从 OpenAPI 生成 API
# 生成 FastAPI 项目
autocode generate-api openapi.yaml --output ./my_api --framework fastapi
# 生成的文件结构
my_api/
├── app/
│ ├── __init__.py
│ ├── main.py # FastAPI 主应用
│ ├── api/
│ │ ├── router.py # API 路由
│ │ └── deps.py # 依赖注入
│ ├── models/
│ │ └── schemas.py # Pydantic 模型
│ └── core/
│ ├── config.py # 配置
│ └── database.py # 数据库
└── requirements.txt
2. 从 SQL DDL 生成模型
# 生成 SQLAlchemy 模型
autocode generate-model schema.sql --output ./my_models --orm sqlalchemy
3. 生成 Docker 配置
autocode generate-docker --project-name myapp --output ./docker
4. 生成 Kubernetes 配置
autocode generate-k8s --project-name myapp --domain api.example.com --output ./k8s
5. 生成 CI/CD 配置
autocode generate-cicd --project-name myapp --output ./.github/workflows
🛠️ 开发
环境设置
# 克隆仓库
git clone https://github.com/yourusername/autocode-gen.git
cd autocode-gen
# 创建虚拟环境
python -m venv venv
source venv/bin/activate # Linux/Mac
# 或
venv\Scripts\activate # Windows
# 安装开发依赖
pip install -r requirements-dev.txt
pip install -e .
运行测试
# 运行所有测试
pytest
# 运行特定测试
pytest tests/test_parsers.py -v
# 生成覆盖率报告
pytest --cov=autocode --cov-report=html
代码格式化
# 格式化代码
make format
# 代码检查
make lint
构建和发布
# 清理构建文件
make clean
# 构建包
make build
# 上传到 PyPI 测试环境
make publish-test
# 上传到正式 PyPI
make publish
或者使用脚本:
python build_test.py
📁 项目结构
autocode-gen/
├── autocode/ # 主包
│ ├── __init__.py
│ ├── cli.py # CLI 入口
│ ├── parsers/ # 解析器
│ │ ├── base.py
│ │ ├── openapi.py # OpenAPI 解析
│ │ └── sql.py # SQL 解析
│ ├── generators/ # 生成器
│ │ ├── base.py
│ │ ├── api.py # API 生成
│ │ ├── model.py # 模型生成
│ │ ├── docker.py # Docker 配置
│ │ ├── kubernetes.py # K8s 配置
│ │ └── cicd.py # CI/CD 配置
│ └── templates/ # 模板
├── tests/ # 测试
├── examples/ # 示例
│ ├── openapi.yaml # 示例 API 规范
│ └── demo.py # 演示脚本
├── setup.py # 包配置
├── pyproject.toml # 项目配置
├── requirements.txt # 依赖
├── requirements-dev.txt # 开发依赖
├── Makefile # 开发命令
├── LICENSE # 许可证
└── README.md # 说明文档
📝 示例
OpenAPI 规范示例
openapi: 3.0.0
info:
title: User API
version: 1.0.0
paths:
/users:
get:
summary: List users
responses:
'200':
description: Success
post:
summary: Create user
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/User'
responses:
'201':
description: Created
components:
schemas:
User:
type: object
properties:
id:
type: integer
name:
type: string
email:
type: string
生成的代码示例
# app/api/router.py
from fastapi import APIRouter, Depends
from typing import List
router = APIRouter()
@router.get("/users", response_model=List[UserResponse])
def list_users(skip: int = 0, limit: int = 100):
return []
@router.post("/users", response_model=UserResponse)
def create_user(user: UserCreate):
return user
🎯 路线图
v0.2 (当前)
- ✅ OpenAPI 解析
- ✅ SQL DDL 解析
- ✅ FastAPI 代码生成
- ✅ SQLAlchemy 模型生成
- ✅ Docker 配置生成
- ✅ Kubernetes 配置生成
- ✅ CI/CD 配置生成
- ✅ CLI 界面
v0.3 (计划中)
- Flask/Django 支持
- 前端组件生成(React/Vue)
- 更多数据库支持
- 模板市场
v1.0 (未来)
- 可视化配置界面
- AI 智能优化
- 团队协作功能
- SaaS 服务
🤝 贡献
欢迎提交 Issue 和 PR!
- Fork 本仓库
- 创建你的特性分支 (
git checkout -b feature/AmazingFeature) - 提交你的修改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 打开一个 Pull Request
📄 许可证
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情
🙏 致谢
Made with ❤️ by AI Assistant
如果这个项目对你有帮助,请给我们一个 ⭐️ Star!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fullstackgenie-0.2.0.tar.gz
(31.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fullstackgenie-0.2.0.tar.gz.
File metadata
- Download URL: fullstackgenie-0.2.0.tar.gz
- Upload date:
- Size: 31.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b73e3a665fa9032851b36b2eab6a98a2014e0242a938281d4f8b6c19ad92ba97
|
|
| MD5 |
adc4a6059676acd05c0c981d3269db8c
|
|
| BLAKE2b-256 |
eb59029e40cc87c10bb708915d1bdf396d739d6bdc8b106e393cddb19d09e5c0
|
File details
Details for the file fullstackgenie-0.2.0-py3-none-any.whl.
File metadata
- Download URL: fullstackgenie-0.2.0-py3-none-any.whl
- Upload date:
- Size: 31.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bca3a1c5a5b00514e1b1bef13d61264e586169729d9a0586cd62c96c1ba51ca9
|
|
| MD5 |
ed278f7b833b6b35ebf5abe68eff7171
|
|
| BLAKE2b-256 |
e47ccfdbc8ab2b9ab555befe25c2a0b5ee15a3950f678f13ce8b0470f4615d5c
|