1. Courses
  2. AI Engineering
  3. Vibe Coding: Build Apps with AI
  4. Stop 2

35 minBeginner

A spec the AI can follow

An AI coding tool builds what you describe, and it fills everything you leave out with a guess. This lesson shows you how to write a one-page spec for Ravi's reorder app (users, screens, data, rules and checks), keep it in the project where the tool reads it, and make the AI ask questions and plan before it writes a line of code.

By the end you can

  • Explain which gaps an AI fills with cheap guesses and which with expensive ones
  • Write a one-page spec with users and roles, screens, data and rules
  • Write acceptance checks as given / when / then examples that you and the AI can test
  • Name the edge cases and the out-of-scope items a first version needs
  • Keep the spec in a SPEC.md file, point your tool at it, and ask for questions and a plan first

The everyday picture

Imagine you phone a caterer and say "food for a party on Saturday". The caterer will not call back with fifty questions. They will guess. Some guesses are cheap: the colour of the napkins, the shape of the plates. If those are wrong, you shrug. Other guesses are expensive: how many guests, whether anyone has a nut allergy, what time the food must arrive, and what the budget is. Those are wrong in ways you only find out at the party, and they cannot be fixed on the night.

A good catering order is one page. It says who is coming, what they eat, the rules (no nuts, delivered by 6 pm, under $400), and what is not included (no drinks, no waiters). And a good caterer reads it and calls you back with two or three questions before cooking anything. Writing a spec for an AI coding tool is the same job. You write the page, the tool asks its questions, and only then does the cooking start.

Why the AI needs a spec: every gap becomes a guess

In What AI coding tools can and cannot do you saw that these tools are good at screens and at , and weak at unwritten rules, security and exact data. The reason is how they work. A coding tool is built on a . It writes the code that is most likely to fit your request, based on the millions of programs it learned from. When your request is silent on a point, the tool does not stop and ask. It picks the most common answer it has seen.

For screens, the most common answer is usually fine. A list with a button, a form with a Save button, a menu at the top. If the AI guesses wrong, you see it at once and say "make the button bigger". That guess cost you ten seconds.

For rules and data, the most common answer is often wrong for your business, and you cannot see it on the screen. Most example apps the model learned from are demos with one user, so they do not limit who sees what. Many store prices as text or as decimal numbers. Almost none know your delivery cut-off. These guesses look fine in a demo and fail with real shops, real money and real deadlines. By then other code is built on top of them, so the fix is slow.

So a spec for an AI has a different job from a spec for a team. In Writing specs people read you learned to write for engineers and designers who share your context and can ask you in the corridor. The AI shares none of your context. It does not know Mangrove Market, partner shops or what a sales rep is. It will not ask unless you tell it to. So your spec spends little space on what screens look like and most of its space on the things the AI would guess wrong: who can see what, what the data is, and the rules.

"build a reorder app" a one-line prompt AI tool fills every gap the gap its guess Who sees orders? everyone hidden, costly How is price kept? as text "6.40" hidden, costly Order cut-off? none hidden, costly Button colour? blue visible, cheap
A short prompt leaves gaps, and the AI fills every one with the most common answer it has seen. A wrong button colour shows on the screen and costs seconds. Wrong guesses about access, money and time look fine in a demo and fail with real shops, so the spec spends its words on them.

Quick check

Imran's first app has four problems. Which one should his spec work hardest to prevent?

The one-page spec: users, screens, data and rules

A spec the AI can follow fits on one page and has four core parts. Each answers a question the AI would otherwise guess.

1. Users and roles: who uses the app, and what may each of them see and do? A is a kind of user with its own permissions. Ravi's app has three. A shop owner like Ravi sees and orders only for his own shop. A sales rep sees the shops in their own area (Mangrove has about 40 reps for about 1,800 partner shops, so roughly 45 shops each) and, in the first version, only reads. An admin on Imran's team manages products, prices and users. If you write only "shop owners order stock", the AI builds one kind of user who can see everything.

