Java to TypeScript in a Day: AI Migration Playbook
Learn from my journey using AI to build a TypeScript version of a Java in-memory database (Kiara DB), including the workflow and pitfalls to avoid.
Introduction
In 2020, while working at Priceline, I created a specialized open-source in-memory database. Designing and implementing took four months. Years later, AI helped me create a TypeScript version in a single day.
But what made a single-day rewrite possible was not just AI. A structured design doc, hundreds of unit and behavior tests, and a well-reviewed and published algorithm made that possible. In short, AI is a super tool if used correctly, with the right ingredients.
The Java library still exists and is still supported. The goal was not to replace it, but to make the same capabilities available to browser and Node.js developers.
This article describes the workflow I would reuse on any similar project, and the mistakes that are easy to make when an AI writes most of the code.

What Is Kiara DB?
Kiara DB is an in-memory database optimized for read-heavy scenarios that empowers users to search by any combination of fields or attributes without having to create any special index.
Simply load the database and search using any attribute with typo forgiveness — no fine-tuning or index creation needed to obtain high-read performance. The algorithm is based on my 2020 research paper published in the Journal of Algorithms and Computation (JAC).
The TypeScript version brings the same capabilities to browsers and Node.js, with zero runtime dependencies.
You don't need to know Kiara DB to follow along. Substitute any library or service you want to make available in another language.
1. Start by Converting Behavior Tests
The most valuable thing I had going into the migration was not the Java source. It was the test suite.
There are two kinds of tests in most projects, and they translate very differently:
- Behavior and integration tests treat the system as a black box by defining how a system should behave. Those tests are language agnostic and carry over directly.
- Implementation-focused unit tests depend heavily on the implementation, its underlying platform and the patterns and feature available in the authoring language. These tests translate poorly or maybe not at all.
Converting the behavior tests first gave the AI a precise, executable definition of "done." From there, the rest of the migration had one job: make those tests pass.
Example. A Java test:
List<Condition> conditions = new LinkedList<>(); conditions.add(new Condition("country", Operator.EQUAL, "US")); conditions.add(new Condition("state", Operator.EQUAL, "FL"));
List<Airport> result = storeSearch.query(airportStore, conditions); assertEquals(3, result.size());
And its TypeScript counterpart:
const result = store.search([ { field: "country", operator: Operator.EQUAL, values: ["US"] }, { field: "state", operator: Operator.EQUAL, values: ["FL"] }, ]);
expect(result).toHaveLength(3);
The setup and syntax changed. The expected answer did not. That is the property you want to protect.
Make the Tests Trustworthy Before Writing Code
A few rules made this step reliable:
- Pin the source version. Record the exact commit the tests come from. A moving branch is not a stable specification.
- Run the original tests first. Review and fix any inconsistencies, because if there are any issues, this is a good time to fix them before we copy over unwanted errors to the new repo.
- Translate the tests using AI with a human review. During translation, maintain a level of isolation. AI model should only see the tests in the source language and not the main application code. The instructions should define the main goal as a test translation without thinking about application code. This prevents AI from bending corners in tests if the application’s code translation in some parts becomes challenging. AI models are very creative in hacking through to meet their goals and then covering their tracks.
- Cover the edges. Include invalid input, empty values, nulls, duplicates, and boundary values, not just successful queries.
- Lock the expectations. An expected result changes only through a reviewed decision. The AI may never edit an assertion just to make its code pass.
At the end, all 448 Java tests were translated to TypeScript tests. In the next phase of code translation, these immutable tests would be used to verify every changed iteration.

