Vibe Engines
YouTube
AI System Design

Design Lovable

Learn AI system design by designing a prompt-to-app builder like Lovable.

The numbers to beat3pages2tables1rule

The whole design, in writing

Learn AI system design by designing a prompt-to-app builder like Lovable. An interactive guide covering why rewriting a forty-file app on every change costs 20,000 tokens and 400 seconds, the brief that writes a plan before any code, a fixed starter kit, the patcher that sends a two-file change instead of the whole app, the live preview whose errors feed back to the model, the data shelf with sign-in and numbered migrations, the ship button with versions and rollback, and the lock check that stops a stranger reading every customer.

Every step of the build above, written out: the problem each piece solves, the option that was taken and the ones that were not, the numbers, and how it fails in production.

The big idea

"Design a prompt-to-app builder" — why is this even hard?

You type one sentence — a booking page for my dog-walking business — and seconds later there is a page: real code, saved data, a link you can send. A model produced that by writing text, in small pieces called tokens. Say the app is forty files at 500 tokens each. That is 20,000 tokens, and at about 50 tokens a second that is 400 seconds. And tomorrow you will want to change the button.

UserBuilder Model
New in this step: User, Builder Model. · swipe to pan the diagram

Never pay that twice. Write a plan first, start from a kit that already runs, send small patches that touch only the files a change needs, run the app and feed its errors back to the model, keep the data and every version, and check the locks before the link goes public.

What the new pieces do

Userclient
The person typing. Their sentence — “a booking page for my dog-walking business” — is the only input; everything else is the builder deciding how to turn it into a running app.
Builder Modelmodel
The model that writes the plan, the code and the patches. It writes about 50 tokens a second, so how much it must write per change is the whole design problem.

Step 1 · The brief

Write the plan before the program

The sentence is fuzzy: how many pages? What data? Who may see what? If the model guesses and writes all forty files, a wrong guess costs a 20,000-token rewrite. What should happen before any code exists?

UserBuilder ModelBrief
New in this step: Brief. · swipe to pan the diagram

What should the builder do first with the sentence?

  1. A wrong guess is then a 20,000-token, 400-second rewrite, and the user has nothing to correct but code.

  2. That stalls the very thing a prompt-to-app tool sells: a page in seconds. Make a sensible plan and let the user change it.

  3. The plan is a few lines, so being wrong costs one sentence, not a rewrite. Three pages, two tables, one rule.

The Brief: from the sentence, three pages (browse walkers, book a slot, my bookings), two tables, and one rule (see only your own). It is readable, and changeable, before anything runs.

Why this piece earns its place

A plan is the cheapest place to be wrong. Changing “two tables” to “three” costs a few words; changing the same decision after forty files exist costs a rewrite. The brief also gives every later part something to agree on: the kit knows which pages to fill, the data shelf knows which tables to create, and the lock check knows which rule was promised and can later ask whether it was kept. The trade is real and worth saying out loud: an extra step before any code appears. The design bet is that a short wait for a plan is worth more than a fast first guess, because the plan is what lets every later edit stay small.

  • 3pages
  • 2tables
  • 1rule

What the new pieces do

Briefplan
A short plan written from the sentence: pages, tables and who may do what. Cheap to read and cheap to change, because nothing is running yet.

Step 2 · The kit

A starter that already runs

The model has to write real code. If it chooses its own language, tools and folder layout for every app, every app is a new house with new ways to fail. What should it start from?

Builder Model20,000 for the whole appStarter Kitfixed stack, already runs
New in this step: Starter Kit.

What should the model write code into?

  1. Every app becomes a new, untested combination, and the model has to invent where everything lives.

  2. A model that has seen a stack a million times knows where the button lives, and the first page is already on screen.

  3. Some of those it will know well and some it will not. A fixed set trades reach for reliability.

The Starter Kit: one fixed stack — same language, same page tools, same folders — already running in the preview. The model fills in rooms, it does not build a house.

Why this piece earns its place

