Skip to content
BlackFig

When to refactor vs rebuild a vibe-coded app

AntPublished Updated 5 min read

Quick answer

Refactor when the data model is sound and the problems are local, like missing error handling, messy components or a broken mobile layout. Rebuild when the data model is wrong, security is broken at the foundations, or you can't get the code out. Most often the answer is in between: keep what works and replace the rest piece by piece.

On this page
  1. It depends on the data model, not the code
  2. Why the classic advice only half applies
  3. Signs refactoring will work
  4. Signs a rebuild is cheaper
  5. The decision table
  6. Three common situations
  7. The middle path
  8. How to decide in a week
  9. What each route costs
  10. When to get help

It depends on the data model, not the code

Founders usually ask this question because the code looks messy. Files run to a thousand lines, the same logic appears in four places, and every prompt seems to break something. That feels like a reason to start again. Usually it isn't.

Messy code can be tidied. Components can be split, duplicated logic pulled into one function, and error handling added screen by screen. What is expensive to change later is the shape of the data: what the tables are, who owns each record and how they link together. Every screen, every query and every access rule depends on it.

So the first question is not "is the code good?" It is "does the database describe my product correctly?" If it does, refactor. If it doesn't, and you have to change it in many places at once, a rebuild is often cheaper than surgery.

The second question is whether you can get the code out at all. If the app lives on a platform you can't export from cleanly, the choice is made for you.

Why the classic advice only half applies

In 2000, Joel Spolsky called rewriting code from scratch the single worst strategic mistake a software company can make. His example was Netscape, which went years without shipping while it rebuilt its browser. His argument was that old code is full of bug fixes found through real-world use, and a rewrite throws that knowledge away.

That argument holds for a product with years of users. A vibe-coded app is usually a few weeks or months old, with few real users and few hard-won fixes in it. There is much less hidden knowledge to lose.

What a vibe-coded app does hold is your product decisions. The screens, the flows and the copy are a working specification, which makes a rebuild faster than the first build. And if real users have signed up, it holds their data, which has to come with you whatever you decide.

Signs refactoring will work

  • You can explain every table in one sentence, and each record has one clear owner.
  • Access rules exist and are roughly right, even if some are missing.
  • The app is built on a stack you would choose anyway, such as React or Next.js with Postgres.
  • The code is in a Git repository you control.
  • The problems are local: a page that crashes, a form with no validation, a layout that breaks on phones.
  • A developer can fix a bug by hand in an hour or two without breaking something else.

Signs a rebuild is cheaper

  • The same thing is stored in several places, or relationships are stored as text instead of links between tables.
  • There is no clear owner on records, so access rules can't be written without changing the schema.
  • Secret keys are used in the browser, and moving them to the server means rewriting most data access.
  • Every change in one place breaks something unrelated, even when done by hand.
  • The code can't be exported, or only exports in a form you can't run outside the builder.
  • The product has changed so much since the first prompt that half the screens are no longer needed.

The decision table

What each finding points to. Most apps have a mix, which is why the middle path is common.
Points to refactorPoints to rebuild
Data modelTables match the product, with clear owners and links.Duplicated data, text where links should be, no clear owner.
SecurityAccess rules exist, some gaps.Secret keys in the browser, no access rules, roles the user can edit.
OwnershipCode in your own Git repository and runs locally.Code locked to a platform, or exports that won't run.
StackA mainstream stack you would choose again.An unusual stack nobody you can hire knows.
Change costBugs fixed by hand in hours.Every change breaks something unrelated.
ScopeThe product is roughly what you built.Half the screens are no longer needed.
Users and dataReal users and data you need to keep working.No users yet, or test data you can throw away.

The last row cuts both ways. Real users make refactoring safer, because the app keeps working while you fix it. No users make rebuilding cheaper, because there is nothing to migrate.

Three common situations

These are common patterns, not specific clients.

