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:
attacker committed 2026-06-15 01:32:15 +08:00
1 parent e8dbe65955
commit 73b5a48df9
37 files changed
+5148 -5237

No files matched your search

+58
View File
@@ -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 提交
+60 -23
View File
@@ -6,24 +6,42 @@
aiops/
├── frontend/ # 前端 (React 18 + TypeScript + Vite)
│ ├── src/
│ │ ├── components/ # 业务组件
│ │ │ ├── aiops/ # AI 智能运维组件
│ │ │ ├── approval/ # 审批流程
│ │ ├── components/ # 业务组件(每个 <700行,超限已模块化拆分)
│ │ │ ├── agent/ # Agent 监控
│ │ │ ├── aiops/ # AI 智能运维(AIPredictiveAnalytics 含 PredictiveCapacityTab)
│ │ │ ├── approval/ # 审批流程(ApprovalFlow + Process/Template Tab)
│ │ │ ├── audit/ # SQL 审计
│ │ │ ├── automation/ # 自动化运维
│ │ │ ├── cloud/ # 云平台管理
│ │ │ ├── dashboard/ # 仪表盘
│ │ │ ├── automation/ # 自动化运维(CronJob/Script/Ansible)
│ │ │ ├── cloud/ # 云平台管理(CloudBilling + Helpers 子组件)
│ │ │ ├── dashboard/ # 仪表盘(Charts/Recent/Stats 子组件)
│ │ │ ├── deploy/ # CI/CD 部署
│ │ │ ├── k8s/ # K8s 集群管理
│ │ │ ├── k8s/ # K8s 集群管理(Detail/Dialog/Topology 子组件)
│ │ │ ├── layout/ # 布局组件
│ │ │ ├── monitor/ # 监控告警
│ │ │ ├── monitor/ # 监控告警(AlertManager + Events/Rules Tab + Dialog 子组件)
│ │ │ │ ├── alert-center/ # 告警中心(AlertCenter + Detail 子组件)
│ │ │ │ ├── dashboard/ # Grafana 仪表盘(GrafanaPanelContent 子组件)
│ │ │ │ ├── logs/ # 日志管理
│ │ │ │ └── trace/ # 链路追踪
│ │ │ ├── navigation/ # 导航管理
│ │ │ ├── server/ # 服务器管理
│ │ │ ├── system/ # 系统管理
│ │ │ └── ui/ # shadcn/ui 基础组件
│ │ │ ├── server/ # 服务器管理(ServerManager + Form/BatchImport 子组件)
│ │ │ ├── system/ # 系统管理(SystemManager + User/Settings/Logs/Roles/LDAP Tab 子组件)
│ │ │ └── ui/ # shadcn/ui 基础组件(sidebar.tsx + sidebar-context.tsx)
│ │ ├── hooks/ # 自定义 Hooks
│ │ ├── lib/ # 工具库
│ │ ├── mocks/ # Mock 数据
│ │ ├── mocks/ # Mock 数据(按 domain 模块化,barrel 统一导出)
│ │ │ ├── data.ts # Barrel re-export(统一入口)
│ │ │ └── modules/ # 按业务域分组
│ │ │ ├── servers.ts # 服务器/机柜
│ │ │ ├── cloud.ts # 云平台
│ │ │ ├── k8s.ts # K8s
│ │ │ ├── alerts.ts # 告警
│ │ │ ├── dashboard.ts # 仪表盘
│ │ │ ├── cicd.ts # CI/CD
│ │ │ ├── automation.ts # 自动化
│ │ │ ├── system.ts # 系统
│ │ │ ├── approval.ts # 审批
│ │ │ ├── monitor.ts # 监控
│ │ │ └── misc.ts # SQL审计/Ansible/导航等
│ │ ├── services/ # API 封装
│ │ ├── store/ # Zustand 状态管理
│ │ ├── types/ # TypeScript 类型定义
@@ -41,17 +59,36 @@ aiops/
│ │ └── main.go # 应用入口
│ ├── internal/
│ │ ├── api/
│ │ │ ├── handlers/ # HTTP 处理器
│ │ │ │ ├── alert.go # 告警管理
│ │ │ │ ├── approval.go # 审批流程
│ │ │ │ ├── audit.go # 审计日志
│ │ │ │ ├── automation.go # 自动化运维
│ │ │ │ ├── dashboard.go # 仪表盘
│ │ │ │ ├── k8s.go # K8s 管理
│ │ │ │ ├── navigation.go # 导航管理
│ │ │ │ ├── pipeline.go # CI/CD 流水线
│ │ │ │ ├── server.go # 服务器管理
│ │ │ │ └── user.go # 用户认证
│ │ │ ├── handlers/ # HTTP 处理器(模块化拆分)
│ │ │ │ ├── agent.go # Agent 管理
│ │ │ │ ├── agent_task.go # Agent 任务分发
│ │ │ │ ├── alert.go # 告警管理
│ │ │ │ ├── alert_engine.go # 告警引擎
│ │ │ │ ├── ansible.go # Ansible Playbook
│ │ │ │ ├── approval.go # 审批流程
│ │ │ │ ├── audit.go # 审计日志
│ │ │ │ ├── automation.go # 自动化运维(入口)
│ │ │ │ ├── automation_cron.go # 定时任务
│ │ │ │ ├── automation_script.go # 脚本管理
│ │ │ │ ├── automation_playbook.go # Playbook
│ │ │ │ ├── billing.go # 云账单
│ │ │ │ ├── cloud_accounts.go # 云账号
│ │ │ │ ├── cloud_domain.go # 域名
│ │ │ │ ├── cloud_platform.go # 云平台
│ │ │ │ ├── cloud_region.go # 区域
│ │ │ │ ├── dashboard.go # 仪表盘
│ │ │ │ ├── k8s.go # K8s 管理
│ │ │ │ ├── ldap.go # LDAP(入口)
│ │ │ │ ├── ldap_ou.go # LDAP OU 管理
│ │ │ │ ├── ldap_users.go # LDAP 用户同步
│ │ │ │ ├── log.go # 日志管理
│ │ │ │ ├── navigation.go # 导航管理
│ │ │ │ ├── pipeline.go # CI/CD 流水线
│ │ │ │ ├── resource_model.go # 资源模型
│ │ │ │ ├── server.go # 服务器管理(入口)
│ │ │ │ ├── user.go # 用户认证
│ │ │ │ ├── user_admin.go # 用户管理(管理员)
│ │ │ │ └── webshell.go # Web 终端
│ │ │ ├── middleware/ # 中间件
│ │ │ │ └── auth.go # JWT 认证 + RBAC
│ │ │ └── routes/