Econify brings top engineering talent to your toughest problems around AI workflows, Data readiness, Cloud cost containment, OTT and Web. Partner with us to get things done.
Insights
How to Rebuild a Large App with AI Agents Without Losing the Plot
BY Econify
•Wed, Dec 2, 2026

A coding agent is good at the task in front of it and poor at remembering what was decided three weeks ago. On a small feature, that doesn't matter. On a rebuild that runs to hundreds of pull requests, it costs you: screens drift from the old app, the same decision gets made twice, and nobody can explain the codebase you end up with. The fix is to move the project's memory out of the chat and into the repository, where every agent session starts from the same material.
One of our senior engineers used this approach to rebuild a client's product. The client had three browser apps, written quickly with AI tools. Each one shipped as a single very large generated file and went out by hand from a laptop, with no pipeline and no concept of tenants. The job was to turn them into one multi-tenant application on AWS with CI/CD, backups and rollbacks, and to match the apps the client's users already knew, pixel for pixel.
The plan written before the build put the work at about 36 weeks for one engineer. Our engineer expected a workflow built around the agents to be ten times faster than that plan, and put the number at 18 days.
It took 22 working days. In that time the build produced 254 merged pull requests, about 200,000 lines of application code, about 260,000 lines of test code holding roughly 10,700 test cases, and 240 recorded decisions. Production went live 3 days later. Behind it sits a catalog of about 1,900 numbered specs, 92% of them backed by automated tests.

Nine steps for a spec-driven rebuild
1. Document the old system before you write anything new
Start by having an agent read the existing codebase and the target, and write it all down. Our engineer built a custom review agent for this. It's a hub that only dispatches: 16 survey subagents each read the old code for one topic (security, the data layer, testing, the odd things nobody can explain), and 11 proposal subagents each design one part of the new system. Survey agents describe what is there and are barred from proposing anything. Every question the hub couldn't answer went to the engineer and into a decision log, which reached 185 rows.
Three documents came out of it: a one-page description of the work for the client, detailed documentation of how the existing code behaves, and a description of how the new code would work. The surveys, the proposals and the one-pager took one afternoon of agent time. The detailed spec took another week of questions and revisions. Every claim about the old code cites a file, a line and a commit, so a later reader can check it.
The one-pager did a second job. It gave the client something short enough to read and correct before any code existed, when corrections were still cheap. The client also wrote a document of their own, about 100 user stories describing what the product is for, and it went into the reference set beside the spec.
2. Turn the requirements into numbered specs that tests must name
Next came the formal specification of behavior, a spec catalog. It's a folder of markdown files, one per domain, and it now holds 1,946 individually numbered specs. Each row has four cells: an id, one plain-language statement of the behavior, the source it came from, and the test that proves it.

Three conventions make the catalog work.
- A legacy test is a test. Until the new system builds a feature, its spec cites the old app's own check. The issue that builds the feature replaces the citation with the new test.
- A spec nothing proves says so. Its test cell reads
untested, with a reason. Today 156 specs carry that word, most of them in two modules. The 92% figure is a count of specs with a named test behind them. - CI reads the catalog. A script fails the build on a duplicate id, a malformed row or an empty test cell, and prints the
untestedcount on every run. Each test names its spec id in its title, so a failing test tells you which spec broke.

