From b5624a664d518a24cc350f98d16b674dd5bf0bfd Mon Sep 17 00:00:00 2001 From: charilezhou Date: Sun, 28 Dec 2025 16:36:19 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=20CLAUDE.md=20?= =?UTF-8?q?=E5=B9=B6=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 补充 React 19、lodash-es、SQLite/cuid2 技术细节 - 运行 prettier 格式化受影响文件 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- CLAUDE.md | 9 +++-- apps/api/src/auth/auth.service.ts | 2 +- .../auth/decorators/current-user.decorator.ts | 2 +- apps/api/src/auth/strategies/jwt.strategy.ts | 2 +- apps/api/src/main.ts | 2 +- docs/design.md | 40 ++++++++++--------- docs/index.md | 4 +- pnpm-lock.yaml | 14 +++---- 8 files changed, 39 insertions(+), 36 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 53a9b97..0e649c0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -36,15 +36,16 @@ cd apps/api && pnpm db:studio # 打开 Prisma Studio ### Monorepo 结构 -- **apps/web** - Next.js 16 前端 (端口 3000) +- **apps/web** - Next.js 16 前端 (端口 3000),使用 React 19 - **apps/api** - NestJS 10 后端 (端口 4000,API 文档: /api/docs) -- **packages/shared** - 共享类型定义和工具函数 +- **packages/shared** - 共享类型定义和工具函数(使用 lodash-es) - **packages/eslint-config** - 共享 ESLint 9 flat config 配置 - **packages/typescript-config** - 共享 TypeScript 配置 ### 后端模块 (apps/api) NestJS 采用模块化架构: + - **PrismaModule** - 全局数据库服务,其他模块通过依赖注入使用 - **AuthModule** - JWT 认证(注册、登录、token 验证) - **UserModule** - 用户 CRUD @@ -58,11 +59,11 @@ import type { User, ApiResponse } from '@seclusion/shared'; import { formatDate, generateId } from '@seclusion/shared'; ``` -**注意**: `packages/shared` 中的工具函数应优先使用 lodash 实现。 +**注意**: `packages/shared` 中的工具函数应优先使用 lodash-es 实现。 ## Key Files -- `apps/api/prisma/schema.prisma` - 数据库模型定义 +- `apps/api/prisma/schema.prisma` - 数据库模型定义(使用 SQLite,ID 使用 cuid2) - `apps/api/.env` - 后端环境变量 (DATABASE_URL, JWT_SECRET) - `apps/web/.env.local` - 前端环境变量 (NEXT_PUBLIC_API_URL) - `turbo.json` - Turborepo 任务依赖配置 diff --git a/apps/api/src/auth/auth.service.ts b/apps/api/src/auth/auth.service.ts index 29fea38..5b7bed3 100644 --- a/apps/api/src/auth/auth.service.ts +++ b/apps/api/src/auth/auth.service.ts @@ -10,7 +10,7 @@ import { RegisterDto, LoginDto } from './dto/auth.dto'; export class AuthService { constructor( private prisma: PrismaService, - private jwtService: JwtService, + private jwtService: JwtService ) {} async register(dto: RegisterDto) { diff --git a/apps/api/src/auth/decorators/current-user.decorator.ts b/apps/api/src/auth/decorators/current-user.decorator.ts index 758616d..fb518c9 100644 --- a/apps/api/src/auth/decorators/current-user.decorator.ts +++ b/apps/api/src/auth/decorators/current-user.decorator.ts @@ -6,5 +6,5 @@ export const CurrentUser = createParamDecorator( const user = request.user; return data ? user?.[data] : user; - }, + } ); diff --git a/apps/api/src/auth/strategies/jwt.strategy.ts b/apps/api/src/auth/strategies/jwt.strategy.ts index bb9cba3..b83b8be 100644 --- a/apps/api/src/auth/strategies/jwt.strategy.ts +++ b/apps/api/src/auth/strategies/jwt.strategy.ts @@ -14,7 +14,7 @@ interface JwtPayload { export class JwtStrategy extends PassportStrategy(Strategy) { constructor( private prisma: PrismaService, - configService: ConfigService, + configService: ConfigService ) { super({ jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 13fc98d..e15a744 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -17,7 +17,7 @@ async function bootstrap() { whitelist: true, transform: true, forbidNonWhitelisted: true, - }), + }) ); // CORS 配置 diff --git a/docs/design.md b/docs/design.md index 2ea9221..8a04bb0 100644 --- a/docs/design.md +++ b/docs/design.md @@ -6,15 +6,15 @@ ## 2. 技术选型 -| 层级 | 技术栈 | 版本 | -|------|--------|------| -| 前端 | Next.js + React + TypeScript | 15 / 19 / 5.7 | -| 后端 | NestJS + Prisma + Swagger | 10 / 6 / 8 | -| 认证 | Passport + JWT | - | -| 数据库 | SQLite (可替换) | - | -| 包管理 | pnpm workspace | 9.x | -| 构建工具 | Turborepo | 2.x | -| 代码规范 | ESLint + Prettier | - | +| 层级 | 技术栈 | 版本 | +| -------- | ---------------------------- | ------------- | +| 前端 | Next.js + React + TypeScript | 15 / 19 / 5.7 | +| 后端 | NestJS + Prisma + Swagger | 10 / 6 / 8 | +| 认证 | Passport + JWT | - | +| 数据库 | SQLite (可替换) | - | +| 包管理 | pnpm workspace | 9.x | +| 构建工具 | Turborepo | 2.x | +| 代码规范 | ESLint + Prettier | - | ## 3. 项目结构 @@ -124,16 +124,16 @@ model User { ## 6. API 接口设计 -| 方法 | 路径 | 描述 | 认证 | -|------|------|------|------| -| POST | /auth/register | 用户注册 | 否 | -| POST | /auth/login | 用户登录 | 否 | -| GET | /auth/me | 获取当前用户 | 是 | -| GET | /users | 获取所有用户 | 是 | -| GET | /users/:id | 获取指定用户 | 是 | -| PATCH | /users/:id | 更新用户信息 | 是 | -| DELETE | /users/:id | 删除用户 | 是 | -| GET | /health | 健康检查 | 否 | +| 方法 | 路径 | 描述 | 认证 | +| ------ | -------------- | ------------ | ---- | +| POST | /auth/register | 用户注册 | 否 | +| POST | /auth/login | 用户登录 | 否 | +| GET | /auth/me | 获取当前用户 | 是 | +| GET | /users | 获取所有用户 | 是 | +| GET | /users/:id | 获取指定用户 | 是 | +| PATCH | /users/:id | 更新用户信息 | 是 | +| DELETE | /users/:id | 删除用户 | 是 | +| GET | /health | 健康检查 | 否 | ## 7. 共享包设计 @@ -165,6 +165,7 @@ model User { ### 8.2 环境变量 **后端 (apps/api/.env)** + ```env DATABASE_URL="file:./dev.db" JWT_SECRET="your-secret-key" @@ -173,6 +174,7 @@ PORT=4000 ``` **前端 (apps/web/.env.local)** + ```env NEXT_PUBLIC_API_URL=http://localhost:4000 ``` diff --git a/docs/index.md b/docs/index.md index 9381097..be5ed96 100644 --- a/docs/index.md +++ b/docs/index.md @@ -4,8 +4,8 @@ ## 文档列表 -| 文档 | 说明 | 适用场景 | -|------|------|----------| +| 文档 | 说明 | 适用场景 | +| ------------------------ | ------------ | -------------------------------- | | [design.md](./design.md) | 项目设计文档 | 了解整体架构、技术选型、模块设计 | ## 快速链接 diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2c7f1fd..87bc88c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4567,8 +4567,8 @@ packages: peerDependencies: zod: ^3.25.0 || ^4.0.0 - zod@4.2.1: - resolution: {integrity: sha512-0wZ1IRqGGhMP76gLqz8EyfBXKk0J2qo2+H3fi4mcUP/KtTocoX08nmIAHl1Z2kJIZbZee8KOpBCSNPRgauucjw==} + zod@3.25.76: + resolution: {integrity: sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==} snapshots: @@ -6967,8 +6967,8 @@ snapshots: '@babel/parser': 7.28.5 eslint: 9.39.2(jiti@2.6.1) hermes-parser: 0.25.1 - zod: 4.2.1 - zod-validation-error: 4.0.2(zod@4.2.1) + zod: 3.25.76 + zod-validation-error: 4.0.2(zod@3.25.76) transitivePeerDependencies: - supports-color @@ -9621,8 +9621,8 @@ snapshots: yocto-queue@0.1.0: {} - zod-validation-error@4.0.2(zod@4.2.1): + zod-validation-error@4.0.2(zod@3.25.76): dependencies: - zod: 4.2.1 + zod: 3.25.76 - zod@4.2.1: {} + zod@3.25.76: {}