← All guidesCodex for Backend Engineering · Future with Shivank
Hands-on guide

9. Auctions & Users

Codex is building Slice 1. In this guide you learn how to review what an agent writes while it writes it: the database migration first, then the API and its tests, then the written design record. Then you open Part 2 in Chrome and send your first follow-up change.

Part 2 · slice 1≈ 20–30 minSame chat as guide 8

What you'll do

Before you start

⚙ Codex settings for this guide
Project / folderworkshop (same chat as guide 8)
ModelGPT-5.6 Sol
ReasoningMedium
ApprovalsApprove for me
1

Open the list of changed files

You do not have to wait for Codex to finish before you start reviewing. While it works, a line like Step 1/4 · 9 files changed +108 -56 appears under its to-do list. The +108 is lines added, the -56 lines removed. Click the words files changed. A Review panel opens on the right side of the Codex window, with one entry per file.

📘 Concept: diff

A diff shows the difference between two versions of a file, line by line. Lines Codex added are marked with + and shown in green; lines it removed are marked - and shown in red; unchanged lines are grey context. Reading diffs instead of whole files is how professional engineers review each other's work, because it shows only what changed. With an agent it matters even more: you did not type this code, so the diff is your first and best view of what actually happened.

✓ You should see

The Review panel, labelled Last Turn at the top, lists files like AGENTS.md, GRILL.md, README.md, package.json and 001_marketplace.sql, each with a mostly green diff because they are new. The file list and the counts keep growing while Codex works, so do not worry if your numbers are different from mine.

💡 Tip

Why review while it runs? Because if the very first file, the migration, is wrong, you can stop Codex with the ■ button and correct it before it builds an API and a UI on top of a wrong foundation. Ten minutes of agent time is cheap; ten minutes of agent time spent on the wrong design is not.

2

Check the database migration first

In the Review panel, click server/migrations/001_marketplace.sql. I always check the database first, because so much goes wrong at the database level, and everything else depends on it. If a column is missing or a price is stored as a decimal, the API and the UI inherit that mistake. Compare each table with your grilling answers from guide 8.

📘 Concept: SQL, CREATE TABLE, INSERT

SQL is the language you use to talk to a relational database like PostgreSQL. A migration file is just SQL statements run in order. CREATE TABLE users (…) defines a new table and its columns, each with a type (TEXT, INTEGER, TIMESTAMPTZ for a timestamp with time zone). A column like seller_user_id that points at a row in another table is a foreign key: it links an auction to the user who posted it, and the database refuses to save an auction whose seller does not exist. CREATE INDEX builds a lookup structure so that searching by that column is fast. INSERT INTO users (…) VALUES (…) adds rows; that is how the seed data gets in.

✓ You should see

Something similar to:

  • CREATE TABLE users with columns id, display_name, handle
  • CREATE TABLE auctions with slug, seller_user_id, title, category, starting_price_cents, ends_at, location, condition, description, specs and more
  • CREATE TABLE bids with auction_id, bidder_user_id, amount_cents, created_at
  • two indexes, then INSERT INTO users with 10 people (Avery Chen, Maya Thompson, Theo Brooks, Priya Shah, Jordan Lee, Sam Rivera, Nora Williams, Eli Martin, Zoe Patel, Marcus Green) and INSERT INTO auctions with the 6 catalog items

Map it back to your decisions: three tables because you asked for users, auctions and bids; ends_at as a timestamp with time zone because you chose UTC closing times; the _cents suffix on every price because you chose integer cents.

💡 Tip

My run used integer IDs (1, 2, 3…). In another run Codex used GUIDs, long random identifiers like 3f9a…. Either is fine for us. What is not fine is a price column without _cents or with a decimal type; if you see that, stop Codex and point at your Q6 answer.

3

Skim the API and the tests

Still in the Review panel, open server/src/app.ts and then server/src/app.test.ts. You are not reading every line; you are checking two things: that the routes match the slices you approved, and that the code follows the project's rules. Part 2's AGENTS.md asks for plain SQL through the pg library (the standard Node.js Postgres driver) with no ORM, and Zod for checking inputs.

📘 Concept: ORM vs plain SQL, and parameterized queries

An ORM (object-relational mapper) is a library that hides SQL behind language objects: you call Auction.find() and it writes the query for you. Convenient, but you stop seeing what hits the database, and that is exactly where our concurrency bugs will live later. So this project writes SQL directly. Direct SQL must be parameterized: the query uses placeholders like $1 and the values are passed separately, never glued into the string. If a user's search text were pasted straight into the SQL, a malicious search like '; DROP TABLE users; -- would run as a command. That attack is called SQL injection, and placeholders make it impossible.

✓ You should see

In app.ts: routes like GET /api/users, GET /api/auctions (with a Zod schema that validates the search query parameters) and GET /api/auctions/:slug, where :slug is a placeholder for one auction's URL-friendly name. All reads, no writes yet; posting and bidding are Slices 2 and 3. In app.test.ts: tests with names such as “lists the ten seeded users” and “lists and searches the six database-backed auctions”.

