JomMula

Kedai: Build a Personal Marketplace · The Plan · Lesson 03

The blueprint

The mockup is a drawing. The master plan is the contract: ten phases, hard invariants, and one rule — no phase is done until its Verify step passes.

9 min readExplanationthe planno codeUpdated October 2026

The mockup is a drawing. It shows what the shop looks like. It cannot show what happens when two buyers click Reserve at the same time, or when a hold expires while the seller is confirming it, or when Resend is down.

That is what the master plan is for.

It is a blueprint written for exactly one situation: a coding agent starting Kedai from an empty folder. Every remaining lesson maps to a phase inside it. The plan is the source of truth; when a lesson and the plan disagree, the plan wins.

The plan itself

Keep it open in a tab. It is written for opencode, but you should know what is inside it.

Download master-plan-kedai.md

One app, not a pile of apps

Kedai is one Next.js app that does everything:

  • The public shelf and item pages render on the server.
  • The back room is the same app, behind a session.
  • The reservation receipt and the upload ticket are the same app too.
  • The database is Neon; the photos are R2; the email is Resend. Those are services, not separate backends.

There is no client/ and no server/. One repo, one deploy, one origin. The only boundary that matters is the one inside the app: public reads vs. constrained public writes vs. authorized admin writes.

The ten phases

This is the shape of the build. Tap a phase to see what it produces.

The build order — 10 phases, no skipping

Tap a phase to see the verify

  1. TypeScript strict, Tailwind 4, Zod-validated env, a health route that checks Neon, and a proxy that only does optimistic redirects.

Read the order like a sentence: get it to boot, get the data right, let yourself in, show the shelf, put the photos on it, take reservations, run the back room, send the receipt, prove the failures, ship it.

What the plan is strict about

The plan has a section called hard invariants — rules it will not bend. You will meet them one at a time, but here is the flavour:

  • The price comes from the database. The browser never sends an amount.
  • One item has at most one pending reservation. A partial unique index enforces it.
  • Only the admin can confirm a sale. A buyer’s claim is recorded, not trusted.
  • An expired reservation releases the item. A cron and a lazy check both help.
  • Authorization happens inside every Server Action and Route Handler. A layout or proxy.ts is only a UX convenience.
  • An item with reservations is never hard-deleted. Archive it; keep the history.
  • Photos are public, the back room is not. The photos are marketing; the mutations are private.
  • Every state transition is conditional and audited. Double-clicks and retries must be idempotent.

These are not decoration. They become database constraints, conditional updates, and tests.

The state machine is the heart

The reservation is the source of truth for a hold. It only moves in a few directions:

pending ──seller confirms──▶ confirmed
   │
   ├──buyer or seller cancels──▶ cancelled
   └──24 hours pass────────────▶ expired

The email is a side effect with its own status:

not_sent ──claim──▶ sending ──Resend──▶ sent
                        │
                        └──failure──▶ failed ──retry──▶ sending

A confirmed sale with a failed receipt is still confirmed. The buyer is entitled to the item; the email is how they find out. That distinction is the difference between a shop that works and a shop that loses orders when an email bounces.

The facts only you can supply

Some phases pause and ask for real values. Nothing secret ever goes into the plan document. Secrets live in .env.local locally and in the hosting platform’s environment store in production.

Fact Where it ends up
Shop name, promise, seller display name SHOP_NAME, page copy, EMAIL_FROM
Production domain PUBLIC_BASE_URL, R2 CORS, email links
WhatsApp number in E.164 without + WHATSAPP_NUMBER
Pickup location and instructions SHOP_LOCATION, PICKUP_INSTRUCTIONS
Seller notification email SHOP_EMAIL
Your admin email and a 12+ character password ADMIN_EMAIL, ADMIN_PASSWORD (seed only)
Neon pooled connection string + a test branch DATABASE_URL, TEST_DATABASE_URL
Cloudflare account id, bucket, R2 token, public bucket URL R2_*
Resend API key RESEND_API_KEY
Default currency DEFAULT_CURRENCY (default MYR)

You do not need all of these today. You need each one exactly when its phase arrives, and the lesson will tell you.

How we will drive it

  1. 1

    Read the plan once

    Not memorize — just know its shape. Download it above and skim the table of contents. You will come back constantly.

                  master-plan-kedai.md
                

    It is written for a coding agent, so you can hand it to opencode. You still need to know what is in it.

  2. 2

    Collect the facts

    The plan refuses to let anyone invent values. Section 0.2 is the list only you can supply. We will gather them as each phase needs them.

                  §0.2 — Facts to collect from the user
                
  3. 3

    Build in order, one lesson per phase

    Each lesson teaches the concept first — the flow, the failure, the invariant — then the files. You brief opencode, review what it produces, and run the Verify.

  4. 4

    Run the mission

    Every lesson ends with a mission box. It is the plan's Verify step in disguise. The app either does the thing or it does not; there is no partial credit.

What this project is not

No customer accounts. No cart. No multi-vendor marketplace. No subscriptions. No Stripe. No reviews. No search. No shipping calculator. No multi-currency.

Every one of those is a real feature, and every one of them would make the first version harder to finish and easier to get wrong. The manual WhatsApp workflow is not a limitation we are apologising for. It is the workflow many small shops actually use. The project is about making that workflow safe.

Your mission

the plan's verify step

Download the plan. Find three things: the hard invariants, the Verify line for phase 6 (reservations and WhatsApp), and the footgun table. Then collect the facts you already know — shop name, domain, WhatsApp number, currency — and leave every secret blank.

If you can point to where the plan prevents a double sale, you are ready for the build.

Recap

The master plan is the contract: one Next.js app, ten phases, each with a Verify step.

The reservation state machine is the heart: pending → confirmed, cancelled, or expired.

The invariants become constraints, conditional updates, and tests — not comments.

Secrets live in env files and the hosting platform, never in the plan.

No skipping phases. The Verify step is the whole discipline.

Next: phase 1. An empty Next.js app that installs, boots, and tells the truth about its database.

Previous: Design the shop window
04

Up next

An empty app that boots

Phase 1 — create the Next.js app, validate the environment, connect to Neon, and add a health route that tells the truth.

Read now