Section 16 of 17
Growing into it and migrating
Contents
Nobody starts with seventy libraries. Fleetline started as one Angular application with a src/app folder; the steps below are the order that worked.
16.1. Migration in eight steps
- Create the workspace around the app.
nx initin the existing repository. Nothing moves yet. - Draw the domains on paper. Use the business words: what do planners, customers and finance talk about? Expect six to ten domains. Write them into a README.
- Turn on the rule as a warning. Add the lint config of section 8.2 with
'warn'. Count the warnings; that is your baseline. - Extract
modelandutilfirst. They have no dependencies, so moving them is safe, and every later step needs them. Usenx g @nx/workspace:move. - Extract
uiper domain. Every component that only has inputs and outputs moves. Components that inject a store stay for now. - Carve
data-accessper domain. Split the root store by domain; move each store feature, its effects and HTTP into the domain'sdata-accessand register it on the domain's route. - Move pages into
feature-*and routes intofeature-shell. The app shrinks to its routes and providers. - Switch the rule to
'error'and add CODEOWNERS. From now on, a new crossing fails CI.
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 (notifications) to learn the moves.
16.2. What usually goes wrong
- A domain called
commonorcore. It becomes the newshared/. Every concept has a business owner; find it. - Domains cut by page instead of by business language. "Dashboard" is not a domain; it is a feature that reads from several domains through their APIs.
- API libraries that re-export everything. Then the boundary is only cosmetic. Export what another team actually uses, and nothing else.
- Disabled lint lines. One
eslint-disablefor the boundary rule becomes forty within a year. Exceptions go into the config, with a reason in the pull request.
16.3. When to split a library
- A
data-accesswith more than three or four store features, or owned by two teams: split by sub-domain. - A
uilibrary imported by only one feature: merge it back into that feature or keep it, but do not move it toshared. - A
featurewith several unrelated routes: one library per use case. - A domain whose libraries are mostly owned by another team: the domain is cut wrong, or the team boundaries are.
16.4. When this is too much
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 (src/domains/<domain>/feature-…, ui-…, data-access, model) 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.