Skip to content
Ylabator
Decision guideIntermediate

When to Repair vs. Rebuild an AI MVP

Repair an AI-built MVP when its data model is sound and it builds from source. When it is not, rebuild the core and keep the screens users already know.

4 min read / Updated / Last checked

Format
Decision guide · Intermediate
Who it is for
Founders and the builders they hire
You leave with
Audit five dimensions with evidence, compare a hardening scope with a minimal replacement, and choose the smaller option that meets the safety bar.

The problem

In April 2000, Joel Spolsky argued that rewriting working software from scratch is a strategic mistake. His example was Netscape, which had gone almost three years without a major release while it rewrote its browser, losing market share the whole time [1]. Old code, he wrote, has been used, tested and debugged, and its odd-looking fixes usually solve real problems.

AI tools change the cost of typing code, not the cost of everything around it. A founder with an AI-built MVP and real users is often handed two quotes: harden what exists, or regenerate it cleanly. Regeneration looks cheap because the code is cheap. The expensive parts sit elsewhere: customer data that must migrate, business rules that live only in the old code, integrations configured by hand, and users who learned the old screens.

The opposite mistake costs as much. Keeping a foundation that cannot hold a permission check or a migration means paying for it in every later feature. Maintenance already dominates engineering time. In Stripe's 2018 survey, developers estimated that 17.3 hours of a 41.1-hour week went to maintenance such as debugging, refactoring and dealing with bad code [2]. A wrong call in either direction buys more of those hours.

How it works

Start with an audit of five dimensions. Score each one green (evidence exists), yellow (repair needed) or red (critical unknown or material defect).

  1. Ownership. The company can reach the repository, hosting, domain, database, credentials and logs.
  2. Security boundaries. Authentication, authorization and secrets are handled on the server.
  3. Structure. A developer can find the code for one business rule and change it without breaking unrelated behavior.
  4. Data model. The schema matches the business, changes go through migrations, and backups restore.
  5. Delivery. The app installs, builds, tests and deploys from a clean clone.

Do not sum the colors into a score. One red can decide the outcome on its own.

Two dimensions usually decide the choice: data model and delivery. Security reds are often repairable when requests enter through one API, because the fix is adding checks in one layer. A wrong data model is different. Every feature reads it, so fixing it touches everything. And if the app cannot be built from source, there is nothing to repair yet.

That leaves three options. Repair keeps everything, adds tests around existing behavior and fixes reds in place. Partial rebuild replaces the core (data model, API and authorization) behind the existing interface and moves routes over one at a time. This is the strangler fig approach Martin Fowler describes: build new parts alongside the old system and move behavior across gradually, which shows results sooner and lowers risk [3]. Full rebuild is for the rare case where nothing builds from source, the data and rules contradict each other throughout, and the interface is not worth keeping.

Which audit result points to which option

Fig. 01
Which audit result points to which option
DimensionRepairPartial rebuildFull rebuild
Data modelSound or fixableWrong, UI fineWrong everywhere
Builds from sourceYesYesNo
Security redsIsolatedInside the coreThroughout
Interface and flowsKeepKeepReplace
Data model and delivery decide most cases. Security reds alone rarely justify a rebuild.

By the numbers

of a 41.1-hour developer week went to maintenance, in Stripe's 2018 survey [2]
17.3 h
yearly worldwide opportunity cost Stripe estimated for time spent on bad code [2]
$85B
CISQ's 2022 estimate of the cost of poor software quality in the US [4]
$2.41T
accumulated US technical debt in the same CISQ report [4]
$1.52T
Netscape went without a major release while it rewrote its code [1]
~3 years
RepairPartial rebuildFull rebuild
KeptAll code, data, interfaceInterface, validated flows, dataData, after migration
ReplacedDefective parts onlyData model, API, authorizationEverything else
Main riskFixes spread wider than plannedTwo systems run side by side for a whileLost business rules, long gap without releases
First proof it worksOld tests plus new negative tests passOne route served by the new core, same outputFull feature parity on a copy of real data
Three options compared, drawing on Spolsky's rewrite warning and Fowler's strangler fig pattern [1][3]

The survey and CISQ figures are broad, and Stripe's are self-reported estimates. They point the same way: most of the cost of software is in changing it, not in writing it. A full rebuild resets the code and keeps every hard part: the data migration, the integrations and the forgotten rules. Netscape's three-year gap shows how long it takes to rediscover what old code already knew.

The table shows why partial rebuild is often the middle answer for AI-built MVPs. The interface is usually the part that works best, because it is what the founder tested every day. The core is where generated code tends to cut corners: ownership checks, constraints, transactions.

Implementation

