Files
full/wiki/architecture.md
2026-08-10 11:42:45 +08:00

39 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 系统架构
## 模块边界
仓库包含 20 个 Go modulemodule 下 19 个业务模块可独立运行all 聚合其中 15 个 base、ec、finance 服务social 三个模块暂未聚合。
典型模块目录职责:
| 目录 | 职责 |
| --- | --- |
| cmd/main | 进程入口、配置和生命周期 |
| internal/config | 模块配置 |
| internal/impl | DB、Redis、etcd、内存缓存 |
| internal/logic | 业务逻辑 |
| internal/server | 服务构造与注册 |
| service | 对 all 公开的 Expose API |
| pb | protobuf 生成代码 |
| etc | 配置样例 |
独立入口初始化自己的基础设施。聚合调用 Expose 时不重复初始化,而是注入 all 创建的共享对象。
## all 启动流程
1. 校验 --workspace 并读取 etc/<workspace>_<runtime>.yaml。
2. 初始化共享 DB、Redis、etcd 和内存缓存。
3. 创建统一 gRPC、grpc-gateway 和 Gin server。
4. 按 Services 或 BSM_SERVICES 调用模块 Expose。
5. 在一个 h2c 端口启动,并响应退出信号。
请求先按 gRPC Content-Type 分流;普通请求先进入 grpc-gatewaygateway 返回 404 时回退到 Gin。
## 依赖注入
ExposeOptions.Dependencies 可接收 RedisClient、etcd Client、gorm DB 和 Cache。参数非 nil 时覆盖模块 internal/impl 对象。address、market、order、mgt 的业务数据库访问已统一使用 internal/impl.DBService。
## 生命周期
统一 HTTP server 设置请求头读取超时、空闲超时和最大请求头。关闭时先执行 gRPC GracefulStop超过 context 截止时间后强制 Stop再关闭 HTTP server。