A CRUD generator following Vertical Slice Architecture (VSA)
Project description
curdezgen
curdezgen 是一个基于垂直切片架构 (Vertical Slice Architecture, VSA) 的 FastAPI CRUD 代码生成工具。它可以根据您的数据库表结构,自动生成符合最佳实践的后端代码。
核心特性
- 垂直切片架构: 每个业务功能(如创建用户、获取商品列表)都是独立的切片,包含路由、逻辑和 DTO。
- 自动数据库扫描: 使用 SQLAlchemy 自动识别数据库表、列、主键和类型。
- 高度可定制: 通过简单的 YAML 配置文件控制生成行为。
- FastAPI 最佳实践: 生成的代码包含 Pydantic 数据验证、依赖注入 (DI) 和自动文档支持。
安装
pip install curdezgen
快速开始
1. 生成默认配置文件模板
运行以下命令,在当前目录下生成 curdezgen.yaml:
curdezgen yaml
手动修改 curdezgen.yaml 中的数据库连接信息。
2. 初始化项目结构
根据配置文件创建项目文件夹(如 app/)和基础架构:
curdezgen init
3. 生成 CRUD 接口
连接数据库并根据表结构生成具体的业务代码:
curdezgen gen
生成的业务代码将存放在 app/features/database_basics/ 目录下。
4. 运行项目
直接启动生成的 FastAPI 应用:
python app/main.py
或使用 uvicorn:
uvicorn app.main:app --reload
架构指南
生成的代码遵循项目中的 ARCHITECTURE.md 指南。
数据库支持
curdezgen 支持所有 SQLAlchemy 支持的数据库。请确保您安装了对应的驱动程序:
- PostgreSQL:
pip install psycopg2-binary - MySQL:
pip install pymysql - SQLite: 内置支持
PostgreSQL 配置示例
修改 curdezgen.yaml:
db:
url: "postgresql://user:password@localhost:5432/your_db"
gen:
output_dir: "output"
base_package: "app"
路线图
- 支持更多数据库驱动 (MySQL, PostgreSQL)
- 支持自动生成 Alembic 迁移脚本
- 支持生成简单的单元测试
- 支持自定义模板
许可证
MIT
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.0.tar.gz.
File metadata
- Download URL: curdezgen-0.1.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe72e6faafbe39c1484c89f52a2676d46956e3e6b1d3ef52619a070afb2e2bcd
|
|
| MD5 |
bd710020b6064fcb2aea0cdf5aebf0eb
|
|
| BLAKE2b-256 |
8bb8e6923e9ad77c4528e290bb0b8ed7b46aff99b06685bc92c98b5d1a15d8ef
|
File details
Details for the file curdezgen-0.1.0-py3-none-any.whl.
File metadata
- Download URL: curdezgen-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.8 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 |
012fb8240852b8d9a7245762ea7bbc083bc755a722d56aa6c8c8b133cb0c5d4c
|
|
| MD5 |
d0b2bfcfd3e16f665bbbd445021d6d7c
|
|
| BLAKE2b-256 |
9773687a0d1ac9b235f25ef587ddd53526e4c4aead00ef50ccec4cea2b1aefe5
|