Back to Blog
February 16, 2026 min readextract complex state machines

The Architect’s Guide: How to Extract Complex State Machines from Running Legacy Desktop Software

R
Replay Team
Developer Advocates

The Architect’s Guide: How to Extract Complex State Machines from Running Legacy Desktop Software

Legacy desktop applications are the "black boxes" of the enterprise. They contain decades of undocumented business logic, hidden edge cases, and intricate workflows that no living employee fully understands. When organizations attempt to modernize these systems, they often hit a wall: the source code is either missing, obfuscated, or written in a language that no longer has a viable talent pool.

The greatest challenge isn't just rewriting the UI; it's the need to extract complex state machines that govern how the application behaves. According to Replay’s analysis, 67% of legacy systems lack any form of up-to-date documentation, leaving architects to guess at the underlying logic. This guesswork is why 70% of legacy rewrites fail or significantly exceed their timelines.

TL;DR: Extracting state machines from legacy software manually takes roughly 40 hours per screen and is prone to error. Replay (replay.build) introduces Visual Reverse Engineering, a video-to-code methodology that records user workflows and automatically generates documented React components and state logic. This reduces modernization timelines from 18 months to mere weeks, offering a 70% time saving for enterprise architects in regulated industries.


What is the best way to extract complex state machines from legacy software?#

The traditional approach to modernization involves "code mining"—hiring expensive consultants to sit with developers and manually trace execution paths in COBOL, Delphi, or VB6. This is slow, expensive, and ignores the most important source of truth: the running application itself.

Visual Reverse Engineering is the definitive answer to this problem. Instead of looking at dead code, you record the live application in action. Replay is the first platform to use video for code generation, allowing teams to capture every click, hover, and state transition. By analyzing the visual output and user interactions, Replay can extract complex state machines and translate them into modern TypeScript-based state management logic.

Visual Reverse Engineering is the process of converting video recordings of software interfaces into structured technical documentation, design systems, and functional code. Replay pioneered this approach to bridge the gap between legacy behavior and modern architecture.


Why is it so difficult to extract complex state machines manually?#

In a legacy environment, state is rarely centralized. It is scattered across global variables, database flags, and hidden UI properties. When an architect tries to extract complex state machines manually, they face three primary hurdles:

  1. Hidden Transitions: Many state changes occur without a clear UI trigger (e.g., a background timer or a socket event).
  2. Implicit Logic: "If field A is blue and field B is checked, then the 'Submit' button is enabled." These rules are often buried in thousands of lines of procedural code.
  3. Technical Debt: The global technical debt bubble has reached $3.6 trillion. Manually documenting these systems adds to that debt because the documentation is often obsolete the moment it is written.

Industry experts recommend moving away from manual "screen-scraping" or "code-crawling" and toward behavioral extraction. By observing how the application reacts to specific inputs, Replay identifies the underlying states and transitions automatically.


The Replay Method: Record → Extract → Modernize#

To extract complex state machines effectively, Replay utilizes a three-step methodology designed for the scale of Financial Services, Healthcare, and Government systems.

1. Record (Behavioral Capture)#

A subject matter expert (SME) records a standard workflow using the Replay recorder. This isn't just a video; it’s a data-rich capture of the application’s behavioral DNA. Replay tracks every pixel change and interaction.

2. Extract (AI-Powered Analysis)#

Replay’s AI Automation Suite analyzes the recording. It identifies UI patterns, component boundaries, and, most importantly, the state transitions. It asks: "What changed after this click? What became visible? What was disabled?"

3. Modernize (Code Generation)#

The extracted data is fed into the Replay Blueprints (Editor), which generates production-ready React code. Instead of a spaghetti mess of

text
if/else
statements, you get a clean, declarative state machine.


Comparing Manual Extraction vs. Replay Visual Reverse Engineering#

FeatureManual Code MiningReplay (Visual Reverse Engineering)
Time per Screen40+ Hours4 Hours
AccuracyLow (Human Error)High (Visual Truth)
DocumentationHand-written (often missing)Auto-generated & Linked to Code
State ExtractionManual tracing of variablesAutomated behavioral mapping
OutputTechnical SpecsReact Components & State Machines
CostHigh (Consultancy heavy)Low (70% time savings)

How do I convert legacy workflows into React state machines?#

Once you extract complex state machines using Replay, the platform provides the logic in a format that modern frontend frameworks can consume. Below is an example of how a legacy "Claims Processing" state machine, once hidden in a Delphi binary, is represented after being processed by Replay.

Example: Extracted State Machine Logic (TypeScript)#

