diff --git a/apps/admin-portal/docs/01-understanding.md b/apps/admin-portal/docs/01-understanding.md new file mode 100644 index 0000000..b19752f --- /dev/null +++ b/apps/admin-portal/docs/01-understanding.md @@ -0,0 +1,233 @@ +# 模块理解确认书 — admin-portal + +> AI:ai07(TS/React · 管理场景域前端 remote) +> 阶段:阶段 1 交付物 +> 日期:2026-07-09 +> 关联:[004 架构影响地图](../../../docs/architecture/004_architecture_impact_map.md) §1.1a/1.1b/§5.4、[AI 分配方案](../../../docs/architecture/ai-allocation.md) §5 ai07、[pending-features P6](../../../docs/architecture/roadmap/pending-features.md)、[known-issues §2.12](../../../docs/troubleshooting/known-issues.md)、[teacher-portal 阶段1](../../teacher-portal/docs/01-understanding.md)、[teacher-portal 阶段2](../../teacher-portal/docs/02-architecture-design.md) + +--- + +## 1. 我在架构中的位置 + +- **层级**:L2 微前端层(004 §3.1 六层架构中的前端层) +- **MF 角色**:**Remote 子应用**,挂载到 teacher-portal Shell(主应用) +- **上游(谁调用我)**:浏览器(系统管理员 / 校管理员) +- **下游(同步)**:api-gateway(REST,经 teacher-portal Shell 的 Next.js `rewrites` 代理 `/api/v1/*`) +- **下游(推送)**:— (**不消费推送**,管理端用轮询) +- **BFF 对接**:teacher-bff 复用(`/admin/*` 聚合)+ iam 直连(`/iam/*` 用户/角色/权限/视口 CRUD) +- **通信方式**:HTTP/REST(前端→Gateway) +- **不直连**:前端不直连任何业务服务或 BFF 后端实例,全部经 api-gateway 代理 + +**说明**: + +- admin-portal 作为 Remote 子应用,挂载到 teacher-portal Shell 提供的 AppShell + 共享依赖(react/react-dom/@tanstack/react-query/zustand/nuqs/ui-components/ui-tokens/contracts/hooks) +- 路由前缀 `/admin/*` 由 teacher-portal Shell 动态加载 admin-portal Remote 模块 +- 场景域 BFF 复用策略(004 §5.4):系统/校管理员复用 teacher-portal Shell + teacher-bff(`/admin/*` 视口)+ iam 直连,不单独建 portal 后端 +- 全部业务请求经 api-gateway 代理,admin-portal 本身不实现 rewrites(依赖 Shell 的 rewrites) + +## 2. 我的限界上下文 + +### 2.1 我负责的聚合 / 实体(前端视图模型) + +- 用户、角色、权限、视口(管理场景域前端视图) +- 组织(学校/年级/班级层级) +- 平台监控(运行时指标、用户活动、错误统计) +- 会话状态(Session)、视口(Viewport)、权限(Permission)(与 teacher-portal 共享,引用 teacher-portal 文档) + +### 2.2 业务领域 + +- **管理场景域**(前端场景域:管理场景域,对应后端 iam 限界上下文 + teacher-bff 管理视口) + +### 2.3 不负责 + +- 教学业务编排(班级/考试/作业/成绩 CRUD,归 teacher-portal) +- 学生作答界面(归 student-portal) +- 家长多子女切换(归 parent-portal) +- 教师仪表盘(归 teacher-portal,admin-portal 仅有管理仪表盘) + +### 2.4 数据范围 + +- DataScope L3-L5(校管理员 L3 学校 / 区教研员 L4 / 系统管理员 L5 全平台) +- 不出现 L1(班级)/ L2(年级)级别的教师数据视角 + +## 3. 我与外部的契约 + +### 3.1 消费的后端 API(经 api-gateway 代理) + +| 路径前缀 | 下游 BFF/服务 | 关键端点 | +| ------------------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | +| `/api/v1/iam/*`(管理用) | iam | `GET /iam/users`、`POST /iam/users`、`PUT /iam/users/:id`、`GET /iam/roles`、`GET /iam/permissions`、`GET /iam/viewports`、`PUT /iam/viewports/:id` | +| `/api/v1/admin/*` | teacher-bff 复用 + iam 直连 | `GET /admin/dashboard`、`GET /admin/monitoring/metrics`、`GET /admin/stats/users`、`GET /admin/stats/active-sessions` | +| `/api/v1/notifications/*` | msg | 通知中心(P5) | + +### 3.2 统一响应契约 + +所有后端响应遵循 `ActionState` 结构(迁移指南 §7.5): + +```typescript +type ActionState = + | { success: true; data: T } + | { + success: false; + error: { code: string; message: string; details?: unknown }; + }; +``` + +错误码前缀按服务名大写(admin-portal 涉及:`IAM_`、`BFF_TEACHER_`、`GW_`、`NETWORK_`)。前端 API 请求层根据 `error.code` 前缀路由到对应的 i18n key。 + +### 3.3 推送契约 + +**— N/A** + +admin-portal **不消费** WebSocket 推送或 SSE 流式响应。管理端场景对实时性要求低,采用**轮询**策略: + +- 平台监控页:60s 轮询 `GET /api/v1/admin/monitoring/metrics` +- 用户活动统计:5min 轮询 `GET /api/v1/admin/stats/active-sessions` +- 通知中心(P5):HTTP 长轮询或定时拉取 `GET /api/v1/notifications`(不走 push-gateway) + +> 长期监控指标推荐用 `