Aziz Khan
← Writing

How to Take an AI-Built App from Prototype to Production

AI Product RescueProductionArchitecture

AI coding tools are good at getting a screen to work. You describe a feature, you get a page, a table and a form that saves. What they don't do on their own is ask what happens when a second customer signs up, a payment arrives twice, or a secret ends up in the browser.

That gap is the difference between a prototype and a product. I use AI agents for most of my own code, so this isn't an argument against them. It's the list I go through before I let anything meet real users, in the order I check it.

1. Find out what you actually have

Before changing anything, get the code out of the tool and into a git repository you own. Then answer four questions:

  • Where does the data live, and who can read it?
  • Which keys does the app use, and where are they stored?
  • What runs on a server, and what runs in the browser?
  • How does a change get from your laptop to the live site?

If you can't answer one of these, that's your first task. Most later problems come from an answer nobody checked.

2. Get secrets out of the browser

Anything shipped to the browser is public. Build the app and search the output:

npm run build
grep -rE "sk_live|sk-|service_role|SECRET" dist/

A publishable Stripe key or a Supabase anon key in there is expected. A secret key, a service-role key or a model provider key is not. Rotate it first, because it may already be copied. Then move the call behind a server route or edge function that holds the key.

3. Make the database enforce who sees what

Generated apps often filter data in the UI: the page asks for "my orders" and shows them. That isn't access control. Anyone with the public key can ask for everyone's orders.

The fix is to put the rule in the database. In Traveo I enforce tenancy with Postgres row-level security, so a forgotten WHERE returns nothing instead of another agency's customers. I wrote about that in two rules you can't fix later. The test is simple: sign in as user A, request user B's rows directly through the API, and confirm you get nothing back.

4. Validate config at startup

Prototypes usually read environment variables wherever they're needed and fall back to a default. In production that means a missing key turns into a strange error three screens later.

Validate everything once, at boot, and refuse to start if it's wrong:

const env = z.object({
  DATABASE_URL: z.string().url(),
  STRIPE_WEBHOOK_SECRET: z.string().min(1),
  PAYMENTS_ADAPTER: z.enum(['mock', 'stripe']),
}).parse(process.env);

Pavly does this, with an extra guard so a mock integration can never run in production. A failed deploy is much cheaper than finding out from a customer.

5. Make payments safe to repeat

Payment providers retry webhooks. Networks drop responses. If your handler creates an order every time it's called, you'll get duplicates.

  • Verify the webhook signature before trusting the body.
  • Store the provider's event id and skip events you've already processed.
  • Decide access from the webhook, not from the success page. Users close tabs.

I built FoxlyFlow around the same idea for messages: idempotency keys and signed webhooks with retries, so a send is never done twice or lost.

6. Move slow work out of the request

Model calls, PDF generation, scraping and email are slow and they fail. If they run inside a web request, the user watches a spinner and a timeout loses the work.

Write a row that says "this needs doing", return straight away, and let a worker pick it up. In Uxlyze the dashboard only writes a report row. A Go worker does the browser and model work, behind a rate limiter, so a burst of requests queues up instead of falling over.

7. Handle the unhappy paths

Open the app and try to break it:

  • Submit every form empty, then with very long input.
  • Turn off the network mid-save.
  • Open a link to something you don't own.
  • Let the session expire and click a button.

Each of these should end in a clear message, not a blank page. Validate input on the server as well as in the form, since the form can be bypassed.

8. Put the schema under migrations

If the database was changed by clicking in a dashboard, nobody can rebuild it. Export the schema into migration files, commit them, and make every future change a new migration. Take a backup and restore it once, so you know it works.

9. Add a gate before deploy

You don't need a big test suite on day one. You need a few checks that run on every push:

- run: npm ci
- run: npm run lint
- run: npm run build
- run: npm test

Start with tests for the paths that cost money when they break: signup, payment, and the one thing your product is for. This matters more with AI tools, because the next generated change can quietly undo an earlier fix. I cover how I keep agents honest in my AI-native dev loop.

10. Know when it breaks, and what it costs

Add error tracking and an uptime check before launch, not after the first complaint. Log each model call with its token count, and set a spending limit at the provider. A loop that calls a model on every keystroke is cheap in a demo and expensive with users.

What to do first

If the list feels long, do steps 2 and 3 today. Leaked keys and open tables are the two that hurt real people. The rest can be worked through in order, and none of it requires throwing the prototype away. Most of the screens you built will survive. The work is in what sits under them.

If you'd rather hand that part over, this is what my AI product rescue work covers.