项目脚手架技能
何时使用
- •新建项目(new-project)模式下,架构设计完成后、编码开发前
- •需要初始化项目目录结构、配置文件、依赖管理时
输出
- •项目目录结构(按架构设计方案创建)
- •包管理配置文件(requirements.txt / package.json / .csproj 等)
- •入口文件和模块骨架
- •测试目录和测试骨架
- •配置文件(.gitignore、README.md、CI 配置等)
初始化步骤
1. 确定工程类型
从架构设计文档(process_templates/architecture.md)中获取技术选型信息,确定工程类型。
2. 创建目录结构
按架构设计的模块划分创建目录:
项目根目录/ ├── src/ 或 app/ # 源代码 │ ├── 模块A/ │ ├── 模块B/ │ └── main 入口文件 ├── tests/ # 测试代码 │ ├── unit/ # 单元测试 │ ├── integration/ # 集成测试 │ └── conftest 或 fixtures ├── docs/ # 文档(可选) ├── 配置文件 ├── .gitignore └── README.md
3. 安装依赖
根据架构设计中的技术选型,初始化包管理器并安装核心依赖。
4. 创建入口文件和模块骨架
- •为每个模块创建空文件(含模块说明注释)
- •创建应用入口文件
- •确保骨架代码可运行(即使功能为空)
5. 创建测试骨架
- •创建测试配置文件(pytest.ini / jest.config 等)
- •为每个模块创建对应的测试文件骨架
6. 更新 workflow_state.json
{
"status": "completed",
"stage": "development",
"notes": "脚手架初始化完成,开始编码开发"
}
工程类型与默认技术栈
Python Web(FastAPI)
项目名/ ├── app/ │ ├── __init__.py │ ├── main.py # FastAPI 入口 │ ├── api/ # 路由层 │ ├── service/ # 业务层 │ ├── repository/ # 数据层 │ ├── models/ # 数据模型 │ └── utils/ # 工具 ├── tests/ │ ├── __init__.py │ ├── conftest.py │ ├── unit/ │ └── integration/ ├── requirements.txt ├── pytest.ini ├── .gitignore └── README.md
核心依赖:fastapi, uvicorn, pydantic, sqlalchemy(或其他ORM), pytest, httpx
Python 工具 / CLI
项目名/ ├── src/ │ └── 包名/ │ ├── __init__.py │ ├── main.py # CLI 入口 │ ├── core/ # 核心逻辑 │ └── utils/ ├── tests/ │ ├── conftest.py │ └── unit/ ├── pyproject.toml ├── .gitignore └── README.md
核心依赖:click 或 typer, rich, pytest
C# / .NET(ASP.NET Core)
项目名/ ├── src/ │ └── 项目名/ │ ├── Controllers/ │ ├── Services/ │ ├── Repositories/ │ ├── Models/ │ ├── Program.cs │ └── 项目名.csproj ├── tests/ │ └── 项目名.Tests/ │ ├── Unit/ │ ├── Integration/ │ └── 项目名.Tests.csproj ├── 项目名.sln ├── .gitignore └── README.md
核心依赖:Microsoft.AspNetCore, xUnit, Moq, FluentAssertions, EFCore, Swashbuckle
Node.js / TypeScript(Express / NestJS)
项目名/ ├── src/ │ ├── index.ts │ ├── routes/ │ ├── services/ │ ├── repositories/ │ └── models/ ├── tests/ │ ├── unit/ │ └── integration/ ├── package.json ├── tsconfig.json ├── .eslintrc.json ├── .gitignore └── README.md
核心依赖:express 或 @nestjs/core, typescript, zod, prisma, jest 或 vitest, eslint, prettier
Java(Spring Boot)
项目名/ ├── src/ │ ├── main/ │ │ ├── java/包路径/ │ │ │ ├── controller/ │ │ │ ├── service/ │ │ │ ├── repository/ │ │ │ ├── model/ │ │ │ └── Application.java │ │ └── resources/ │ │ └── application.yml │ └── test/ │ └── java/包路径/ │ ├── unit/ │ └── integration/ ├── pom.xml 或 build.gradle ├── .gitignore └── README.md
核心依赖:spring-boot-starter-web, spring-boot-starter-data-jpa, JUnit5, Mockito, H2(测试)
Go
项目名/ ├── cmd/ │ └── main.go ├── internal/ │ ├── handler/ │ ├── service/ │ ├── repository/ │ └── model/ ├── pkg/ # 可复用的公共包 ├── tests/ │ ├── unit/ │ └── integration/ ├── go.mod ├── go.sum ├── .gitignore └── README.md
核心依赖:gin 或 echo, gorm, testify, golangci-lint
C++(CMake)
项目名/ ├── src/ │ ├── main.cpp │ └── modules/ ├── include/ │ └── 项目名/ ├── tests/ │ ├── unit/ │ └── CMakeLists.txt ├── CMakeLists.txt ├── vcpkg.json 或 conanfile.txt ├── .gitignore └── README.md
核心依赖:CMake ≥3.16, Google Test, vcpkg 或 conan
Rust
项目名/ ├── src/ │ ├── main.rs │ ├── lib.rs │ └── modules/ ├── tests/ │ └── integration_test.rs ├── Cargo.toml ├── .gitignore └── README.md
核心依赖:serde, tokio, actix-web 或 axum(Web项目), clap(CLI项目)
通用配置文件
.gitignore
根据工程类型生成对应的 .gitignore(参考 github/gitignore 仓库模板)。
README.md
至少包含:项目名称、简介、安装步骤、运行方式、测试方式。
CI 配置(可选)
如项目需要,生成 .github/workflows/ci.yml,包含:依赖安装 → 构建 → 测试 流水线。
注意事项
- •脚手架生成的代码必须可直接运行(即使功能为空壳)
- •测试骨架生成后至少有一个可通过的示例测试
- •目录结构必须与架构设计文档中的模块划分一致
- •不要安装不必要的依赖,保持最小化