tanish-jain-225/fixbot-incident-response-manager
GitHub: tanish-jain-225/fixbot-incident-response-manager
AI 驱动的事故分析平台,将生产日志和堆栈跟踪转化为根因诊断和生产级修复建议。
Stars: 0 | Forks: 0
# FixBot
AI 驱动的事件分析平台,可将日志和堆栈跟踪转化为具体的根本原因和可用于生产环境的代码修复。
FixBot 由三个可部署的服务构建而成:
- `client` - Vite + React UI
- `server` - Express API、认证和 MongoDB 持久化
- `ml-server` - 具备提供商回退功能的 Express AI 推理服务
## 为什么选择 FixBot
生产环境调试通常缓慢、手动且不一致。FixBot 通过以下方式缩短了从事件发生到修复的闭环:
- 分析真实的日志文本和可选的代码片段,
- 严重程度分类,
- 生成上下文感知的修复和解释,
- 按认证用户存储历史记录,
- 自动发送分析报告邮件(需配置 SMTP),
- 使用弹性的 AI 路由(Resinix 为主,Gemini 为备用)。
## 核心功能
- 具有严格输入验证的日志 + 代码分析端点
- 严重程度分类(`Critical`、`Warning`、`Minor`)
- 根本原因诊断和具体修复建议
- 置信度评分(`0-100`)
- JWT 认证(`signup`、`login`、`me`)
- 用户范围内的事件历史记录
- 删除单个事件或清除所有事件历史记录
- 可选的邮件通知,附带事件分析附件
- 双 AI 提供商策略以实现更高可用性
## 架构
```
[React Client]
|
| HTTP
v
[Server API + MongoDB]
|
| HTTP
v
[ML Server]
| \
| \
Resinix Gemini (fallback)
```
### 服务端口(本地)
- Client: `5173`
- Server: `5000`
- ML Server: `8000`
## 仓库布局
```
Syrus2026_HackHunters/
client/
server/
ml-server/
```
### 重要路径
```
client/src/services/api.js
server/server.js
server/routes/authRoutes.js
server/routes/incidentRoutes.js
server/controllers/authController.js
server/controllers/incidentController.js
server/services/mlService.js
ml-server/mlServer.js
ml-server/routes/analyze.js
ml-server/services/resinixService.js
ml-server/prompts/debugPrompt.js
```
## 前置条件
- Node.js `20.x`(推荐用于 Vercel 兼容性)
- npm `9+`
- MongoDB 实例(本地或 Atlas)
- Resinix API key
- Gemini API key(推荐作为备用)
- 可选的 SMTP 凭证用于邮件报告
## 本地设置
### 1. 安装依赖
```
cd client && npm install
cd ../server && npm install
cd ../ml-server && npm install
```
### 2. 配置环境变量
#### `server/.env`
```
# MongoDB
MONGO_URI=mongodb://localhost:27017
MONGO_DB_NAME=fixbot
USERS_COLLECTION_NAME=users
INCIDENTS_COLLECTION_NAME=incidents
# Server
PORT=5000
CORS_ORIGIN=http://localhost:5173
# Auth
JWT_SECRET=replace_with_a_long_random_secret
# ML integration
ML_SERVER_URL=http://localhost:8000
# Optional email notifications
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your_email@example.com
EMAIL_PASS=your_app_password
EMAIL_FROM=
```
#### `ml-server/.env`
```
PORT=8000
CORS_ORIGIN=*
# Primary AI
RESINIX_API_KEY=your_resinix_api_key_here
RESINIX_API_URL=https://api.resinix.ai/v1/chat/completions
# Fallback AI
GEMINI_API_KEY=your_gemini_api_key_here
GEMINI_MODEL=gemini-2.5-flash
```
#### `client/.env`
```
VITE_API_URL=http://localhost:5000
VITE_APP_NAME=FixBot
VITE_APP_VERSION=0.1.0
```
### 3. 启动服务(3 个终端)
```
# Terminal 1
cd ml-server
npm run dev
```
```
# Terminal 2
cd server
npm run dev
```
```
# Terminal 3
cd client
npm run dev
```
打开 `http://localhost:5173`。
## API 概述
Base URL (server): `http://localhost:5000`
### Auth
#### `POST /api/auth/signup`
创建用户账户。
请求:
```
{
"email": "user@example.com",
"password": "secret123"
}
```
响应:
```
{
"token": "jwt-token",
"user": {
"id": "...",
"email": "user@example.com"
}
}
```
#### `POST /api/auth/login`
认证并返回 JWT。
#### `GET /api/auth/me`
获取当前用户资料。需要 `Authorization: Bearer `。
### Incidents(需认证)
#### `POST /api/incidents/analyze`
分析事件并将其持久化。
请求:
```
{
"logText": "TypeError: Cannot read properties of undefined",
"codeSnippet": "function x(y){ return y.map(z => z.id); }"
}
```
响应字段包括:
- `severity`
- `rootCause`
- `suggestedFix`
- `explanation`
- `confidenceScore`
- 存储的事件元数据(`_id`、时间戳等)
#### `GET /api/incidents`
获取用户事件历史记录。
Query params:
- `severity`
- `limit`(默认 `50`,最大 `100`)
- `skip`(默认 `0`)
#### `GET /api/incidents/:id`
根据 ID 获取单个事件。
#### `DELETE /api/incidents/:id`
根据 ID 删除单个事件。
#### `DELETE /api/incidents`
清除当前用户的所有事件。
### Health Endpoints
- Server: `GET /health`
- ML Server: `GET /health`
## AI 流程
1. Client 提交 `logText` 和可选的 `codeSnippet`。
2. Server 验证 payload 并调用 ML Server(`/api/analyze`)。
3. ML Server 构建结构化 prompt。
4. 首先调用主提供商。
5. 如果出现符合条件的失败,则使用备用提供商。
6. 返回规范化的分析结果并将其持久化。
7. Server 将最终的事件对象返回给 client。
## 部署(Vercel)
此仓库作为三个独立的 Vercel 项目部署:
- `client`
- `server`
- `ml-server`
每个服务都有自己的 `vercel.json`。
### 推荐的部署流程
1. 在每个 Vercel 项目设置中将 Node.js 运行时设置为 `20.x`。
2. 在每个 Vercel 项目中配置环境变量。
3. 从各自文件夹的根目录部署每个项目。
### 本地预部署冒烟测试
```
cd client && npx vercel build --yes
cd ../server && npx vercel build --yes
cd ../ml-server && npx vercel build --yes
```
如果您看到 `Project Settings could not be retrieved`,请使用 Vercel CLI 重新链接该文件夹。
## 脚本
### Client
- `npm run dev`
- `npm run build`
- `npm run preview`
- `npm run lint`
- `npm run lint:fix`
### Server
- `npm run dev`
- `npm run start`
- `npm run backfill:user-email`
### ML Server
- `npm run dev`
- `npm run start`
## 故障排除
### Server 初始化失败
检查:
- `JWT_SECRET` 是否存在
- `MONGO_URI` 是否存在
- `MONGO_DB_NAME` 是否存在
### 事件分析返回 503
检查:
- ML server 是否正在运行
- `ML_SERVER_URL` 是否正确
### 浏览器 CORS 错误
检查:
- `server/.env` 中的 `CORS_ORIGIN`
- `client/.env` 中的 `VITE_API_URL`
### 无邮件通知
邮件发送是可选的。在 server 中配置 SMTP 环境变量并验证凭证。
### AI 认证/限流错误
验证 Resinix 和 Gemini API keys 以及配额状态。
## 安全注意事项
- 不要将 `.env` 文件加入版本控制
- 使用强 `JWT_SECRET`
- 在生产环境中将 CORS 限制为已知来源
- 定期轮换 AI 和 SMTP 密钥
标签:AIOps, BurpSuite集成, Express, Gemini, GNU通用公共许可证, JWT 认证, MITM代理, MongoDB, Node.js, React, REST API, Syscalls, Vite, 事件分析, 人工智能, 代码修复, 代码生成, 堆栈跟踪, 安全认证, 微服务架构, 故障排查, 智能运维, 根因分析, 渗透测试工具, 生产环境, 用户模式Hook绕过, 自动修复, 自定义脚本, 软件调试, 运维工具, 邮件通知, 错误诊断