Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

curdezgen-0.1.1.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

curdezgen-0.1.1-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file curdezgen-0.1.1.tar.gz.

File metadata

  • Download URL: curdezgen-0.1.1.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

Hashes for curdezgen-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b7419c6ec5b3d23a337636074ec945a0f889342f2bf7e119a6c3c3dd909b79b7
MD5 080bbd0a28d25fcfcc1153819ac0dd01
BLAKE2b-256 3715ddde85a587926b17605f8f23a4198015bc5c370fef25cb8ca49cc0a8a95b

See more details on using hashes here.

File details

Details for the file curdezgen-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: curdezgen-0.1.1-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

Hashes for curdezgen-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 43c1ed4611c3548053882b6e481b47cf7aba2cecf44ec0f1f3b72bd5728408d2
MD5 9c6ec3c28bca83857254bb83658425bf
BLAKE2b-256 bea567c45d8cac86b4fe1dee67572a3f3877737416c218ccda1876be305c5cac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page