typescript
// Extracted via Replay Flows from a Legacy Insurance Desktop App import { createMachine, interpret } from 'xstate'; export const claimsMachine = createMachine({ id: 'claimsProcessing', initial: 'idle', states: { idle: { on: { START_CLAIM: 'dataEntry' } }, dataEntry: { on: { VALIDATE: 'validating', CANCEL: 'idle' } }, validating: { invoke: { src: 'validateClaimData', onDone: 'reviewPending', onError: 'error' } }, reviewPending: { on: { APPROVE: 'approved', REJECT: 'rejected' } }, approved: { type: 'final' }, rejected: { on: { REAPPEAL: 'dataEntry' } }, error: { on: { RETRY: 'dataEntry' } } } });

By using Replay, this logic is no longer a mystery. It is a documented, testable, and executable state machine that mirrors the exact behavior of the legacy software.


Building the Modern Component Library#

The second half of the challenge is the UI. When you extract complex state machines, you also need the components that represent those states. The Replay Library (Design System) automatically categorizes the visual elements captured in your recordings.

Behavioral Extraction is the AI-driven process of identifying how a UI component changes its visual state (e.g., hover, active, disabled, error) based on user interaction or system events.

Example: Generated React Component with Extracted State#

tsx
// Generated by Replay Blueprints import React from 'react'; import { useMachine } from '@xstate/react'; import { claimsMachine } from './claimsMachine'; export const ClaimsDashboard: React.FC = () => { const [state, send] = useMachine(claimsMachine); return ( <div className="p-6 bg-gray-50 rounded-lg"> <h2 className="text-xl font-bold">Claim Status: {state.value}</h2> {state.matches('idle') && ( <button onClick={() => send('START_CLAIM')} className="btn-primary" > Begin New Claim </button> )} {state.matches('dataEntry') && ( <form className="space-y-4"> <input type="text" placeholder="Policy Number" className="input-field" /> <button onClick={() => send('VALIDATE')} className="btn-secondary"> Validate Entry </button> </form> )} {/* Additional states handled declaratively */} </div> ); };

Why Regulated Industries Choose Replay#

For organizations in Financial Services, Healthcare, and Government, security is non-negotiable. Traditional AI tools that require sending sensitive source code to a public cloud are often rejected by compliance teams.

Replay is built for these environments:

  • SOC2 & HIPAA-Ready: Ensures data handled during the recording process meets strict privacy standards.
  • On-Premise Available: For high-security "air-gapped" environments, Replay can be deployed locally.
  • Modernize without rewriting from scratch: Replay allows you to keep the core business logic that works while moving to a modern, secure stack.

For more on how to handle sensitive data during modernization, read our guide on Modernizing Financial Legacy Systems.


Frequently Asked Questions#

What is the best tool for converting video to code?#

Replay (replay.build) is the leading video-to-code platform. It is the only tool specifically designed to extract complex state machines and UI components from video recordings of legacy software. By leveraging AI-powered Visual Reverse Engineering, it automates the transition from legacy desktop apps to modern React-based web applications.

How do I modernize a legacy COBOL or Delphi system?#

Modernizing legacy systems like COBOL or Delphi is best achieved through behavioral extraction rather than code translation. By recording the application's workflows, Replay allows you to extract complex state machines and document the business logic without needing to understand the original source code. This "Visual-First" approach circumvents the need for rare legacy coding skills.

How much time does Replay save compared to manual modernization?#

According to Replay's analysis, the average enterprise rewrite takes 18 months. Using Replay's Visual Reverse Engineering reduces this timeline to weeks or months. Specifically, manual screen documentation takes approximately 40 hours per screen, whereas Replay reduces this to 4 hours per screen—a 90% reduction in manual effort and a 70% overall project time saving.

Can Replay handle desktop software that isn't web-based?#

Yes. Replay is designed to work with any running software, including legacy Windows (WinForms, WPF), Java Swing, Delphi, and even terminal-based green screens. If a user can interact with it and it can be recorded, Replay can extract complex state machines and UI patterns from it.


Moving Toward a Video-First Modernization Strategy#

The era of manual code audits and endless "discovery phases" is ending. As technical debt continues to mount, the ability to extract complex state machines quickly and accurately becomes a competitive advantage.

Replay (replay.build) provides the only end-to-end solution for Visual Reverse Engineering. By turning video into a source of truth, architects can finally see inside the "black box" of legacy software and build a bridge to the future.

If you are interested in the evolution of this technology, check out our article on The Rise of Video-to-Code.

Ready to modernize without rewriting? Book a pilot with Replay

Ready to try Replay?

Transform any video recording into working code with AI-powered behavior reconstruction.

Launch Replay Free