- 架构类型 :Modern Full-Stack Web Application
- 核心目标 :构建一个高性能、可扩展、类型安全的现代化 Web 应用。
- 部署环境 :Vercel (首选)
- Framework : Next.js 14+ (App Router)
- Language : TypeScript 5+ (Strict Mode)
- Package Manager : pnpm
- Internationalization : 待定(Phase 5,优先完成中文版本)
- Styling : Tailwind CSS 3.4+ (使用 Utility-first 原则)
- Components : Shadcn/ui (基于 Radix UI)
- Icons : Lucide React
- State Management :
- Server State: TanStack Query (React Query) 或 Next.js Server Actions
- Global Client State: Zustand (仅在必要时使用,优先利用 URL state 和 Server State)
- Forms : React Hook Form + Zod (Validation)
- API Pattern : Next.js Server Actions (优先) + Route Handlers (用于 Webhooks/REST)
- Database : PostgreSQL
- ORM : Drizzle ORM (首选,因其轻量且类型推断强) 或 Prisma
- Auth : Clerk / NextAuth.js (Auth.js)
- Env 管理 :
src/lib/env.ts使用 Zod 校验process.env - Linting : ESLint + Next.js
next lint - Date Handling : date-fns
- UI 基础 : shadcn/ui(配置见
components.json) - 调试工具 :
/api/health/db路由可快速验证数据库连接
采用基于功能的模块化结构,而非单纯基于文件类型。
src/
├── app/ # App Router 页面与 API
│ ├── api/health/db # 数据库健康检查 Route Handler
│ ├── layout.tsx # Root layout(含 Header/Footer)
│ └── page.tsx # 首页占位
├── components/
│ ├── shared/ # Header、Footer 等跨页面组件
│ └── ui/ # shadcn/ui 基础组件 (button 等)
├── db/ # Drizzle schema 定义
├── lib/
│ ├── db.ts # Drizzle + postgres 连接
│ ├── env.ts # Zod 校验的环境变量
│ └── utils.ts # cn 等工具函数
说明:
server/与types/目录可在后续阶段按需补充(如需要自定义 Server Actions 或全局类型)。
.env基于env.example配置,必须提供DATABASE_URLdrizzle.config.ts指向src/db/schema.ts,迁移输出在/drizzle- Docker PostgreSQL 推荐端口:
5433 -> 5432(避免与系统实例冲突) components.json已初始化,新增 UI 组件时使用pnpm dlx shadcn@latest add ...
- Server Components First : 默认使用服务端组件(RSC)。仅在需要
useState,useEffect, 或事件监听时添加"use client"。 - Composition : 避免创建巨大的单一组件,拆分为小型的、单一职责的组件。
- Props Interface : 所有组件必须显式定义 Props 接口,避免使用
any。
- 在 RSC (Server Components) 中,直接通过 DB/ORM 调用获取数据,不要通过内部 API Route fetch。
- 在 Client Components 中,使用 Server Actions 或 React Query。
- 严禁使用 CSS Modules 或 styled-components,必须使用 Tailwind CSS。
- 使用
clsx或cn工具函数处理条件类名。 - 保持响应式设计,优先使用
sm:,md:,lg:前缀。
- UI 层使用
error.tsx(Error Boundaries)。 - Server Actions 必须返回标准化的
{ success: boolean, data?: T, error?: string }结构,而非直接抛出异常导致页面崩溃。
- Files :
kebab-case.tsx(如user-profile.tsx) 或PascalCase(组件文件)。 - Components :
PascalCase(如UserProfile)。 - Functions :
camelCase(如getUserById)。 - Database :
snake_case(表名和字段名)。