基于 Next.js + TypeScript + Prisma + Dify API 构建的智能对话网站,支持 RAG 检索、人物关系管理和事务板管理。
- 🤖 智能对话: 基于 Dify API 的 AI 对话,支持 RAG 上下文检索
- 👥 人物关系管理: 创建、编辑、删除人物信息,支持标签分类
- 📋 事务板管理: 工作任务管理,支持状态跟踪和优先级设置
- 🔐 用户认证: 基于 Clerk 的完整用户认证系统
- 📱 响应式设计: 现代化 UI,支持移动端和桌面端
- Next.js 14: React 框架,使用 App Router
- TypeScript: 类型安全的 JavaScript
- TailwindCSS: 实用优先的 CSS 框架
- shadcn/ui: 现代化的 React 组件库
- Zustand: 轻量级状态管理
- React Query: 数据获取和缓存
- tRPC: 端到端类型安全的 API
- Prisma: 现代化的数据库 ORM
- PostgreSQL: 关系型数据库
- Clerk: 用户认证和管理
- Dify API: 大模型对话和 RAG 检索服务
src/
├── app/ # Next.js App Router 页面
│ ├── api/ # API 路由
│ ├── chat/ # 聊天页面
│ ├── people/ # 人物管理页面
│ ├── work/ # 事务管理页面
│ └── settings/ # 设置页面
├── components/ # React 组件
│ ├── ui/ # 基础 UI 组件
│ └── providers/ # 上下文提供者
├── lib/ # 工具函数和配置
│ ├── db.ts # 数据库连接
│ ├── dify.ts # Dify API 服务
│ ├── trpc.ts # tRPC 客户端
│ └── utils.ts # 通用工具函数
├── server/ # 服务端代码
│ └── api/ # tRPC 路由
│ ├── routers/ # API 路由定义
│ ├── root.ts # 根路由
│ └── trpc.ts # tRPC 配置
├── store/ # Zustand 状态管理
└── types/ # TypeScript 类型定义
git clone <repository-url>
cd smart-chat-appnpm install复制 .env.example 到 .env 并配置以下环境变量:
# 数据库
DATABASE_URL="postgresql://username:password@localhost:5432/smart_chat_db"
# Clerk 认证
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_xxx
CLERK_SECRET_KEY=sk_test_xxx
# Dify API
DIFY_API_KEY=app-xxx
DIFY_BASE_URL=https://api.dify.ai/v1
# Next.js
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-secret-here# 生成 Prisma 客户端
npm run db:generate
# 推送数据库 schema
npm run db:push
# 或者运行迁移
npm run db:migratenpm run dev访问 http://localhost:3000 查看应用。
- 将代码推送到 GitHub
- 在 Vercel 中导入项目
- 配置环境变量
- 自动部署
# 构建项目
npm run build
# 启动生产服务器
npm startuser.*: 用户相关操作peopleBook.*: 人物关系管理workBoard.*: 事务板管理chat.*: 聊天相关操作
// 用户
api.user.getProfile.useQuery()
api.user.createOrUpdate.useMutation()
// 人物关系
api.peopleBook.getAll.useQuery()
api.peopleBook.create.useMutation()
api.peopleBook.update.useMutation()
api.peopleBook.delete.useMutation()
// 事务板
api.workBoard.getAll.useQuery()
api.workBoard.create.useMutation()
api.workBoard.update.useMutation()
api.workBoard.delete.useMutation()
// 聊天
api.chat.getSessions.useQuery()
api.chat.createSession.useMutation()
api.chat.retrieveContext.useMutation()
api.chat.sendMessage.useMutation()- 在
prisma/schema.prisma中定义数据模型 - 在
src/server/api/routers/中创建 tRPC 路由 - 在
src/types/中定义 TypeScript 类型 - 在
src/components/中创建 UI 组件 - 在
src/app/中创建页面
- 使用 TypeScript 进行类型检查
- 使用 ESLint 进行代码检查
- 使用 Prettier 进行代码格式化
- 遵循 React 和 Next.js 最佳实践
- Fork 项目
- 创建功能分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 打开 Pull Request
本项目基于 MIT 许可证 - 查看 LICENSE 文件了解详情。
如有问题或建议,请创建 Issue 或联系开发者。