Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

You must move a package-by-layer codebase of about 400 classes to package by feature without a big-bang change. How do you do it?

We identify features from business capabilities and from which classes change together in version history, then move one feature at a time with IDE refactoring in small reviewed pull requests, reducing visibility to package-private after each move. Architecture tests stop new classes appearing in the old layer packages and detect package cycles, we coordinate moves with the teams to avoid painful merge conflicts, for example in quiet periods, and we track progress by the number of classes still left in layer packages.

Why this question is asked

Moving 400 classes from package by layer to package by feature is mostly a mechanical change, yet it can easily go wrong: a single giant pull request that nobody can review, weeks of merge conflicts for every other branch, or a half-finished move that leaves the codebase in two styles forever. Interviewers ask this scenario to see whether we can run a refactoring of this size safely while the team keeps shipping features. In this answer, we will find the features, plan the order of moves, walk through one move step by step, lock in the progress with architecture tests, handle the human side of merge conflicts, and track the migration to completion.

1Finding the Features

Before moving anything, we decide what the feature packages will be. There are two sources of evidence. The first is the business: the capabilities the application serves, such as orders, customers, invoicing, catalogue and shipping. Product managers and the screens of the application are good guides.

The second is the code itself. Version history tells us which classes change together: if OrderService, OrderController and OrderLineMapper appear in the same commits again and again, they belong in the same feature. A simple script over git log, or a tool that computes change coupling, gives a ranked list of class pairs that change together. Combined with the business view, this usually produces a feature map that covers about 80 to 90 percent of the classes clearly; the rest are genuine shared infrastructure or need a team discussion.

YAML
# Classes changed together most often in the last year (simplified)
git log --since=1.year --name-only --pretty=format:'--' -- src/main/java \
| python3 cochange.py | head
# OrderService.java OrderController.java 41 commits together
# OrderService.java OrderLineMapper.java 33
# InvoiceService.java PdfRenderer.java 27

Notice that the result can surprise us. If PricingService changes with orders far more than with catalogue, it probably belongs in orders, whatever its name suggests.

2Planning the Order of Moves

We move one feature at a time, starting with one that is well understood and loosely connected, so the first move is a low-risk rehearsal that shows the team how it works. Small leaf features, those that other code depends on little, are easiest. Large central features, such as orders in a shop, come once the team is comfortable.

Each feature move is one or a few pull requests of a size reviewers can actually read. With 400 classes and, say, 15 features, that is around 15 to 30 pull requests over several weeks, interleaved with normal feature work.

Step throughMoving one feature
  1. Pick the next featureleaf features first, central ones later
  2. Create the feature packagecom.acme.shop.invoices
  3. Move classes with IDE refactoringimports and references updated automatically
  4. Build and tests green?
    YesReduce visibility to package-privateNoFix references, often a hidden dependency
  5. Open a small PRpure move, no behaviour changes
  6. Merge quicklythen update the progress count

6 steps in order. Play them, or step through them one at a time.

One feature per cycle, each cycle short enough to merge within a day or two.

3Doing One Move Safely

For the move itself we use the IDE's refactoring, such as Move Class in IntelliJ IDEA, which updates every import and reference, rather than moving files by hand. The pull request contains only the move: no renames, no logic changes, no reformatting. That makes review fast, because reviewers check that nothing but package declarations and imports changed, and git can track the files as renames.

After the move compiles and tests pass, we reduce visibility. Classes that only their own feature uses, such as the repository, the controller and helper classes, become package-private by removing public. If the compiler then complains that another feature uses one of them, we have found a real dependency between features. Sometimes it is legitimate and the class stays public as part of the feature's API; often it is a shortcut, such as invoicing calling OrderRepository directly, which we note and fix in a follow-up by going through OrderService.

There is one technical detail to check: anything that refers to classes by package name, such as @EntityScan, @EnableJpaRepositories with explicit base packages, component scan filters, or JPQL queries using fully qualified names. With Spring Boot defaults scanning from the main application package down, moves usually just work, but configured package names must be updated.

4Locking In Progress With Architecture Tests

Without guard rails, new code keeps arriving in the old layer packages, because developers copy what they see. So, after the first move, we add ArchUnit tests. One rule forbids new classes in the old packages, while tolerating the classes still waiting to move. Another rule detects cycles between feature packages, so features do not grow tangled as they are created.

