Rescuing a Failing Software Project: How I Take Over a Legacy Codebase
How to rescue a failing software project: the 48-hour access checklist, the code audit, rewrite vs refactor, and how to take over a legacy codebase safely.
By Pavle AleksicHiring & Project Planning25 min read
On this page
- The short answer
- Warning signs your software project needs a rescue
- The first 48 hours: secure access before you touch code
- Source code
- Hosting and infrastructure
- Domains, DNS, and email
- Data
- Credentials and third-party services
- Build and deployment
- Knowledge
- Take a backup you have actually restored
- The code and infrastructure audit
- Can it build and run from scratch?
- Repository history
- Dependencies
- Secrets in the code and history
- Tests and coverage
- Production behavior
- Infrastructure
- Triage: security and data-loss risks first
- Rewrite vs refactor: the decision that sinks most rescues
- The strangler fig pattern
- Stabilizing: tests, CI, monitoring, backups
- Tests around critical paths first
- CI that blocks bad merges
- Monitoring and alerting
- Backups on a schedule, with restores on a schedule
- Reducing technical debt incrementally
- Communicating with stakeholders and estimating
- Deliver the audit as a written report
- Estimating inherited code honestly
- Weekly updates, written
- How to avoid ending up here again
- Frequently asked questions
- Should I rewrite my app from scratch or fix the existing code?
- What should I do first if my developer disappeared mid-project?
- How long does a code audit take?
- How much does it cost to rescue a failing software project?
- Can a new developer take over a codebase without any documentation?
- What is technical debt and how do I know if my project has too much?
- Working with me
The call usually starts the same way. The developer stopped answering. Or the agency delivered "90% done" six months ago and the last 10% never arrived. Or the product works, mostly, but every release breaks something and nobody wants to touch the billing code. If you need to rescue a failing software project, or you have just been asked to take over a legacy codebase you did not write, this is the playbook I use.
I have inherited a lot of other people's code over 18 years and 600+ projects. Some of it was good code with a bad process around it. Some of it was a decade of shortcuts held together by one person's memory. The order of operations is the same either way: secure access and data first, understand what you have second, stop the bleeding third, and only then start improving things. Most rescues that go wrong do so because someone skipped straight to step four.
This post is for two readers. Founders whose developer or agency disappeared, or whose product is stuck, will get a checklist they can run before hiring anyone. Engineers who inherit a codebase from another developer will get the audit commands, the triage order, and the honest version of the rewrite-vs-refactor conversation.
The short answer
If you are in the middle of it right now, here is the condensed version:
- Get ownership of everything before you touch code. Repos, hosting, domains, DNS, databases, backups, payment accounts, email, app store accounts. If the previous developer holds any of these in their personal account, that is the emergency, not the bugs.
- Take a backup and prove you can restore it. A backup you have never restored is a hope, not a backup.
- Audit before you change. Two to five days of reading code, running dependency and secret scans, and looking at production errors tells you more than two weeks of fixing whatever the loudest ticket says.
- Fix security and data-loss risks first. Leaked credentials, missing backups, unauthenticated admin endpoints. Feature work waits.
- Default to refactoring, not rewriting. Replace the worst parts incrementally behind a stable interface. Full rewrites of working products rarely finish on time.
- Put tests, CI, and monitoring around the critical paths (sign-up, login, checkout, billing) before making large changes.
- Report progress in plain language, weekly, with risks ranked, not a wall of tickets.
The rest of this post is the detail behind each of those.
Warning signs your software project needs a rescue
Projects rarely fail in one moment. They drift. The signals I take seriously, most worrying first:
- Nobody on your side has admin access to production. The developer "handles the server." You do not know where the database lives. This is the single biggest risk on the list because it turns every other problem into a hostage situation.
- Deadlines slide by weeks, every time, with vague reasons. One slip is normal. A pattern of "almost done" for months means either the scope is not understood or the code is fighting back.
- Every release breaks something unrelated. That points to tight coupling and no automated tests. Each change is a gamble.
- Deploys are manual and only one person can do them. If the deploy process is "SSH in and run some commands I keep in my head," you have a bus factor of one.
- Bug reports come from customers, not from monitoring. If you learn about outages from support tickets, there is no error tracking.
- Simple changes get estimated in weeks. Adding a form field should not be a sprint. When it is, the codebase has become expensive to change.
Two or more of these and it is worth an outside audit even if things seem to be "working."
The first 48 hours: secure access before you touch code
When a developer left mid-project, or a relationship with an agency is ending badly, the first job is not engineering. It is making sure the business owns its own assets. I do this before I read a single line of code, because access has a way of disappearing once a handover gets awkward.
Here is the checklist I work through with the founder. Every item should end with the business, not an individual, as the owner, and with at least two people holding admin rights.
Source code
- Git repository (GitHub, GitLab, Bitbucket) owned by a company organization, not a personal account
- All branches pushed, including anything the developer has locally that never made it up
- Any private packages, forks, or submodules the project depends on
- Mobile app source, if separate, plus signing keys and certificates
Hosting and infrastructure
- Cloud accounts (AWS, GCP, Azure, Cloudflare, Vercel, a VPS provider): root or owner access, billing in the company's name
- SSH keys for any servers, with the previous developer's keys removed afterwards
- Container registries, Kubernetes clusters, load balancers
- Infrastructure-as-code (Terraform, CloudFormation) and its state files, if they exist
Domains, DNS, and email
- Domain registrar account, with the company as registrant
- DNS provider (often different from the registrar)
- TLS certificate setup and renewal (is it automatic, or did someone renew it by hand?)
- Transactional email provider (SendGrid, Postmark, SES) and the sending domain's DNS records
Data
- Production database credentials with full admin rights
- Location of backups, how often they run, how long they are retained
- File storage (S3 buckets, uploads directories on the server)
- Analytics and any data warehouse
Credentials and third-party services
- Every API key the application uses: payments, maps, SMS, AI providers, OAuth apps
- Payment provider accounts (Stripe, PayPal) with the company as account owner
- App store and Play Console accounts
- Error monitoring, logging, uptime tools
- Password manager or vault where secrets live, if there is one
Build and deployment
- CI/CD service (GitHub Actions, GitLab CI, CircleCI) and its stored secrets
- The actual deploy steps, written down, even if they are ugly
- Environment variable lists for every environment (local, staging, production)
- Any cron jobs, scheduled tasks, or background workers and where they run
Knowledge
- Existing docs, the known-bug list, and a recorded walkthrough with the outgoing developer if they are willing
With a cooperative developer this takes a day. Otherwise the hard items are the domain and cloud account, often tied to a personal email. Start those transfers first; ownership disputes can take days.
Once you have access, rotate every credential the previous developer had. Not because they are malicious (they almost never are), but because you cannot know where those keys have been copied. Database passwords, API keys, cloud access keys, SSH keys, CI secrets. My post on secrets management covers where those should live afterwards so this is easier next time.
Take a backup you have actually restored
Before any change, I take my own backup of the production database and file storage, and then I restore it into a separate environment to prove it works. The restore is the part people skip, and it is the part that matters.
For Postgres, the pg_dump documentation describes the custom format (-Fc), which is compressed and restored with pg_restore:
# Dump production (run from a machine that can reach the DB)
pg_dump -Fc --no-acl "$PROD_DATABASE_URL" > prod-$(date +%F).dump
# Restore into a scratch database to prove the dump is usable
createdb rescue_check
pg_restore --no-owner -d rescue_check prod-$(date +%F).dump
# Sanity check: do the row counts look like production?
psql -d rescue_check -c "
SELECT relname, n_live_tup
FROM pg_stat_user_tables
ORDER BY n_live_tup DESC
LIMIT 15;"For MySQL it is mysqldump --single-transaction plus a restore into a fresh instance. For uploaded files, sync the bucket or directory somewhere you control.
In projects I have taken over, "we have backups" is untrue or untested more often than not: a job failing silently for months, or dumps stored on the same server as the database.
The code and infrastructure audit
With access and a backup in hand, I spend a few days reading before writing. The goal is a written risk register: what is dangerous, what is fragile, what is just ugly. Ugly is the least important category and the one people notice first.
Can it build and run from scratch?
Clone the repo on a clean machine and try to run it using only what is written down. If that takes a day of archaeology, every future developer will pay the same tax. I write down each missing step as I go; that list becomes the new README.
Repository history
Git history tells you where the pain lives. Files that change constantly are where bugs cluster and where the original developer was struggling.
# Most frequently changed files in the last year (churn hotspots)
git log --since="1 year ago" --name-only --pretty=format: \
| grep -v '^$' | sort | uniq -c | sort -rn | head -25
# Who wrote what (finds the one-person areas)
git shortlog -sn --since="1 year ago"High churn plus high complexity plus no tests is where I expect the next production incident.
Dependencies
Outdated and vulnerable packages are the most common finding, and the easiest to measure. For a Node project:
# Known vulnerabilities in production dependencies; non-zero exit at "high" or worse
npm audit --omit=dev --audit-level=high
# How far behind everything is
npm outdated
# Unused files, exports, and dependencies (dead weight to delete later)
npx knipThe npm audit docs explain the flags: --audit-level sets the severity that fails the command, which makes it usable in CI later. Knip finds unused files, exports, and dependencies, which is gold in an inherited codebase full of abandoned experiments. For Python, pip-audit does the equivalent job; for PHP, composer audit.
A vulnerable transitive dependency is not automatically an emergency; reachability matters. A runtime that no longer gets security patches is a real risk and goes on the register. If the dependency tree looks suspicious beyond just being old, my post on npm supply chain attacks covers what to look for.
Secrets in the code and history
Hardcoded credentials are depressingly common in inherited code, and deleting them from the current files does not remove them from git history. I scan the full history:
# Scan every commit for API keys, tokens, passwords
gitleaks git -v .
# Quick manual pass for the obvious ones
git grep -nE "(sk_live_|AKIA[0-9A-Z]{16}|-----BEGIN (RSA|OPENSSH) PRIVATE KEY)"Gitleaks scans the git log, not just the working tree. If the repo is on GitHub, GitHub secret scanning also scans the entire history on all branches and is worth enabling. Any secret that ever appeared in the repo gets rotated, full stop. Rewriting history to remove it is optional; rotating it is not.
Tests and coverage
I look for three things: do tests exist, do they pass, and do they cover anything that matters.
# Does the suite even run?
npm test
# Coverage, if the runner supports it (Vitest shown; Jest uses --coverage too)
npx vitest run --coverageThe coverage percentage is less interesting than where the coverage is. Eighty percent coverage of utility functions and zero coverage of the checkout flow is worse than thirty percent concentrated on payments and auth. In most rescues I take on, the honest answer is "there are a few tests, half of them fail, and nobody has run them in a year."
Production behavior
Code tells you what the system is supposed to do. Production tells you what it actually does. I want to know:
- Error rates. Is there error tracking (Sentry or similar)? If not, I add it before anything else, because it is cheap and it turns guesses into a ranked list.
- Logs. Structured, retained, searchable?
- Slow queries. For Postgres,
pg_stat_statementsshows which queries eat the most time. Reading the plans with EXPLAIN ANALYZE usually finds a missing index or two that make a dramatic difference. - Resource usage. Is the server at 95% disk? Is memory creeping until a nightly restart "fixes" it?
- Cron jobs and workers. The most commonly forgotten part of a system.
If the system has none of this, I set up the basics early. My observability guide covers logs, metrics, and traces in more depth; for a rescue, error tracking plus uptime checks plus structured logs is enough to start.
Infrastructure
I map out what actually runs in production, because it rarely matches what anyone believes. Which servers, which managed services, which DNS records point where, what costs money each month. It is common to find forgotten instances, a staging environment that is actually serving real traffic, or an S3 bucket set to public read.
Triage: security and data-loss risks first
At the end of the audit you will have a long list. The temptation is to fix whatever is most annoying. Resist it. I rank every finding by two questions: what is the worst realistic outcome, and how likely is it to happen soon?
| Priority | Examples | When |
|---|---|---|
| P0: stop everything | Leaked live credentials, no working backups, unauthenticated admin routes, SQL injection, public buckets with customer data | This week, before any feature work |
| P1: high risk | Runtime or framework without security patches, no error monitoring, single-person deploys, payment webhooks without signature checks | Next two to four weeks |
| P2: drag on velocity | No tests on critical paths, manual deploys, tangled modules, slow queries | Ongoing, alongside feature work |
| P3: cosmetic | Inconsistent naming, old patterns, formatting, "I would have done it differently" | Opportunistically, or never |
P0 items are not negotiable. A founder will understand a one-week feature freeze far better than a breach notification or a lost database. P3 items are where new developers waste the most time and earn the least trust: rewriting working code to match your taste is not a rescue.
A common P0 I find in inherited Node APIs is a route that looks protected in the UI but not on the server:
// Before: the admin page hides the button, but the API trusts anyone
app.post("/api/admin/users/:id/delete", async (req, res) => {
await db.user.delete({ where: { id: req.params.id } });
res.json({ ok: true });
});
// After: the server enforces the rule, regardless of what the UI shows
app.post(
"/api/admin/users/:id/delete",
requireSession,
requireRole("admin"),
async (req, res) => {
await db.user.delete({ where: { id: req.params.id } });
await audit.log(req.session.userId, "user.delete", req.params.id);
res.json({ ok: true });
},
);That kind of fix takes minutes once found. Finding it requires going route by route through every endpoint that mutates data, which is why the audit is not optional.
Rewrite vs refactor: the decision that sinks most rescues
Every rescue has a moment where someone says "it would be faster to just rewrite it." Sometimes that someone is the founder, exhausted. Sometimes it is the incoming developer, who finds the existing code distasteful. My default answer is no, and the reasoning is old and well documented. Joel Spolsky's Things You Should Never Do, Part I made the case back in 2000: the ugly old code contains years of bug fixes and edge-case knowledge, and a rewrite throws all of it away while the business stands still.
That said, "never rewrite" is too absolute. Here is how I actually decide:
| Factor | Points toward refactor | Points toward rewrite (of a part, rarely the whole) |
|---|---|---|
| Does it work for users today? | Yes, mostly | No, core flows are broken |
| Size | Large, years of behavior baked in | Small, a few weeks of original work |
| Platform | Supported runtime and framework | Dead platform with no upgrade path |
| Business logic | Complex, poorly documented, but correct | Simple and well understood |
| Data model | Sound, or fixable with migrations | Fundamentally wrong for the product |
| Business tolerance for a freeze | Low, features must keep shipping | High, or the product is pre-launch |
A small, pre-launch MVP that barely works, built on an abandoned framework, can be a reasonable rewrite candidate. A product with paying customers and three years of behavior almost never is.
The strangler fig pattern
The approach I use instead is what Martin Fowler calls the Strangler Fig application: build new pieces alongside the old system and move behavior over gradually, until the old parts can be deleted. You get the benefits of a rewrite without the big-bang risk, and the business keeps shipping the whole time.
In practice it looks like this:
- Put a seam in front of the old code. A reverse proxy, an API gateway, or simply a routing layer inside the app that decides whether a request goes to old or new code.
- Pick one slice to replace. Ideally something painful and well bounded, like reporting, notifications, or a single API resource.
- Build the new version behind a flag. Run it for internal users or a small percentage of traffic first.
- Compare results. For read paths, call both and log differences before switching.
- Switch over, then delete the old code. The deletion is the step that gets skipped. Without it, you just have two systems.
A routing seam can be as small as this:
// A seam: one place that decides old vs new for a given capability
import { legacyInvoices } from "./legacy/invoices";
import { invoicesV2 } from "./invoices-v2";
import { flags } from "./flags";
export async function getInvoices(accountId: string) {
if (await flags.isEnabled("invoices-v2", { accountId })) {
return invoicesV2.list(accountId);
}
return legacyInvoices.list(accountId);
}Every caller goes through getInvoices, so switching (and switching back) is a flag change, not a deploy. When the database itself needs to change shape, the same incremental thinking applies; my playbook on zero-downtime database migrations covers the expand-and-contract approach that lets old and new code run against the same schema.
Stabilizing: tests, CI, monitoring, backups
Once P0 risks are closed and you have decided on an approach, the next phase is making the system safe to change. This is what turns "every release breaks something" into "releases are boring."
Tests around critical paths first
Do not try to reach a coverage target. Write tests for the flows that cost money or trust when they break: sign-up, login, password reset, checkout, subscription changes, and whatever the product's core action is.
For legacy code, the most useful kind is a characterization test: a test that records what the system currently does, right or wrong, so you notice when a change alters it.
// Characterization test: pin current behavior before refactoring
import { describe, it, expect } from "vitest";
import { calculateOrderTotal } from "../src/legacy/orders";
describe("calculateOrderTotal (current behavior)", () => {
it("applies discount before tax, as production does today", () => {
const total = calculateOrderTotal({
items: [{ price: 100, qty: 2 }],
discountPercent: 10,
taxRate: 0.2,
});
// Captured from production behavior, not from a spec.
expect(total).toBe(216);
});
it("returns 0 for an empty cart instead of throwing", () => {
expect(calculateOrderTotal({ items: [], discountPercent: 0, taxRate: 0.2 }))
.toBe(0);
});
});If the current behavior turns out to be a bug, you fix it deliberately, as its own change, with the business agreeing that it is a bug. Some "bugs" are things customers rely on.
A few end-to-end tests (I use Playwright) on the top three journeys catch more regressions than hundreds of unit tests on helpers.
CI that blocks bad merges
If there is no CI, I add a minimal pipeline in the first couple of weeks: install, type-check, lint, test, audit. It does not need to be elaborate; it needs to run on every pull request and block merges when it fails.
name: ci
on:
pull_request:
push:
branches: [main]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
- run: npm ci
- run: npx tsc --noEmit
- run: npm run lint
- run: npm test
- run: npm audit --omit=dev --audit-level=highThen I automate the deploy so it no longer lives in one person's head. My post on GitHub Actions patterns has the caching, environment, and deploy setups I reuse.
Monitoring and alerting
Error tracking, uptime checks on the critical URLs, and alerts that go to a channel someone reads. Add alerts on the things that hurt quietly: failed background jobs, payment webhook failures, disk space, and backup job failures. The goal is that you hear about a problem before your customers email you.
Backups on a schedule, with restores on a schedule
Automated backups stored outside the production account or region, with a retention policy, plus a restore drill at a fixed interval (monthly is reasonable for most small products). Put the restore steps in the README. The day you need them is not the day to figure them out.
Reducing technical debt incrementally
With a safety net in place, debt reduction becomes routine work rather than a heroic project. The rules I follow:
- Boy-scout rule, scoped. When you touch a file for a feature, leave it a little better: add the missing test, extract the function, delete the dead code. Do not turn a one-hour fix into a two-day refactor.
- Prioritize by churn. Refactor the files that change most often (the hotspot list from the audit). Ugly code nobody touches can stay ugly.
- Upgrade dependencies in small steps. One major version at a time, one package family at a time, each in its own pull request with tests passing. Jumping three framework versions in one go is how upgrades turn into month-long branches.
- Delete aggressively. Unused files, dead feature flags, abandoned experiments. Every deleted line is one less thing to understand. Knip's report from the audit is a good starting list.
- Add types at the boundaries. In a JavaScript codebase, typing the edges first (API handlers, database access, external integrations) gives most of the safety for a fraction of the effort.
- Budget it explicitly. I recommend agreeing on a fixed share of each cycle for debt work, so it does not compete ticket by ticket with features and always lose. Something in the range of 15 to 30 percent is a common starting point, adjusted by how painful the codebase is.
The measure of success is not clean code. It is changes that used to take a week taking a day, without breaking anything else.
Communicating with stakeholders and estimating
The technical work is half the rescue. The other half is rebuilding trust with people who have been burned, often more than once.
Deliver the audit as a written report
At the end of the audit, I hand over a short document, not a call:
- What exists. A plain-language map of the system and what it costs to run.
- Risks, ranked. The P0 to P3 list, each with what could happen and roughly what it takes to fix.
- Recommendation. Refactor, partial rewrite, or (rarely) start over, with reasoning.
- Plan for the next four to eight weeks. In order, with what the business gets at each step.
A non-technical founder should be able to make decisions from it.
Estimating inherited code honestly
Estimates on code you did not write are less reliable than estimates on code you know, and pretending otherwise is how the previous developer lost the client's trust. What works:
- Estimate in ranges, with the assumption stated. "Two to four days, assuming the payment integration works the way the code suggests. If it relies on the undocumented webhook I found, add two days."
- Time-box discovery. "I will spend one day investigating the export bug and come back with either a fix or an estimate." That beats a blind guess.
- Expect the first month to be slower. Velocity improves as the safety net goes in and the codebase becomes familiar. Say this upfront.
- Separate stabilization from features in the plan. Otherwise, debt work looks like delay.
Weekly updates, written
Every week: what was done, what was found, what is next, and what needs a decision. Bad news goes out the day it is found. Founders burned by a disappearing developer care more about predictability than speed.
If you are evaluating who should do the rescue in the first place, my posts on how to hire a freelance full-stack developer and freelancer vs agency vs in-house cover the tradeoffs.
How to avoid ending up here again
Most failed projects I see did not fail because the original developer was bad at programming. They failed because the business had no visibility and no ownership. The fixes are mostly cheap:
- The company owns every account from day one. Repos in a company organization, cloud accounts billed to the company, domains registered to the company. Developers get invited as members, never the other way around.
- Access for at least two people. Founder plus developer at minimum, on everything. A password manager shared at the company level.
- Code in a repository you can see, with regular commits. If you cannot see progress in the repo every week, ask why.
- CI and automated deploys from early on. If only one person can deploy, you are one resignation away from a frozen product.
- Monitoring and backups before launch, not after the first incident.
- Small, frequent deliveries. A demo every week or two of working software is the best early warning system there is. "Big reveal at the end" projects are the ones that collapse.
None of this requires technical knowledge from the founder. It requires insisting on ownership and visibility in the contract and in practice.
Frequently asked questions
Should I rewrite my app from scratch or fix the existing code?
In most cases, fix the existing code incrementally. A working product carries years of edge cases and bug fixes that a rewrite discards, and the business has to keep running on the old system during the rewrite. A rewrite makes sense mainly for small, pre-launch products, or when the platform itself is dead and cannot be upgraded. Even then, replacing it piece by piece (the strangler fig pattern) is usually safer than a big-bang switch.
What should I do first if my developer disappeared mid-project?
Secure ownership of your accounts before anything else: code repository, hosting, domain, DNS, database, and payment provider. Then take a backup of the database and files and confirm it can be restored. Only after that should anyone start fixing bugs or writing features. Rotate every credential the previous developer had access to.
How long does a code audit take?
For a typical small-to-medium web application, a useful audit takes roughly two to five working days, depending on the size of the codebase, how many services are involved, and how much documentation exists. Larger systems with many integrations or several codebases take longer. The output should be a written report with ranked risks and a recommended plan, not just a list of complaints about code style.
How much does it cost to rescue a failing software project?
It depends heavily on the state of the code, the size of the product, and how much stabilization is needed before feature work can resume. As a rough guide, the audit is a fixed, small piece of work measured in days, while stabilization (tests on critical paths, CI, monitoring, security fixes) is often measured in weeks. A good audit should end with an estimate for the next phase, given as a range with its assumptions stated.
Can a new developer take over a codebase without any documentation?
Yes, but it costs time. The new developer reconstructs the knowledge from the code, git history, production behavior, and the database, and writes it down as they go. Getting even a one-hour recorded walkthrough from the previous developer saves days. Treat the first few weeks as partly discovery and plan estimates accordingly.
What is technical debt and how do I know if my project has too much?
Technical debt is the accumulated cost of shortcuts that make future changes slower and riskier. You have too much when simple changes take days, releases regularly break unrelated features, and developers are afraid to touch certain parts of the code. The fix is rarely a big cleanup project; it is a steady, budgeted share of each development cycle spent on tests, refactoring, and upgrades.
Working with me
Taking over and stabilizing inherited systems is a large part of what I do: audits, security triage, getting tests and CI around the critical paths, and then steady incremental improvement while features keep shipping. If your project is stuck or your developer has gone quiet, take a look at my backend development services or get in touch with a short description of the stack and the situation. I will tell you honestly whether it needs a rescue, a cleanup, or just a second pair of eyes.