A fixed stack is a bet on familiarity. The model has read enormous amounts of code in common tools, so inside that set it is predictable: it knows where a page lives, how a button is styled, how a component is imported. The kit also means there is never an empty state; the user sees a running page immediately, and every later change is an edit to something real. The cost is honest: no exotic tools, whatever the user asked for. A builder that can do anything is a builder that fails in a hundred new ways; one that does one stack well fails in a few ways it has learned to handle. Fix the stack so that the rest of the design can be small.

  • 1fixed stack
  • 0empty states
  • samefolders every time

What the new pieces do

Starter Kitstore
A fixed starter project: same language, page tools and folders every time. The model fills in its rooms instead of inventing a house.

Step 3 · The patcher

A patch, not a rewrite

The app runs. You type: make the button blue. The obvious build sends all forty files and gets all forty back: 20,000 tokens, 400 seconds. And any of those forty files might change when it should not. What should the model send instead?

Builder Model1,000 tokens a changeStarter Kit38 of 40 files untouchedPatcherfile · old · new
New in this step: Patcher.

How should a change be expressed?

  1. Two files, 1,000 tokens, 20 seconds: 20× less. And if the old text no longer matches, the patch is refused rather than applied blindly.

  2. It costs 20,000 tokens and 400 seconds, and every file written is another chance to change something unasked for.

  3. That hands the work back to the person. The builder’s job is to make the change.

The Patcher: a patch names the file, the old text and the new text. A project map opens only 2 files. 1,000 tokens, 20 seconds, 20× less — and about 2% chance of an unrelated change against about 33%. If the old text no longer matches, it is refused.

Why this piece earns its place

There are two savings and they are different. The first is cost: write what you changed, not what you kept. The second is risk, and it is the subtler one. Suppose each file written has a 1% chance of an unintended change. Rewrite forty and the chance that at least one moves is 1 − 0.99⁴⁰, about 33%; write two and it is about 2%. So a patch is not only cheaper, it is safer, because the files you did not write cannot be altered. The refusal rule is the part that makes this robust: a patch states what it expects to find, and if the file has since changed, the match fails and the builder reads the file again rather than overwriting someone’s work. A patch that can be refused is a patch you can trust when it is accepted.

  • 1,000tokens, not 20,000
  • 20 snot 400 s
  • 2%vs 33% surprise

What the new pieces do

Patcherservice
Turns a change into a patch that names the file, the old text and the new text. A project map means only the touched files are opened, and a patch is refused if the old text no longer matches.

Step 4 · The preview

The page runs, and talks back

You ask: show each walker’s free slots. The model writes a patch, and the page turns red. But the model never saw the screen, so it never saw the error. How does it find out?

Live Previewerrors back · max 3 triesSandboxa sealed room
New in this step: Live Preview, Sandbox.

How should the builder find out the code is broken?

  1. Then the user is the test suite, and every error costs a human round trip.

  2. The model gets the same error you would have pasted, writes a repair patch, and the loop stops at three tries.

  3. A model reading its own code tends to agree with it. Running it is the only real test.

The Live Preview runs the app in a Sandbox, a sealed room. The error is written down and flows back to the model as if the user had pasted it, a repair patch follows, and the loop is capped at 3 tries. Then it stops and asks you.

Why this piece earns its place

Feeding errors back closes a loop that would otherwise have a human in it. The model is no longer guessing whether its code works; it is told, in text, exactly what failed. The sandbox matters twice. It lets generated code run without being able to reach anything that matters, and it makes a crash a message rather than an incident. The loop itself needs a limit, because a model that cannot fix an error will happily try again forever, spending tokens and the user’s time on the same red page. Three tries is a design choice, not a magic number: enough to fix the ordinary typo-class errors, few enough that a genuinely stuck build hands the problem to a person quickly, with the error attached.

  • 0people in the loop
  • 3tries, then ask
  • sealedsandbox

What the new pieces do

Live Previewservice
The app running live beside the chat. Its errors are written down and sent back to the model, which writes a repair patch — capped at three tries.
Sandboxexec
Where the generated code actually runs, sealed off from everything else, so a crash or a bad program cannot reach anything that matters.