Java
@ArchTest
static final ArchRule noClassesInLayerPackages = FreezingArchRule.freeze(
noClasses().should().resideInAnyPackage("..shop.controller..", "..shop.service..", "..shop.repository..")
.because("new code goes into a feature package"));
// First run: the 400 existing classes are recorded as known violations in the freeze store
// Later: a new class in ..shop.service.. -> the test fails
// a class moved out of a layer -> its entry leaves the store
@ArchTest
static final ArchRule noFeatureCycles =
slices().matching("com.acme.shop.(*)..").should().beFreeOfCycles();

FreezingArchRule wraps an ordinary rule. The first time it runs, it records every existing violation in a store that we commit with the code, and after that it fails only on violations that are not in the store. When a class moves out of a layer package, its entry is removed from the store, so the store can only shrink. When it is empty, the migration is complete and we replace the frozen rule with the plain one, so the layer packages can never come back.

5Avoiding Merge Pain

A move touches many imports, so any branch that edits the same files will conflict. We reduce this in three ways. We announce each move a day ahead in the team channel, so people can merge or rebase first. We keep moves small and merge them quickly, the same day if possible, so they do not sit open while branches diverge. And for the large central features we schedule the move at a quiet time, such as right after a release or at the start of a sprint, when few long-lived branches are open.

Because the pull request is a pure move, conflicts are usually easy to resolve: the other branch's changes can be reapplied to the file in its new location.

6Tracking the Migration to the End

Large refactorings fail most often by stalling at 70 percent. So we track one simple number: classes still in layer packages. It starts at 400 and should fall every week. The size of the freeze store gives the count, and we show it on the team board.

Migration progress
WeekClasses in layer packagesFeatures moved
0400none
2352invoices, shipping
4268catalogue, customers, notifications
6141orders
837pricing, returns, reporting
90shared config placed; exemptions deleted
A shrinking number keeps the migration visible until it is finished.

7Follow-up questions

Should we fix design problems while moving classes?

Not in the same pull request. Mixing moves with logic changes makes review hard and hides behaviour changes inside a huge diff. We note problems found during the move, such as cross-feature shortcuts, and fix them in separate small pull requests afterwards.

What about classes used by many features?

If a class is genuine infrastructure, such as a security configuration or a clock, it goes into a small, clearly named shared package. If it is business logic used by several features, it usually belongs to one feature that exposes it through its public API. A large shared package is a sign that feature boundaries need more thought.

How do you convince the team the effort is worth it?

By moving the first feature and letting them work in it. Seeing a change touch one package, and the compiler stopping cross-feature shortcuts, is more convincing than any argument. We also keep the cost visible and small, a few days spread over weeks, rather than a feature freeze.

8Conclusion

In this answer, we moved a 400-class package-by-layer codebase to package by feature without a big-bang change. We found features from business capabilities and change history, moved one feature at a time with IDE refactoring in small, pure-move pull requests, and reduced visibility to package-private after each move. ArchUnit rules stopped new classes landing in the old packages and caught cycles, announcements and quick merges kept conflicts small, and a falling count of classes in layer packages tracked the work to completion.

What to say in the interviewAbout 90 seconds aloud

Open with

I would start by deciding the target features from two sources: the business capabilities, like orders, invoicing and shipping, and the git history, because classes that change together in the same commits belong together.

Then, if they want more

Then I would move one feature at a time, starting with a small, loosely connected one as a rehearsal. Each move uses the IDE's Move Class refactoring and goes into its own small pull request that contains only the move, no renames or logic changes, so it is quick to review and merges the same day.

After each move I would make everything package-private that other features do not need. Where the compiler complains, I have found a real cross-feature dependency, which I either make part of that feature's public API or fix in a follow-up. I would also check anything configured with explicit package names, like entity scanning.

To stop new code landing in the old packages, I would add ArchUnit rules early: a frozen rule that tolerates the classes still waiting to move but fails for any new class in the layer packages, and one that checks feature packages are free of cycles.

I would announce moves ahead and do the big central features in quiet periods to limit merge conflicts. And I would track one number, classes still in layer packages, going from 400 to zero, so the migration does not stall.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "You must move a package-by-layer codebase of about 400 classes to package by feature...": https://scrivio-interview-library.netlify.app/java/application-architecture/2087c6cc87/