Get facts before opinions. Run the script below from a fresh clone. It measures delivery, data model, security boundaries and structure on a Node and Supabase project, and every number it prints goes into the findings report.

measure.shbash
#!/usr/bin/env bash
# measure.sh: facts for the repair-or-rebuild call. Run from a fresh clone.
set -u
echo "== Delivery"
npm ci >/dev/null 2>&1 && echo "install: ok" || echo "install: FAILED"
npm run build >/dev/null 2>&1 && echo "build: ok" || echo "build: FAILED"
echo "type errors: $(npx tsc --noEmit 2>/dev/null | grep -c 'error TS')"
echo "test files: $(git ls-files | grep -cE '\.(test|spec)\.(ts|tsx|js)$')"

echo "== Data model"
echo "migration files: $(git ls-files | grep -ciE 'migrations?/')"
echo "create table statements: $(git ls-files '*.sql' | xargs cat 2>/dev/null | grep -ciE 'create table')"

echo "== Security boundaries"
echo "client files querying the database: $(grep -rlE 'supabase\.from\(' --include='*.tsx' . 2>/dev/null | grep -v node_modules | wc -l)"
echo "routes mentioning auth: $(grep -rlE 'getUser|getSession|auth\(' --include='route.ts' . 2>/dev/null | grep -v node_modules | wc -l)"

echo "== Structure: most changed files in 6 months (hot spots)"
git log --since="6 months ago" --name-only --format= | grep -v '^$' | sort | uniq -c | sort -rn | head -10

The output is a starting point for a reviewer, not a verdict. A high count of client files querying the database is normal for a Supabase app, and only a problem if row-level security is weak. Hot spots show where business rules live and where repairs will land. Then write the findings in one shared format, so two proposals can be compared line by line.

FINDINGS.mdmarkdown
# Repair or rebuild: findings for <app>, <date>
Reviewer: <name> | Commit reviewed: <sha>

| Dimension | G / Y / R | Evidence | Note |
|---|---|---|---|
| Ownership | | Account list, who holds admin on each | |
| Security boundaries | | Cross-user test, secret scan | |
| Structure | | Hot spots, where rules live | |
| Data model | | Schema against business rules, migrations | |
| Delivery | | measure.sh output, deploy steps | |

## Option A: repair
- Changes and the red items they close:
- Kept: everything not listed above
- Unknowns and how they will be resolved:
- Milestones, each with an acceptance test:
- Cost and duration, with assumptions:

## Option B: minimal replacement (partial rebuild)
- New core: data model, API, authorization
- Kept: interface routes and flows
- Data migration plan, rehearsal and downtime:
- Order in which routes move to the new core:
- Cost and duration, with assumptions:

## Recommendation, and the single red item that decides it

Ask every bidder to fill the same file. A quote that does not name the red items it closes cannot be compared with one that does.

Test it

Test the decision with a small pilot before signing the full scope. Write down first what result would change your mind.

pilot-plan.txttext
Repair pilot (fixed timebox):
  Fix the worst red item in one resource, with tests.
  Expected: done within the estimate, full test suite still green,
  change touches the files the findings predicted.
  Signal to rebuild instead: the fix spreads across unrelated files.

Partial rebuild pilot (fixed timebox):
  Serve one read-only screen from the new core behind the old interface.
  Expected: identical JSON for the same records, old and new side by side.
  Run the migration script twice on a copy of production data.
  Expected: same row counts both times, no manual fixes.
  Signal to repair instead: the old data model needs no change after all.

Also restore yesterday's backup into a scratch environment before either pilot. Every option depends on the data surviving, and a restore that fails changes the plan regardless of which option wins.

Decision

Choose the smallest option that reaches the safety and maintainability bar the product needs.

  • Repair when the data model is green or yellow and the app builds from source, even with several security reds.
  • Partial rebuild when the data model is red but the interface and flows work. Move routes to the new core one at a time.
  • Full rebuild only when nothing builds from source and the interface is not worth keeping.
  • Require both proposals on the same findings file, with a migration plan and stated assumptions. Treat no quote as firm before the code and dependencies have been inspected.
  • For the security inspection that feeds the second dimension, see The 12 Failure Modes of AI-Built MVPs.

Sources

  1. [1]Things You Should Never Do, Part I (opens in a new tab)Joel on Software, April 2000
  2. [2]The Developer Coefficient (opens in a new tab)Stripe, September 2018
  3. [3]Strangler Fig Application (opens in a new tab)Martin Fowler, August 2024
  4. [4]The Cost of Poor Software Quality in the US: A 2022 Report (opens in a new tab)Consortium for Information and Software Quality, December 2022

Technical guidance, not legal or security certification.

Need a technical review of an AI-built MVP?

Discuss your build