The tidy-looking app with a broken data model. The screens are good and the design is consistent. But the database stores, for example, the organiser's name as text on every booking rather than linking to an organiser record. Changing that means touching every query. Here I would keep the screens as a reference and rebuild the data layer, then reconnect the screens one by one.

The messy app with sound foundations. Components are huge and copied around, there is no error handling and the mobile layout is broken. But the tables make sense and the access rules mostly work. That is a refactor. Two or three focused passes leave you with an app that is much easier to change.

The app that outgrew its prompt. The product has pivoted twice. Half the tables belong to features nobody uses. If nobody depends on it yet, a clean rebuild of the current product, with the old app as a clickable specification, is usually quicker than deleting your way to it.

The middle path

Most decisions end up in between. Martin Fowler calls this a strangler fig approach: rather than one big rewrite, you build new parts alongside the old system and move behaviour across piece by piece until the old code can be removed.

For a vibe-coded app, that usually looks like this:

  1. Keep the database, fixing the schema where it is wrong, with migrations that move existing data.
  2. Move secret keys and sensitive logic to the server first, because that is where the risk is.
  3. Replace the most important journey next, such as sign-up to first value, or checkout.
  4. Replace the remaining screens as you touch them for other reasons.
  5. Delete old code as soon as nothing uses it.

The app keeps working the whole time, and users never see a big switchover. The risk is that it drags on, so set an end date for the old code.

How to decide in a week

You don't need weeks of analysis. A few days of looking at the right things is enough.

  1. Get the code into your own repository. If you can't, that answers the ownership question.
  2. Draw the data model on one page. If you can't, or the drawing doesn't match how you describe the product, that is the biggest signal.
  3. Check the access rules and keys. Supabase's docs say a secret key bypasses every Row Level Security policy and must never be in a browser or source control. If yours is, find out how much code depends on it.
  4. Fix one real bug by hand. Time it. Note what else broke.
  5. List the screens you still need. Compare it with what exists.

Then put the findings next to the table above. If you want help with steps 2 to 4, that is what the free vibe-code health check is for.

What each route costs

A refactor is usually cheaper up front and keeps the app live. A rebuild costs more up front but can be cheaper over the next year, because every later change is faster. I go through the numbers, with UK day rates, in what a vibe-code rescue costs in the UK.

Whichever way you go, the next person to work on the code needs to understand it. How to hand a vibe-coded app to a developer covers what to prepare, and the vibe-code rescue checklist lists everything I check before recommending either.

When to get help

If the signs above point clearly one way, you may not need anyone to tell you. If they are mixed, which is common, a second opinion is cheap compared with picking wrong. My guide to fixing a vibe-coded app covers the wider picture.

A Rescue Sprint starts from the free health check and ends with the fixes done, not just a report. If the honest answer is a rebuild, I will say so and scope it like an MVP Build.

The vibe-code rescue checklist, as a PDF

About 40 checks across auth, data, payments, errors, mobile and secrets, on two pages.

You get the PDF now and two short follow-ups over the next week. Reply “stop” and the rest never arrive.

Questions founders ask

Is it ever right to rebuild an app from scratch?

Yes, when the foundations are wrong: a data model that can't represent your product, auth and access rules that would need rewriting everywhere, or code you can't export and own. Messy code on its own is rarely a reason.

Can I keep my database and rebuild the front end?

Often, yes. If the tables are sound and real user data is already in them, keeping the database and replacing screens one at a time is usually the cheapest route.

How long does a rebuild of an AI-built MVP take?

It depends on scope. A rebuild is a new build with a head start: the product decisions are made and the screens exist as a reference. I scope it the same way as an MVP Build.

Should I keep prompting the AI tool while I decide?

Pause new features. Every prompt adds code, and if you end up rebuilding, it is code you will throw away. Fixes for real users are the exception.

Ant

Product designer who builds MVPs, based in Nottingham. 10+ years designing digital products, and the only person at BlackFig. More about me