A CRUD generator following Vertical Slice Architecture (VSA)
Project description
curdezgen
curdezgen 是一个基于垂直切片架构 (Vertical Slice Architecture, VSA) 的 FastAPI CRUD 代码生成工具。它可以根据您的数据库表结构,自动生成符合最佳实践的后端代码。
核心特性
- 垂直切片架构: 每个业务功能(如创建用户、获取商品列表)都是独立的切片,包含路由、逻辑和 DTO。
- 自动数据库扫描: 使用 SQLAlchemy 自动识别数据库表、列、主键和类型。
- 高度可定制: 通过简单的 YAML 配置文件控制生成行为。
- FastAPI 最佳实践: 生成的代码包含 Pydantic 数据验证、依赖注入 (DI) 和自动文档支持。
- Docker 一键部署: 自动生成 Dockerfile、docker-compose.yml 以及跨平台的启动/停止/重启脚本。
- 中文本地化: 生成的代码注释、提示信息及 Docker 脚本均已本地化为中文。
安装
pip install curdezgen
快速开始
1. 创建配置文件
在项目根目录下创建一个名为 curdezgen.yaml 的文件,并填入以下内容:
db:
type: postgresql # 支持 postgresql, mysql
host: localhost
port: 5432
user: postgres
password: your_password
name: your_db_name
schema_name: public
gen:
output_dir: output
base_package: app
docker:
enabled: true
python_version: "3.10"
2. 初始化项目结构
根据配置文件创建项目骨架(包括 core, shared, features 目录):
python -m curdezgen.cli init
3. 生成 CRUD 代码
连接数据库并根据表结构生成具体的业务代码:
python -m curdezgen.cli crud
生成的业务代码将存放在 app/features/{db_name}_{ip}/{schema}_{table}/ 目录下。
4. 生成 Docker 部署文件
生成容器化部署所需的配置文件和一键管理脚本:
python -m curdezgen.cli docker
文件将生成在 output/docker_file/ 目录下。
5. 运行项目
本地运行
uvicorn app.main:app --reload
Docker 运行
进入 docker_file 目录并运行启动脚本:
Windows (PowerShell):
.\docker_file\start_docker.ps1
Linux / macOS:
./docker_file/start_docker.sh
脚本会自动构建镜像、启动服务(后台运行),并输出访问地址。
常用命令
init: 初始化项目骨架。crud(或gen): 逆向工程,生成 CRUD 代码。slice: 正向工程,生成空白业务切片。docker: 生成 Docker 部署文件。
详细命令说明请参考 COMMANDS.md。
架构指南
生成的代码遵循垂直切片架构,详情请参考 ARCHITECTURE.md。
数据库支持
- PostgreSQL: 需安装
psycopg2-binary - MySQL: 需安装
pymysql
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
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 curdezgen-0.1.2.tar.gz.
File metadata
- Download URL: curdezgen-0.1.2.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a32bfe6da2db715e9d45747319373948608768a2f6dee90ee96c1cd45e23b7a9
|
|
| MD5 |
cc3286a9e13cb1c8334fc3371f214b57
|
|
| BLAKE2b-256 |
232a5ced48fbd63c0aecb2ffb668a29a08b49a05691855d4379ea79e467b2924
|
File details
Details for the file curdezgen-0.1.2-py3-none-any.whl.
File metadata
- Download URL: curdezgen-0.1.2-py3-none-any.whl
- Upload date:
- Size: 22.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20f2cc1ad5afe216de72ca03e06df719b6cf6087a713873d3b6ca1c162803cb8
|
|
| MD5 |
66920d828c28231a4beb449a44cfd5b4
|
|
| BLAKE2b-256 |
b6eb13809b46f2ac6a73da33a67c8ad0c930ebc6e660b037a2525dc46b36b44a
|