2. Screens and flows: what does each person see, in what order? List the screens by name with one line each, then write the main path. For Ravi: sign in, My usual order (last week's items with today's prices), edit quantities on that same screen, Confirm (total and delivery day), and Order history. The main path is three taps: open the app, tap Review, tap Send. You do not need drawings. The AI is good at layout, and you will adjust it by looking.

3. Data: what is stored, and in what form? Apps keep their data in a , as of rows and columns, and you met them properly in Modeling data in tables. You can describe them in plain words. Ravi's app needs five: shops, products, usual order lines (what each shop normally orders), orders, and order lines (what is in each order). For each table, list its and mark which are required. Then state the formats the AI gets wrong:

  • Money is whole cents. $6.40 is stored as the number 640. Text cannot be added up safely, and decimal numbers in most programming languages are slightly inexact (in JavaScript, 0.1 + 0.2 gives 0.30000000000000004). Whole cents add up exactly.
  • Quantities are whole numbers. Ravi orders 10 bags of rice, never 9.5. Give a range, such as 1 to 999.
  • Each order line keeps the price at the time of the order. If the price of rice changes next week, last week's order must still show what Ravi paid.
  • Times have a time zone. "4 pm" means 4 pm in the shop's local time. Say so.

4. Rules: what must always or never happen? These are the the AI cannot know. Number them, so you and the AI can point at them later (R1, R2…). For Ravi's app:

  • R1 A shop sees only its own orders. A rep sees only the shops in their area. This is checked on the server, never only by hiding buttons.
  • R2 The minimum order is $50.00. Below it, Send is disabled and the screen says how much is missing.
  • R3 Orders sent before 4:00 pm shop time are delivered the next day; at 4:00 pm or later, the day after.
  • R4 Products that are out of stock, or no longer sold, cannot be added or sent.
  • R5 A shop can cancel an order only before the distribution centre starts packing it.

Write each rule so that someone could check it with a yes or no. "Orders should be on time" cannot be checked. "Orders sent before 4:00 pm shop time are delivered the next day" can.

My usual order edit quantities tap 2: Review Confirm screen total, delivery day tap 3: Send server checks, in order 1. own shop only? 2. all in stock? 3. at least $50? 4. delivery day 4 pm cut-off a no on 1, 2 or 3 all pass Not sent screen says why Order saved with order number
The screens are the easy part: open the app (tap 1), Review (tap 2), Send (tap 3). The rules run on the server when Ravi taps Send, in a fixed order. A no on ownership, stock or the minimum stops the order with a reason; the 4 pm cut-off never blocks, it picks the delivery day.

Quick check

A 5 kg bag of rice costs $6.40. How should the spec tell the AI to store that price?

Acceptance checks, edge cases and what is out

Rules say what must be true. show it with real numbers, so both you and the AI can test it. You learned the given / when / then format in User stories and acceptance criteria: given a starting situation, when someone does one thing, then you can see a result. For an AI, these examples do two jobs. The AI can turn each one into an automatic test, and you can tap through each one by hand in a minute. A check you can tap through is your proof that the app does what the spec says, whatever the AI tells you.

Output
A2 Cut-off
  Given Ravi's usual order totals $156.70 and the shop's time is 4:00 pm
  When he taps Send
  Then one order is saved with delivery the day after tomorrow
  And the Sent screen shows that date

Write checks for the boundaries, because that is where guesses hide. If the cut-off is 4:00 pm, write one check at 3:59 pm and one at exactly 4:00 pm. If the minimum is $50.00, write one at $49.99 or below and one at exactly $50.00. Use real values ("$42.00", "3:59 pm"), never "a small order" or "late in the day". Aim for five to ten checks for a first version, at least one for every rule.

