docs(wiki): 全景梳理 — 更新 9 个 wiki + CLAUDE.md scope + 头脑风暴记录
基于 3 个并行探索代理的全面扫描结果,更新 wiki 数据至实际状态: - index.md: 18 crate / 76 迁移 / 44 实体 / 77k 行 / 409 提交 - erp-health.md: 44 实体 / 21 handler / 22 权限 / 25 事件 / 6 消费者 - erp-server.md: 9 后台任务 / RLS 中间件栈 - architecture.md: 新增 erp-ai/dialysis 到依赖图 / 测试覆盖表 - testing.md: 225 单元 + 159 集成 / 4 模块零测试警告 - database.md: 76 迁移 / RLS+哈希链+盲索引+Dead Letter - erp-core.md: PiiCrypto 加密体系 / EventBus 完整描述 - frontend.md: 163 文件 / 5 store / 10 API 文件 - CLAUDE.md: 新增 health/ai/dialysis/assessment scope 头脑风暴 4 个议题决策: - dialysis: 接入激活 - 测试: 按风险排序(workflow > ai > message > config) - AI: 数据桥接优先 - 路线图: AI 驱动 3 个月 5 Phase
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: erp-core
|
||||
updated: 2026-04-25
|
||||
updated: 2026-04-28
|
||||
status: stable
|
||||
tags: [core, error, event-bus, module-trait, shared-types]
|
||||
---
|
||||
@@ -14,9 +14,10 @@ tags: [core, error, event-bus, module-trait, shared-types]
|
||||
`erp-core` 是 L1 基础层,所有业务模块的唯一共同依赖。定义**跨模块共享的契约**,不含业务逻辑。
|
||||
|
||||
核心决策:
|
||||
- **AppError 统一错误体系** — 6 种变体映射 HTTP 状态码,`?` 传播 + Axum `IntoResponse` 自动转换
|
||||
- **EventBus 进程内广播** — `tokio::sync::broadcast` 实现零耦合通信
|
||||
- **ErpModule 插件 trait** — 统一注册路由和事件处理器
|
||||
- **AppError 统一错误体系** — 8 种变体映射 HTTP 状态码,`?` 传播 + Axum `IntoResponse` 自动转换
|
||||
- **EventBus 进程内广播** — broadcast channel (1024) + PostgreSQL Outbox + LISTEN/NOTIFY + 幂等消费 + Dead Letter
|
||||
- **PiiCrypto 加密体系** — AES-256-GCM + KEK/DEK 分层管理 + HMAC 盲索引 + 数据脱敏
|
||||
- **ErpModule 插件 trait** — 统一注册路由和事件处理器 + 拓扑排序启动
|
||||
- **BaseFields 强制多租户** — 所有实体基础字段模板
|
||||
|
||||
## 2. 关键文件 + 数据流
|
||||
@@ -29,7 +30,11 @@ tags: [core, error, event-bus, module-trait, shared-types]
|
||||
| `crates/erp-core/src/events.rs` | DomainEvent、EventBus、EventHandler trait |
|
||||
| `crates/erp-core/src/module.rs` | ErpModule trait、ModuleRegistry |
|
||||
| `crates/erp-core/src/types.rs` | BaseFields、Pagination、ApiResponse、TenantContext |
|
||||
| `crates/erp-core/src/crypto/` | PiiCrypto(engine/key_manager/masking/hmac_index),AES-256-GCM + KEK/DEK |
|
||||
| `crates/erp-core/src/sanitize.rs` | strip_html_tags()、sanitize_string() |
|
||||
| `crates/erp-core/src/entity/` | audit_log, domain_event, processed_event, dead_letter_event |
|
||||
| `crates/erp-core/src/audit.rs` | 审计日志记录 |
|
||||
| `crates/erp-core/src/rbac.rs` | require_permission 权限检查 |
|
||||
| `crates/erp-core/src/lib.rs` | 模块导出入口 |
|
||||
|
||||
### 集成契约
|
||||
@@ -59,10 +64,15 @@ tags: [core, error, event-bus, module-trait, shared-types]
|
||||
### 事件总线
|
||||
|
||||
```
|
||||
EventBus::publish(DomainEvent) → broadcast channel → Receiver<DomainEvent>
|
||||
事件字段: id(UUIDv7), event_type("user.created"), tenant_id, payload(JSON), timestamp
|
||||
EventBus::publish(DomainEvent)
|
||||
→ INSERT pending → 内存 broadcast(channel 1024) → UPDATE published → NOTIFY outbox_channel
|
||||
Outbox Relay: PgListener (LISTEN/NOTIFY) + 30s 兜底轮询 + 自动重连
|
||||
幂等消费: processed_events 表 + consumer_id
|
||||
Dead Letter: 失败事件 → dead_letter_events 表
|
||||
```
|
||||
|
||||
事件字段: id(UUIDv7), event_type("user.created"), tenant_id, payload(JSON), timestamp
|
||||
|
||||
命名规则:`{模块}.{动作}` 如 `user.created`, `workflow.task.completed`
|
||||
|
||||
健康模块事件:`patient.created`, `appointment.confirmed`, `appointment.cancelled`
|
||||
@@ -75,7 +85,7 @@ ErpModule trait → ModuleRegistry::register() →
|
||||
register_handlers(): 注册事件处理器 → EventBus
|
||||
```
|
||||
|
||||
已注册模块:AuthModule → ConfigModule → WorkflowModule → MessageModule → PluginModule → **HealthModule**
|
||||
已注册模块:AuthModule → ConfigModule → WorkflowModule → MessageModule → PluginModule → **HealthModule** → **AiModule**
|
||||
|
||||
### 共享类型
|
||||
|
||||
|
||||
Reference in New Issue
Block a user