第 3 节,共 17 节
一页看懂这套架构
目录
apps/<app>/ thin: bootstrap, root routes, root providers
libs/<domain>/feature-<use-case>/ smart components for one use case (a page or a flow)
libs/<domain>/ui-<name>/ presentational components: inputs in, events out
libs/<domain>/data-access/ state, effects, HTTP, facade
libs/<domain>/model/ types and pure domain functions, no framework
libs/<domain>/util-<name>/ technical helpers for this domain
libs/<domain>/api/ the only thing other domains may import
libs/<domain>/feature-shell/ the domain's routes and providers
libs/shared/<type>-<name>/ used by every domain, knows none of them
需要记住的六句话:
- 每个库只有一个领域和一个类型,以标签的形式写下,标签决定它可以导入什么。
- 导入沿着类型阶梯向下指:feature → ui、data-access → model → util。从不向上,功能之间也从不横向导入。
- 一个领域只能通过另一个领域的
api库看到它。 领域中的其余一切都是私有的。 shared不知道任何领域。 如果一个“共享”文件提到了工单,它就属于 maintenance。- 组件从不直接与 HTTP 打交道。 数据经由
data-access流动;功能看到的是 facade 或 selector,而不是 URL。 - 应用是薄的。 应用负责连接路由和 provider;功能位于库中,所以第二个应用几乎没有成本。