Assessing a Codebase Before You Migrate

The urge on day one of a migration is to start moving files. Resist it. Without a measured picture of where the codebase stands, you cannot choose a first step, you cannot tell whether the second step helped, and you cannot answer the manager who asks how it is going. The book's assessment chapter is about producing that picture before any code moves.

Start with the graph

The first task is to extract the dependency graph. Every import, every require call and every dynamic module resolution is an edge between files, or between packages if you prefer a coarser view. Tools such as madge, dependency-cruiser or the book's own lvd-lint can build this graph in minutes, even for codebases of several hundred thousand lines.

Three analyses then do most of the work.

  • Cycles. Run a strongly-connected-components search to find every circular dependency. The book treats each as a hard constraint: no layer assignment is valid until the cycle is broken. Record how many cycles there are, how many files each touches and which edges hold them together.
  • Volatility. Using six to twelve months of version-control history, compute each component's change frequency relative to the busiest component. Sort by the result. If the distribution is bimodal or multimodal, the clusters hint at natural layer boundaries: a stable group that looks like Schema and Utils, and a busy group that belongs in Tools or above.
  • Baselines. Record today's values for the core metrics. The book gives typical starting figures for an unlayered codebase, such as many files per change, a tangle of cycles and low cohesion, so you know what "normal" looks like before the work starts.

The baselines are the quiet hero. Migration progress is measured against them, and the lvd-metrics trend reports later become the evidence that the effort is paying off.

Find the gaps

With the current state written down, map every component to the layer it should live in, using its measured volatility. The gap analysis looks for four kinds of problem.

  1. Missing layers. Many legacy systems have no explicit Schema, Utils or Resources. Validation, helpers and API clients sit together in one source folder. Every layer that is absent represents extraction work waiting to be done.
  2. Misplaced components. A component is misplaced when its measured volatility does not fit the range of the layer it sits in. Picture a distance-conversion helper that never changes, buried inside a booking module that changes every week. It should be extracted to Utils.
  3. Dependency violations. Any import that breaks the rule that dependencies flow from higher to lower volatility goes on a list, classified as cross-layer or within-layer, with a rough estimate of the effort to fix it.
  4. Interface mismatches. Components that leak implementation details, such as connection objects, raw HTTP responses or third-party SDK types, must be changed to speak in domain terms. This matters most for the Resources layer, which exists to present a clean boundary.

Turn gaps into a plan

The result is a prioritised backlog, sequenced by three principles. The first is bottom-up extraction: Schema and Utils have the fewest dependencies and the lowest change rate, so they are the safest start, and each extracted layer is immediately useful to everything above it. The second is risk-adjusted scheduling: the riskier extractions, Resources and Tools, are scheduled when the team has some practice and when pressure to ship features is lowest. The third is continuous verification: after every step, run the linter, the metrics and the existing tests, and treat the step as unfinished until all of them pass.

The roadmap should also record who does the work, whether dedicated engineers or part-timers from feature teams, a calendar with milestones and some slack for surprises, and explicit rollback criteria. The book's examples of such criteria include a test failure rate above a stated limit, or a Change Impact Radius that rises instead of falling. Agreeing on the exit conditions in advance makes it far easier to reverse a step calmly.

The takeaway

An assessment turns "this codebase is a mess" into a list with numbers: how many cycles, which components are in the wrong place, which layers are missing. That list is both the plan and the yardstick. The plan itself is laid out in the nine-step roadmap, and the underlying idea of cycles is explored in detecting dependency cycles.

What the book covers

  • A procedure for extracting a codebase's dependency graph
  • How cycle counts and volatility histograms guide layer assignment
  • Typical pre-migration metric baselines to compare against
  • Rollback criteria and resource planning for the roadmap