Step 5 · The data shelf

A page that remembers

The page runs and looks right. You book a walk, reload, and the booking is gone. A booking page that forgets bookings is only a drawing. Where do bookings live, and who is allowed to make them?

Builder Model1,000 tokens a changeData Shelfdatabase · sign-in
New in this step: Data Shelf.

Where should the app’s data and users live?

  1. Memory in a page disappears on reload and is never shared with anyone else.

  2. Data mixed into code means every booking is a code change, and it gets overwritten by the next patch.

  3. Real tables survive a reload, a sign-in says who is who, and a migration replays in order.

The Data Shelf: a hosted database with tables, like spreadsheets, and a sign-in. Each change to the tables is a numbered migration, so it replays in order. Book a walk, reload, and it is still there.

Why this piece earns its place

Hosting the data buys a real database with no setup, which is most of what makes a generated app a real app rather than a demo. The numbered migration is the quiet part. A change to the tables is a small, ordered, replayable step, so the database can be rebuilt from nothing and an edit to the schema is something the history can show and roll back, exactly like a code patch. The sign-in is what makes “my bookings” mean anything, and it also sets up the final step: once the page can tell users apart, the question of who may read which row becomes a rule you can state. The cost is a dependency: the app now relies on someone else’s service staying up and staying affordable.

  • tableslike spreadsheets
  • 1sign-in
  • numberedmigrations

What the new pieces do

Data Shelfstore
A hosted database with tables, like spreadsheets, and a sign-in. Every change to the tables is a numbered migration, so it replays in order.

Step 6 · The ship button

Every change is a version

The model edits confidently and is sometimes wrong. Version four breaks the page. And once it works, the user needs a link to send to a first customer, and a copy of the files they actually own. What does the builder keep?

UserBuilder ModelBriefStarter KitPatcherLive PreviewSandboxData ShelfShip Button
New in this step: Ship Button. · swipe to pan the diagram

What should happen to each change the model makes?

  1. One bad edit then has no way back except asking the model to fix its own mistake.

  2. Any edit can be undone, the user owns the files, and one click gives a link.

  3. That puts the burden of history on the person, and people forget.

The Ship Button: every patch is a numbered version. Version four breaks the page; one click and you are back on version three. The files can be copied to a code host so you own them, and one more click gives a public address.

Why this piece earns its place

Versions turn a confident but sometimes wrong editor into something safe to use. The history is cheap because each version is a patch, not a full copy of forty files, and a rollback is just choosing an earlier point. Exporting to a code host is a statement about ownership: the user is not locked into the builder, and can take the project somewhere else. The public address is the last gesture and the one that changes the risk. Until now the app was private: a preview only its author could see. A link to a first customer makes it public by design, which is exactly why the build is not finished when the ship button works.

  • 1click to roll back
  • v3the one before v4
  • 1public address

What the new pieces do

Ship Buttonservice
Every patch is saved as a numbered version, one click rolls back, the files can be copied to a code host, and one more click gives a public address.

Step 7 · The lock check

The hidden slot: who can open the link?

Six of six parts are built, the page works, bookings save, the link is public. A stranger opens it and then the browser’s developer tools. Everything the page can fetch, they can fetch. And the customers table has no lock. What is the slot you only find when the app goes live?

SandboxData ShelfShip ButtonLock Check
New in this step: Lock Check. · swipe to pan the diagram

The app works perfectly and the link is public. What must you check before sharing it?

  1. A page is public by design. Row rules say who may read each row, and secret keys belong on a server.

  2. Speed matters, but a fast page that leaks every customer is still a leak.

  3. A model writes what works, not what is safe. An open table works perfectly and exposes everything.

The Lock Check: row rules on every table, so you see only your own rows and so does the page’s key; secret keys on a server, never in the page; and a check of what the finished app can fetch before the link is shared, not after.

Why this piece earns its place

