Skip to content

duyuanchao/private_chat

Repository files navigation

智能对话网站

基于 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: 用户认证和管理

AI 服务

  • 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 类型定义

安装和运行

1. 克隆项目

git clone <repository-url>
cd smart-chat-app

2. 安装依赖

npm install

3. 环境配置

复制 .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

4. 数据库设置

# 生成 Prisma 客户端
npm run db:generate

# 推送数据库 schema
npm run db:push

# 或者运行迁移
npm run db:migrate

5. 运行开发服务器

npm run dev

访问 http://localhost:3000 查看应用。

部署

Vercel 部署(推荐)

  1. 将代码推送到 GitHub
  2. 在 Vercel 中导入项目
  3. 配置环境变量
  4. 自动部署

手动部署

# 构建项目
npm run build

# 启动生产服务器
npm start

API 文档

tRPC 路由

  • user.*: 用户相关操作
  • peopleBook.*: 人物关系管理
  • workBoard.*: 事务板管理
  • chat.*: 聊天相关操作

主要 API 端点

// 用户
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()

开发指南

添加新功能

  1. prisma/schema.prisma 中定义数据模型
  2. src/server/api/routers/ 中创建 tRPC 路由
  3. src/types/ 中定义 TypeScript 类型
  4. src/components/ 中创建 UI 组件
  5. src/app/ 中创建页面

代码规范

  • 使用 TypeScript 进行类型检查
  • 使用 ESLint 进行代码检查
  • 使用 Prettier 进行代码格式化
  • 遵循 React 和 Next.js 最佳实践

贡献

  1. Fork 项目
  2. 创建功能分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 打开 Pull Request

许可证

本项目基于 MIT 许可证 - 查看 LICENSE 文件了解详情。

联系方式

如有问题或建议,请创建 Issue 或联系开发者。

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •