From Legacy to Intelligent: AI-Assisted Refactoring in Action

10 min read• By Stefan Nactrab
News
From Legacy to Intelligent: AI-Assisted Refactoring in Action
AI-assisted refactoring transforms legacy systems into knowledge-based software by extracting business logic, structuring code, and enabling transparent, future-proof modernisation with HITL AI.

At the beginning of every successful modernisation lies a clear target vision. It is not about replacing old code with new code or technically “cleaning up” historically evolved systems. The real goal is a software system that is understood: a system with transparent business logic, traceable relationships, and explicit knowledge, not knowledge hidden in thousands of lines of legacy code or in the minds of individual experts. A system that allows technological evolution without becoming a risk every single time.

This very target vision, the transition from historically grown legacy code to an intelligent, knowledge-based system, forms the starting point of AI-Assisted Refactoring and is the guiding thread throughout the entire modernisation approach.

Legacy systems are the backbone of many companies, and at the same time one of their greatest risks. Grown over many years or even decades, often insufficiently documented and highly customised, they create technical debt, strong dependencies on individual experts, and limited innovation capacity. Classic refactoring approaches quickly reach their limits here, as they primarily focus on code, not on the business and technical knowledge embedded within it.

AI-assisted refactoring opens up a new path. Instead of merely cleaning up or migrating legacy code, it is systematically understood, structured, and transformed into sustainable knowledge. The modernisation process consistently aligns with the target vision of an explainable, future-proof system.


Four Core Principles of AI-Assisted Refactoring

At the heart of the approach are four key principles: AI First, Agentic, Supervision, and Data & Knowledge.

AI First: Artificial Intelligence as the Primary Driver

The AI-first approach means that artificial intelligence is not merely used as support, but as the primary driver of refactoring. AI autonomously analyses large-scale code bases, identifies patterns, dependencies, and structures, and continuously optimises its results based on defined quality metrics and KPIs.

A key advantage lies in the ability to process very large contexts. While human developers can only grasp parts of a system at a time, AI analyses hundreds of classes and modules in parallel. Thanks to a vendor-agnostic design, the approach remains flexible and future-proof in the long term.

Agentic: Specialised AI Agents

Instead of a monolithic AI, the approach relies on specialised, agentic AI units. Each agent focuses on a clearly defined area of responsibility, such as code structure, business logic, data flows, or API interfaces.

These agents act in a context-sensitive manner and develop adaptive strategies tailored to the specific application. By combining specialised analyses, a holistic and precise understanding of the application emerges, significantly more robust than linear or purely rule-based approaches.

Supervision: Human Control Remains Central

Despite a high degree of automation, humans remain a central part of the process. Critical decisions are deliberately validated by experienced experts. Strategically placed quality gates ensure that AI results are reviewed, approved, and corrected if necessary.

This continuous human feedback is then fed back into the optimisation of the AI agents. The result is a productive balance between speed and control, an essential success factor for AI-driven modernisation projects.

Data & Knowledge: From Code to a Knowledge Base

The fourth principle addresses the core of many legacy problems: missing or fragmented knowledge. AI-assisted refactoring therefore deliberately focuses on extracting, structuring, and enriching knowledge from existing applications and other available data sources.

The extracted information is semantically enriched, structured and transferred into ontologies and knowledge graphs. This creates a context-rich, machine - and human – readable understanding of the application, far beyond what traditional code reviews can achieve.


Knowledge Graph, Ontology, and Semantics: Systematically Understanding Code

The ontology defines the conceptual schema of the system. It describes relevant technical and business entities, such as classes, methods, business objects, or validation rules, as well as their relationships and structural dependencies. Even complex relationships can be modelled explicitly, for example which classes implement certain business objects or how cross-cutting logic operates across multiple components.

Based on this stable schema, the AI specifically identifies the corresponding structures in the source code. The concrete manifestations of these concepts, such as a specific class or method, form the instances of the model. The entirety of these instances and their relationships is represented in the knowledge graph.

The knowledge graph makes dependencies, control flows, and couplings explicitly visible and serves as the foundation for further analyses, such as impact analyses, the identification of refactoring candidates, or the step-by-step modernisation of legacy systems.

Because the ontological schema remains stable, the source code can be analysed sequentially without overloading the AI’s context window. This approach, sequential analysis based on a stable schema, enables consistent results even for very large code bases and makes complex legacy systems systematically explainable for the first time.


The 3-Step Solution: From Analysis to Transformation

On this knowledge base, the concrete three-step solution of AI-assisted refactoring is built.

1. AI Code Analysis

In the first step, the AI automatically analyses the complete source code, even very large codebases with several hundred or thousands of classes or modules. It identifies structures, APIs, data flows, business objects, and implicit logic.

This already creates significant added value: knowledge that was previously implicit or tied to individuals is systematically extracted and made available.

2. Knowledge Graph Processing

The analysis results are then structured and interconnected in a knowledge graph. Code, logic, and business concepts are related to one another and thus become contextually understandable.

On this basis, technical debt, dependencies, and modernisation potential can be objectively identified and assessed.

3. Knowledge-Based Transformation

In the final step, the acquired knowledge is actively used, for example, to design modern target architectures or to migrate to low-code and automation platforms.

The key difference from classic approaches: existing code is not migrated uncritically; instead, the knowledge embedded within it is deliberately reused.


The Benefits: Sustainable Modernisation Instead of Risk

AI-assisted refactoring delivers clearly measurable benefits.

Costs and risks are reduced through significantly faster knowledge generation and fewer operational disruptions during modernisation. At the same time, dependency on individual knowledge holders is minimised.

Hidden business logic is made explicit and becomes available as living, continuously up-to-date documentation. Decisions about refactoring and migration measures are no longer based on assumptions, but on solid, data-driven analyses.

Last but not least, the approach significantly accelerates modernisation: analysis and preparation phases are reduced from months or years to just a few weeks, while AI agents actively support the transformation.


Conclusion

AI-assisted refactoring is more than technical modernisation. It marks the transition from legacy code to structured, usable knowledge. Companies gain transparency, speed, and security, and create the foundation for sustainable in

novation.

From Legacy to Intelligent is therefore not just a slogan, but a concretely achievable path into the digital future.