Edge cases are the unusual situations that break a happy path. Ask "what if?" about each screen. For Ravi's app, four matter:

  • No usual order yet. A new shop has no last week. The spec says: show the product list so the owner can build a first order, and save it as the usual order.
  • Product no longer sold. Mangrove stops selling a brand of tea. The line shows greyed out with "no longer sold" and is left out of the total.
  • Price changed since last week. Rice went from $6.40 to $6.60. The app shows today's price and marks the line "price changed", so the total on the Confirm screen does not surprise Ravi.
  • Signal lost while sending. Ravi taps Send, the shop's mobile data drops, the app retries, and the request reaches the server twice. Without a rule, that is two orders and two deliveries. The fix has a name: an . The phone creates one unique code when Ravi taps Send and sends it with every retry. The server saves the code with the order, and if the same code arrives again it returns the order it already has. You do not need to build this yourself. You need to write the rule ("one tap on Send creates at most one order, even if the request is repeated") so the AI builds it.

Out of scope is the list of things the first version will not do. It matters more for an AI than for a team, because AI tools tend to add features nobody asked for, such as a payment page "to make the app complete". For Ravi's prototype: no payments (invoices stay as they are today), no delivery tracking, no promotions, one shop per owner. When the AI's plan includes one of these, you point at the list.

Quick check

Which acceptance check could you test by tapping through the app?

Handing it over: SPEC.md, instruction files and a plan first

Write the spec in . It is plain text with a few marks: # starts a heading and - starts a list item. Every AI coding tool reads it well, and it shows nicely on GitHub.

Save it as a file named SPEC.md in the project folder, next to the code. A spec pasted into a chat is lost when the chat ends, and most tools start each new session with no memory of the last one. A file stays. You point the tool at it ("read SPEC.md first"), you change it when you decide something, and the history of your decisions lives with the code. When you and the AI disagree about what the app should do, the file wins.

Many tools also read a project instruction file automatically at the start of every session. The names differ by tool and change over time, so check your tool's documentation. At the time of writing, Claude Code reads CLAUDE.md; AGENTS.md is an open format read by many tools, including Cursor and GitHub Copilot's coding agent; Cursor also has project rules in a .cursor/rules folder. Browser app builders such as Lovable or Bolt usually keep project instructions in a settings or knowledge area instead of a file. You saw these files from a developer's side in Working with AI coding assistants.

Keep the two apart. The instruction file says how to work in this project, in a few lines that are true for every feature: read SPEC.md before changing anything, money is whole cents, access rules live in the database, plan before building. The spec says what the app does, and it grows with each feature. And remember that both are advice the tool usually follows, never a lock. A rule like "a shop sees only its own orders" must also be enforced by the database itself, which you will set up in Data and security basics.

Then give your first prompt, and make it ask for two things before any code:

  • Questions. "List everything in SPEC.md that is unclear, missing or contradictory." The AI is good at spotting gaps in someone else's text. Each question it asks is a guess it would otherwise have made silently.
  • A plan, not code. "Propose a plan of small steps, and wait." Some tools have a planning mode that reads and plans without changing files; in others you say it in the prompt. A wrong step in a plan costs you one sentence to fix. The same mistake in code costs an hour. You will steer the plan one step at a time in Building in small steps.

When the questions come back, write your answers into SPEC.md, not only into the chat. Then ask for the plan again, or approve it.

Build it

