Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .claude/settings.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"Bash(npx tsc:*)",
"Bash(findstr:*)",
"Bash(npx prettier:*)",
"Bash(cd:*)"
"Bash(cd:*)",
"Bash(npm install:*)"
]
}
}
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
- name: Write .env file
run: |
cat > /tmp/.env << EOF
NODE_ENV=${{ github.event.inputs.environment == 'release' && 'production' || 'development' }}
LOG_LEVEL=${{ github.event.inputs.environment == 'release' && 'info' || 'debug' }}
AI_API_KEY=${{ secrets.AI_API_KEY }}
AI_MODEL=${{ vars.AI_MODEL }}
AI_BASE_URL=${{ vars.AI_BASE_URL }}
Expand Down
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ Required environment variables (see `backend/.env.example`):
PORT=8080
NODE_ENV=development
WS_PATH=/ws
LOG_LEVEL=debug # Winston log level: debug|info|warn|error (default: info)
TENCENT_SECRET_ID=your_secret_id # Required for ASR service
TENCENT_SECRET_KEY=your_secret_key # Required for ASR service
TENCENT_REGION=ap-guangzhou # Required for ASR service
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@
│ └── utils/ # 工具函数
├── backend/ # Node.js 后端
│ ├── logs/ # 运行日志 (error.log, combined.log)
│ └── src/
│ ├── routes/ # HTTP 路由
│ ├── controllers/ # 控制器
│ ├── middleware/ # Express 中间件 (requestLogger)
│ ├── services/ # 业务逻辑 (core, websocket, handlers)
│ ├── models/ # 数据模型
│ └── types/ # 类型定义
│ ├── types/ # 类型定义
│ └── utils/ # 工具函数 (Winston logger)
└── docs/ # 项目文档
├── miniprogram/ # 前端文档 (页面、组件、服务)
Expand Down Expand Up @@ -92,10 +95,21 @@ npm run prepare # 初始化 Husky
```bash
npm run dev # 开发模式 (tsx watch, 热重载)
npm run build # 编译 TypeScript
npm start # 生产模式
npm start # 生产模式 (自动创建 logs/ 目录)
npm run lint # ESLint 检查
```

### 日志

后端使用 Winston 结构化日志,日志文件写入 `backend/logs/`:

| 文件 | 内容 |
| ------------------- | ------------------------ |
| `logs/combined.log` | 所有级别,JSON 格式 |
| `logs/error.log` | 仅 error 级别,JSON 格式 |

开发环境 Console 输出彩色可读格式,生产环境输出 JSON。通过 `LOG_LEVEL` 环境变量控制级别(默认 `info`)。

## 核心功能

### 房间系统
Expand Down
17 changes: 13 additions & 4 deletions backend/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ Three-layer architecture: Routes → Controllers → Services
| File | Purpose |
|------|---------|
| `src/index.ts` | Entry point, creates HTTP server, calls `initWebSocket()` |
| `src/app.ts` | Express app — only `express.json()` middleware + routes |
| `src/app.ts` | Express app — `express.json()` + `requestLogger` middleware + routes |
| `src/ws.ts` | WebSocket init, assigns `conn_*` IDs, delegates to controller |
| `src/utils/logger.ts` | Winston logger — dual API: legacy `log(tag, msg)` + structured `info(event, { meta })` |
| `src/middleware/requestLogger.ts` | Express middleware — logs every HTTP request with method/path/status/durationMs |
| `src/controllers/ws-controller.ts` | Central message router — routes messages AND orchestrates drum game timing + verdict generation |
| `src/controllers/verdict-http.controller.ts` | GET /v1/rooms/:roomId/verdict — fallback to fetch cached verdict |
| `src/services/core/verdict-orchestrator.service.ts` | Async verdict generation (LLM call + mapping + WS push) |
Expand Down Expand Up @@ -105,7 +107,6 @@ Schemas are in `src/models/schemas/`: `http-request.schema.ts`, `ws-message.sche
- **Database**: MongoDB config in `src/database/` — stubbed, not connected. All storage is in-memory via `room-manager.ts`
- **Repository layer**: Interfaces in `src/repositories/` — defined but no implementations
- **room-crud.service.ts**: All methods throw "Not implemented"
- **Middleware**: Error handler, request logger, and validation middleware are defined in `src/middlewares/` but **not used** by `app.ts`

## Adding New WebSocket Message Types

Expand Down Expand Up @@ -163,13 +164,21 @@ Key constants in `src/constants/config.ts`:
Required (see `.env.example`):
```bash
PORT=8080
NODE_ENV=development
NODE_ENV=development # 'production' enables JSON console output
WS_PATH=/ws
TENCENT_SECRET_ID=... # Required for ASR STS tokens
LOG_LEVEL=debug # Winston log level: debug | info | warn | error (default: info)
TENCENT_SECRET_ID=... # Required for ASR STS tokens
TENCENT_SECRET_KEY=...
TENCENT_REGION=ap-guangzhou
```

In CI/CD (`deploy.yml`), `NODE_ENV` and `LOG_LEVEL` are derived from the deployment environment:

| Environment | `NODE_ENV` | `LOG_LEVEL` |
|-------------|------------|-------------|
| `trial` | `development` | `debug` (all levels) |
| `release` | `production` | `info` (info/warn/error) |

Note: `.env.example` contains additional unused variables (OpenAI, LLM Worker) — only the above are read by the code.

## HTTP Endpoints
Expand Down
Loading
Loading