3. Build the backlog from the specs, size every issue, and give every issue the same shape
The build plan in the spec became a GitHub project. The backlog opened with 84 issues on the first day and grew to 309 over the month, as our engineer understood the work better. Dependencies are GitHub's own "blocked by" links, 406 of them by the end of development. The agent contract relies on them: an agent takes only an issue it was assigned, and only when nothing open blocks it.
The main lesson was about size. Every issue carries one, and only small and medium issues count as ready for an agent. Anything large or extra-large gets broken into sub-issues first. More than half of the backlog ended up as a child of a larger issue.
Every issue has the same shape, because the issue is the only source of scope an agent gets:
- Goal. One paragraph that cites the spec ids and the legacy lines behind it.
- Acceptance criteria. Checkboxes. The agent ticks each one as the work lands and mirrors the list in the pull request. A box that doesn't apply gets a written reason.
- Never. What this issue must not do, such as "Do not add a second enrichment call site."
- Pointers. The spec sections and user stories to read before writing code.
- Screenshots, for a UI issue. Step 8 covers these.
The issue also carries the history. The agent comments when it starts, when the pull request opens and when it merges, so anyone can see the state of the work without asking.
A small issue has a clear finish line, a diff a person can review, and a test that says whether it worked. If you take one rule from this article, take this one.
4. Freeze the reference material and record changes as decisions
On the day coding started, our engineer froze the documentation from step 1. The spec, the eleven proposals and the client's user stories went into a reference folder with a banner on each file: do not edit. From then on, code came only from issues on the backlog. When reality disagreed with the spec, the change went into an Architecture Decision Record in the repo's docs folder, and the spec stayed as it was.
The usual objection to spec-driven work is that specs go stale, and an agent then answers confidently from outdated text. A frozen spec can't go stale, because it describes the original intent. The ADRs describe every departure from it. The agent instructions spell out the precedence: the issue says what to build, the spec catalog and the ADRs say how it must behave, and the frozen reference is background.

An ADR here is small. It covers context, decision and consequences in about 30 lines, and the agent writes it in the same pull request as the code. By the end of the second week the numbering had passed 80. It stands at 280 today. Roughly three quarters record a feature decision, such as the shape of a table or a route. The rest record process, guardrails and scope.
5. Put the workflow in the repo: instructions, skills, subagents and permissions
The agent configuration is committed to the codebase alongside the code itself, so every session, and every engineer who joins later, starts from the same rules.
One instruction file, about 150 lines. It opens with a table of where to look for each kind of question. Then come the session routine, a ten-item agent contract (one issue per branch, do not widen the issue, a decision is an ADR in the same pull request) and twelve "never" rules. Among them: never read a secrets file, never deploy, never take a tenant id from anywhere but the URL path, never let AI output write application state without a person confirming it.
A permission file that enforces the rules that matter most. A sentence in a prompt is a request the model can choose to honor. The tool enforces a deny rule whether the model agrees or not. The checked-in settings deny 49 command patterns: reading secret-shaped files, every form of deploy, cloud writes from the shell, pushes to the main branch and force pushes. Our engineer still treats that list as a safety net. The real control is cloud permissions: only the pipeline's role can change an environment.
Four subagents with narrow jobs. A reviewer works through an eleven-item checklist and writes no code. A tenant-isolation checker may write test files and nothing else, and marks an item clear only when a test it ran proves it. A porter moves one legacy calculation module at a time through a fixed six-step method. A health checker reports on a deployed environment with read-only commands.
Seven skills for procedures. They cover how to write an ADR, how to finish a pull request (step 6), how to set up a new dev machine from scratch, how to bring up a cloud environment, how to check the health of a deployed one, how to give a tester access, and how to redraw the dependency graph of the backlog.

All of this was in place from the first week so the client could take the project over, and they did. At the end of the month the repository moved to the client's GitHub organization. Since then, most pull requests have come from the client's own account, through the same process: an ADR for each decision, the AI review on each push, production by manual promotion. A newcomer runs one skill to set up a laptop, opens an issue and works the same way, because the process is part of the repository.
6. Work in two phases: build to the pull request, then finalize
Doing everything in one session works badly. When the session that wrote the code also reviews it, fixes the findings and merges, the review runs at the end of a long context and spends a lot of tokens confirming its own work.
The fix is two phases with a hard stop between them.
Build. A session takes one issue, comments that work has started, moves the card on the board and builds. It ends when it opens the pull request. It doesn't review its own work and it doesn't wait for CI. It writes a summary for the engineer and stops.
Finalize. A fresh session, or the same one after its context is compacted, runs a finalize skill. The skill is a loop with a fixed order: resolve merge conflicts, then fix red CI checks, then fix the blocking findings of the AI review. After every push it starts again at the top. The order matters. CI does not run on a pull request with conflicts, and the review comment is rewritten on every push, so a finding read too early can be stale. When everything is green, the skill ticks the acceptance boxes, moves the card to Done, merges, confirms the issue closed, comments on it, and removes the working copy and the test database.

