architecture.canvas 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. {
  2. "nodes": [
  3. {
  4. "id": "title",
  5. "type": "text",
  6. "text": "# tg-live-game-hono 架构\n\n**版本**: v1.1.0\n**技术栈**: Hono + Cloudflare Workers + D1\n**状态**: ✅ 已实现\n\n新增功能:\n- JWT 认证\n- 用户管理\n- RBAC 权限",
  7. "x": -100,
  8. "y": -600,
  9. "width": 350,
  10. "height": 160,
  11. "color": "6"
  12. },
  13. {
  14. "id": "entry",
  15. "type": "text",
  16. "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",
  17. "x": -550,
  18. "y": -380,
  19. "width": 280,
  20. "height": 220,
  21. "color": "4"
  22. },
  23. {
  24. "id": "middleware",
  25. "type": "text",
  26. "text": "**中间件**\n`src/middleware/auth.ts`\n\n- authMiddleware()\n 验证 JWT Token\n- requireRole(roles)\n 角色权限检查\n- requirePermission()\n 资源权限检查\n- optionalAuth()\n 可选认证",
  27. "x": -550,
  28. "y": -100,
  29. "width": 280,
  30. "height": 200,
  31. "color": "5"
  32. },
  33. {
  34. "id": "routes_auth",
  35. "type": "text",
  36. "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",
  37. "x": -200,
  38. "y": -380,
  39. "width": 260,
  40. "height": 220,
  41. "color": "2"
  42. },
  43. {
  44. "id": "routes_user",
  45. "type": "text",
  46. "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",
  47. "x": 120,
  48. "y": -380,
  49. "width": 280,
  50. "height": 280,
  51. "color": "2"
  52. },
  53. {
  54. "id": "routes_stream",
  55. "type": "text",
  56. "text": "**Stream 路由**\n`src/routes/stream.ts`\n\n视频管理 (13个端点)\n直播管理\n\n需认证 ✅",
  57. "x": 460,
  58. "y": -380,
  59. "width": 220,
  60. "height": 140,
  61. "color": "2"
  62. },
  63. {
  64. "id": "services_auth",
  65. "type": "text",
  66. "text": "**认证服务**\n`src/services/auth.ts`\n\nAuthService:\n- login()\n- register()\n- refreshToken()\n- getCurrentUser()\n- changePassword()\n- logAudit()",
  67. "x": -200,
  68. "y": -100,
  69. "width": 260,
  70. "height": 180,
  71. "color": "3"
  72. },
  73. {
  74. "id": "services_cf",
  75. "type": "text",
  76. "text": "**Stream 服务**\n`src/services/cloudflare.ts`\n\nCloudflareStreamService:\n- 视频 CRUD\n- 直播 CRUD\n- 播放信息",
  77. "x": 460,
  78. "y": -180,
  79. "width": 220,
  80. "height": 140,
  81. "color": "3"
  82. },
  83. {
  84. "id": "utils",
  85. "type": "text",
  86. "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",
  87. "x": 120,
  88. "y": -40,
  89. "width": 280,
  90. "height": 200,
  91. "color": "4"
  92. },
  93. {
  94. "id": "database",
  95. "type": "text",
  96. "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",
  97. "x": -550,
  98. "y": 160,
  99. "width": 280,
  100. "height": 200,
  101. "color": "1"
  102. },
  103. {
  104. "id": "env_vars",
  105. "type": "text",
  106. "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",
  107. "x": -200,
  108. "y": 140,
  109. "width": 260,
  110. "height": 220,
  111. "color": "4"
  112. },
  113. {
  114. "id": "types",
  115. "type": "text",
  116. "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- ...",
  117. "x": 460,
  118. "y": 20,
  119. "width": 220,
  120. "height": 220,
  121. "color": "5"
  122. }
  123. ],
  124. "edges": [
  125. {
  126. "id": "edge_entry_mw",
  127. "fromNode": "entry",
  128. "fromSide": "bottom",
  129. "toNode": "middleware",
  130. "toSide": "top",
  131. "label": "use()"
  132. },
  133. {
  134. "id": "edge_entry_auth",
  135. "fromNode": "entry",
  136. "fromSide": "right",
  137. "toNode": "routes_auth",
  138. "toSide": "left",
  139. "label": "/api/auth"
  140. },
  141. {
  142. "id": "edge_entry_user",
  143. "fromNode": "entry",
  144. "fromSide": "right",
  145. "toNode": "routes_user",
  146. "toSide": "left",
  147. "label": "/api/users"
  148. },
  149. {
  150. "id": "edge_user_stream",
  151. "fromNode": "routes_user",
  152. "fromSide": "right",
  153. "toNode": "routes_stream",
  154. "toSide": "left",
  155. "label": "/api/stream"
  156. },
  157. {
  158. "id": "edge_auth_service",
  159. "fromNode": "routes_auth",
  160. "fromSide": "bottom",
  161. "toNode": "services_auth",
  162. "toSide": "top",
  163. "label": "AuthService"
  164. },
  165. {
  166. "id": "edge_service_utils",
  167. "fromNode": "services_auth",
  168. "fromSide": "right",
  169. "toNode": "utils",
  170. "toSide": "left",
  171. "label": "jwt/password"
  172. },
  173. {
  174. "id": "edge_stream_cf",
  175. "fromNode": "routes_stream",
  176. "fromSide": "bottom",
  177. "toNode": "services_cf",
  178. "toSide": "top",
  179. "label": "StreamService"
  180. },
  181. {
  182. "id": "edge_mw_db",
  183. "fromNode": "middleware",
  184. "fromSide": "bottom",
  185. "toNode": "database",
  186. "toSide": "top",
  187. "label": "权限查询"
  188. },
  189. {
  190. "id": "edge_service_db",
  191. "fromNode": "services_auth",
  192. "fromSide": "bottom",
  193. "toNode": "database",
  194. "toSide": "right",
  195. "label": "用户查询"
  196. },
  197. {
  198. "id": "edge_cf_types",
  199. "fromNode": "services_cf",
  200. "fromSide": "bottom",
  201. "toNode": "types",
  202. "toSide": "top",
  203. "label": "import"
  204. }
  205. ]
  206. }