Rescue or Rewrite? How We Decide for an AI-Built Codebase
Founders who reach us with a broken AI-built app often arrive with the decision already half made: "the code is a mess, we need to rebuild". Sometimes they are right. More often the mess sits in a few places, and the rest of the app works.
Why "rewrite everything" feels right and usually isn't
A codebase generated by Cursor, Lovable or Bolt can look chaotic: duplicated helpers, inconsistent naming, components that are 600 lines long. That is ugly, but ugly code that works is cheap to live with. The expensive problems are the ones you cannot see by reading: missing authorization checks, a webhook handler that double-charges, data that leaks between accounts.
A rewrite fixes the ugliness and risks reintroducing the invisible problems, because the new code still has to rediscover every edge case the old code learned the hard way. And while the rewrite runs, the old app keeps serving users and keeps needing fixes. You pay twice.
The questions we ask per module
We don't decide for the whole app. We split it into modules (auth, billing, data access, core feature, admin, integrations) and ask four questions about each.
1. Does it have a correct data model?
Code is easy to change. Data that is shaped wrong is not. If a table has no owner column and every query filters by something else, fixing access rules means a migration either way. That module leans toward rewrite.
2. Can we put tests around it?
If we can write tests that pin down the current behaviour, we can change the code safely. If the module mixes UI, database calls and third-party APIs in one function, testing it means untangling it first, which is half a rewrite already.
3. How often will it change?
A messy module nobody touches can stay messy. A messy module on the critical path of every new feature costs you on every sprint. That one is worth replacing.
4. What does each option cost?
We estimate both: hours to make it production-safe in place, and hours to replace it including migration and testing. If replacing costs less than about 1.5x patching, and the module changes often, we recommend replacing it. Otherwise we fix it.
Signs a rewrite is the right call
- The data model is wrong in a way that touches most tables.
- The framework or a core library is abandoned and blocks security updates.
- No part of the app has tests and the core flows can't be isolated enough to add them.
- The app is small enough that a rebuild takes weeks, not months.
When we do recommend a rebuild, we do it module by module behind the running app (the "strangler" approach), not as a big switch-over on one weekend.
Signs a rescue is enough
- Users can do the main job. The problems are crashes, security gaps and edge cases.
- The data model is roughly right.
- The team can ship a small change in a day.
- Most of the errors in monitoring trace back to a few causes.
In our experience this describes most AI-built apps that reach real users. The happy path works because that is what the AI tools optimise for. What's missing is authorization on the server, database rules, input validation, idempotent webhooks, error monitoring and tests. All of that can be added to the existing code.
What a decision document looks like
At the end of an audit you should get, per module:
| Module | Main problems | Fix in place | Replace | Recommendation |
|---|---|---|---|---|
| Auth | token refresh race, no rate limit | 2 days | 6 days | fix |
| Billing | client-side prices, no webhook signature | 3 days | 5 days | fix |
| Reporting | wrong data model, slow queries | 8 days | 7 days | replace |
The numbers above illustrate the format, not a real project. The point is that the decision is made per row, with costs you can compare, instead of one gut call for the whole app.
If you are stuck between "patch it again" and "start over", our produces exactly this table, with a fixed price agreed after a free 30-minute repo health check.
FAQ
What services do we provide?
We specialize in creating innovative digital solutions including web development, mobile applications, CRM systems, and enterprise software. Our services are tailored to meet your specific business needs and drive growth.

Oleksii Stupak
CEO @ AleannLab
"Want to explore how we can help your business grow? Let's connect and discuss your project on LinkedIn."
Ready to discuss your project with us?