💡 Tip

Test names are the fastest way to check an agent's understanding. Read them as a list of sentences. If a sentence describes behaviour you did not ask for, or an important behaviour is missing from the list, you have found a gap before you have run anything.

4

Browse the code in VS Code

The Review panel is good for diffs but awkward for moving around a project. I find VS Code much easier for that, so from here on we read code there and keep Codex for the conversation. Close the Review tab in Codex, then open the workshop in VS Code. Skip the command if VS Code is still open on the workshop from guide 8.

❯Run in TerminalTerminal app · any folder
code ~/codex-course/workshop

In the Explorer, expand part-2-create-auction-and-bid, then server and web. The split is the same in every part: server/ is the Fastify API (backend), web/ is the React app (frontend). Each has its own src/ folder with the source code.

✓ You should see

Inside part-2-create-auction-and-bid: server/migrations/ with the SQL file from Step 2; server/src/ with app.ts (routes), index.ts (starts the server), migrate.ts (runs migrations), otel.ts (tracing setup we use in guide 25); and web/src/components/UserSwitcher.tsx, the new footer switcher component, among others. Red squiggly underlines in the editor are normal until npm install has run in this folder and Codex has finished; they mean VS Code cannot find packages yet, not that the code is wrong.

5

Read GRILL.md

Now the most important document of the slice. GRILL.md in the Part 2 folder is the grilling session written down: every decision from guide 8, in the form Codex must follow while it builds. It is also what future chats read, so if it is wrong today, every later slice inherits the error. Open it and check it line by line against your round 1 and round 2 answers.

❯Run in TerminalTerminal app · any folder
code ~/codex-course/workshop/part-2-create-auction-and-bid/GRILL.md

Giving code a file path instead of a folder opens just that file in the existing VS Code window. Press Cmd+K then V for the formatted preview.

✓ You should see

Sections similar to Actors (ten predefined users, footer switcher, no login), Auctions (required fields, category illustrations, live on creation, UTC closing), Money and bidding (USD integer cents, $1 minimum increment, no self-bidding, ended auctions reject bids), Reset behavior (only db:reset wipes auction_part_2) and Delivery slices (the three slices you approved). Every item should be something you consciously decided in guide 8.

💡 Tip

The domain-modeling skill usually also writes a CONTEXT.md glossary (what “auction”, “bid” and “active user” mean in this project), and sometimes docs/adr/ files. In my run it did not; everything went into GRILL.md, and that is fine. If yours created CONTEXT.md or ADRs, read those too. If anything in these files contradicts what you answered, tell Codex in the chat with one sentence, for example “GRILL.md says bids need $5 increments; we agreed $1. Fix the doc and the code.”

6

Let Codex check its work in a real browser

Go back to the Codex chat and let it finish. Near the end of Slice 1 it does four things in order: resets the Part 2 database, runs the migration, runs the tests and the TypeScript type checks, and then opens the app in a real browser to click through it. I want to stress this part. An agent will tell you “done” very confidently whether the code works or not. Confidence is not evidence. The only defence is to give it tools that produce evidence: tests that pass or fail, a compiler that accepts or rejects, a browser that renders or throws errors.

📘 Concept: automated tests and type checks

An automated test is a small program that runs part of your app and checks the result: “call GET /api/users, expect 10 rows”. You run all tests with one command and get a pass/fail list in seconds, every time anything changes. A type check is different: TypeScript reads the code without running it and verifies that every value is used the way its type allows, so passing a string where a number is expected is caught before the app even starts. “Strict” TypeScript, which our AGENTS.md demands, turns on the toughest version of these checks. Tests catch wrong behaviour; type checks catch wrong plumbing. Together they are how Codex proves a slice to you, and how you will later prove your fixes to Codex.

✓ You should see

A message similar to: “Database reset, migration, all six tests, and both strict TypeScript checks pass. I'm using the Chrome control skill now because the project requires real browser verification…” followed by a Chrome window opening on the Part 2 site. In my run the browser check found a real bug: the dev server kept restarting because tsx watch (the tool that restarts the server when files change) was also watching OpenTelemetry files inside node_modules. Codex noticed the restarts, worked out the cause and fixed the watch configuration on its own. Tests alone would never have caught that; the browser check did.

💡 Tip

With an API key, Codex's built-in browser is not available. Your Codex will most likely use Playwright with Chrome instead, as in guide 6, and it may ask to install it: approve that. If it says it cannot check in a browser at all, do not worry; you do the check yourself in Step 8.

7

Read the Slice 1 summary

When Codex stops (about 9 minutes after you approved the slices, in my run), read its final message from top to bottom. Do not skip to the URL. The summary is structured so you can verify each claim, and that is what the next step does. Click the diagram to enlarge it and compare it with the one from guide 8: it should be the same architecture, now built.

✓ You should see