2. Define Clear Responsibilities for Every Agent
If we simply ask an agent to translate the code to another language, the agent will try to take the shortest path and may produce code that, although it passes behavior tests, creates application code riddled with unstable patches, broken algorithms that adversely affect performance, missed features, etc.
Careful planning matters; the devil is in the details.
Breaking down a bigger task into several agents (with clear responsibilities and how they interact with each other in a loop) gave us the results we hoped for.
Agent #1: The Code Analyzer
Job: Examine codebase structures to define project specifications.
Produces: A requirements inventory with references back to the source:
- Functional requirements, in the format of request-response, input normalization, error behavior, and result limits.
- Non-functional requirements, like latency, memory usage, dependencies, and supported runtimes.
- Any Algorithmic requirements, meaning the translation preserves core data structures and algorithms — for this translation of KiaraDB, this was very important.
The last category is the one most often missed. KiaraDB's value comes from its search algorithm. A simple Array.filter() over every record can return the right answers on a small test dataset while losing everything that makes the library useful at scale.
Rule: The core algorithm must be translated as is, not replaced. Write idiomatic TypeScript while maintaining core data structures and search methods. Should papers, code, or test outcomes diverge, an automated analyzer mandates human review for resolution of conflict.
Agent 2: Planner
Job: Turn requirements into small, verifiable steps.
Produces: An implementation plan with each step defining the requirements it covers, the tests that prove it is done, and known risks.
For example, in the case of KiaraDB, the planner broke down the translation into individual features, implemented separately in sequence.
Schema and data loading ->
structured queries ->
collections, ranges, and keyword search ->
browser worker support and release checks
The planner should also be instructed to scope the work strictly to rewrite and not introduce improvements present in the target language, so new features don't sneak into a code rewrite.
Agent 3: Developer
Job: Implement one planned step at a time in the target language.
Grounded in: Your team's coding policies, for example, strict typing, explicit error handling, no skipped tests, no unrelated refactoring, and documentation of any intentional difference.
Language differences show up here. Java can inspect a class's fields at runtime, while TypeScript types disappear after compilation. The TypeScript version therefore offers both explicit schema definitions and decorators that feed the same search engine. That changes how users describe their data, not how queries behave.
The developer can propose changing an expected result. However, an agent cannot approve that change; it must coordinate with the other agents we created, who will work together in a loop and bring in a human whenever required
Agent 4: Tester and Gap Analyzer
Job: Audit both programming projects for structural discrepancies and find missing components
Produces: A ranked list of gaps, each with a reproducible example.
This agent looks beyond the developer's own tests: requirements with no tests, tests whose expected values came from the AI, changed algorithms, and missing public APIs. A useful gap report is specific, for example:
NOT_CONTAINSon a collection field returns 2 rows; Java returns 3. Tests for this use case are missing in both TypeScript and Java.
Range queries in TypeScript are significantly slower than the Java version because of an algorithm mismatch.
Agent 5: Product Manager
Job: Communicate work produced during releases to interested stakeholders.
Produces: Public technical notes plus announcement drafts describing working, tested modules.
This agent acts like a quality gate for the final product delivery. While producing final artifacts, if it finds that the delivered product doesn’t meet expectations, then it will work with Code analyzer, planner, developer, and tester agents in a loop until the identified gaps are filled.
A Reusable Prompt Template
Each role works better with a short, explicit brief. Here is the shape I'd reuse:
Role: Tester and gap analyzer. Inputs: Java repo at <commit>,
TypeScript repo, requirements list, latest test results. Task: Find the highest-impact behavior or algorithm gap between the two.
Output: One gap with requirement ID, expected vs. actual, and a failing test. Rules: Do not modify implementation code. Do not change expected results.
Stop when: One gap is reported, or none is found after checking all requirements.
3. Connect the Agents in a Loop That Knows When to Stop
The agents work as a cycle. The analyzer defines goals. The planner chooses sequential moves. The developer builds functions, and the testers verify output consistency. Each gap goes back to the role that can fix it
- Misunderstood source behavior goes to the analyzer.
- Missing or mis-ordered work goes to the planner.
- A bug goes to the developer.
- A request to accept a difference from Java goes to a human.
When everything passes, the product manager prepares the release communication and does a final quality check.

