By Ayena TCHIKPE, founder and software engineer Published
In this article
In short
- Before any decision, protect secrets and data, freeze new features and put tests on the journeys that bring in money.
- Decide on five criteria: data model, authentication, testability, technical choices and the share of business rules that are correct. Not on a feeling that "the code is messy".
- When the app already has users and data, we advise replacing it piece by piece rather than rewriting it all at once.
- Your data, what you learned from your customers and often the interface are worth keeping. They hold the value, not the code.
You built your app with Lovable, Bolt, Cursor or a coding agent. The demo was impressive, the first customers arrived, and now every week brings an incident: a payment that never confirms, a customer who sees someone else's order, a page that takes seconds to load on a phone.
Should you rescue this AI-generated app, or rebuild it? Neither by reflex. Here is how we audit, decide on precise criteria, and avoid ending up here again.
Signs your AI-generated app no longer holds up
Several of these together mean more than a bug.
- Every fix breaks something else. The AI fixes sign-up and the cart fails. No automated test catches it before your customers do.
- Nobody understands the code. The same calculation is written in four places, with four results.
- It slows down with real users. A page loads thousands of rows every time it opens.
- The data contradicts itself. Duplicate customers, orders with no owner, "paid" orders that were never paid.
- You doubt its security. Keys in the code, an open database, a login nobody checked.
That last point is not theoretical. In 2025, researcher Matt Palmer analysed 1,645 apps from Lovable's public showcase. According to his report, 170 let anyone read or modify their data tables without logging in, through 303 endpoints, from the home pages alone. Exposed data included emails, phone numbers, payment details and API keys, and he could insert a record marked "paid" by bypassing the payment check. This is one party's account, but the flaw received an official identifier (CVE-2025-48757).
It is not one tool's problem. In its own tests published on 30 July 2025, Veracode had more than 100 AI models write code for 80 tasks: 45% of the results contained a security flaw. A security vendor's lab test, not a survey of real apps, but enough to justify a check.
How we run the audit, step by step
Each step reduces risk before the next.
- Protect secrets and data now. Rotate every key and password found in the code or repository history: a leaked key stays dangerous after deletion. For Supabase, the official documentation says to enable Row Level Security (RLS) on every table in an exposed schema and never put a secret key in the browser. Take a full backup and test it by restoring it.
- Freeze new features. Only fix what blocks customers. The hardest call for a founder, and the most useful.
- Test the critical journeys. Sign-up, login, ordering, payment, and what is specific to your trade. Tests record what the app does today, bugs included.
- Measure. Load times on an entry-level phone, heaviest queries, production errors, data inconsistencies. Without numbers, the debate stays impressions.
- Read the code against the five criteria below, and end with a written, reasoned recommendation: consolidate, partially rewrite, or rebuild.
Step one is not overcautious. GitGuardian's 2025 report (2024 data) counts 23.8 million secrets exposed in public GitHub repositories, and a 6.4% leak rate in public repositories using Copilot, 40% above the average.
Rescue or rebuild: the decision grid
No criterion decides alone, but the data model and authentication weigh most: they are the most expensive to change once the app is full of real customers.
| Criterion | Consolidate | Partial rewrite | Full rebuild |
|---|---|---|---|
| Data model | Tables reflect your business | A few tables to rework without loss | Duplicates everywhere, unreliable relations |
| Authentication and permissions | Recognised provider, correct access rules | Access rules to rewrite, login sound | Home-made login, permissions checked only in the browser |
| Testability | Critical journeys testable as they are | Some parts tangled | No calculation can be isolated |
| Technical choices | Common, maintained technologies | One component to replace (hosting, database, payment) | Closed platform you cannot export from, or incoherent stack |
| Business rules | Mostly correct | Some wrong or duplicated | Wrong or impossible to find |
In 2000, Joel Spolsky argued that rewriting a large production system from scratch is one of the worst strategic mistakes, because you throw away years of invisible fixes, but that rewriting small experimental code is fine. A prototype a few weeks old with no users is in that category: rebuilding it is often faster than repairing it. Once there are real customers, real data and proven business rules, the logic changes.
Our advice: unreadable code is not necessarily wrong code, so be wary of "throw it all away". Conversely, we advise against consolidating an app whose database or login is wrong at the root: you will pay for every new feature twice.
Replace piece by piece instead of rewriting everything
When the grid points to a rewrite and the app has users, we apply what Martin Fowler calls the strangler fig. In his article dated 22 August 2024, he explains that replacing a system in one go often fails, and recommends building the new one beside the old and moving functions over one by one. In his view, lower risk and earlier value outweigh the cost.
For an AI-generated app:
- Put a single entry point in front of the app, routing everything to the old code for now.
- Rebuild the riskiest piece first, often payment or permissions, with its tests.
- Switch it over for some users, then all, with a one-step rollback.
- Repeat until the old code is unused, then delete it.
The app stays online, customers keep paying, and you see progress weekly instead of waiting months for a version that may never ship.
What you keep, even in a rebuild
Three things have value, and they are not in the code.
Your data. Clean it, test the migration script several times on a copy, and check totals before and after. A migration that loses orders costs more than everything else.
What you learned. Which screens customers use, where they drop off. That was the prototype's job, and it sets the priorities of the new version.
Often, the interface. AI-generated screens often look fine and customers are used to them. Keep the journey and the look, replace what sits behind.
How to avoid ending up here again
The problem was not AI but the lack of guardrails around it:
- Automated tests on every change, before any merge into the main branch.
- Continuous integration rerunning lint, types and tests with the same verdict as on the developer's machine.
- Human review of changes to payment, access rights and the database.
- Written rules for agents in the repository.
- Secrets out of reach, with automatic detection of a key slipped into a commit.
For this we wrote and open-sourced aycod, a small program between agent and repository. It works with Claude Code, Codex CLI and Copilot CLI. It refuses forced or direct pushes to the main branch and reading secrets, forbids disabling a test without the owner's written justification, and blocks ending a task, committing or pushing until lint, types and tests are green, with the same verdict in GitHub Actions or GitLab CI. We use it on our own projects.
What to do next
An AI-generated app that breaks proved there is demand, the hardest part. It now needs foundations.
Our team audits and takes over this kind of app: securing it, testing, a reasoned decision, then consolidation or gradual replacement, as part of our custom software work. We then set up guardrails for your AI agents, so you keep the speed without the breakage. If your prototype is starting to crack, email us a few lines on the tool you used, your number of users and what breaks.
Sources (as of 8 November 2026): Matt Palmer, statement on CVE-2025-48757 (Lovable, 2025) · Veracode, 2025 GenAI Code Security Report, press release of 30 July 2025 · GitGuardian, State of Secrets Sprawl Report 2025 · Supabase, Row Level Security · Martin Fowler, Strangler Fig, 22 August 2024 · Joel Spolsky, Things You Should Never Do, Part I, 6 April 2000.
