diff --git a/README.md b/README.md index 702ea34..0cbdd85 100644 --- a/README.md +++ b/README.md @@ -214,14 +214,16 @@ CamTalk/ - **PostgreSQL** >= 15(可选 Docker) - **Redis** >= 7(可选,用于缓存加速) -### 1. 克隆项目 +### 本地开发 + +#### 1. 克隆项目 ```bash git clone https://github.com/yourusername/CamTalk.git cd CamTalk ``` -### 2. 配置环境变量 +#### 2. 配置环境变量 ```bash # 复制环境变量模板 @@ -235,7 +237,7 @@ cp backend/.env.example backend/.env # - CAMTALK_AI_TTS_API_KEY(MiMo/OpenAI API Key) ``` -### 3. 启动后端 +#### 3. 启动后端 ```bash cd backend @@ -250,7 +252,7 @@ go run ./cmd/server migrate go run ./cmd/server ``` -### 4. 启动前端 +#### 4. 启动前端 ```bash cd frontend @@ -262,27 +264,93 @@ npm install npm run dev ``` -### 5. 访问应用 +#### 5. 访问应用 打开浏览器访问 [http://localhost:5173](http://localhost:5173),注册账号后即可开始使用。 ---- - -### 🐳 Docker 快速部署(生产环境) +#### 6. 代码检查与测试 ```bash -# 一键启动全部服务(frontend + backend + postgres + redis) +# 安装 Go 代码检查工具 +go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + +# 运行后端代码检查 +cd backend +golangci-lint run + +# 后端单元测试 +go test ./... + +# 后端集成测试(需要 PostgreSQL) +go test -tags=integration ./... + +# 前端代码检查 +cd frontend +npm run lint + +# 前端测试 +npm test +``` + +### 远程部署 + +#### 方式一:Docker Compose(推荐) + +```bash +# 1. 克隆代码到服务器 +git clone https://github.com/yourusername/CamTalk.git +cd CamTalk + +# 2. 配置环境变量 +cp backend/.env.example backend/.env +# 编辑 .env 文件,填入生产环境配置 + +# 3. 一键部署(frontend + backend + postgres + redis) ./deploy.sh up -# 停止服务 -./deploy.sh down - -# 查看日志 +# 4. 查看日志 ./deploy.sh logs + +# 5. 停止服务 +./deploy.sh down ``` 部署完成后访问 [http://localhost:9000](http://localhost:9000) +#### 方式二:手动部署 + +```bash +# 1. 构建前端 +cd frontend +npm install +npm run build # 输出到 dist/ + +# 2. 构建后端 +cd backend +go build -o camtalk ./cmd/server + +# 3. 配置 Nginx +# 参考 nginx.conf.example 配置反向代理 + +# 4. 启动服务 +APP_ENV=prod ./camtalk + +# 5. 使用 systemd 管理(可选) +sudo systemctl enable camtalk +sudo systemctl start camtalk +``` + +#### 环境变量检查清单 + +部署前确保已配置以下环境变量: + +- ✅ `CAMTALK_AUTH_JWT_SECRET`(使用 `openssl rand -hex 32` 生成) +- ✅ `CAMTALK_STORAGE_DSN`(PostgreSQL 连接字符串) +- ✅ `CAMTALK_AI_LLM_API_KEY`(DashScope API Key) +- ✅ `CAMTALK_AI_STT_API_KEY`(STT 服务 API Key) +- ✅ `CAMTALK_AI_TTS_API_KEY`(TTS 服务 API Key) +- ✅ `APP_ENV=prod`(启用生产环境配置) + ### 配置优先级 ``` @@ -443,10 +511,6 @@ CamTalk 采用 **JWT 双 token 轮转 + Refresh Token Rotation** 安全机制: **水平扩展**:Gateway 无状态设计,会话状态存储在 Redis/PostgreSQL,支持多实例部署。 -## 📖 文档 -|------|------| -| [01-架构设计](docs/01-架构设计.md) | 三层架构、技术栈、数据库设计、部署方案 | -| [02-接口文档](docs/02-接口文档.md) | WebSocket 协议、REST API、AI 服务层、编排器、配置管理 | ## 📖 文档 ### 核心设计文档 @@ -472,107 +536,6 @@ CamTalk 采用 **JWT 双 token 轮转 + Refresh Token Rotation** 安全机制: | [09-情景切换](docs/09-情景切换.md) | 情景模式设计与实现 | | [12-自定义情景](docs/12-自定义情景.md) | 用户自定义情景功能(规划中) | -## 🛠️ 本地开发和远程部署指南 - -### 本地开发环境配置 - -#### 1. 代码检查工具 - -```bash -# 安装 Go 代码检查工具 -go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest - -# 运行代码检查 -cd backend -golangci-lint run - -# 前端代码检查 -cd frontend -npm run lint -``` - -#### 2. 运行测试 - -```bash -# 后端单元测试 -cd backend -go test ./... - -# 后端集成测试(需要 PostgreSQL) -go test -tags=integration ./... - -# 前端测试 -cd frontend -npm test -``` - -#### 3. 数据库迁移 - -```bash -# 运行迁移(自动创建/更新表结构) -cd backend -go run ./cmd/server migrate - -# 回滚迁移 -go run ./cmd/server migrate:rollback -``` - -### 远程服务器部署 - -#### 方式一:Docker Compose - -```bash -# 1. 克隆代码到服务器 -git clone https://github.com/yourusername/CamTalk.git -cd CamTalk - -# 2. 配置环境变量 -cp backend/.env.example backend/.env -# 编辑 .env 文件,填入生产环境配置 - -# 3. 一键部署 -./deploy.sh up - -# 4. 查看日志 -./deploy.sh logs - -# 5. 停止服务 -./deploy.sh down -``` - -#### 方式二:手动部署 - -```bash -# 1. 构建前端 -cd frontend -npm install -npm run build # 输出到 dist/ - -# 2. 构建后端 -cd backend -go build -o camtalk ./cmd/server - -# 3. 配置 Nginx -# 参考 nginx.conf.example 配置反向代理 - -# 4. 启动服务 -APP_ENV=prod ./camtalk - -# 5. 使用 systemd 管理(可选) -sudo systemctl enable camtalk -sudo systemctl start camtalk -``` - -#### 环境变量检查清单 - -部署前确保已配置以下环境变量: - -- ✅ `CAMTALK_AUTH_JWT_SECRET`(使用 `openssl rand -hex 32` 生成) -- ✅ `CAMTALK_STORAGE_DSN`(PostgreSQL 连接字符串) -- ✅ `CAMTALK_AI_LLM_API_KEY`(DashScope API Key) -- ✅ `CAMTALK_AI_STT_API_KEY`(STT 服务 API Key) -- ✅ `CAMTALK_AI_TTS_API_KEY`(TTS 服务 API Key) -- ✅ `APP_ENV=prod`(启用生产环境配置) ## 🐛 问题反馈