Define "Done" Before the Loop Starts
The loop needs an exit condition the agents can't negotiate. Mine looked like this:
- All converted behavior tests pass, including error and edge cases.
- Secure all high and critical risks.
- Rewritten algorithm matches the source with no unapproved modifications.
- Build, type checks, and browser tests pass.
- Performance and memory meet thresholds agreed on before implementation.
- Every remaining difference from Java is documented and approved.
Track Gaps in One Shared List
Rather than forcing agents to repeat the whole project review, every phase maintains one unified tracker. Each entry records the requirement, expected versus actual behavior, a reproducer, severity, owner, and status. Agents report what changed, not everything they know.
4. Avoid Common Mistakes
Infinite and Trivial Loops That Burn Tokens
While breaking down a big task into multiple agents working together in a loop is essential for success, agents can create endless dialogue without meaningful iterative progress. Therefore, it is essential to keep the agentic loop in check.
Set an explicit control policy. I started by capping work at five iterations per batch and reviewing results before approving more. You can use instructions like the following for your main orchestrator agent:
Work on one planned step at a time. Run at most five implement-and-verify cycles per batch.
After each cycle, record what changed and the test result. If two cycles in a row produce no new fix or evidence,
stop and escalate. Never skip tests, weaken assertions, or expand scope to claim success.
Five is not a magic number. The point is we will allow a human to intervene and check if more iterations are required to achieve the focused goal, instead of going in a loop and burning up tokens.
Not Isolating Behavior Tests
The agent rewriting the code must never be allowed to rewrite behavior tests to avoid agents tweaking the tests to just pass them. An independent agent who has no knowledge of other agents doing rewrites should first translate the behavior tests and, once done, they should be immutable.
Matching Results but Losing the Algorithm
A brute force algorithm can pass every test but performs poorly at scale, which is why reviewing and comparing the underlying algorithm must be part of the validation.
Treating Runtime Differences as Syntax
Some differences between Java and TypeScript look minor but change results:
| Area | What to watch OUT for |
|---|---|
| Numbers | Java long values can exceed what a JavaScript number represents exactly. Test large values explicitly. |
| Test data | JSON numbers can lose precision before a test even runs. Store large integers as strings. |
| Nulls | Missing, null, empty strings, and the text "null" may behave differently. Test each one. |
| Dates and locales | Pin the time zone and locale. Reject unsupported date formats rather than guessing. |
| Reflection | TypeScript types are erased at runtime. Provide metadata explicitly. |
| Web workers | Class instances lose their methods when sent to a worker. Test the actual message boundary. |
Moving the Goalposts
Don't relax a performance threshold because the implementation missed it. Don't relabel a missing feature as optional without approval. Improvements are welcome, but they should be explicit options, not silent changes to how the original behaved.
Conclusion
The TypeScript transition in a single day was made possible by reusing previous human labor. The published algorithm, along with extensive test history, established the foundation for success.
If you have a similar project, here are my suggestions:
- Convert behavior tests first, with expected results taken from the original system.
- Split the work into focused agent roles that can't approve their own output.
- Orchestrate the agents in a loop with guardrails to protect against going into infinite loops.
- The validation set should include both functional and non-functional requirements, such as automated tests, comparison of source and target algorithms, gap analysis for missing features, etc.
The two codebases that we worked on are open source, so you can compare them side by side:
- Java: github.com/kapoorlabs/kiara
- TypeScript: github.com/kapoorlabs/kiara-ts
References
- Kapoor, A. "Efficient Storage and Retrieval of In-Memory Static Data." Journal of Algorithms and Computation.
- Kiara DB Java repository and the pinned migration baseline.
- Kiara TS TypeScript repository.
- Migration plan, parity ledger, and compatibility decisions.
- TypeScript 5.2 decorator metadata.
Opinions expressed by DZone contributors are their own.