docs: 更新 CLAUDE.md 并格式化代码

- 补充 React 19、lodash-es、SQLite/cuid2 技术细节
- 运行 prettier 格式化受影响文件

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
charilezhou
2025-12-28 16:36:19 +08:00
parent 0a2eda3961
commit b5624a664d
8 changed files with 39 additions and 36 deletions

View File

@@ -36,15 +36,16 @@ cd apps/api && pnpm db:studio # 打开 Prisma Studio
### Monorepo 结构 ### Monorepo 结构
- **apps/web** - Next.js 16 前端 (端口 3000) - **apps/web** - Next.js 16 前端 (端口 3000),使用 React 19
- **apps/api** - NestJS 10 后端 (端口 4000API 文档: /api/docs) - **apps/api** - NestJS 10 后端 (端口 4000API 文档: /api/docs)
- **packages/shared** - 共享类型定义和工具函数 - **packages/shared** - 共享类型定义和工具函数(使用 lodash-es
- **packages/eslint-config** - 共享 ESLint 9 flat config 配置 - **packages/eslint-config** - 共享 ESLint 9 flat config 配置
- **packages/typescript-config** - 共享 TypeScript 配置 - **packages/typescript-config** - 共享 TypeScript 配置
### 后端模块 (apps/api) ### 后端模块 (apps/api)
NestJS 采用模块化架构: NestJS 采用模块化架构:
- **PrismaModule** - 全局数据库服务,其他模块通过依赖注入使用 - **PrismaModule** - 全局数据库服务,其他模块通过依赖注入使用
- **AuthModule** - JWT 认证注册、登录、token 验证) - **AuthModule** - JWT 认证注册、登录、token 验证)
- **UserModule** - 用户 CRUD - **UserModule** - 用户 CRUD
@@ -58,11 +59,11 @@ import type { User, ApiResponse } from '@seclusion/shared';
import { formatDate, generateId } from '@seclusion/shared'; import { formatDate, generateId } from '@seclusion/shared';
``` ```
**注意**: `packages/shared` 中的工具函数应优先使用 lodash 实现。 **注意**: `packages/shared` 中的工具函数应优先使用 lodash-es 实现。
## Key Files ## Key Files
- `apps/api/prisma/schema.prisma` - 数据库模型定义 - `apps/api/prisma/schema.prisma` - 数据库模型定义(使用 SQLiteID 使用 cuid2
- `apps/api/.env` - 后端环境变量 (DATABASE_URL, JWT_SECRET) - `apps/api/.env` - 后端环境变量 (DATABASE_URL, JWT_SECRET)
- `apps/web/.env.local` - 前端环境变量 (NEXT_PUBLIC_API_URL) - `apps/web/.env.local` - 前端环境变量 (NEXT_PUBLIC_API_URL)
- `turbo.json` - Turborepo 任务依赖配置 - `turbo.json` - Turborepo 任务依赖配置

View File

@@ -10,7 +10,7 @@ import { RegisterDto, LoginDto } from './dto/auth.dto';
export class AuthService { export class AuthService {
constructor( constructor(
private prisma: PrismaService, private prisma: PrismaService,
private jwtService: JwtService, private jwtService: JwtService
) {} ) {}
async register(dto: RegisterDto) { async register(dto: RegisterDto) {

View File

@@ -6,5 +6,5 @@ export const CurrentUser = createParamDecorator(
const user = request.user; const user = request.user;
return data ? user?.[data] : user; return data ? user?.[data] : user;
}, }
); );

View File

@@ -14,7 +14,7 @@ interface JwtPayload {
export class JwtStrategy extends PassportStrategy(Strategy) { export class JwtStrategy extends PassportStrategy(Strategy) {
constructor( constructor(
private prisma: PrismaService, private prisma: PrismaService,
configService: ConfigService, configService: ConfigService
) { ) {
super({ super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),

View File

@@ -17,7 +17,7 @@ async function bootstrap() {
whitelist: true, whitelist: true,
transform: true, transform: true,
forbidNonWhitelisted: true, forbidNonWhitelisted: true,
}), })
); );
// CORS 配置 // CORS 配置

View File

@@ -6,15 +6,15 @@
## 2. 技术选型 ## 2. 技术选型
| 层级 | 技术栈 | 版本 | | 层级 | 技术栈 | 版本 |
|------|--------|------| | -------- | ---------------------------- | ------------- |
| 前端 | Next.js + React + TypeScript | 15 / 19 / 5.7 | | 前端 | Next.js + React + TypeScript | 15 / 19 / 5.7 |
| 后端 | NestJS + Prisma + Swagger | 10 / 6 / 8 | | 后端 | NestJS + Prisma + Swagger | 10 / 6 / 8 |
| 认证 | Passport + JWT | - | | 认证 | Passport + JWT | - |
| 数据库 | SQLite (可替换) | - | | 数据库 | SQLite (可替换) | - |
| 包管理 | pnpm workspace | 9.x | | 包管理 | pnpm workspace | 9.x |
| 构建工具 | Turborepo | 2.x | | 构建工具 | Turborepo | 2.x |
| 代码规范 | ESLint + Prettier | - | | 代码规范 | ESLint + Prettier | - |
## 3. 项目结构 ## 3. 项目结构
@@ -124,16 +124,16 @@ model User {
## 6. API 接口设计 ## 6. API 接口设计
| 方法 | 路径 | 描述 | 认证 | | 方法 | 路径 | 描述 | 认证 |
|------|------|------|------| | ------ | -------------- | ------------ | ---- |
| POST | /auth/register | 用户注册 | 否 | | POST | /auth/register | 用户注册 | 否 |
| POST | /auth/login | 用户登录 | 否 | | POST | /auth/login | 用户登录 | 否 |
| GET | /auth/me | 获取当前用户 | 是 | | GET | /auth/me | 获取当前用户 | 是 |
| GET | /users | 获取所有用户 | 是 | | GET | /users | 获取所有用户 | 是 |
| GET | /users/:id | 获取指定用户 | 是 | | GET | /users/:id | 获取指定用户 | 是 |
| PATCH | /users/:id | 更新用户信息 | 是 | | PATCH | /users/:id | 更新用户信息 | 是 |
| DELETE | /users/:id | 删除用户 | 是 | | DELETE | /users/:id | 删除用户 | 是 |
| GET | /health | 健康检查 | 否 | | GET | /health | 健康检查 | 否 |
## 7. 共享包设计 ## 7. 共享包设计
@@ -165,6 +165,7 @@ model User {
### 8.2 环境变量 ### 8.2 环境变量
**后端 (apps/api/.env)** **后端 (apps/api/.env)**
```env ```env
DATABASE_URL="file:./dev.db" DATABASE_URL="file:./dev.db"
JWT_SECRET="your-secret-key" JWT_SECRET="your-secret-key"
@@ -173,6 +174,7 @@ PORT=4000
``` ```
**前端 (apps/web/.env.local)** **前端 (apps/web/.env.local)**
```env ```env
NEXT_PUBLIC_API_URL=http://localhost:4000 NEXT_PUBLIC_API_URL=http://localhost:4000
``` ```

View File

@@ -4,8 +4,8 @@
## 文档列表 ## 文档列表
| 文档 | 说明 | 适用场景 | | 文档 | 说明 | 适用场景 |
|------|------|----------| | ------------------------ | ------------ | -------------------------------- |
| [design.md](./design.md) | 项目设计文档 | 了解整体架构、技术选型、模块设计 | | [design.md](./design.md) | 项目设计文档 | 了解整体架构、技术选型、模块设计 |
## 快速链接 ## 快速链接

14
pnpm-lock.yaml generated
View File

@@ -4567,8 +4567,8 @@ packages:
peerDependencies: peerDependencies:
zod: ^3.25.0 || ^4.0.0 zod: ^3.25.0 || ^4.0.0
zod@4.2.1: zod@3.25.76:
resolution: {integrity: sha512-0wZ1IRqGGhMP76gLqz8EyfBXKk0J2qo2+H3fi4mcUP/KtTocoX08nmIAHl1Z2kJIZbZee8KOpBCSNPRgauucjw==} resolution: {integrity: sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==}
snapshots: snapshots:
@@ -6967,8 +6967,8 @@ snapshots:
'@babel/parser': 7.28.5 '@babel/parser': 7.28.5
eslint: 9.39.2(jiti@2.6.1) eslint: 9.39.2(jiti@2.6.1)
hermes-parser: 0.25.1 hermes-parser: 0.25.1
zod: 4.2.1 zod: 3.25.76
zod-validation-error: 4.0.2(zod@4.2.1) zod-validation-error: 4.0.2(zod@3.25.76)
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
@@ -9621,8 +9621,8 @@ snapshots:
yocto-queue@0.1.0: {} 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: dependencies:
zod: 4.2.1 zod: 3.25.76
zod@4.2.1: {} zod@3.25.76: {}