The second phase is short in practice. The median pull request merged 21 minutes after it opened, and about 60% of pull requests needed revision after the initial push.
7. Let the pipeline check the agent
An agent produces code faster than a person can read it, so the pipeline has to catch what a reviewer no longer can. That takes more than the standard typecheck, lint and test jobs. Eleven jobs run on every pull request, and the most useful ones each encode a rule that a human reviewer would otherwise have to remember.
- Tenant isolation, proved twice. One suite calls every tenant route in the API as a member of tenant A asking for tenant B's data, and expects "not found". Then it runs again with the database's row-level security replaced by allow-all policies, to prove the application layer holds on its own. A new route joins the sweep without anyone writing a test for it.
- A migration guard. It fails any SQL migration that drops a tenant column, switches off row-level security, or creates a tenant table without the exact policy.
- An oracle for ported logic. The scoring engine was ported from the old app, and the old code was kept in the repository as a test fixture. Property-based tests feed the same random input to both and compare the output. A script holds the number of checks per ported file and fails if one goes missing.
- An infrastructure diff. It posts the Terraform plan on the pull request and fails if the plan would destroy or replace a database, a bucket or a user pool without an explicit label.
- Supply chain. A secret scan over the whole history, a dependency advisory scan and a license check.

The AI review
One of the eleven jobs is an agent review, and it runs on every pull request that touches code. It follows a written procedure, because a prompt that only says "review this pull request" gets back a polite summary of the diff. The agent reads the instruction file, the newest ADRs and the spec file for the domain the change touches, and only then the diff. Then it works through a checklist of eleven items. For each item it answers "clear", or it gives the file and line, what is wrong and which rule it breaks. A passing test isn't grounds for calling a change fine. The agent has to say which rule it checked and what it read.
The checklist is two reviews, kept separate on purpose.
- The conventions review asks whether the code obeys the project's standing rules, whatever the feature. It has eight items: tenant scope, sessions and authorization, secrets, vendor calls, output encoding, logging, the shape of a write, and infrastructure. A finding here is labelled BLOCK.
- The spec review asks whether this change does what it should. It has three items. Every spec the change implements has an id and a test that names it. New code has tests, with no skipped test and no weakened assertion. A changed screen uses the recorded look values of the old app. A finding here is labelled FIX.
Anything else worth saying is a NOTE. The agent posts one comment, most severe finding first, and ends it with a one-line verdict. The labels tell the finalize session what it is looking at: a BLOCK is a broken project rule, and a FIX is a gap between the change and its spec.
Of 227 reviewed pull requests, 40% passed clean on the first review and 31 drew a first verdict of BLOCK.
Deploys
Only the pipeline deploys. A merge builds one artifact, records its checksum and ships it to the sandbox environment: infrastructure, then database migrations, then the app, then a smoke test, then browser tests against the deployed system. Production takes that exact artifact, never a rebuild, from a manual run by a named person.

