Architectural refactoring changes a boundary, not a contract

External consumers are not only users: they include API clients, modules, tests, event subscribers, and other services. Architectural refactoring can move responsibility into a collaborator or interface, but the endpoint, topic, payload, signatures, and side-effect order must remain unchanged.

For example, event publication can move from OrderService to OrderEventPublisher if business logic does not change the external topic or payload.

BoundaryWhat to preserve
REST APIRoutes, statuses, body, and public signatures
Event integrationTopic, payload, and publication order
Data flowRecords, transactions, and observable side effects
ArchitectureClearer responsibility without a hidden migration

What must not be added silently to a refactor

  • changes to REST responses or public signatures;
  • renaming a topic or changing the event format;
  • updating Spring, Kafka, or other dependencies;
  • changing business rules and fixing defects;
  • changing transport or serialization configuration;
  • broad cleanup in neighboring modules.

Plan an architectural change

  1. Record current behavior with integration, API, and characterization tests.
  2. Define one architectural boundary to clean up.
  3. Move responsibility into a collaborator or interface without changing the contract.
  4. Work in small steps without dependency updates or unrelated formatting.
  5. Run applicable unit, integration, build, lint, and type-check checks.
  6. Check the diff and whether one logical revert is possible.

PR acceptance criteria

CriterionWhat to confirm
BehaviorExternal results and contracts are unchanged
ScopeThe diff is limited to one idea
QualityRelevant checks succeed
ArchitectureClass responsibilities are clearer
SafetyNo accidental dependencies, config changes, or migration
RecoveryThe changes are easy to revert with one revert

The human role in acceptance

Tools and tests provide evidence, but they do not define the task boundary by themselves. A person decides whether the change is truly refactoring, whether the work should be split, whether the interface improves the architectural boundary, and whether the PR is clear enough for safe acceptance.

In the PR description, show the goal, affected files, non-goals, commands run, risk assessment, and behavior-preservation status separately.

Canonical lesson source · JavaRush

Open JavaRush material