Something like: “Slice 1 is complete and verified. The app remains running at http://localhost:5102…”, then four blocks:

  • Implemented: its own auction_part_2 database and ports 3102/5102, the 001_marketplace.sql migration, 10 users and 6 auctions seeded, database-backed read APIs in app.ts, the footer switcher in UserSwitcher.tsx, and the decisions recorded in GRILL.md
  • a diagram: React/Vite Web App → HTTP reads → Fastify API → Parameterized SQL → PostgreSQL (users · auctions · bids)
  • Verification passed: server tests 4 passed, web tests 2 passed, both TypeScript checks passed, browser console clean
  • To review: a short list of browser steps for you, ending with “If Slice 1 looks right, tell me to continue with Slice 2: Post an auction.”

Notice that Codex has stopped and is waiting. That pause between slices is the AGENTS.md rule in action; it will not start Slice 2 until you say so.

8

Open Part 2 in Chrome

Codex leaves the app running and tells you the URL, http://localhost:5102. Its reply may also show a Web preview card, but that built-in preview does not work with an API key, so open the URL in Chrome yourself. Part 1 is still on 5101 if you left it running; the two do not interfere.

↗Open in browser
http://localhost:5102

Then follow Codex's To review list. This is your browser checkpoint for Slice 1:

  1. Look around the homepage. It should look like Part 1, but every item is now coming from the database.
  2. Change Browsing as in the footer to a different user, then reload the page with Cmd+R. The choice should survive the reload; that is the localStorage decision from Q10.
  3. Search for memory in the search bar. The search now runs as a SQL query on the server, not as a filter on a hard-coded list.
  4. Open the result and check the seller name and the starting price are shown correctly. The price proves cents-to-dollars formatting works.

If the page does not load at all, the app is not running. Start it yourself from the Terminal app with the command below; it installs the packages for Part 2 and starts everything, exactly like npm start did for Part 1 in guide 7.

❯Only if the page doesn't loadTerminal app
cd ~/codex-course/workshop/part-2-create-auction-and-bid && npm install && npm start
✓ You should see

The Auction House homepage (“Serious hardware. Less serious prices.”) with a 10 Demo users label at the top right and Browsing as … (@handle) in the footer, for example Jordan Lee (@jordan). After a reload, the user you picked is still selected. Searching memory returns the DDR5 memory kit.

💡 Tip

Also open http://localhost:5102/api/users in a new tab. You get raw JSON with the ten users straight from the API, the same data the footer switcher uses. Looking at API responses directly is a habit that will save you hours of guessing whether a bug is in the frontend or the backend.

9

Ask for a random user on page load

The slice works, but one detail bothers me: the “10 Demo users” label at the top right is meaningless to a visitor, and every new window starts as the same first user. I want each window to start as a random user, with that user's name shown at the top right. The reason is practical: in guides 11 and 12 we open several browser windows and make them bid against each other, and we need to see at a glance who is who in each window. Send this follow-up in the same chat:

✦Paste into CodexCodex message box, same chat
randomly assign the user on page load AND put the user's name on the top right, not "10 demo users"

Notice the prompt is short, specific and names the exact text to replace. Two concrete changes, nothing vague. You do not need to re-grill for a tweak like this; grilling is for design decisions, not for every edit. This is also a change to a decision recorded in GRILL.md (Q10 said “start with the first seeded user”), so watch whether Codex updates the document as well as the code. It should.

✓ You should see

Codex replies with a short plan similar to: “I'll make the initial user random per browser tab, then keep that identity stable through navigation and reloads in the same tab; the footer switcher can still override it… replacing “10 Demo users” with the selected user's actual name. This updates the earlier localStorage decision in GRILL.md.” Then it edits a few files, mostly under web/src/, and runs the tests again before it stops. Guide 10 starts by checking the result in the browser.

💡 Tip

Even a small change ends with tests. “Never stop without running tests” is, in my experience, a big part of why this workflow produces code you can trust. If you ever see Codex finish an edit without running anything, ask it to run the tests before you look at the result.

Stuck or got a very different result?

If Slice 1 failed or looks very different from what I describe, first tell Codex what you see, in the same chat, with the exact error text or a description of the wrong behaviour. That fixes most problems. To catch up instead, replace your Part 2 with the reference copy's version. Be aware that it is the end state of the whole part: all three slices done, the random user per tab, and a bidding-war test that we add in guide 12. In guide 10 you would then skip the build steps and only do the browser checks.

❯Catch up: copy the finished Part 2 from the referenceTerminal app
cd ~/codex-course/workshop && rm -rf part-2-create-auction-and-bid && cp -R ../reference/part-2-create-auction-and-bid ./ && git add -A && git commit -m "Catch up: part 2 from reference"

That line deletes your Part 2, copies the reference Part 2 in its place, and commits it so the catch-up is recorded in your Git history.

❯Then run it (open http://localhost:5102)Terminal app
cd ~/codex-course/workshop/part-2-create-auction-and-bid && npm install && npm start

Key takeaways