[{"data":1,"prerenderedAt":275},["ShallowReactive",2],{"blog-frontend-architecture-16-en":3},{"number":4,"title":5,"summary":6,"parts":7,"toc":11,"minutes":274},16,"Growing into it and migrating","Nobody starts with seventy libraries. Fleetline started as one Angular application with a src\u002Fapp folder; the steps below are the order that worked.",[8],{"kind":9,"html":10},"html","\u003Cp>Nobody starts with seventy libraries. Fleetline started as one Angular application with a \u003Ccode>src\u002Fapp\u003C\u002Fcode> folder; the steps below are the order that worked.\u003C\u002Fp>\n\u003Ch3 id=\"s16-1\">16.1. Migration in eight steps\u003C\u002Fh3>\n\u003Col>\n\u003Cli>\u003Cstrong>Create the workspace around the app.\u003C\u002Fstrong> \u003Ccode>nx init\u003C\u002Fcode> in the existing repository. Nothing moves yet.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Draw the domains on paper.\u003C\u002Fstrong> Use the business words: what do planners, customers and finance talk about? Expect six to ten domains. Write them into a README.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Turn on the rule as a warning.\u003C\u002Fstrong> Add the lint config of section 8.2 with \u003Ccode>'warn'\u003C\u002Fcode>. Count the warnings; that is your baseline.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Extract \u003Ccode>model\u003C\u002Fcode> and \u003Ccode>util\u003C\u002Fcode> first.\u003C\u002Fstrong> They have no dependencies, so moving them is safe, and every later step needs them. Use \u003Ccode>nx g @nx\u002Fworkspace:move\u003C\u002Fcode>.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Extract \u003Ccode>ui\u003C\u002Fcode> per domain.\u003C\u002Fstrong> Every component that only has inputs and outputs moves. Components that inject a store stay for now.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Carve \u003Ccode>data-access\u003C\u002Fcode> per domain.\u003C\u002Fstrong> Split the root store by domain; move each store feature, its effects and HTTP into the domain's \u003Ccode>data-access\u003C\u002Fcode> and register it on the domain's route.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Move pages into \u003Ccode>feature-*\u003C\u002Fcode> and routes into \u003Ccode>feature-shell\u003C\u002Fcode>.\u003C\u002Fstrong> The app shrinks to its routes and providers.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Switch the rule to \u003Ccode>'error'\u003C\u002Fcode> and add CODEOWNERS.\u003C\u002Fstrong> From now on, a new crossing fails CI.\u003C\u002Fli>\n\u003C\u002Fol>\n\u003Cp>Steps 4 to 7 run domain by domain, and the application keeps shipping between them. In Fleetline the whole migration took four months next to feature work, one domain at a time, starting with the smallest one (\u003Ccode>notifications\u003C\u002Fcode>) to learn the moves.\u003C\u002Fp>\n\u003Ch3 id=\"s16-2\">16.2. What usually goes wrong\u003C\u002Fh3>\n\u003Cul>\n\u003Cli>\u003Cstrong>A domain called \u003Ccode>common\u003C\u002Fcode> or \u003Ccode>core\u003C\u002Fcode>.\u003C\u002Fstrong> It becomes the new \u003Ccode>shared\u002F\u003C\u002Fcode>. Every concept has a business owner; find it.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Domains cut by page instead of by business language.\u003C\u002Fstrong> &quot;Dashboard&quot; is not a domain; it is a feature that reads from several domains through their APIs.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>API libraries that re-export everything.\u003C\u002Fstrong> Then the boundary is only cosmetic. Export what another team actually uses, and nothing else.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Disabled lint lines.\u003C\u002Fstrong> One \u003Ccode>eslint-disable\u003C\u002Fcode> for the boundary rule becomes forty within a year. Exceptions go into the config, with a reason in the pull request.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch3 id=\"s16-3\">16.3. When to split a library\u003C\u002Fh3>\n\u003Cul>\n\u003Cli>A \u003Ccode>data-access\u003C\u002Fcode> with more than three or four store features, or owned by two teams: split by sub-domain.\u003C\u002Fli>\n\u003Cli>A \u003Ccode>ui\u003C\u002Fcode> library imported by only one feature: merge it back into that feature or keep it, but do not move it to \u003Ccode>shared\u003C\u002Fcode>.\u003C\u002Fli>\n\u003Cli>A \u003Ccode>feature\u003C\u002Fcode> with several unrelated routes: one library per use case.\u003C\u002Fli>\n\u003Cli>A domain whose libraries are mostly owned by another team: the domain is cut wrong, or the team boundaries are.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch3 id=\"s16-4\">16.4. When this is too much\u003C\u002Fh3>\n\u003Cp>For one application, one team and one or two domains, the full structure costs more than it saves. Start with folders inside one project instead (\u003Ccode>src\u002Fdomains\u002F&lt;domain&gt;\u002Ffeature-…\u003C\u002Fcode>, \u003Ccode>ui-…\u003C\u002Fcode>, \u003Ccode>data-access\u003C\u002Fcode>, \u003Ccode>model\u003C\u002Fcode>) and enforce them with Sheriff (section 8.4). Moving those folders into Nx libraries later is a mechanical step, because the dependency rules are already true.\u003C\u002Fp>\n",[12,26,30,34,38,58,74,90,114,142,154,174,214,242,246,250,270],{"id":13,"text":14,"depth":15,"children":16},"s1","1. Why front-ends need an architecture",2,[17,22],{"id":18,"text":19,"depth":20,"children":21},"s1-1","1.1. Goals",3,[],{"id":23,"text":24,"depth":20,"children":25},"s1-2","1.2. Non-goals",[],{"id":27,"text":28,"depth":15,"children":29},"s2","2. Where the idea comes from",[],{"id":31,"text":32,"depth":15,"children":33},"s3","3. The architecture on one page",[],{"id":35,"text":36,"depth":15,"children":37},"s4","4. Vocabulary",[],{"id":39,"text":40,"depth":15,"children":41},"s5","5. The example: Fleetline",[42,46,50,54],{"id":43,"text":44,"depth":20,"children":45},"s5-1","5.1. Applications",[],{"id":47,"text":48,"depth":20,"children":49},"s5-2","5.2. Domains and teams",[],{"id":51,"text":52,"depth":20,"children":53},"s5-3","5.3. The workspace",[],{"id":55,"text":56,"depth":20,"children":57},"s5-4","5.4. One use case through the layers",[],{"id":59,"text":60,"depth":15,"children":61},"s6","6. Library types",[62,66,70],{"id":63,"text":64,"depth":20,"children":65},"s6-1","6.1. Who may import whom",[],{"id":67,"text":68,"depth":20,"children":69},"s6-2","6.2. How big is a library",[],{"id":71,"text":72,"depth":20,"children":73},"s6-3","6.3. Styles",[],{"id":75,"text":76,"depth":15,"children":77},"s7","7. Domains and boundaries",[78,82,86],{"id":79,"text":80,"depth":20,"children":81},"s7-1","7.1. The API library",[],{"id":83,"text":84,"depth":20,"children":85},"s7-2","7.2. Shared is a domain too",[],{"id":87,"text":88,"depth":20,"children":89},"s7-3","7.3. When two domains need the same thing",[],{"id":91,"text":92,"depth":15,"children":93},"s8","8. Enforcing the rules",[94,98,102,106,110],{"id":95,"text":96,"depth":20,"children":97},"s8-1","8.1. Tags",[],{"id":99,"text":100,"depth":20,"children":101},"s8-2","8.2. The lint rule",[],{"id":103,"text":104,"depth":20,"children":105},"s8-3","8.3. The framework dimension",[],{"id":107,"text":108,"depth":20,"children":109},"s8-4","8.4. Without Nx: Sheriff",[],{"id":111,"text":112,"depth":20,"children":113},"s8-5","8.5. In CI",[],{"id":115,"text":116,"depth":15,"children":117},"s9","9. State with NgRx",[118,122,126,130,134,138],{"id":119,"text":120,"depth":20,"children":121},"s9-1","9.1. The model",[],{"id":123,"text":124,"depth":20,"children":125},"s9-2","9.2. Events",[],{"id":127,"text":128,"depth":20,"children":129},"s9-3","9.3. The feature: state, reducer, selectors",[],{"id":131,"text":132,"depth":20,"children":133},"s9-4","9.4. HTTP and effects",[],{"id":135,"text":136,"depth":20,"children":137},"s9-5","9.5. Providers",[],{"id":139,"text":140,"depth":20,"children":141},"s9-6","9.6. The public API of data-access",[],{"id":143,"text":144,"depth":15,"children":145},"s10","10. The facade, and when to skip it",[146,150],{"id":147,"text":148,"depth":20,"children":149},"s10-1","10.1. Why a facade",[],{"id":151,"text":152,"depth":20,"children":153},"s10-2","10.2. Why the facade is optional",[],{"id":155,"text":156,"depth":15,"children":157},"s11","11. Angular end to end",[158,162,166,170],{"id":159,"text":160,"depth":20,"children":161},"s11-1","11.1. The ui library",[],{"id":163,"text":164,"depth":20,"children":165},"s11-2","11.2. The feature library",[],{"id":167,"text":168,"depth":20,"children":169},"s11-3","11.3. The shell",[],{"id":171,"text":172,"depth":20,"children":173},"s11-4","11.4. The application",[],{"id":175,"text":176,"depth":15,"children":177},"s12","12. React and Next.js",[178,182,186,190,194,198,202,206,210],{"id":179,"text":180,"depth":20,"children":181},"s12-1","12.1. What maps to what",[],{"id":183,"text":184,"depth":20,"children":185},"s12-2","12.2. Tags for server and client",[],{"id":187,"text":188,"depth":20,"children":189},"s12-3","12.3. HTTP and the query client",[],{"id":191,"text":192,"depth":20,"children":193},"s12-4","12.4. Queries and mutations",[],{"id":195,"text":196,"depth":20,"children":197},"s12-5","12.5. Client state in Zustand",[],{"id":199,"text":200,"depth":20,"children":201},"s12-6","12.6. The facade hook",[],{"id":203,"text":204,"depth":20,"children":205},"s12-7","12.7. Feature, ui and route",[],{"id":207,"text":208,"depth":20,"children":209},"s12-8","12.8. The shell and another domain's API",[],{"id":211,"text":212,"depth":20,"children":213},"s12-9","12.9. Pitfalls specific to Next.js",[],{"id":215,"text":216,"depth":15,"children":217},"s13","13. Vue and Nuxt",[218,222,226,230,234,238],{"id":219,"text":220,"depth":20,"children":221},"s13-1","13.1. What maps to what",[],{"id":223,"text":224,"depth":20,"children":225},"s13-2","13.2. Turn off auto-imports for libraries",[],{"id":227,"text":228,"depth":20,"children":229},"s13-3","13.3. The store",[],{"id":231,"text":232,"depth":20,"children":233},"s13-4","13.4. The facade composable and store scope",[],{"id":235,"text":236,"depth":20,"children":237},"s13-5","13.5. Feature, ui, shell and page",[],{"id":239,"text":240,"depth":20,"children":241},"s13-6","13.6. Pitfalls specific to Nuxt",[],{"id":243,"text":244,"depth":15,"children":245},"s14","14. Side by side",[],{"id":247,"text":248,"depth":15,"children":249},"s15","15. Testing per library type",[],{"id":251,"text":252,"depth":15,"children":253},"s16","16. Growing into it and migrating",[254,258,262,266],{"id":255,"text":256,"depth":20,"children":257},"s16-1","16.1. Migration in eight steps",[],{"id":259,"text":260,"depth":20,"children":261},"s16-2","16.2. What usually goes wrong",[],{"id":263,"text":264,"depth":20,"children":265},"s16-3","16.3. When to split a library",[],{"id":267,"text":268,"depth":20,"children":269},"s16-4","16.4. When this is too much",[],{"id":271,"text":272,"depth":15,"children":273},"s17","17. Questions",[],36,1795449737368]