{ "nodes": [ { "id": "title", "type": "text", "text": "# tg-live-game-hono 架构\n\n**版本**: v1.1.0\n**技术栈**: Hono + Cloudflare Workers + D1\n**状态**: ✅ 已实现\n\n新增功能:\n- JWT 认证\n- 用户管理\n- RBAC 权限", "x": -100, "y": -600, "width": 350, "height": 160, "color": "6" }, { "id": "entry", "type": "text", "text": "**入口文件**\n`src/index.ts`\n\n功能:\n- Hono 应用初始化\n- CORS/日志中间件\n- 路由挂载\n - /api/auth (公开)\n - /api/users (admin)\n - /api/stream\n\n端口: localhost:8787", "x": -550, "y": -380, "width": 280, "height": 220, "color": "4" }, { "id": "middleware", "type": "text", "text": "**中间件**\n`src/middleware/auth.ts`\n\n- authMiddleware()\n 验证 JWT Token\n- requireRole(roles)\n 角色权限检查\n- requirePermission()\n 资源权限检查\n- optionalAuth()\n 可选认证", "x": -550, "y": -100, "width": 280, "height": 200, "color": "5" }, { "id": "routes_auth", "type": "text", "text": "**认证路由**\n`src/routes/auth.ts`\n\n公开接口:\n- POST /login\n- POST /register\n- POST /refresh\n\n需认证:\n- GET /me\n- POST /change-password\n- POST /logout", "x": -200, "y": -380, "width": 260, "height": 220, "color": "2" }, { "id": "routes_user", "type": "text", "text": "**用户路由**\n`src/routes/user.ts`\n\n需 admin 角色:\n- GET /users\n- GET /users/:id\n- POST /users\n- PUT /users/:id\n- DELETE /users/:id\n\n权限管理:\n- GET /users/:id/permissions\n- POST /users/:id/permissions\n- DELETE /users/:id/permissions/:id", "x": 120, "y": -380, "width": 280, "height": 280, "color": "2" }, { "id": "routes_stream", "type": "text", "text": "**Stream 路由**\n`src/routes/stream.ts`\n\n视频管理 (13个端点)\n直播管理\n\n需认证 ✅", "x": 460, "y": -380, "width": 220, "height": 140, "color": "2" }, { "id": "services_auth", "type": "text", "text": "**认证服务**\n`src/services/auth.ts`\n\nAuthService:\n- login()\n- register()\n- refreshToken()\n- getCurrentUser()\n- changePassword()\n- logAudit()", "x": -200, "y": -100, "width": 260, "height": 180, "color": "3" }, { "id": "services_cf", "type": "text", "text": "**Stream 服务**\n`src/services/cloudflare.ts`\n\nCloudflareStreamService:\n- 视频 CRUD\n- 直播 CRUD\n- 播放信息", "x": 460, "y": -180, "width": 220, "height": 140, "color": "3" }, { "id": "utils", "type": "text", "text": "**工具函数**\n`src/utils/`\n\njwt.ts:\n- createToken()\n- verifyToken()\n- generateId()\n\npassword.ts:\n- hashPassword()\n- verifyPassword()\n\n算法: PBKDF2 + HMAC-SHA256", "x": 120, "y": -40, "width": 280, "height": 200, "color": "4" }, { "id": "database", "type": "text", "text": "**D1 数据库**\n\n表:\n- users\n- user_permissions\n- cameras\n- live_sessions\n- videos\n- view_stats\n- audit_logs\n\n详见: d1-database.canvas", "x": -550, "y": 160, "width": 280, "height": 200, "color": "1" }, { "id": "env_vars", "type": "text", "text": "**环境变量**\n\nCloudflare:\n- CF_ACCOUNT_ID\n- CF_API_TOKEN\n- CUSTOMER_SUBDOMAIN\n\nJWT:\n- JWT_SECRET\n- JWT_EXPIRES_IN\n- REFRESH_EXPIRES_IN\n\nD1:\n- DB binding", "x": -200, "y": 140, "width": 260, "height": 220, "color": "4" }, { "id": "types", "type": "text", "text": "**类型定义**\n`src/types/index.ts`\n\n新增:\n- JwtPayload\n- LoginRequest\n- RegisterRequest\n- AuthResponse\n- User\n- UserPermission\n- Camera\n- LiveSession\n- ...", "x": 460, "y": 20, "width": 220, "height": 220, "color": "5" } ], "edges": [ { "id": "edge_entry_mw", "fromNode": "entry", "fromSide": "bottom", "toNode": "middleware", "toSide": "top", "label": "use()" }, { "id": "edge_entry_auth", "fromNode": "entry", "fromSide": "right", "toNode": "routes_auth", "toSide": "left", "label": "/api/auth" }, { "id": "edge_entry_user", "fromNode": "entry", "fromSide": "right", "toNode": "routes_user", "toSide": "left", "label": "/api/users" }, { "id": "edge_user_stream", "fromNode": "routes_user", "fromSide": "right", "toNode": "routes_stream", "toSide": "left", "label": "/api/stream" }, { "id": "edge_auth_service", "fromNode": "routes_auth", "fromSide": "bottom", "toNode": "services_auth", "toSide": "top", "label": "AuthService" }, { "id": "edge_service_utils", "fromNode": "services_auth", "fromSide": "right", "toNode": "utils", "toSide": "left", "label": "jwt/password" }, { "id": "edge_stream_cf", "fromNode": "routes_stream", "fromSide": "bottom", "toNode": "services_cf", "toSide": "top", "label": "StreamService" }, { "id": "edge_mw_db", "fromNode": "middleware", "fromSide": "bottom", "toNode": "database", "toSide": "top", "label": "权限查询" }, { "id": "edge_service_db", "fromNode": "services_auth", "fromSide": "bottom", "toNode": "database", "toSide": "right", "label": "用户查询" }, { "id": "edge_cf_types", "fromNode": "services_cf", "fromSide": "bottom", "toNode": "types", "toSide": "top", "label": "import" } ] }