[{"data":1,"prerenderedAt":277},["ShallowReactive",2],{"blog-frontend-architecture-3-zh":3},{"number":4,"title":5,"summary":6,"parts":7,"toc":14,"minutes":276},3,"一页看懂这套架构","@@diagram:fe-grid@@",[8,11],{"kind":9,"name":10},"diagram","fe-grid",{"kind":12,"html":13},"html","\u003Cpre class=\"code-tree\">\u003Ccode>\u003Cspan class=\"t-dir\">apps\u002F&lt;app&gt;\u002F\u003C\u002Fspan>\u003Cspan class=\"t-note\">                         thin: bootstrap, root routes, root providers\u003C\u002Fspan>\n\u003Cspan class=\"t-dir\">libs\u002F&lt;domain&gt;\u002Ffeature-&lt;use-case&gt;\u002F\u003C\u002Fspan>\u003Cspan class=\"t-note\">   smart components for one use case (a page or a flow)\u003C\u002Fspan>\n\u003Cspan class=\"t-dir\">libs\u002F&lt;domain&gt;\u002Fui-&lt;name&gt;\u002F\u003C\u002Fspan>\u003Cspan class=\"t-note\">            presentational components: inputs in, events out\u003C\u002Fspan>\n\u003Cspan class=\"t-dir\">libs\u002F&lt;domain&gt;\u002Fdata-access\u002F\u003C\u002Fspan>\u003Cspan class=\"t-note\">          state, effects, HTTP, facade\u003C\u002Fspan>\n\u003Cspan class=\"t-dir\">libs\u002F&lt;domain&gt;\u002Fmodel\u002F\u003C\u002Fspan>\u003Cspan class=\"t-note\">                types and pure domain functions, no framework\u003C\u002Fspan>\n\u003Cspan class=\"t-dir\">libs\u002F&lt;domain&gt;\u002Futil-&lt;name&gt;\u002F\u003C\u002Fspan>\u003Cspan class=\"t-note\">          technical helpers for this domain\u003C\u002Fspan>\n\u003Cspan class=\"t-dir\">libs\u002F&lt;domain&gt;\u002Fapi\u002F\u003C\u002Fspan>\u003Cspan class=\"t-note\">                  the only thing other domains may import\u003C\u002Fspan>\n\u003Cspan class=\"t-dir\">libs\u002F&lt;domain&gt;\u002Ffeature-shell\u002F\u003C\u002Fspan>\u003Cspan class=\"t-note\">        the domain's routes and providers\u003C\u002Fspan>\n\u003Cspan class=\"t-dir\">libs\u002Fshared\u002F&lt;type&gt;-&lt;name&gt;\u002F\u003C\u002Fspan>\u003Cspan class=\"t-note\">          used by every domain, knows none of them\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>需要记住的六句话：\u003C\u002Fp>\n\u003Col>\n\u003Cli>\u003Cstrong>每个库只有一个领域和一个类型\u003C\u002Fstrong>，以标签的形式写下，标签决定它可以导入什么。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>导入沿着类型阶梯向下指\u003C\u002Fstrong>：feature → ui、data-access → model → util。从不向上，功能之间也从不横向导入。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>一个领域只能通过另一个领域的 \u003Ccode>api\u003C\u002Fcode> 库看到它。\u003C\u002Fstrong> 领域中的其余一切都是私有的。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>\u003Ccode>shared\u003C\u002Fcode> 不知道任何领域。\u003C\u002Fstrong> 如果一个“共享”文件提到了工单，它就属于 maintenance。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>组件从不直接与 HTTP 打交道。\u003C\u002Fstrong> 数据经由 \u003Ccode>data-access\u003C\u002Fcode> 流动；功能看到的是 facade 或 selector，而不是 URL。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>应用是薄的。\u003C\u002Fstrong> 应用负责连接路由和 provider；功能位于库中，所以第二个应用几乎没有成本。\u003C\u002Fli>\n\u003C\u002Fol>\n",[15,28,32,36,40,60,76,92,116,144,156,176,216,244,248,252,272],{"id":16,"text":17,"depth":18,"children":19},"s1","1. 前端为什么需要架构",2,[20,24],{"id":21,"text":22,"depth":4,"children":23},"s1-1","1.1. 目标",[],{"id":25,"text":26,"depth":4,"children":27},"s1-2","1.2. 非目标",[],{"id":29,"text":30,"depth":18,"children":31},"s2","2. 思路的来源",[],{"id":33,"text":34,"depth":18,"children":35},"s3","3. 一页看懂这套架构",[],{"id":37,"text":38,"depth":18,"children":39},"s4","4. 术语",[],{"id":41,"text":42,"depth":18,"children":43},"s5","5. 示例：Fleetline",[44,48,52,56],{"id":45,"text":46,"depth":4,"children":47},"s5-1","5.1. 应用",[],{"id":49,"text":50,"depth":4,"children":51},"s5-2","5.2. 领域和团队",[],{"id":53,"text":54,"depth":4,"children":55},"s5-3","5.3. 工作区",[],{"id":57,"text":58,"depth":4,"children":59},"s5-4","5.4. 一个用例贯穿各层",[],{"id":61,"text":62,"depth":18,"children":63},"s6","6. 库类型",[64,68,72],{"id":65,"text":66,"depth":4,"children":67},"s6-1","6.1. 谁可以导入谁",[],{"id":69,"text":70,"depth":4,"children":71},"s6-2","6.2. 一个库应该多大",[],{"id":73,"text":74,"depth":4,"children":75},"s6-3","6.3. 样式",[],{"id":77,"text":78,"depth":18,"children":79},"s7","7. 领域和边界",[80,84,88],{"id":81,"text":82,"depth":4,"children":83},"s7-1","7.1. API 库",[],{"id":85,"text":86,"depth":4,"children":87},"s7-2","7.2. shared 也是一个领域",[],{"id":89,"text":90,"depth":4,"children":91},"s7-3","7.3. 当两个领域需要同一样东西时",[],{"id":93,"text":94,"depth":18,"children":95},"s8","8. 执行规则",[96,100,104,108,112],{"id":97,"text":98,"depth":4,"children":99},"s8-1","8.1. 标签",[],{"id":101,"text":102,"depth":4,"children":103},"s8-2","8.2. lint 规则",[],{"id":105,"text":106,"depth":4,"children":107},"s8-3","8.3. 框架维度",[],{"id":109,"text":110,"depth":4,"children":111},"s8-4","8.4. 不用 Nx：Sheriff",[],{"id":113,"text":114,"depth":4,"children":115},"s8-5","8.5. 在 CI 中",[],{"id":117,"text":118,"depth":18,"children":119},"s9","9. 用 NgRx 管理状态",[120,124,128,132,136,140],{"id":121,"text":122,"depth":4,"children":123},"s9-1","9.1. 模型",[],{"id":125,"text":126,"depth":4,"children":127},"s9-2","9.2. 事件",[],{"id":129,"text":130,"depth":4,"children":131},"s9-3","9.3. feature：状态、reducer、selector",[],{"id":133,"text":134,"depth":4,"children":135},"s9-4","9.4. HTTP 和 effect",[],{"id":137,"text":138,"depth":4,"children":139},"s9-5","9.5. Provider",[],{"id":141,"text":142,"depth":4,"children":143},"s9-6","9.6. data-access 的公开 API",[],{"id":145,"text":146,"depth":18,"children":147},"s10","10. Facade，以及何时省略它",[148,152],{"id":149,"text":150,"depth":4,"children":151},"s10-1","10.1. 为什么需要 facade",[],{"id":153,"text":154,"depth":4,"children":155},"s10-2","10.2. 为什么 facade 是可选的",[],{"id":157,"text":158,"depth":18,"children":159},"s11","11. 端到端的 Angular",[160,164,168,172],{"id":161,"text":162,"depth":4,"children":163},"s11-1","11.1. ui 库",[],{"id":165,"text":166,"depth":4,"children":167},"s11-2","11.2. feature 库",[],{"id":169,"text":170,"depth":4,"children":171},"s11-3","11.3. Shell",[],{"id":173,"text":174,"depth":4,"children":175},"s11-4","11.4. 应用",[],{"id":177,"text":178,"depth":18,"children":179},"s12","12. React 和 Next.js",[180,184,188,192,196,200,204,208,212],{"id":181,"text":182,"depth":4,"children":183},"s12-1","12.1. 对应关系",[],{"id":185,"text":186,"depth":4,"children":187},"s12-2","12.2. 服务端和客户端的标签",[],{"id":189,"text":190,"depth":4,"children":191},"s12-3","12.3. HTTP 和查询客户端",[],{"id":193,"text":194,"depth":4,"children":195},"s12-4","12.4. 查询和 mutation",[],{"id":197,"text":198,"depth":4,"children":199},"s12-5","12.5. 用 Zustand 管理客户端状态",[],{"id":201,"text":202,"depth":4,"children":203},"s12-6","12.6. Facade hook",[],{"id":205,"text":206,"depth":4,"children":207},"s12-7","12.7. feature、ui 和路由",[],{"id":209,"text":210,"depth":4,"children":211},"s12-8","12.8. Shell 和其他领域的 API",[],{"id":213,"text":214,"depth":4,"children":215},"s12-9","12.9. Next.js 特有的陷阱",[],{"id":217,"text":218,"depth":18,"children":219},"s13","13. Vue 和 Nuxt",[220,224,228,232,236,240],{"id":221,"text":222,"depth":4,"children":223},"s13-1","13.1. 对应关系",[],{"id":225,"text":226,"depth":4,"children":227},"s13-2","13.2. 为库关闭自动导入",[],{"id":229,"text":230,"depth":4,"children":231},"s13-3","13.3. Store",[],{"id":233,"text":234,"depth":4,"children":235},"s13-4","13.4. Facade composable 和 store 的作用域",[],{"id":237,"text":238,"depth":4,"children":239},"s13-5","13.5. feature、ui、shell 和页面",[],{"id":241,"text":242,"depth":4,"children":243},"s13-6","13.6. Nuxt 特有的陷阱",[],{"id":245,"text":246,"depth":18,"children":247},"s14","14. 并排对照",[],{"id":249,"text":250,"depth":18,"children":251},"s15","15. 按库类型测试",[],{"id":253,"text":254,"depth":18,"children":255},"s16","16. 逐步成长与迁移",[256,260,264,268],{"id":257,"text":258,"depth":4,"children":259},"s16-1","16.1. 八步迁移",[],{"id":261,"text":262,"depth":4,"children":263},"s16-2","16.2. 常见的错误",[],{"id":265,"text":266,"depth":4,"children":267},"s16-3","16.3. 何时拆分一个库",[],{"id":269,"text":270,"depth":4,"children":271},"s16-4","16.4. 何时这套架构过重",[],{"id":273,"text":274,"depth":18,"children":275},"s17","17. 常见问题",[],32,1795449743956]