All posts

How to add AI to an existing app without a rewrite

Adding AI to an existing app does not require a rewrite. How to pick the first feature, put an AI layer beside your legacy system, and keep failures from reaching users.

CodeKrypt 5 min read

Your product works, customers pay for it, and nobody wants to touch the code that runs the business. Then the roadmap asks for AI. The instinct is to say the platform must be rebuilt first, but adding AI to an existing app rarely needs that. It needs a clean boundary between the code you trust and the code that calls a model. This post covers how to draw that boundary, which feature to build first, and what to put in place so a model failure never becomes an outage.

Do you need a rewrite to add AI to an existing app?

Almost never. A model call is an HTTP request that returns text or JSON. Whatever your stack, if it can call an API and store a result, it can host an AI feature. What a legacy system usually lacks is not language support but seams: places where new behaviour can attach without editing tangled core code.

This is the same idea behind the strangler fig pattern that Martin Fowler describes for legacy modernisation: build new functionality alongside the old, find seams, and move pieces one at a time instead of replacing everything at once. He notes it lowers risk because each piece is small, and returns arrive as each part is finished. An AI layer is the same shape, except you often never replace the old code at all. You put something beside it.

A rewrite is justified only when the system has no usable seam at all: no API, no export, no database you can read, no way to deploy a second service next to it. That is rarer than teams assume.

Which AI feature should come first?

Pick the feature that is read-only or draft-only, uses data you already hold, and can be switched off without anyone noticing the app changed.

Feature typeWrites to your system of record?Risk if wrongGood first feature?
Search over your own contentNoLow: user sees a bad resultYes
Summaries of long records or threadsNoLow: user can open the originalYes
Suggested replies, autofill draftsDraft onlyLow: a person sends itYes
Classification and taggingYes, metadataMedium: wrong tags spreadAfter a review step
Autonomous updates to recordsYesHigh: silent data corruptionNot first

The reason to start at the top is not caution for its own sake. Features that cannot change records let you learn how the model behaves on your real data before anything depends on it. If search or summaries need retrieval over your content, see pgvector vs a dedicated vector database and RAG chunking strategy.

Where does the AI layer sit?

Beside the app, not inside it. A sidecar service owns prompts, model calls, retrieval and logging. The legacy app talks to it through one narrow interface.

An AI layer beside an existing app, with a fallback path to the old behaviourExisting appunchanged core codeFlag + timeoutone narrow interfaceAI serviceprompts, retrieval, modelon error, timeout or flag off: old behaviourRead-only data access

Three choices make this work:

How do you keep a model failure from becoming an outage?

Treat the AI call as an optional dependency, because it is one. Models time out, rate-limit and get retired.

  1. Feature flag in front of every AI path, so you can turn it off per customer or globally without a deploy.
  2. A hard timeout shorter than your page or request budget. When it fires, render the old experience.
  3. Asynchronous work where the user is not waiting. Summaries and tagging can be computed in a queue and shown when ready.
  4. A fallback for provider trouble. See LLM API fallback and handling 429 errors.

The old behaviour is the fallback. That is the main advantage of building beside the legacy code rather than replacing it: the worst case is the product you already ship today.

What about your data and your customers' data?

Retrofitting AI often means sending records that were never designed to leave your system to a third-party API. Decide before the first call what may be sent. Redact personal data where you can (LLM PII redaction), and expect enterprise customers to ask about retention (LLM data retention and zero data retention). If your product is multi-tenant, retrieval must respect tenant boundaries from the first release (multi-tenant RAG isolation). Indian products should also check obligations under the DPDP Act.

How do you know it is working?

Define the measure before launch, on the existing product's own numbers: time to complete a task, search success, tickets deflected without a drop in satisfaction. Keep a small set of real examples as a regression test so a prompt change does not quietly degrade the feature (LLM evals in CI), and roll changes out gradually (shadow, canary and A/B rollout). For choosing which features deserve building at all, read the AI features worth building into a SaaS product and build vs buy for AI features.

What should you do next?

  1. List the three places users in your product read long text, search, or write repetitive replies.
  2. Pick one that can be read-only or draft-only.
  3. Find the seam: the API, view or export your AI service will read from.
  4. Put a flag and a timeout in front of it, with the old behaviour as the fallback.
  5. Ship to a small group, measure against your current numbers, then widen.

If you want a second opinion on where the seams are in your product, our AI modernisation service is built for this: AI added to software already in production, without a full rewrite.

CodeKrypt avatar

CodeKrypt

Drafted by CodeKrypt's AI writing pipeline, built and maintained by our engineers, under fixed rules on sources and claims. How we write

Frequently asked questions

Can I add AI to an existing app without rewriting it?
Usually yes. The AI feature runs as a separate service that reads from and writes to your app through its existing APIs or database views, so the legacy code stays in place. You only touch the core system where it has no seam to attach to.
What should the first AI feature in an existing product be?
A read-only or draft-only feature on data you already hold: search, summaries, suggested replies, autofill. These are easy to reverse, easy to measure and cannot corrupt records.
Do I need to clean up my data first?
Only the slice the first feature uses. Cleaning everything before starting delays value; cleaning the one dataset a feature depends on is part of building it.
How do I stop the AI layer from breaking the main app?
Isolate it. Call it asynchronously or behind a timeout, put a feature flag in front of it, and make the old behaviour the fallback when the AI call fails or is switched off.

Related reading

Chat on WhatsApp