How to Fix an Inherited Codebase
By David Fromant ·
Someone Else Built It. Now You Own It.
The developer has moved on. The agency stopped answering emails. The founder who "built it himself over a weekend with AI" has handed you the repository and wished you luck. Whatever the story, you're now responsible for software you didn't write, can't fully read, and can't confidently change.
This is different from building a mess yourself. When you inherit a codebase you also inherit its assumptions - and nobody left a note explaining what they were. I'll call this handover debt: the gap between what the code does and what anyone still around can explain about it.
5 Signs You've Inherited Handover Debt:
- No one can answer "why" - the code works, but nobody can explain a single architectural decision
- There's no migration history - the database exists, but there's no record of how it got that shape
- The README is aspirational - setup instructions that no longer produce a running application
- Credentials live in the repository - API keys, database passwords and tokens committed to source control
- Nobody will quote on it - other developers look at it, go quiet, and stop returning your calls
None of these are fatal. All of them are expensive to ignore.
Why AI-Generated Codebases Fail in Exactly Two Places
I've now audited enough AI-assisted projects to notice something consistent: the failures cluster. Interface code is usually fine - AI writes competent forms, layouts and components. What it doesn't do well is anything requiring a decision that spans the whole system. That means the two things that break are almost always the data model and the security model.
Schema Debt: When the Data Model Was Never Designed
AI generates database tables one prompt at a time. Each table is reasonable on its own; together they aren't a design. The symptoms are recognisable: no foreign key constraints, so orphaned records accumulate silently. Money stored as floating point, so totals drift by cents. Dates stored as strings, so sorting and reporting quietly lie to you. Related data duplicated across three tables with no single source of truth. JSON blobs used where columns belong, which works beautifully until you need to search or report on what's inside them.
In multi-tenant applications there's a worse version: the tenant identifier exists on some tables but not others, and it's applied in some queries but not all. That's not a bug you notice in testing. It's a bug one customer notices when they see another customer's data.
Schema debt is the most expensive kind because it compounds. Every week the application runs, more data accumulates in the wrong shape, and the eventual migration gets harder.
Security Debt: Protection That Was Never Modelled
AI tools produce login screens readily. They rarely produce an authorisation model. The distinction matters: authentication asks who you are, authorisation asks what you're allowed to touch. Inherited AI code typically has the first and not the second.
What that looks like in practice: API endpoints that check you're logged in but not whether the record you requested is yours. Record identifiers passed straight from the URL to the database. Validation performed only in the browser, where anyone can bypass it. Secrets committed to Git, still valid, still in the history. Sessions that never expire. File upload endpoints that accept anything.
For Australian organisations this isn't just a technical concern. Under the Privacy Act, serious or repeated interference with privacy now carries penalties in the tens of millions, and eligible data breaches must be reported to the OAIC. "The AI wrote it" is not a defence anyone has successfully run.
The Inherited Codebase Audit
Before anyone writes code, the codebase needs to be made legible. This is the work I do first on every inherited system, usually inside a fortnight.
1. Establish what actually runs
Get the application running locally from source, reproducibly. If that isn't possible, that's finding number one - you don't have a codebase, you have a server nobody can rebuild.
2. Map the data model
Reverse-engineer the schema as it exists, not as documented. Identify missing constraints, unsafe types, duplicated truth and tenancy gaps. This produces the remediation sequence for everything that follows.
3. Model the threats
Enumerate every route that touches data, and check each one against authentication, authorisation and validation. Rotate every credential found in source control - assume all of them are compromised.
4. Assess the blast radius
Determine what can be changed safely. Without tests, nothing can - so the first tests written are the ones that pin down current behaviour, before any refactoring starts.
5. Sequence the repair
A prioritised plan separating what must be fixed this week, what can wait a quarter, and what should be left alone. Most inherited systems don't need rebuilding. They need three or four decisions reversed, in the right order.
Rescue Beats Rebuild, Nearly Always
The instinct on seeing bad code is to start again. It's usually the wrong call. A working application - even an ugly one - encodes real business rules that were learned expensively, and a rebuild throws all of them away along with the problems. Repair keeps the knowledge and removes the risk, and it keeps the application earning while the work happens.
The exception is when the data model is so wrong that every fix requires another fix. Even then, the answer is usually a new schema behind the existing application, migrated in stages - not a blank repository.
Frequently Asked Questions
What is an inherited codebase audit?
A structured review of software you didn't build, covering the data model, security model, deployment process and testability. It produces a written assessment of the risks and a prioritised remediation plan, so you can make decisions about the system rather than guesses.
Can AI-generated code be fixed, or does it need rebuilding?
It can almost always be fixed. AI-generated code is typically well-formatted and readable - the problems are structural rather than cosmetic, concentrated in the database schema and the authorisation model. Fixing those two things resolves the majority of issues without discarding working functionality.
How do I know if my application has a data model problem?
Common indicators are reports that don't reconcile, duplicate records appearing without explanation, totals that drift by small amounts, and features that become slower as data volume grows. If your database has no foreign key constraints and no migration history, assume it has a data model problem.
What should I do first if a developer has left without a handover?
Secure access before anything else: take ownership of the domain, hosting, repository and any cloud accounts, then rotate every credential. Take a verified backup of the database and confirm you can restore it. Only then start assessing the code. Or contact me - I can do all of this for you.
How much does it cost to fix an inherited codebase?
An audit is a fixed-price engagement, typically completed within two weeks, and it's deliberately separable from the remediation work - you get the assessment and can act on it however you choose. Remediation is quoted per project once the scope is known, because quoting repair work before you've read the code is how the original mess got made.
Get a Straight Answer About Your Codebase
If you've inherited an application and you're not sure whether you're sitting on a minor cleanup or a serious liability, that's a question worth answering before it answers itself. Get in touch and I'll tell you what you've actually got.
Related service: inherited code rescue & audits