ai newsDo., 29. Okt.
EilmeldungGoogle Connected Apps Platform Preview Brings One MCP Path to Search and Gemini

Build a repeatable PHP-to-Java migration engine with Kiro

Turn a PHP-to-Java migration from a one-time leap of faith into a measurable, repeatable process with Kiro. This post walks through a reusable engine: a mechanical discovery scanner and an eight-phase, parity-first workflow that treats the original PHP application as the specification and verifies t

AWS ML BlogDonnerstag 19:14 · 29.10.8 Min. Lesezeit
Bild: AWS ML Blog

When your team moves a mature PHP application to Java, you gain stronger type safety, broader library support, and more predictable scaling. A PHP codebase built over the years with Laravel, Symfony, or Doctrine carries business rules in places that are not obvious, from Eloquent traits to XML mapping files, so a structurally similar Java port can compile cleanly and still behave differently.

This post shows how to turn PHP-to-Java migration from a one-time leap of faith into a measurable, repeatable process using Kiro. Kiro is an AI integrated development environment (IDE) that pairs an AI agent with your codebase to run multi-step engineering tasks with you in the loop. The approach centers on a reusable engine: a shared methodology, a mechanical discovery scanner, and an eight-phase workflow. This engine treats the original PHP application as the specification and refuses to declare the Java port correct until a parity harness verifies it.

You start with an open repository, so you can run the engine yourself rather than read about it. Everything the engine knows lives in a small set of skill files, and with those files, you can run the same methodology in more than one way.

Everything here is packaged as skill files: versioned Markdown capability packages that encode the migration methodology (php-to-java-migration) and the discovery scanner workflow (php-model-discovery). Because that knowledge lives in files rather than any one tool, you can run the same methodology in two ways.

Kiro brings an AI agent into your editor to drive a migration step by step. Open the repository root as a Kiro workspace and the skills activate automatically when you ask Kiro to migrate a PHP application. Kiro then walks the eight-phase workflow with explicit approval gates, so you review the discovery manifest, approve the rulebook, and sign off on each phase before the next begins. It’s the mode used for every example in this post.

AWS Transform is the AWS agentic AI service for large-scale migration and modernization, and it now integrates natively with Kiro. Through that integration, you can hand AWS Transform the same skill files that govern an interactive Kiro session, so discovery before translation, the parity harness as referee, and ‘ fix the loop, not the code ’ apply to an autonomous run.

The engine is organized around a single principle: one shared brain, many projects. To open it, clone the repository locally, then in Kiro open a folder and select the repository root (the folder containing.kiro/). Kiro loads the skills and steering automatically, with fuller steps in “Getting started.”

The workspace separates a shared methodology layer from the individual projects that use it, as shown in the following diagram. At the top is a global.kiro/ layer that every project draws on. Beneath it sit the per-project folders, each with its own PHP source, Java output, and specification sub-folder.

Figure 1: The workspace is split into a shared, global methodology layer and per-project code and spec folders

Those same shared skill files can be run in two different ways, shown in the following diagram. The identical eight-phase, parity-first pipeline can be driven either by Kiro (interactive, one application at a time) or by AWS Transform (agentic, at portfolio scale), and both convert PHP source into parity-verified Spring Boot Java.

Figure 2: The same shared skill files drive two execution paths: Kiro (interactive, one app at a time) and AWS Transform (agentic, portfolio scale). Both run the identical eight-phase parity-first pipeline, converting PHP source into parity-verified Spring Boot Java

A shared, global layer under.kiro/ holds two Skills, php-model-discovery (the scanner) and php-to-java-migration (the eight-phase playbook), plus the core-workflow.md Steering file. Each per-project folder holds its own PHP source, Java output, and spec sub-folder under.kiro/specs/, so improving the methodology once lets every project inherit the gain.

The single most important rule fires before anything else: Don’t read, guess at, or hand-translate a model or entity file until the scanner has run.

The scanner works in a single pass with no dependencies, as shown in the following diagram. It applies three discovery strategies to the source tokens and emits one JSON manifest, with anything ambiguous routed to a review-flag queue for a human to resolve.

Figure 3: The scanner runs three discovery strategies over source tokens and emits a single JSON manifest with a review-flag queue