The failure here is not a crash, and that is what makes it the interesting one. The app works perfectly. A model writes what works rather than what is safe, and an open table is the simplest thing that works. Every earlier part was about writing less or seeing more; this one is about asking who. The page runs in a stranger’s browser, so anything it can fetch, they can fetch, and anything in the page, including a secret key, is theirs to read. The remedy is dull and effective: rules attached to the rows themselves, a server for anything secret, and a habit of looking at what the published app can actually reach before the link goes out. It also closes the loop with the brief, which promised one rule: see only your own.

  • every tablegets row rules
  • 0secret keys in the page
  • beforethe link, not after

What the new pieces do

Lock Checkgate
The hidden seventh slot. A published link is public by design, so every table needs row rules and every secret key belongs on a server, never in the page.

The payoff

You designed a prompt-to-app builder

From “ask for the whole app” to a build ladder: a brief that plans before code, a fixed kit that already runs, a patcher that changes only what you asked, a preview that catches errors while running, a data shelf that remembers, a ship button with versions, and a lock check, because anyone with the link can open it.

UserBuilder ModelBriefStarter KitPatcherLive PreviewSandboxData ShelfShip ButtonLock Check
The finished design, end to end. · swipe to pan the diagram

Now rewrite the whole app and watch twenty thousand tokens go by, let the repair loop run with no cap, then publish a table with no lock. Those three are the whole trade-off: writing less buys speed and safety, and every part has a price.

Everything you assembled, in order

  • Brief — a plan from the sentence: pages, tables, a rule
  • Starter kit — a fixed stack that already runs
  • Patcher — file + old text + new text; 1,000 not 20,000 tokens
  • Live preview — runs in a sandbox; errors fed back; max 3 tries
  • Data shelf — hosted database, sign-in, numbered migrations
  • Ship button — numbered versions, rollback, code host, public link
  • Lock check — row rules on every table; secret keys on a server
  • The numbers — 20,000 → 1,000 tokens · 400 → 20 s · 33% → 2% surprise

Deep cut · 8:32

One sentence, one running app.

The interactive build above lays out a prompt-to-app builder: a brief that writes a plan before any code, a fixed starter kit the model fills in, a patcher that names the file, the old text and the new text, a live preview whose errors flow back to the model, a hosted data shelf with sign-in and numbered migrations, and a ship button with versions and a public address. The film builds the same parts live inside a builder window, one slot of a plan panel at a time, following a single sentence, “a booking page for my dog-walking business”, and then finds the hidden seventh slot: the lock check. It is the public design plus first principles, not anyone’s internals.

  • See the envelope: forty files at about 500 tokens is 20,000 tokens, 400 seconds at 50 tokens a second. A two-file patch is 1,000 tokens and 20 seconds, 20 times less. At a 1% chance per file of an unintended change, that is about 33% across forty files and about 2% across two.
  • Take it into the interview: never rewrite what you can patch, feed the preview’s errors back to the model with a cap of three tries, and check every table for row rules and every secret key for a server before the link is public.

Where an interviewer pokes next

Getting the boxes right is the easy half. These are the questions that separate a candidate who drew the diagram from one who has run the thing. Answer each one out loud before you open it.

  1. Why is a patch safer than a rewrite, and not only cheaper?

    Because the files you do not write cannot be altered. If each file written has a 1% chance of an unintended change, rewriting forty gives about a 33% chance that something unasked for moved, while writing two gives about 2%. The patch also states what it expects to find, so it is refused if the file has since changed rather than overwriting it blindly.

  2. Why feed errors back to the model, and why cap the loop at three?

    The model never sees the screen, so running the app and sending the error text back gives it the same information you would have pasted, with no person in the loop. The cap exists because a model that cannot fix an error will retry forever, so after three tries it should stop and hand the problem, with the error attached, to a person.

  3. Why fix the stack instead of letting the model choose the best tools?

    A model is most predictable inside ground it has seen a million times: it knows where things live. A fixed kit also means there is never an empty state, because the first page is already running. The cost is no exotic tools whatever the user asked for, which is the right trade for reliability.

  4. Why is a numbered migration better than editing the tables directly?

    It is a small, ordered, replayable step, so the database can be rebuilt from nothing in order and a schema change shows up in the history and can be rolled back like a code patch. An untracked edit leaves no record of how the tables came to look the way they do.

  5. The app works and the link is public. What is the first thing you check, and why?

    What a stranger could fetch with the developer tools open: row rules on every table, and no secret key in the page. A model writes what works rather than what is safe, and an open table works perfectly while exposing every customer, so the failure is silent. The check happens before the link goes out, not after.

