refactor: 全局代码模块化重构 — 所有文件<700行
后端 handler 拆分: - automation.go(1067→4文件), server.go(1011→5文件), ldap.go(815→3文件), user.go(704→2文件) 前端组件拆分: - SystemManager(1782→569), AlertManager(1133→220), K8sClusters(1062→4文件) - Dashboard(941→4文件), ServerManager(905→640), ApprovalFlow(830→548) - AlertCenter(775→693), AIPredictiveAnalytics(760→670) - CloudBilling(728→663), GrafanaDashboard(717→643), sidebar(726→689) Mock 数据模块化: - mocks/data.ts(2552行→barrel+11个domain模块) 新增 CLAUDE.md 项目全局开发规范 修复: AlertCenter/LogManager ListResponse.data→.list 类型不匹配 验证: go build ✅ + tsc --noEmit ✅ + npm run build ✅
This commit is contained in:
1 parent
e8dbe65955
commit
73b5a48df9
37 files changed
+5148
-5237
No files matched your search
@@ -577,3 +577,61 @@ cd ~/devops/aiops
|
||||
- 定时任务/脚本执行接入 Agent 远程执行(当前仅 AIOps 主机本地执行)
|
||||
- K8s 拓扑图增加缩放/拖拽交互(当前为静态 SVG)
|
||||
- 新增的孤儿子组件文件(ApprovalProcessTab/ApprovalTemplateTab 等)确认是否被引用,未引用可清理
|
||||
|
||||
## 2026-06-15 全局代码模块化重构(<700行强制拆分)
|
||||
|
||||
### 背景
|
||||
按照 CLAUDE.md 定义的架构规范(单文件不超过700行),对全项目进行系统性模块化拆分。创建 CLAUDE.md 作为项目全局 AI 开发规范,定义了 700 行拆分规则、命名规范、架构约束和开发流程。
|
||||
|
||||
### 后端 Go handler 拆分(4 个超限文件 → 12 个模块化文件)
|
||||
|
||||
| 原文件 | 原行数 | 拆分后 | 最大行数 |
|
||||
|--------|--------|--------|----------|
|
||||
| `automation.go` | 1067 | automation.go + automation_cron.go + automation_script.go + automation_playbook.go | 358 |
|
||||
| `server.go` | 1011 | server.go + cloud_accounts.go + cloud_domain.go + cloud_platform.go + cloud_region.go | 370 |
|
||||
| `ldap.go` | 815 | ldap.go + ldap_ou.go + ldap_users.go | 397 |
|
||||
| `user.go` | 704 | user.go + user_admin.go | 360 |
|
||||
|
||||
### 前端组件拆分(15+ 超限组件 → 全部 <700行)
|
||||
|
||||
| 组件 | 原行数 | 拆分后 | 行数 |
|
||||
|------|--------|--------|------|
|
||||
| `SystemManager.tsx` | 1782 | SystemManager + SystemUserTab + SystemSettingsTab + SystemLogsTab + SystemRolesTab + LdapManagementSection + UserFormDialog | 569 |
|
||||
| `AlertManager.tsx` | 1133 | AlertManager + AlertEventsTab + AlertRulesTab + AlertRuleDialog + AlertChannelDialog | 220 |
|
||||
| `K8sClusters.tsx` | 1062 | K8sClusters + K8sClusterDetail + K8sClusterDialog + TopologyView | <600 |
|
||||
| `Dashboard.tsx` | 941 | Dashboard + DashboardCharts + DashboardRecent + DashboardStats | <500 |
|
||||
| `ServerManager.tsx` | 905 | ServerManager + ServerForm + BatchImport + CloudServerImport + ExcelServerImport | 640 |
|
||||
| `ApprovalFlow.tsx` | 830 | ApprovalFlow + ApprovalProcessTab + ApprovalTemplateTab | 548 |
|
||||
| `AlertCenter.tsx` | 775 | AlertCenter + AlertCenterDetail | 693 |
|
||||
| `AIPredictiveAnalytics.tsx` | 760 | AIPredictiveAnalytics + PredictiveCapacityTab | 670 |
|
||||
| `CloudBilling.tsx` | 728 | CloudBilling + CloudBillingHelpers | 663 |
|
||||
| `GrafanaDashboard.tsx` | 717 | GrafanaDashboard + GrafanaPanelContent | 643 |
|
||||
| `ui/sidebar.tsx` | 726 | sidebar.tsx + sidebar-context.tsx(提取常量/Context/variants) | 689 |
|
||||
|
||||
### Mock 数据模块化(2552行 → 11 个 domain 模块 + barrel 导出)
|
||||
|
||||
`mocks/data.ts`(2552行)→ barrel pattern:
|
||||
- `data.ts`(80行 barrel re-export,保持 `@/mocks/data` 导入路径不变)
|
||||
- `modules/servers.ts`(328), `modules/cloud.ts`(330), `modules/k8s.ts`(471)
|
||||
- `modules/alerts.ts`(200), `modules/dashboard.ts`(98), `modules/cicd.ts`(118)
|
||||
- `modules/automation.ts`(258), `modules/system.ts`(178), `modules/approval.ts`(173)
|
||||
- `modules/monitor.ts`(162), `modules/misc.ts`(479)
|
||||
|
||||
### 顺手修复的编译错误
|
||||
- `AlertCenter.tsx`: `res.data` → `res.list`(ListResponse 类型不匹配)
|
||||
- `AlertCenter.tsx`: `toggleRule(ruleId, enabled)` → `toggleRule(ruleId)`(API 签名变更)
|
||||
- `LogManager.tsx`: 同上 `res.data` → `res.list`
|
||||
|
||||
### 验证结果
|
||||
- 后端 `go build -o aiops-server ./cmd/` 编译通过 ✅
|
||||
- 前端 `npx tsc --noEmit` 类型检查通过(零错误)✅
|
||||
- 前端 `npm run build`(tsc -b + vite build)通过 ✅
|
||||
- **全项目无任何文件超过700行** ✅
|
||||
|
||||
### 新增规范文件
|
||||
- `CLAUDE.md` — 项目全局 AI 开发规范(8KB),包含:
|
||||
- 架构约束:前端700行/后端400行拆分规则
|
||||
- 命名规范:中文注释 + `// Logan.Li` 署名
|
||||
- 前端约定:shadcn/ui 导入路径、Token 获取方式、严格模式
|
||||
- 开发流程:编译验证 + 文档更新 + Git 提交
|
||||
|
||||
Reference in new issue
Block a user