8. Use screenshots of the old app as the spec for the UI
Numbered specs describe behavior well and appearance badly. In the second week our engineer captured screenshots of the old apps, so that an agent building a screen could see the one it was replacing. A few days later they became more than a convenience. The spec had accepted a generic component look, and that decision changed: each module would look like the app it replaced, so the client would be reviewing apps they already knew. The screenshots became the reference for the look, and the agent instructions put it in one line: the screenshots are correct.
Gathering. One issue, closed in under two hours. Subagents first wrote a shot list: every screen, menu and dialog of the three old apps, each with the click path that reaches it, written in the labels a person sees. Then agents drove a real browser through the list with Puppeteer MCP and captured 110 screenshots.
Attaching. Each UI issue got a marked "Legacy screenshots" section at the end of its body: the image, the click path, and the command to fetch the file. It goes in the body because the command an agent uses to read an issue doesn't show comments. 86 issues carry that section. Each also carries one more acceptance box: the screen matches its legacy screenshots and the old app.
Values, not code. Agents read fonts, sizes, colors and spacing from computed styles and from pixels. Each value becomes a named token, and a look file records where it came from. That file has about 950 rows. No markup or stylesheet is copied from the old apps. One rule came out of this work: a look value is whatever the old app renders on screen, even when its source says something else.
Review tickets. The last issue of each module is a review of the whole product against the old one. A browser test takes the new app's screenshot for every legacy screenshot, and the pull request shows the pairs side by side. The review fixes look gaps and files anything larger as a new issue. These reviews found what per-screen work missed. For anything a still image cannot show, the agent opens both apps through the Puppeteer MCP server and compares them live.
There's a limit, and the process admits it. An agent can match a screenshot. Signing off a look takes a person, so the parity box stays open until the engineer compares the deployed build with the old app.
9. Design the system so an agent can work in it
Our engineer made some implementation choices for the agent as much as for the product. They're the cheapest quality control in the project, because each one removes a decision an agent would otherwise make differently every session.
- One finished slice is the pattern for every later one. The first small feature went through every layer, from the database migration to the browser test. An ADR then listed its files, one per layer, as the template. The next agent copies a known file instead of inventing a shape.
- Architecture rules are lint rules. Imports between modules are denied by default and allowed by a short list. A database repository function must accept an authorization decision that only the authorization layer can construct, and a custom lint rule fails any that does not use it. Each rule has its own tests.
- One definition, three outputs. A route is defined once. The server, the API document and the typed client all come from that definition, and CI fails if the committed copies fall behind.
- The UI runs locally with synthetic data held in memory. A local stand-in answers every API route from a deterministic synthetic dataset of 5,000 rows. Agents built dense screens against it while the real backend was still eight issues away, and the local browser tests need nothing but a laptop.
- Parallel agents cannot step on each other. Sessions that run in parallel each get their own working copy and their own database for tests. The test helper refuses to touch any database that is not on a short list of names.
- Procedures are scripts. The by-hand checklist for a new cloud environment ran to about 40 commands. It became scripts with a dry-run mode and tests of their own, which an agent may run only after the engineer approves each call.
- Dead code is deleted. The old apps told their agents never to remove code that looked unused. The new rule is the opposite, and git keeps the old copy.
Know when this is too much
Not every task needs 1,900 specs. Another of our engineers keeps a TODO file at the root of a project and a research folder with one subfolder per spec, and says only about 5 to 10% of his work ends up with a spec folder. A few paragraphs in the TODO file cover the rest. Use the heavy version when the system is large, the behavior must match something that already exists, or the code will be handed to someone else. Use the light version for a feature one person can hold in their head.
The heavy version has a cost of its own. More than half of this codebase is tests. Six in ten pull requests took more than one push to get through CI and review. And someone has to read what the agents decide: 280 ADRs is a lot of reading. On a rebuild that must match an existing product and outlive its first engineer, that cost is worth paying.
What to do this week
1. Pick one project and have an agent write a one-page description of it. Ask the client or the product owner to correct it.
2. Number the requirements. Give each one a cell for its test, and write untested in every cell you cannot fill.
3. Size every backlog item. Split anything large before an agent touches it.
4. Choose where decisions get recorded (a docs folder of ADRs works) and agree that specs don't get edited in place.
5. Move your agent instructions into the repo. Turn the rules that must never be broken into deny rules, lint rules or CI checks.
6. End every build session at the pull request. Review and merge from a fresh context.
7. Add a CI review step, even an advisory one. Give it a written checklist with a conventions review and a spec review, and read that checklist from the main branch.
8. If the new UI must match an old one, screenshot the old one and put the images in the issues.
If you're facing a rebuild or a migration and want an engineer who has run this process on a real one, tell us what you're working with through our contact page.