Check yourself — the answers, and why

Eight steps in, these are the calls you should be able to make cold. Pick one, then read why.

  1. An app is forty files at ~500 tokens each, written at ~50 tokens a second. What does rewriting all of it for one button cost?

    40 × 500 = 20,000 tokens, and 20,000 ÷ 50 = 400 seconds. A two-file patch is 1,000 tokens and 20 seconds, 20× less.

  2. What does a patch contain?

    Naming the file, the old text and the new text lets the builder change only what was asked, and refuse the patch if the old text no longer matches.

  3. At a 1% chance per file of an unintended change, roughly how likely is a surprise from rewriting 40 files versus patching 2?

    1 − 0.99⁴⁰ is about 33%; 1 − 0.99² is about 2%. Files you do not write cannot be changed by accident.

  4. The preview shows a red error. What happens next in a well-designed builder?

    The model never sees the screen, so the error is fed back as text. The loop needs a cap, then it stops and asks the person.

  5. The app works perfectly and the link is public. What must be true before you share it?

    A page is public by design, so anything it can fetch a stranger can fetch. Row rules go on every table and secret keys stay on a server.

How you’d open this design in an interview

Before any boxes: agree what it must do, pin the qualities that shape everything, then build — naming each trade-off as you make it. The walkthrough above is that exact order.

What it must do

Agree on these before drawing a single box.

  • Plan: turn one fuzzy sentence into a plan someone could build.
  • Write: produce real code in a shape that is sure to run.
  • Change: alter one thing when asked and leave everything else alone.
  • Show: run the app live and catch its own errors.
  • Keep: store the data, keep a history and put the app online.
  • Protect: stay safe, because anyone with the link can open it.

The qualities that shape everything

Each one names the mechanism that buys it.

An app is forty files, about 20,000 tokens
The whole codebase is too much text to write for every change. 40 × 500 = 20,000 tokens (illustrative). The design is about never paying that twice.
A change costs what it touches
A patch to 2 files is 1,000 tokens, 20 seconds at 50 tokens a second, against 400 seconds for a rewrite: 20× less.
Unrelated files stay unchanged
At 1% per file, rewriting 40 files changes something unasked about 33% of the time; patching 2 files, about 2%.
Errors are caught without a person
The preview runs the app in a sandbox and sends its error text back to the model as if the user had pasted it, capped at three tries.
Any edit can be undone
Every patch is saved as a numbered version; one click returns to the version before a bad edit.
No table is readable by a stranger
Row rules on every table, and secret keys on a server, never in the page. A published link is public by design.

The trade-offs you say out loud

Senior signal isn’t the boxes — it’s naming what you gave up and why it was the right price.

Write a plan first over going straight to code

You are wrong for a sentence, not a twenty-thousand-token rewrite. The cost is one extra step before anything appears on screen.

Fix the stack over letting the model choose tools

A model that has seen a stack a million times knows where the button lives, and the kit already runs. The price is no exotic tools, whatever the user asked for.

Send patches, not files over regenerating the whole app

Twenty times less to write and far fewer surprises. A patch can be refused when the old text no longer matches, which is a feature: the file changed, read it again.

Run a live preview over trusting the code

The model sees its own errors instead of shipping a blank page. It needs a sandbox, and a loop that needs a limit.

Version every change over overwriting in place

A model edits confidently and is sometimes wrong, so any edit can be undone. The history keeps growing.

Check before publishing over sharing the link as soon as it works

A generated app works perfectly and may let a stranger read every customer. It is one more gate between the user and a link.

The answer, out loud

