BACK_TO_COURSE
Steering the Build
Write the Spec, Not the Code
AI Fills Every Blank You Leave
Say "build me a contact form" and you'll get one. It'll pick the database, the limits, what happens on failure and who can see the data. It picked by guessing. A spec is just you making those calls first.
One page is enough:
WHAT: A contact form that saves leads and emails me.
PLATFORM: Cloudflare Workers, wrangler.jsonc, no Node server.
ROUTES
- POST /api/lead: accepts JSON { name, email, message }
STORAGE
- D1 table "leads" (id, name, email, message, created_at). Source of truth.
- Nothing in KV. Nothing in memory.
BACKGROUND
- Queue "lead-email" sends the email. Retry 3 times, then dead letter queue.
RULES
- Name 1-100 chars, message 1-2000 chars, email must look like an email. Bad input: 400.
- Rate limit: about 5 per minute per IP. Over the limit: 429.
- Email key is a secret. Never in code, config or logs.
WHEN IT BREAKS
- D1 down: return 500, save nothing, send nothing.
- Email API down: the lead is still saved and the visitor still gets 202.
DONE MEANS
- Good post returns 202, and the row is in D1.
- Bad email returns 400, and no row exists.
- The same queue message delivered twice sends one email.
- Email API failing four times puts the message in the dead letter queue.
Two sections do most of the work:
- WHEN IT BREAKS. AI writes the sunny day by default. This is where you say what matters more: the lead or the email.
- DONE MEANS. Every line is something you can run and see. "Works well" isn't. "Bad email returns 400 and no row exists" is.
Notice what's missing: no code. You don't have to know how. You have to know what, and what you won't accept.
Then Make It Think First
Read the spec. Before writing code:
1. List anything the spec leaves open and what you would assume.
2. Check every Cloudflare limit this design touches against
developers.cloudflare.com and link the page. Do not use memory.
3. Tell me what breaks first if traffic goes up 100x.
Wait for my answer, then write the tests from DONE MEANS, then the code.
Number 1 finds the holes in your spec while they're cheap. Number 2 kills stale limits. Number 3 tells you if the design only works while nobody uses it.
QUIZ
Which of these is a good DONE MEANS line?
Sign in to track lesson progress and earn a certificate.SIGN IN TO SAVE PROGRESS