Layered、Package by Feature 与领域边界
Freshness metadata
last_verified:2026-08-24version_scope:stable architecture conceptssource_type:architecture literature + engineering synthesisstability:stable-concept
controller/service/repository 全局分层容易让一个业务变更跨越全仓库。Package by feature 以 orders, inventory, billing 聚合代码,再在模块内部使用 adapter/application/domain 分层。
orders/
api/ # published API/events
internal/
web/
application/
domain/
persistence/
Bounded Context 是模型/语言边界,不是“每个表一个服务”。Application Service 处理 use case、权限上下文和事务;Domain Service 处理不自然属于单一实体的领域规则;Repository boundary 只暴露领域需要的集合式接口。
验证依赖
- 模块外只能调用公开 API;
- domain 不依赖 Spring MVC/JPA annotations(是否完全纯净按成本决定);
- 禁止跨模块直接访问 internal repository/table;
- architecture test 或 Spring Modulith verification 检查 cycle 与暴露面。