Write the full one-page spec for Ravi's reorder app, a short instruction file, and the first prompt that hands both to your AI tool. You need no code yet, only a project folder and a text editor.

  1. Create the project folder and start SPEC.md

    Make an empty folder named partner-reorder. Create a file SPEC.md in it and write the goal, users, screens and data. The * marks a required field.

    Markdown
    # SPEC: Partner reorder app (v1 prototype)
    
    ## Goal
    Partner shops reorder their usual weekly stock in three taps instead of
    phoning a sales rep. Prototype for 5 test shops. Owner: Imran.
    
    ## Users and roles
    - Shop owner (for example Ravi): sees and orders only for their own shop.
    - Sales rep: sees the shops in their own area. Read only in v1.
    - Admin (Imran's team): manages products, prices, stock flags and users.
    
    ## Screens and flows
    1. Sign in: email and a one-time code.
    2. My usual order: last week's products and quantities, today's prices,
       the total. Quantities change here with - and + buttons.
    3. Confirm: every line, the total, the delivery day, a Send button.
    4. Sent: the order number and the delivery day.
    5. Order history: this shop's orders, newest first, with status.
    Main path: open the app (tap 1), Review (tap 2), Send (tap 3).
    
    ## Data (* = required)
    - shop: id*, name*, area*, owner email*
    - product: id*, name*, pack size*, price_cents*, in_stock*, active*
    - usual_order_line: shop*, product*, quantity*
    - order: id*, shop*, created_by*, status*, total_cents*, delivery_date*,
      created_at*, request_key* (unique)
    - order_line: order*, product*, quantity*, price_cents* (price when ordered)
    Money: whole cents, never text or decimals. $6.40 is stored as 640.
    Quantities: whole numbers from 1 to 999.
    Status: sent, packing, on_the_way, delivered, cancelled.
    Times: stored in UTC, shown and judged in the shop's local time.
  2. Add the rules and acceptance checks

    Number every rule and check, and give each rule at least one check. Note the pair of checks on each side of the cut-off.

    Markdown
    ## Rules
    R1 A shop owner sees and changes only their own shop's data. A rep sees
       only shops in their area. Enforced in the database, not only in screens.
    R2 Minimum order total: $50.00 (5000 cents). Below it, Send is disabled.
    R3 Sent before 4:00 pm shop time: delivered next day. At or after 4:00 pm:
       delivered the day after.
    R4 Out-of-stock or inactive products cannot be added or sent.
    R5 A shop can cancel an order only while its status is "sent".
    R6 Prices come from the product table when the order is sent, never from
       the phone.
    R7 One tap on Send creates at most one order, even if the request repeats.
    
    ## Acceptance checks
    A1 Given Ravi's usual order totals $156.70 and it is 3:59 pm
       When he taps Review, then Send
       Then one order is saved with status "sent" and delivery tomorrow
    A2 Given the same order and it is 4:00 pm
       When he taps Send
       Then the order is saved with delivery the day after tomorrow
    A3 Given Ravi's order totals $42.00
       When he opens Confirm
       Then Send is disabled and the screen says "Add $8.00 to reach $50.00"
    A4 Given Ravi is signed in
       When he opens the link of another shop's order
       Then he sees "Order not found" and none of that order's data
    A5 Given Ravi's order has status "packing"
       When he opens it in Order history
       Then there is no Cancel button, and a cancel request is refused
    A6 Given Ravi taps Send and the request is sent twice with one request_key
       Then exactly one order exists
  3. Add edge cases and what is out of scope

    This finishes the one page. Read it once as if you were the AI and knew nothing about Mangrove: is there anything you would have to guess?

    Markdown
    ## Edge cases
    - No usual order yet: show the product list; the first order becomes
      the usual order.
    - Product no longer sold: line greyed out, "no longer sold", not in total.
    - Price changed since last week: show today's price, mark "price changed".
    - Signal lost while sending: the app keeps the same request_key on every
      retry; the server returns the existing order for a repeated key.
    
    ## Out of scope for v1
    Payments (invoices stay as today), delivery tracking, promotions,
    more than one shop per owner, reps placing orders, other languages.
    
    ## Decisions log
    (Add each answer to the AI's questions here, with the date.)
  4. Add a short project instruction file

    Name it for your tool: CLAUDE.md for Claude Code, AGENTS.md for the many tools that read that format, or the project instructions box in an app builder. Keep it to stable rules about how to work.

    Markdown
    # Notes for AI tools working on this project
    - Read SPEC.md before planning or changing anything. If the code and
      SPEC.md disagree, stop and ask me.
    - Money is integer cents everywhere. Never store prices as text or decimals.
    - Access rule R1 is enforced in the database, not only in the screens.
    - Plan first, wait for my approval, then build one step at a time.
    - After each step, tell me how to check it by hand, using the A-checks.
    - Never put secret keys in the code or in the browser.
  5. Give the first prompt: questions and a plan, no code

    Open your AI tool in the project folder (or paste the spec into the app builder's instructions) and send this.

    Output
    Read SPEC.md and the project notes. Do not write any code yet.
    
    1. List everything in SPEC.md that is unclear, missing or contradictory,
       as numbered questions. For each one, say what you would have guessed.
    2. Propose a build plan of 5 to 8 small steps. For each step: what it adds,
       which acceptance checks (A1 to A6) it makes pass, and how I can test it
       by hand in under five minutes.
    3. Name the tools and services you would use, one line each, and why.
    
    Wait for my answers before you start step 1.
  6. Answer into the spec, then review the plan

    Write every answer into SPEC.md as a rule or in the decisions log. Then read the plan with three questions: does an early step set up the access rule (R1)? Does anything in it appear on the out-of-scope list? Does every acceptance check appear in some step? If all three are fine, you are ready to build step 1 in the next lesson.

Bring it to your team

Ask these before you hand a spec to an AI tool, or when someone shows you an app an AI built.

  • Who can see each piece of data, and where is that enforced?
  • How is money stored? Show me the field for one price.
  • Which rules have a time or an amount in them, and is there a check on each side of the boundary?
  • What happens if the same request arrives twice?
  • What is out of scope for this version, and is it written down?
  • Where are the answers to the AI's questions recorded?

Red flags

  • The spec describes screens in detail and has no rules section.
  • "The AI handled security" with no rule that names who sees what.
  • Prices or quantities stored as text.
  • Acceptance checks with no numbers in them.
  • The spec lives only in an old chat, and nobody can find it.

Practice

Write the spec section for "skip this week"

Ravi asks for a "skip this week" button: some weeks, during a holiday, he does not want his usual order. Imran agrees to add it. Assume the spec above, where every order is sent by hand, plus one new idea: from now on, a shop can turn on "auto-send", and the app then sends its usual order every Monday at 10:00 am shop time. "Skip this week" stops that automatic order for one week. Write the Rules (numbered, starting at R8) and three to five acceptance checks in given / when / then form, with real times and values.

  • A rule says a shop can skip only its own week, and a rep or another shop cannot skip for it (or reps are read only)
  • A rule gives a deadline for skipping, tied to the 10:00 am auto-send, in shop local time
  • A rule says what a skip affects (one week only; the usual order is unchanged) and how to undo it before the deadline
  • At least one pair of checks sits on each side of the deadline (for example 9:59 am and 10:00 am)
  • Every check has concrete values and a result you can see on a screen or in Order history
Show a model answer
Markdown
R8  A shop owner can skip or un-skip only their own shop's next auto-send.
    Reps and admins cannot skip for a shop in v1.
R9  Skip and un-skip are allowed until 10:00 am shop time on the Monday of
    that week. At 10:00 am the auto-send runs and the choice is locked.
R10 A skip affects one week only. The usual order and next week's
    auto-send do not change.
R11 A skipped week shows in Order history as "Skipped by owner" with the
    date, and no order is created.

A7 Given auto-send is on and it is Sunday 8:00 pm
   When Ravi taps "Skip this week"
   Then the home screen says "Next order: Monday in 8 days"
   And on Monday at 10:00 am no order is created
A8 Given Ravi skipped this week and it is Monday 9:59 am
   When he taps "Undo skip"
   Then at 10:00 am his usual order of $156.70 is sent as normal
A9 Given it is Monday 10:00 am and the auto-send has run
   When Ravi opens the home screen
   Then there is no Skip button for this week
A10 Given Ravi skipped last week
    When the next Monday 10:00 am arrives
    Then his usual order is sent as normal

The deadline is the rule an AI would most likely guess wrong, because nothing in the old spec mentions it. Without R9, the tool might allow a skip after the order was sent, leaving an order in the distribution centre's packing list that the shop thinks it cancelled.

Check an order against the rules

This is the kind of small function an AI writes for rules R2, R3 and R4. Finish it so it follows the spec. The comments explain every input. Check stock first, then the minimum, then pick the delivery day. Exactly 4:00 pm counts as after the cut-off.

JavaScript exerciseRuns in your browser with tests
// order: { lines: [{ name, qty, priceCents, inStock }] }
// now:   { hour: 0 to 23, minute: 0 to 59 } in the shop's local time
// rules: { minOrderCents: 5000, cutoffHour: 16 }
//
// Return one of these:
//   { ok: false, reason: 'out-of-stock', delivery: null }   any line not in stock
//   { ok: false, reason: 'below-minimum', delivery: null }  total under the minimum
//   { ok: true, reason: '', delivery: 'next-day' }          before the cut-off
//   { ok: true, reason: '', delivery: 'day-after' }         at or after the cut-off
function canSendOrder(order, now, rules) {
  let totalCents = 0;
  for (const line of order.lines) {
    totalCents = totalCents + line.qty * line.priceCents;
  }
  // TODO 1: refuse the order if any line is out of stock
  // TODO 2: refuse the order if totalCents is under rules.minOrderCents
  // TODO 3: choose the delivery day from now.hour and rules.cutoffHour
  return { ok: true, reason: '', delivery: 'next-day' };
}
Ctrl + Enter runs
Show a solution
JavaScript
function canSendOrder(order, now, rules) {
  let totalCents = 0;
  for (const line of order.lines) {
    totalCents = totalCents + line.qty * line.priceCents;
  }
  // R4: one line out of stock stops the whole order
  if (order.lines.some((line) => !line.inStock)) {
    return { ok: false, reason: 'out-of-stock', delivery: null };
  }
  // R2: exactly the minimum is allowed, one cent less is not
  if (totalCents < rules.minOrderCents) {
    return { ok: false, reason: 'below-minimum', delivery: null };
  }
  // R3: 16:00 and later counts as after the cut-off
  const delivery = now.hour < rules.cutoffHour ? 'next-day' : 'day-after';
  return { ok: true, reason: '', delivery };
}
Pass the exercise to finish this task.

Check yourself

In a test, a shop's mobile data drops just after the owner taps Send, the app retries, and the shop receives two identical deliveries. Which line, added to the spec, would have led the AI to prevent this?

The AI's plan for Ravi's app includes step 6: "Add a card payment page so shops can pay at checkout." What should you do?

You are setting up the project. Where do "money is integer cents everywhere" and "the minimum order is $50.00" belong?

Flashcards

Open my review

Key takeaways

  • An AI fills every gap with a guess. Screen guesses are cheap and visible; rule and data guesses are hidden and costly, so the spec spends its words there.
  • A one-page spec has users and roles, screens and flows, data (money in whole cents, whole-number quantities) and numbered rules.
  • Acceptance checks in given / when / then form, with real values on both sides of every boundary, let you and the AI prove the app follows the spec.
  • Edge cases (no usual order, discontinued product, changed price, a repeated send) and an out-of-scope list stop the most common surprises.
  • Keep the spec in SPEC.md, stable working rules in your tool's instruction file, and ask for questions and a plan before any code.

Sources and further reading

Episode transcriptWhy the AI guessed everyone could see · about 13 minutes · tap any line to play from there
  1. NadiaImran, you built an app in twenty minutes last month. Tell people what happened next.
  2. ImranIt looked finished. Ravi's usual order, a list, a Send button. Then Leila signed in as a second test shop, opened Order history, and saw Ravi's orders as well as her own.
  3. NadiaAnd you'd typed one line to get it.
  4. ImranBuild a reorder app for shops. That was the whole prompt. So today is about the page I should have written first.
  5. NadiaLet's start with a caterer. You phone and say, food for a party on Saturday. They won't call back with fifty questions. They'll guess.
  6. ImranSome of those guesses don't matter. Napkin colour, the shape of the plates.
  7. NadiaRight, those are cheap. If they're wrong you shrug. But how many guests, whether someone has a nut allergy, what time the food arrives, the budget? Those you only find out at the party, and you can't fix them on the night.
  8. ImranSo a good catering order is one page. Who's coming, what they eat, the rules, and what's not included.
  9. NadiaAnd a good caterer reads it and calls back with two or three questions before cooking anything. That's the whole lesson in one picture.
  10. ImranWhy does the AI guess, though? Couldn't it just ask me?
  11. NadiaIt could, if you tell it to. By default, a coding tool writes the code that's most likely to fit your request, based on the huge amount of code it learned from. When your request is silent on something, it picks the most common answer it has seen.
  12. ImranAnd the most common answer for a screen is fine.
  13. NadiaUsually. A list, a button, a form. If it's wrong, you see it at once and say make the button bigger. Ten seconds. The trouble is rules and data. Most example apps the model learned from are demos with one user, so they don't limit who sees what.
  14. ImranWhich is my bug. If you can see the screen, the first diagram shows my one-line prompt going into the AI, and four gaps coming out with four guesses.
  15. NadiaIf you can't see it, picture four rows. Who sees orders? The guess is everyone. How is the price kept? The guess is text. Is there an order cut-off? The guess is none. And the button colour, the guess is blue.
  16. ImranThe first three are marked hidden and costly. Only the button is visible and cheap.
  17. NadiaTell them about the prices, because that one surprised Tomás.
  18. ImranEvery price was stored as text, like six point four zero in quotes. When the code added two prices stored as text, it glued them together. Six forty plus two seventy-five came out as one long string of digits.
  19. NadiaAnd the cut-off?
  20. ImranThere wasn't one. An order sent at nine at night promised delivery the next morning, which the distribution centre can't do. None of the three showed on the screens. I deleted the app and started again.
  21. NadiaThis matters for Mangrove because about fifteen hundred partner orders a week still come by phone to about forty sales reps, and roughly one phone order in twelve gets corrected after delivery. The app is meant to fix that, not add new mistakes.
  22. ImranSo the spec for an AI is different from the specs I write for the team.
  23. NadiaYes. A team shares your context and can ask you in the corridor. The AI doesn't know what Mangrove is, what a partner shop is or what a sales rep does. So you spend few words on how screens look, and most of your words on who can see what, what the data is, and the rules.
  24. ImranWalk me through the page. I think it's four parts.
  25. NadiaFour core parts. First, users and roles. A role is a kind of user with its own permissions. Ravi's app has three: a shop owner who sees only his own shop, a sales rep who sees the shops in their area and only reads in version one, and an admin on your team.
  26. ImranSecond, screens and flows. Sign in, My usual order, Confirm, the Sent screen, and Order history. The main path is three taps: open the app, tap Review, tap Send.
  27. NadiaNo drawings needed. The AI is good at layout, and you'll adjust it by looking. Third is data. Five tables: shops, products, usual order lines, orders and order lines. For each one, list the fields and mark which are required.
  28. ImranAnd this is where you write money as whole cents.
  29. NadiaExactly. Six dollars forty is stored as the number six hundred and forty. Text can't be added safely, and decimal numbers in most languages carry tiny errors. Whole cents add up exactly. Quantities are whole numbers too, and each order line keeps the price at the time of the order.
  30. ImranSo last week's order still shows what Ravi paid, even if rice went up.
  31. NadiaThat's it. And times get a time zone. Four pm means four pm in the shop's local time. Fourth part, rules. Number them, R one, R two and so on, so you and the AI can point at them later.
  32. ImranRule one, a shop sees only its own orders, and a rep only sees shops in their area. Checked on the server, not just by hiding buttons.
  33. NadiaRule two, a minimum order of fifty dollars. Rule three, orders sent before four pm are delivered the next day, and at four or later, the day after. Rule four, out of stock products can't be added. Rule five, a shop can cancel only before packing starts.
  34. ImranThe second diagram shows those rules at work. If you're looking, Ravi goes from My usual order to the Confirm screen to Send, and then the server checks, in order.
  35. NadiaIf you're listening on a walk: first, is this his own shop. Second, is everything in stock. Third, is it at least fifty dollars. A no on any of those stops the order, and the screen says why. The fourth step never blocks. It uses the four pm cut-off to pick the delivery day.
  36. ImranThen come the acceptance checks. We use given, when, then for those already.
  37. NadiaSame format, with one extra reason. The AI can turn each check into an automatic test, and you can tap through each one by hand in a minute. That's your proof, whatever the AI tells you.
  38. ImranAnd you put checks on both sides of a boundary.
  39. NadiaAlways. One at three fifty-nine and one at exactly four pm. One under fifty dollars and one at exactly fifty. Boundaries are where the guesses hide.
  40. ImranNow the edge case that worries me most. Ravi taps Send, his mobile data drops, and the app retries.
  41. NadiaWithout a rule, the request reaches the server twice, and Ravi gets two deliveries. The fix is called an idempotency key. The phone creates one unique code when he taps Send and sends it with every retry. If the server sees the same code again, it returns the order it already has.
  42. ImranAnd I don't have to build that myself.
  43. NadiaNo. You write the rule: one tap on Send creates at most one order, even if the request repeats. The AI builds it. The other edge cases are a new shop with no usual order yet, a product that's no longer sold, and a price that changed since last week.
  44. ImranThen an out of scope list. Payments, delivery tracking, promotions.
  45. NadiaThat list matters more for an AI than for a team. These tools like to add features nobody asked for, like a payment page to make the app complete. When the plan includes one, you point at the list.
  46. ImranWhere does all this live? I pasted mine into the chat the first time.
  47. NadiaIn a file called SPEC dot M D, in the project folder, written in Markdown, which is plain text with a few marks for headings and lists. A chat is forgotten when the session ends. A file stays, every session can read it, and when you and the AI disagree, the file wins.
  48. ImranAnd the instruction files? Claude Code reads CLAUDE dot M D, and lots of tools read AGENTS dot M D.
  49. NadiaRight, and Cursor also has its own rules folder. The names differ by tool and change over time, so check the documentation. Keep them short: how to work in this project. Read the spec first, money is whole cents, plan before building. The spec says what the app does.
  50. ImranAnd both are advice, not a lock.
  51. NadiaYes. The tool usually follows them, but the rule that a shop sees only its own orders has to be enforced by the database too. That's a later lesson.
  52. ImranSo the Build it section. You make a project folder, write SPEC dot M D with the goal, users, screens and data, then the numbered rules and six acceptance checks, then edge cases and out of scope.
  53. NadiaThen a short instruction file for your tool. Then the first prompt, and this is the part people skip. Ask for no code. Ask it to list everything unclear, missing or contradictory, and then to propose a plan of five to eight small steps.
  54. ImranMy second attempt came back with nine questions. Is the cut-off in the shop's time or the distribution centre's? Can a rep place an order for a shop? Do prices include tax?
  55. NadiaEach question is a guess it would otherwise have made silently. And where did you put the answers?
  56. ImranInto the spec, as numbered rules. The next plan had the access rule in step two, before any order screens, and Ravi's first test order of a hundred and fifty-six dollars seventy went through first time.
  57. NadiaWhat will you ask the next time someone shows you an app an AI built?
  58. ImranWho can see each piece of data, and where is that enforced. Show me the field for one price. And what happens if the same request arrives twice.
  59. NadiaGood. The practice has a spec section to write, for a skip this week button on an automatic Monday order, plus a small coding exercise that checks an order against the stock, minimum and cut-off rules.
  60. NadiaHere's one to think about. The AI's plan for Ravi's app adds a card payment page in step six. What do you do? Take a second.
  61. ImranI'd point at the out of scope list in the spec and ask for the plan again without it. The plan is the cheap place to say no.
  62. NadiaRight. Building it and hiding it means code that handles money, which must be secured, for nothing.
  63. ImranMy three takeaways. One, the AI fills every gap with a guess, and the costly guesses are about rules and data, so that's where the words go.
  64. ImranTwo, one page: users and roles, screens, data in whole cents, numbered rules, then checks with real values on both sides of every boundary. Three, keep it in a file and ask for questions and a plan before code.
  65. NadiaOne nuance on the third. Write the answers back into the file, not only the chat, or the next session makes the same guesses again.
  66. ImranThe flashcards cover the four parts, whole cents and the idempotency key.
  67. NadiaNext time, we build Ravi's app one small step at a time: plan, build, check, commit.
Finished reading?Mark it complete to fill in its stop on your course line.

Use it at work

Unit-test starter

A function with a test file: the happy path, the edges and the errors, grouped and named clearly.

Open in the Code Lab
Next stopBuilding in small steps
Was this lesson helpful?
Questions and discussion

Loading the discussion…