feat(server): integrate AppState, ModuleRegistry, health check, and graceful shutdown

- Add AppState with DB, Config, EventBus, ModuleRegistry via Axum State
- ModuleRegistry now uses Arc for Clone support, builder-pattern register()
- Add /api/v1/health endpoint returning status, version, registered modules
- Add graceful shutdown on CTRL+C / SIGTERM
- erp-common utils: ID generation, timestamp helpers, code generator with tests
- Config structs now derive Clone for state sharing
- Update wiki to reflect Phase 1 completion
This commit is contained in:
iven
2026-04-11 01:19:30 +08:00
parent 5901ee82f0
commit 810eef769f
9 changed files with 216 additions and 30 deletions

View File

@@ -7,13 +7,14 @@
关键数字:
- 8 个 Rust crate4 个 placeholder1 个前端 SPA
- 1 个数据库迁移tenant 表)
- Phase 1 基础设施完成约 85%
- Health Check API (`/api/v1/health`)
- Phase 1 基础设施完成
## 模块导航树
### L1 基础层
- [[erp-core]] — 错误体系 · 事件总线 · 模块 trait · 共享类型
- [[erp-common]] — 共享工具(当前为 stub
- [[erp-common]] — ID 生成 · 时间戳 · 编号生成工具
### L2 业务层(均为 placeholder
- erp-auth — 身份与权限Phase 2
@@ -22,7 +23,7 @@
- erp-message — 消息中心Phase 5
### L3 组装层
- [[erp-server]] — Axum 服务入口 · 配置加载 · 数据库连接 · 迁移执行
- [[erp-server]] — Axum 服务入口 · AppState · ModuleRegistry 集成 · 配置加载 · 数据库连接 · 优雅关闭
### 基础设施
- [[database]] — SeaORM 迁移 · 多租户表结构 · 软删除模式
@@ -40,7 +41,9 @@
**错误怎么传播?** 业务 crate 用 thiserror → AppError → Axum IntoResponse 自动转 HTTP。详见 [[erp-core]] 错误处理链。
**为什么没有路由?** Phase 1 只搭建基础设施。ModuleRegistry 已定义但未集成到 [[erp-server]]Phase 2 开始注册路由
**状态如何共享?** AppState 包含 DB、Config、EventBus、ModuleRegistry通过 Axum State 提取器注入所有 handler
**ModuleRegistry 怎么工作?** 每个 Phase 2+ 的业务模块实现 ErpModule trait在 main.rs 中链式注册。registry 自动构建路由和事件处理器。
**版本差异怎么办?** package.json 使用 React 19 + Ant Design 6比规格文档更新以实际代码为准。
@@ -48,7 +51,7 @@
| Phase | 内容 | 状态 |
|-------|------|------|
| 1 | 基础设施 | 85% — 缺 README、ModuleRegistry 集成、中间件 |
| 1 | 基础设施 | 完成 |
| 2 | 身份与权限 | 待开始 |
| 3 | 系统配置 | 待开始 |
| 4 | 工作流引擎 | 待开始 |