What a strong answer to “Design Lovable” sounds like, first question to last trade-off. It is about 4 minutes of talking; the whiteboard and the interviewer fill the rest of the 45. Read it aloud once, then close the page and give it yourself.

  1. 0–2 min

    Put the number on the board

    Before I draw a box I want one number. Say the app is forty files at about five hundred tokens each. That is twenty thousand tokens, and a model writes maybe fifty tokens a second, so a full rewrite is four hundred seconds, nearly seven minutes, to change one button. These figures are illustrative and I am designing from public product descriptions and first principles, not anyone’s internals. But the shape of the argument is the point: the whole design is about never paying twenty thousand tokens twice. So I would spend the first minute on cost, because cost and risk both scale with how much the model writes, and every part I add is a way of making it write less or see more.

  2. 2–4 min

    Plan, then a kit that already runs

    I would not let the model go straight to code. First a brief: from the sentence, three pages, two tables and one rule, which a person can read and change before anything runs. Then a fixed starter kit: same language, same page tools, same folders every time, already running in the preview. The model fills in rooms instead of building a house. The cost I would own is that you get that stack whatever the user asked for.

    Built in step 2: A starter that already runs
  3. 4–6 min

    Patch, never rewrite

    Now the central decision. A change is a patch: the file, the old text and the new text. A map of the project lets the builder open only the two files that matter. That is a thousand tokens and twenty seconds, twenty times less. It also changes the risk: if one file in a hundred changes by mistake, rewriting forty changes something unasked about a third of the time, patching two about two percent. And a patch is refused if the old text no longer matches, which is a safety net, not a bug.

    Built in step 3: A patch, not a rewrite
  4. 6–7 min

    The preview talks back

    The model never sees the screen, so I give it eyes. The app runs live in a sandbox beside the chat, the error is written down and sent straight back to the model, which writes a second patch. I would cap that loop at three tries and then stop and ask the person, because an uncapped repair loop is a bill with no ceiling.

    Built in step 4: The page runs, and talks back
  5. 7–8 min

    Data, versions, and the lock check

    A booking page that forgets is a drawing, so I would connect a hosted database and sign-in, with every table change a numbered migration. Every patch becomes a numbered version with one-click rollback, a code-host copy so the user owns it, and a public address. And then the seventh slot, which I would raise myself: the app works perfectly and a stranger can read every customer. So before publishing, row rules on every table and secret keys on a server, never in the page. Trade: writing less buys speed and safety, and costs a plan step, a fixed stack, a sandbox and one more gate. I would close by saying that out loud: each part has a price, and I would rather name the prices than pretend the design is free.

    Built in step 7: The hidden slot: who can open the link?

What this teaches

Learn AI system design by designing a prompt-to-app builder like Lovable. An interactive guide covering why rewriting a forty-file app on every change costs 20,000 tokens and 400 seconds, the brief that writes a plan before any code, a fixed starter kit, the patcher that sends a two-file change instead of the whole app, the live preview whose errors feed back to the model, the data shelf with sign-in and numbered migrations, the ship button with versions and rollback, and the lock check that stops a stranger reading every customer.

Key takeaways

  • Brief — a plan from the sentence: pages, tables, a rule
  • Starter kit — a fixed stack that already runs
  • Patcher — file + old text + new text; 1,000 not 20,000 tokens
  • Live preview — runs in a sandbox; errors fed back; max 3 tries
  • Data shelf — hosted database, sign-in, numbered migrations
  • Ship button — numbered versions, rollback, code host, public link
  • Lock check — row rules on every table; secret keys on a server
  • The numbers — 20,000 → 1,000 tokens · 400 → 20 s · 33% → 2% surprise

Concepts covered

  • "Design a prompt-to-app builder" — why is this even hard?
  • Write the plan before the program
  • A starter that already runs
  • A patch, not a rewrite
  • The page runs, and talks back
  • A page that remembers
  • Every change is a version
  • The hidden slot: who can open the link?
built to be reasoned about, not memorized — plan first, patch never rewrite, watch it run, lock the table before the link goes out.
Finished this one? 0 / 65 AI System Designs done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More AI System Designs