The scanner is discover-models.php, a single-file, dependency-free PHP command-line tool that doesn’t execute the target code. It only reads source text as tokens, so it runs against apps of your choice whether its dependencies are installed. It runs three strategies on every scan: Eloquent model discovery (walking the class inheritance chain to Illuminate\Database\Eloquent\Model), Doctrine attribute detection (the #[ORM\Entity] attribute), and ORM XML mapping (external *.orm.xml files).

The output is a single JSON manifest. A models[] array carries every field, cast, relationship, and visibility rule, and a flags[] array appears on every entry. The scanner flags ambiguity rather than guessing.

For example, a $fillable list built from a runtime expression becomes a plain-English flag, and that flag list is the human review queue.

Phase 0 is preparatory: it runs the scanner and assembles the inventory. The first three phases then concentrate human expertise. Phase 1 builds the parity harness before Java is written, replaying request/response pairs against both the PHP original and the Java port. The harness must pass against working PHP and fail when you break it deliberately, because a harness that misses injected breakage is not trusted. Phase 2 seeds the rulebook and gap inventory (RULEBOOK.md, GAP_INVENTORY.md), and Phase 3 stress-tests it against representative files before committing it across the application.

Figure 4: Human judgment is front-loaded into a preparatory Phase 0 and Phases 1–3. Phases 4–8 are mostly self-driving loops, refereed by a parity harness

The first four phases concentrate human expertise. Phase 0 runs the scanner and assembles the inventory. Phase 1 builds the parity harness before Java is written, replaying request/response pairs against both the PHP original and the Java port. The harness must pass against working PHP and fail when you break it deliberately, because a harness that misses injected breakage is not trusted. Phase 2 seeds the rulebook and gap inventory (RULEBOOK.md, GAP_INVENTORY.md), and Phase 3 stress-tests it against representative files before committing it across the application.

Phases 4–8 are mostly self-driving loops: Phase 4 scaffolds the project, Phase 5 translates the data model from the manifest, Phase 6 translates the I/O layer (routes become controllers, middleware becomes filters, validation becomes annotated data transfer objects), Phase 7 converts business logic in batches, and Phase 8 proves parity against the harness and cuts over. Two principles govern the loop. First, the PHP code is the specification: the port is done when the referee agrees, or each mismatch is logged as an approved change. Second, you fix the loop, not the code, amending the rulebook and regenerating rather than hand-patching.

The laravel-eloquent-sample project is a working, bounded example: a read-only slice of an open source Laravel application, with the Book, Chapter, Page, and User models migrated to Spring Boot 3.4.1 on Java 21 with Maven and an in-memory H2 database.

The mapping from PHP to Spring Boot is mechanical and traceable, as shown in the following diagram. Each manifest entry on the left maps to a Java construct on the right, producing the layered runtime architecture of the generated application slice.

Figure 5: Manifest-driven mappings on the left. The layered runtime architecture of the generated application slice on the right

The mappings are mechanical and traceable back to the manifest: a PHP namespace becomes a Java package, an Eloquent model becomes a JPA @Entity, has Many and belongs to relationships become @OneToMany and @ManyToOne, and Eloquent query scopes become Spring Data repository methods. The discipline shows in serialization: html, markdown, and text carry @JsonIgnore because the manifest recorded them in Page’s $hidden list, while Book’s description deliberately doesn’t.

The spec is candid that only 4 of 37 models were ported and, most important, that the parity harness was never built for this slice, which it calls “the single biggest gap.” Documenting where it falls short is itself part of the design.

The complete migration engine is available in the sample PHP-to-Java migration repository.

The methodology auto-detects Laravel, Symfony, CodeIgniter, and plain PHP, and extension is additive: add a detection row and a references/<framework>-to-spring.md guide for a new framework. Because Kiro and AWS Transform read the same files, refining them once upgrades both engines.

If you deployed the sample Spring Boot application during this walkthrough:

We showed how to build a repeatable PHP-to-Java migration engine with Kiro that turns large-scale rewrites into a measurable, compounding process. The key principles are:

None of this is specific to PHP or Java. The same shape applies to other migrations where the old system is the only complete specification. Clone the sample PHP-to-Java migration repository, open it as a Kiro workspace, and explore the Skills and Steering capabilities that power it, or bring the same skill files to AWS Transform. For more about language migration patterns on AWS, see the AWS Prescriptive Guidance documentation.

Sarat is a Principal Solutions Architect at Amazon Web Services (AWS), where he partners with Strategic Accounts to design and deliver cloud solutions at scale. Passionate about artificial intelligence (AI) and machine learning (ML), he helps customers drive innovation and transformation while preserving business agility. Outside of work, Sarat enjoys playing co-op games on the PS5 with his son, traveling, and playing badminton.

Phani is a Senior Technical Account Manager (Strat) at Amazon Web Services with 22+ years of experience in building and scaling enterprise platforms. He drives architecture excellence, system reliability, and operational performance for large-scale enterprise workloads. Phani specializes in distributed systems, microservices architecture, and cloud-native platforms, with a focus on enabling enterprise transformation and Generative AI solutions.

Pallavi is a Technical Consultant at Amazon Web Services, helping customers boost developer productivity through Kiro and the AI-Driven Development Lifecycle (AIDLC). She works with enterprises modernizing their engineering practices, focusing on delivering higher-quality software faster with AI-assisted, spec-driven development. Outside work, she enjoys creating music and hiking.

Quelle: AWS ML Blog (AWS ML Blog). Original öffnen