Skip to content

The Code Under Your App

Summary

Names the frameworks, languages, packages, storage buckets and background jobs that make up a typical AI-built app, and ends with a map of the reader's own app.

Concepts Covered

This chapter covers the following 15 concepts from the learning graph:

Concept Concept Impact Score
Frontend Framework 6
React 1
Build Tool 4
Server Framework 2
Express 1
Node.js 34
TypeScript 18
Type Checking 9
Package Manager 15
Package Dependency 13
Lock File 1
File Storage Bucket 19
Background Job 33
Scheduled Job 13
App Parts Map 7

Prerequisites

This chapter builds on concepts from:


The Noise in the Car

Most drivers have made this phone call. The car makes a grinding sound when it turns left, so you call the repair shop. The mechanic asks a few questions. Is it coming from the front or the back? Does it happen when you brake? Is the battery light on? You don't know. You drive the car every day, and you have never once opened the hood.

He isn't trying to make you feel small. He needs a rough idea of which part is involved before he can say whether it's a ten-minute fix or a week in the shop. So you describe the noise as best you can, he tells you to bring it in, and you wait to hear what it costs.

A second driver has the same car and the same noise. She can't fix a car either. But years ago someone showed her the parts under the hood: the battery, the alternator, the brakes, the belts. On the phone she says, "It's front left, only when I turn, and it's not the brakes." The mechanic says it sounds like a wheel bearing and gives her a price. She didn't need to know how to replace a bearing. She needed to know the names of the parts and roughly what each one does.

An app built with an AI agent is the same kind of machine. It runs, members use it, and the builder may never have looked at the parts underneath. Then something breaks, and the agent asks which part is involved, or guesses. This chapter opens the hood. It names the parts of a typical AI-built app, says what each one does, and ends with you drawing a map of your own app.

Know the Parts Before Something Breaks

Sawyer waving welcome You don't need to fix every part of your app. You need to know their names, so you can tell your agent where the noise is coming from. By the end of this chapter you'll have a one-page map of your own app, with what a member would notice if each part stopped. You can't ask "Gate or wall?" about a part you can't name.

The Stack in One Picture

The set of tools an app is built from is called its stack, because the parts sit on top of each other. Chapter 2 split a web app into the browser front end and the back-end server. This chapter fills in what each half is made of. Two words come up often. The host is the service that runs your app on the internet; in the dating-safety app it's Railway. To deploy is to send a new version of the app to the host so members get it.

The dating-safety app uses one of the most common stacks that AI agents produce.

Part The tool in the dating-safety app Where it runs
Frontend framework React The member's browser
Build tool Vite Your laptop, and the host when it builds the app
Server framework Express The server
Runtime Node.js Your laptop and the server
Language TypeScript Everywhere, turned into JavaScript before it runs
Package manager npm Your laptop, and the host when it installs
Database Postgres, through Drizzle, a library that lets code talk to the database (Chapter 11) A database service
File storage A private storage bucket A storage service
Background work Jobs that run the eight checks The server
Scheduled work Jobs that run on a timer The server or the host

Your app may use different names. A Next.js app blends the front end and the server into one project, and a Python app might use FastAPI in place of Express. Each part still does the same job, and the questions in this chapter work on any stack.

Sort the New Names

Sawyer sharing a tip When your agent names a tool you've never heard of, ask it which row of this table the tool belongs in and where it runs. Most new names turn out to be another brand of a part you already know.

The Front End: React and Vite

Frontend Framework

Every screen a member sees is built from HTML, CSS and JavaScript, the three languages a browser understands. Keeping hundreds of buttons, forms and lists in step with changing data by hand is slow and full of mistakes, so most apps use a framework.

A frontend framework is a library of code that builds and updates the screens of a web app in the browser. The developer writes small pieces called components, such as a photo upload box or a trust score badge. The framework puts them together into pages and redraws them when data changes.

Because a frontend framework runs in the member's browser, everything in it can be read by anyone, as Chapter 2 showed. Secrets, permission checks and rules that protect people, such as never showing a location, belong on the server. Layout, wording and anything else that is cheap to change can live in the front end. In Chapter 1's terms, most of it is good enough for now. The exceptions are the places where it decides what a member is told, such as showing "not checked" for a check that didn't run.

React

React is the most widely used frontend framework. Facebook released it in 2013, and it is now open source, free for anyone to use and change. Agents pick it by default because they have read more React code than any other kind. In the dating-safety app, React draws the upload screen, the scan progress screen and the results page.

React code lives in files that end in .tsx or .jsx, named after what they show, such as TrustScore.tsx. When the agent says it "updated the component," it means it changed one of these files.

Build Tool

Browsers can't run a React project as written. It is split across hundreds of files, uses TypeScript (covered below), and pulls in other people's code. A build tool is a program that turns a project's source files into the files that are served to users. It also runs a development server that shows changes on your laptop as you make them. The dating-safety app uses Vite, which does two jobs:

  1. While you work, npm run dev starts a development server on your laptop. When the agent saves a file, the browser updates in about a second.
  2. When you ship, npm run build produces a folder, usually named dist, holding the finished files the host serves to members.

Those two modes behave differently. In the dating-safety app, review later found developer-only plugins, add-ons meant to help while building, shipped inside the build that members download. Nothing broke on screen, so nobody noticed. Chapter 14 covers keeping the two builds apart.

Vite has one more trap. Any setting whose name starts with VITE_ is copied into the front-end code at build time, where every member can read it. A secret given that prefix by mistake is published with the next build. Chapter 6 covers this and other ways secrets leak.

Tell your agent

"List every file in the front end that reads a setting or environment variable, and every variable name that starts with VITE_. For each one, tell me whether it would be harmful if a stranger read it. Then list any Vite plugins we load and say which ones should only run in development. Don't change anything yet."

The Server: Express on Node.js

Node.js

JavaScript began as a language that only ran inside web browsers. In 2009 a developer named Ryan Dahl took the JavaScript engine out of Google's Chrome browser and wrapped it in a program that runs on any computer. Node.js is that program: a runtime, which runs JavaScript code outside a browser, on a laptop or a server. Express, Vite and npm all run on Node.js, and in most projects so does the type checker.

Because so much depends on it, the version of Node.js matters. Node.js releases two new major versions a year, and each one changes some behavior. Say the agent uses a built-in function that arrived in a recent version. On your laptop, which has Node 24, everything works. You deploy, the host picks its own default of Node 22, and the server crashes on start with an error saying the function isn't defined. Nothing is wrong with the code. The two machines disagreed about which Node.js they were running.

A cheap fix is to write the version down in the project, where both your laptop and the host read it.

Where the version is written What reads it
An engines entry in package.json, such as "node": ">=24" Many hosts use it to pick a version, and npm can be set to refuse a mismatch
A .nvmrc or .node-version file containing 24 Version tools on your laptop and many hosts
The host's settings page The host only, and it's easy to forget it's there

Chapter 14 returns to keeping your laptop, a test copy of the app and the live server in step.

Tell your agent

"Tell me which version of Node.js is installed on this machine and which version our host uses. If you can't tell what the host uses, say so. If the project doesn't already state its Node version in package.json and a .nvmrc file, show me the change that would add both, using the version we run locally."

Server Framework

Chapter 2 described what a server does: it receives an HTTP request on a route, does some work, and sends back a response. A server framework is a library that handles the plumbing every server needs, such as matching routes, reading JSON and sending errors, so the developer writes only what each route does. It also runs shared steps before a route's own code, such as checking that a member is signed in or logging the request. Those shared steps are called middleware.

Express

Express is the most widely used server framework for Node.js. It has been around since 2010, it is small, and AI agents write it fluently. In the dating-safety app, Express receives the upload from the browser, starts a scan, and returns results.

The code below says: when a POST request arrives on /api/scans, first run the requireSignIn middleware, then run the function that starts a scan. You don't need to write this. You need to recognize it, so you can find the route a bug report points to.

app.post("/api/scans", requireSignIn, async (req, res) => {
  const scan = await startScan(req.user.id, req.body);
  res.status(202).json({ scanId: scan.id });
});

The 202 status code means "accepted, still working." It's a clue that the slow work happens somewhere else, in a background job, which this chapter covers below.

Tell your agent

"Make a list of every Express route in the server, with its HTTP method, its path, the middleware it runs, and the file it lives in. Save it as docs/routes.md. Mark any route that has no sign-in middleware in front of it."

TypeScript and Type Checking

TypeScript

JavaScript lets you put any kind of value anywhere. A variable that held a number can later hold a piece of text, and nothing complains until the program does something odd while a member is using it.

TypeScript is JavaScript with labels added that say what kind of value each piece of code expects, such as a number, a piece of text, or one of a fixed list of words. Microsoft released it in 2012. These labels are called types. Before the code runs, a tool strips them out and leaves plain JavaScript.

Like most agent-written code today, the dating-safety app's code is TypeScript. Here is a type that says every check result has a name and a status, and that the status must be one of exactly three words.

type CheckStatus = "pass" | "fail" | "not_checked";

type CheckResult = {
  check: string;          // such as "reverse image search"
  status: CheckStatus;    // one of the three words above
};

That type is the product rule from Chapter 1, written in code. Every check has three results, and "not checked" is one of them. A type can't make the rule true on its own, but it gives a tool something to check against.

Type Checking

Type checking is running a program, the type checker, that reads every file and reports any place where the code uses a value in a way its type doesn't allow. For TypeScript, the type checker is tsc, and the usual command is npx tsc --noEmit, which checks without producing any output files. It takes seconds to a minute and costs nothing.

Here is the kind of mistake it catches. Say the agent writes the code that turns check results into a trust score, and spells one status a little differently than the type does.

if (result.status === "notChecked") {
  continue; // leave this check out of the score
}

To a person skimming, that looks right. To the program, "notChecked" and "not_checked" are different words, so this line never matches. Every check that didn't run would fall through to the scoring code below it. The type checker stops it before it ships:

error TS2367: This comparison appears to be unintentional because
the types 'CheckStatus' and '"notChecked"' have no overlap.

A small spelling difference that could have turned a failed vendor call into a false all-clear shows up as a red line in under a minute.

There's a catch that surprises many builders. Vite doesn't check types. It strips the labels and runs the code, so an app can start, build and serve members while it has hundreds of type errors. Most tools that run TypeScript servers during development work the same way. Type checking happens only if someone runs tsc.

A Passing Build Isn't a Type Check

Sawyer warning about a pitfall A passing Vite build only proves the labels could be stripped, not that the types agree. When your agent says the build passed, ask whether it also ran npx tsc --noEmit, and what the error count was.

Type checking also has a limit. It checks the code against itself. It can't check data that arrives while the app runs, such as a vendor's JSON reply or a form a member fills in. Chapter 9 covers checking outside data when it arrives. Try predicting what the type checker catches.

Diagram: Will the Type Checker Catch It?

Run the Will the Type Checker Catch It? MicroSim Fullscreen

Will the Type Checker Catch It?

Type: microsim sim-id: type-checker-catch-it
Library: p5.js
Status: Specified
Bloom Level: Understand
Bloom Verb: classify
Learning Objective: The learner will classify ten mistakes in a TypeScript app as caught or not caught by type checking, with at least eight of ten correct on the first attempt.

Prerequisites: TypeScript, type, type checking, the CheckStatus type with three values, Vite not checking types, the limit that type checking can't see data arriving while the app runs (all defined in the section above).

Evidence of Mastery: For each of ten mistake cards, the learner commits a prediction, "Caught by type checking" or "Not caught," before the answer is shown. A prediction is correct when it matches the answer column in Content. Mastery is 8 of 10 correct on the first attempt. Reading the code snippet on a card is exploration, not evidence.

Misconceptions: (1) If the app builds and runs, the types must be fine. (2) Type checking catches every bug. (3) Type checking checks data from vendors and members. (4) A typo in a word inside quotes can never be caught.

Instructional Rationale: Predicting before the reveal makes the learner apply the one rule that separates the two groups: the type checker sees only the code, and only when someone runs it. Mixing mistakes that look alike, such as a misspelled status in code and a misspelled status in vendor data, forces classification by that rule rather than by surface.

Content:

The type shown at the top of the sim, verbatim:

type CheckStatus = "pass" | "fail" | "not_checked";
type CheckResult = { check: string; status: CheckStatus };
# Mistake shown to the learner Correct answer Why (feedback)
1 Code compares result.status === "notChecked" Caught "notChecked" is not one of the three words the type allows, so the comparison can never be true.
2 Code sets status: "skipped" on a new result Caught "skipped" is not a CheckStatus.
3 A function that expects a number is given the text "50" Caught The type says number, and "50" in quotes is text.
4 Code reads result.staus, a misspelled field name Caught CheckResult has no field named staus.
5 A vendor's JSON reply has "status": "notChecked" Not caught The reply arrives while the app runs; the type checker only reads code.
6 The score code uses <= where it should use < Not caught Both are valid comparisons of numbers; the types are fine and the logic is wrong.
7 A member types letters into the age field of a form Not caught Form input arrives while the app runs, so it needs checking when it arrives.
8 A route forgets the sign-in middleware Not caught The code is valid with or without it; types don't know which routes need sign-in.
9 Code calls computeScore() with no arguments when it needs a list of results Caught The function's type says it needs one argument.
10 The project has a type error, and the team only ever runs npm run dev with Vite Not caught Vite strips types without checking, so the error is never reported unless someone runs tsc.

Provenance: Item 1 and the CheckStatus type are from the section "Type Checking" above. Items 2 to 10 are illustrative mistakes of the same kinds and must be labeled "illustrative." The TS2367 error text is the TypeScript compiler's message for comparisons with no overlap.

Rules: Each card has exactly one correct answer. A mistake is "Caught" when the type checker, run with npx tsc --noEmit, would report it from the code alone. It is "Not caught" when the mistake is in data that arrives while the app runs, in logic that uses valid types, or when the type checker is never run. Five cards are Caught (1, 2, 3, 4, 9) and five are Not caught (5, 6, 7, 8, 10).

Learner Activity:

  1. The learner sees the CheckStatus type and the first card.
  2. The learner chooses "Caught by type checking" or "Not caught." The choice locks.
  3. The card shows whether the prediction was right and the Why text. For a Caught card, the card also shows a one-line error in the style of a tsc message.
  4. The learner moves to the next card until all ten are done.
  5. The learner should notice that cards 1 and 5 contain the same misspelling, and only the one in code is caught.

Feedback: Ten cards in the order listed, one attempt each. Correct: "Right. " followed by the Why text. Incorrect: "Not quite. This one is [correct answer]. " followed by the Why text. After card 5, if the learner answered card 1 correctly and card 5 incorrectly, add: "Same typo, different place. The type checker reads code, not data." The final screen shows "n of 10 correct" and "Mastery reached" at 8 or more, with a list of the cards missed.

Starting State: The CheckStatus type at the top, card 1 below it, and the question "If you run the type checker, will it catch this?"

Chapter Anchors: The type has three status values: "pass", "fail" and "not_checked". The chapter's example mistake is "notChecked", caught with error TS2367. The command is npx tsc --noEmit. Vite does not check types. Type checking can't check data that arrives while the app runs (Chapter 9).

Tell your agent

"Run npx tsc --noEmit on the whole project, front end and server, and tell me how many type errors there are and in which files. Don't fix them yet, and don't change the build. Tell me whether our build script runs the type checker. Then show me a plan to fix the errors in small batches, starting with files that touch scoring, sign-in and payments."

Dozens of errors on the first run is normal for a project that has never been checked. Don't make the build fail on type errors until the count is zero, or the next deploy will stop. Chapter 17 shows how to make the check run on every change so the count can only go down.

Packages, Dependencies and the Lock File

Package Manager

No one writes a modern app from nothing. The dating-safety app uses Express, Drizzle, Stripe's code and dozens of smaller pieces, each written by someone else and shared for free. Each shared piece is called a package.

A package manager is a program that downloads the packages a project needs, puts them where the code can find them, and records which ones were installed. For Node.js projects the standard one is npm, which comes with Node.js. You may also see pnpm, Yarn or Bun, which do the same job. Three files and folders show up in every npm project.

Name What it is Commit it to git?
package.json The list of packages the project asks for, plus named scripts such as dev and build Yes
package-lock.json The exact version of every package installed, including the packages those packages need Yes
node_modules/ The downloaded code itself, often hundreds of megabytes No, it can be rebuilt from the two files above

When the agent runs npm install stripe, npm downloads the Stripe package, adds a line for it to package.json, and updates the lock file. npm run build means "run the script named build in package.json."

Package Dependency

A package dependency is a package that a project's code needs in order to run, listed in package.json. If the package has a bug, your app has the bug. If the package stops being updated, your app inherits whatever problems are found in it later.

Each package has its own dependencies, and those have theirs. The ones you asked for are direct dependencies, and the ones that came along are transitive dependencies. An app like the dating-safety app lists a few dozen direct dependencies and installs several hundred packages in total. Here is part of its list.

"dependencies": {
  "express": "^5.1.0",
  "drizzle-orm": "^0.44.0",
  "stripe": "^18.0.0",
  "react": "^19.1.0"
}

The caret (^) in front of each version allows later versions. "^5.1.0" means "version 5.1.0 or any later version 5." For a version that starts with 0, such as Drizzle's, the caret is stricter: "^0.44.0" allows only fixes within 0.44. So two installs a month apart can get different code. Usually the difference is harmless. Once in a while a later version changes behavior, and an app that worked yesterday fails today with no change to its own code.

Each dependency is also a choice about trust, which Chapter 16 covers. For now, before the agent adds a package, ask what it's for and whether the app could do without it.

Lock File

A lock file is a file the package manager writes that records the exact version of every package installed, direct and transitive, so every later install gets the same code. For npm it's package-lock.json. It's machine-written, and you never edit it by hand, but you do commit it to git. The command npm ci installs exactly what the lock file says and fails if package.json and the lock file disagree. Most hosts run it, or something like it, on every deploy.

When an install fails with a tangle of version errors, an agent will sometimes delete the lock file and node_modules and install again. That often makes the error go away. It also quietly upgrades every package to the newest version package.json allows that day. Treat deleting the lock file as a one-way door: ask what will change before it happens.

Tell your agent

"Show me our direct dependencies from package.json with one line each on what we use them for. Flag any we don't seem to use. Confirm package-lock.json is committed to git. From now on, don't add a new package or delete the lock file without asking me first."

Where the Photos Go: File Storage Buckets

A database is good at rows of short facts: a member's ID, a scan's date, a check's status. Large files such as photos and voice clips make it slow and expensive to back up, so apps keep them somewhere else.

A file storage bucket is a container in a cloud storage service that holds files, each saved under a name called a key, and serves them back when asked. Amazon S3 started the idea in 2006, and Cloudflare R2, Google Cloud Storage and Supabase Storage work the same way. Keys with slashes in them look like folders, such as scans/8812/photo-1.jpg.

When a member of the dating-safety app uploads three photos of a match and a voice clip, here is what happens:

  1. The server receives the files from the browser.
  2. It saves each file in the bucket under a key that includes the scan's ID.
  3. It saves a row in the database for the scan, with the keys of its files, but not the files themselves.
  4. When a check needs a photo, the server reads the key from the database and fetches the file from the bucket.

That split creates two places that have to agree. If a scan is deleted from the database but its photos stay in the bucket, the photos are orphaned. They are still stored and still cost money, but no record ties them to the member they belong to. For private photos, that is a privacy problem as well as a cost. The dating-safety app runs a regular sweep that finds files with no matching scan, a scheduled job of the kind covered below.

Whether a bucket is public or private is a must-be-right setting. A public bucket serves any file to anyone who knows or guesses its key. The dating-safety app keeps its bucket private, and members reach their photos only through short-lived links, which Chapter 8 explains.

Tell your agent

"Find every place the app saves or reads a file. Tell me which storage service and bucket it uses, whether the bucket is public or private, how file keys are named, and what happens to the files when the record they belong to is deleted."

Work That Happens Off to the Side

Background Job

Chapter 2's request and response works when the answer takes a fraction of a second. The dating-safety app's eight checks against outside services can take far longer, and a browser that waits that long on a single request may give up.

A background job is work the server does outside the request and response, so it can reply right away and finish the job afterward. The request starts the job, the job runs on its own, and the browser checks back later. Here is one scan, step by step.

Time What happens Which part does it
0.0 s Member taps Scan. Browser sends POST /api/scans with the photos React front end
0.4 s Server saves the photos to the bucket and a scan row with status "running" Express route
0.5 s Server starts the scan's background job and replies 202 with the scan ID Express route
0.5 s Browser shows "Checking..." and asks for the scan's status every few seconds React front end
0.5 to 40 s The job runs the eight checks in parallel and records each result as pass, fail or not checked Background job
40 s The job computes the trust score and sets the scan to "done" Background job
41 s The next status request gets the finished scan, and the browser shows the results Express route, React front end

These timings are illustrative, but most AI-built apps work this way. The 202 status in the Express example is the moment the work moves into the background.

The Claim Ticket

Sawyer thinking it over Think of the claim ticket at a repair shop. The counter takes your car and hands you a ticket right away, and the work happens in the back while you wait for a call. The 202 is that ticket, and the background job is the mechanic in the back.

Background jobs bring three questions that a plain request doesn't.

  • What if the job dies halfway? A job running inside the web server stops when the server restarts, and servers restart on every deploy. In the dating-safety app, a deploy could end scans in progress. Chapter 14 covers protecting work in flight.
  • What if the job fails? Nobody is watching the screen when a background job breaks. If the failure isn't recorded, the scan stays "running" forever, or finishes with checks quietly missing. Chapter 12 covers noticing this.
  • What if the job runs twice? Retries and restarts can start a job a second time. A job that sends a text or charges a card must be safe to run twice. Chapter 9 covers retries.

Simple apps run background jobs inside the same running program as the web server. Larger ones hand them to a job queue, a list of jobs that a separate worker program takes one at a time and can pick up again after a restart. Either can be good enough for now, as long as you know which one you have. Step through one scan in the diagram below.

Diagram: One Scan, Step by Step

Run the One Scan, Step by Step MicroSim Fullscreen

One Scan, Step by Step

Type: microsim sim-id: one-scan-step-by-step
Library: p5.js
Status: Specified
Bloom Level: Understand
Bloom Verb: explain
Learning Objective: The learner will explain which part of the app does the work at each of seven steps of one scan, and why the server replies before the checks finish, with at least six of seven predictions correct.

Prerequisites: React front end, Express route, file storage bucket, database row, background job, status code 202 (all defined in the chapter above or in Chapter 2).

Evidence of Mastery: Before each step is revealed, the learner predicts which part does it by choosing one of four parts: React front end, Express route, Background job, Storage bucket. A prediction is correct when it matches the "Part" column in Content. Mastery is 6 of 7 correct. At the end, the learner answers one multiple-choice question about why the server replies early; the correct choice is marked in Content.

Misconceptions: (1) The browser waits on one request until all the checks finish. (2) The photos are stored in the database. (3) If the browser shows "Checking...", something must be watching for failures. (4) A background job keeps running through a deploy.

Instructional Rationale: Stepping through with a prediction at each step makes the learner place each piece of work in a part before seeing it, which is the explanation the objective asks for. Showing the timeline with concrete times keeps the long gap between 0.5 s and 40 s visible, which is why a background job exists.

Content:

The four parts, each with a label and a one-line definition shown on click:

  • React front end: the screens in the member's browser.
  • Express route: the server code that answers one URL.
  • Background job: work the server does after it has replied.
  • Storage bucket: where photos and voice clips are kept.

The seven steps:

# Time Step shown after the prediction Part (correct answer) Why (feedback)
1 0.0 s Member taps Scan; the browser sends POST /api/scans with three photos React front end The button and the request start in the browser.
2 0.4 s The three photos are saved under keys like scans/8812/photo-1.jpg Storage bucket Large files go to the bucket; the database keeps only their keys.
3 0.5 s The server replies 202 with scan ID 8812 Express route The route answers right away so the browser isn't left waiting.
4 0.5 s The screen shows "Checking..." and asks for the status every 3 seconds React front end The browser checks back instead of holding one long request open.
5 0.5 to 40 s Eight checks run in parallel; each records pass, fail or not checked Background job This is the slow work, done after the reply.
6 40 s The trust score is computed and the scan is set to "done" Background job The job finishes its own work and records the result.
7 41 s The next status request returns the finished scan Express route A route answers the browser's status request with the stored result.

Final question: "Why does the server reply at 0.5 s instead of 40 s?"

  • A. The checks can take far longer than a browser should wait on one request, so the server replies and finishes the work in a background job. (correct)
  • B. Express can only run for half a second.
  • C. The photos haven't been saved yet.
  • D. The browser runs the checks itself.

Provenance: Steps and parts are from the section "Background Job" above. Times, scan ID 8812 and the 3-second status interval are illustrative and must be labeled "illustrative timings."

Rules: Steps advance only after a prediction is committed. Each prediction has one attempt. Score is the count of correct predictions out of 7. A "What if?" toggle after step 7 lets the learner choose "A deploy restarts the server at 20 s"; the sim then shows step 5 stopping at 20 s, the scan stuck at "running", and the note "A job inside the web server ends when the server restarts. See Chapter 14." The toggle is exploration and not scored.

Learner Activity:

  1. The learner sees the timeline with seven empty steps and the four parts.
  2. For step 1, the learner picks a part. The step fills in and the chosen part is marked right or wrong with the Why text.
  3. The learner repeats for steps 2 to 7.
  4. The learner answers the final question.
  5. The learner may turn on the "What if?" toggle to see a deploy interrupt the job.
  6. The learner should notice that steps 3 and 5 overlap in time: the reply goes out while the work has barely started.

Feedback: Correct: "Right. " plus the Why text. Incorrect: "This step is done by the [correct part]. " plus the Why text. Final question, correct: "Yes. The reply is quick and the slow work moves to the background." Incorrect: "Look again at the gap between step 3 and step 6." The summary shows "n of 7 correct", "Mastery reached" at 6 or more, and the final question's result.

Starting State: The empty seven-step timeline from 0 s to 41 s, the four parts, and the prompt "A member just tapped Scan. Which part handles this first?"

Chapter Anchors: About eight checks per scan. The server replies with status 202. The illustrative timings are 0.0 s, 0.4 s, 0.5 s, 40 s and 41 s. Each check records pass, fail or not checked. A job inside the web server ends on restart (Chapter 14).

Tell your agent

"List every piece of work in this app that runs after the server has already replied, or outside any request. For each one, tell me what starts it, whether it runs inside the web server or in a separate worker, what happens if the server restarts while it's running, and where a failure would be recorded."

Scheduled Job

A scheduled job is a background job that runs automatically at set times, such as every night at 3 a.m. or every fifteen minutes. The classic tool is called cron, after a Unix program from the 1970s. Its short code 0 3 * * * means "at minute 0 of hour 3, every day." A dating-safety app of this kind has several jobs that should run on a clock:

  • A nightly sweep for orphaned scans and the photos left behind with them.
  • A daily reset of each member's scan count, which enforces the daily scan cap.
  • A check of the credit balance at each vendor, with an alert when one runs low.
  • A purge of data the app has kept longer than its retention period. At first the dating-safety app didn't have this one. Chapter 8 covers retention.

Scheduled jobs can run in two places. The host can run a command on a schedule; Railway and most other hosts offer this. Or a scheduler library inside the server can start the job itself. A scheduler library is easier to set up. But if the host runs two copies of the server to handle more traffic, each copy runs its own scheduler, and the nightly job runs twice.

A scheduled job runs when no one is looking, so its mistakes can go unseen for a long time. In the dating-safety app, a scheduled sending job used the wrong comparison and marked many messages sent when only one went out. Nothing crashed. Chapter 11 walks through that bug, and Chapter 12 covers how to notice a job that never ran.

Tell your agent

"List every scheduled job in this app. For each one, give its schedule in plain words, where it runs (the host or a scheduler inside the server), what it changes, and what would happen if it ran twice or didn't run for a week. Put the list in docs/scheduled-jobs.md."

Drawing Your App Parts Map

An App Parts Map is a one-page picture and table of an app's parts. For each part it shows the name, the tool it's built with, where it runs, which other parts and outside services it talks to, and what happens if it stops. It's the diagram the mechanic has in his head. With it, you can say "the bug is in the nightly sweep, which reads the bucket and the database" instead of "something is wrong with the photos."

When something breaks, the map tells you and your agent which part to look in. When you ask for a change, it shows which other parts the change could reach. When you hand the app to an engineer, as Chapter 18 describes, it's the first page they'll read.

Here is the map for the dating-safety app, as a table. A few details, such as the daily cap being reset by its own job, are illustrative. A drawn version follows.

Part Built with Runs where Talks to If it stops
Front end React, built by Vite Member's browser Server API Members see a blank or broken page
Server API Express on Node.js, TypeScript Host Database, bucket, Stripe, background jobs Nothing works
Database Postgres through Drizzle Database service Server, jobs Nothing works; data at risk without backups
Photo storage Private storage bucket Storage service Server, jobs Uploads fail; past results can't show photos
Scan job Background job in the server Host Bucket, database, about eight outside services Scans stay "running"; checks must show not checked
Nightly sweep Scheduled job Host Database, bucket Orphaned photos pile up quietly
Daily cap reset Scheduled job Host Database Members can't scan, or can scan without a limit
Payments Stripe, plus a webhook route Stripe and host Server Members can't pay, or pay and get nothing
Outside services AI models, image search, people search, SMS Vendors Scan job, server Checks return not checked

The last column asks Chapter 1's question of every part: what happens to a member if this goes wrong?

Diagram: App Parts Map for the Dating-Safety App

Run the App Parts Map for the Dating-Safety App MicroSim Fullscreen

App Parts Map for the Dating-Safety App

Type: graph-model sim-id: app-parts-map-explorer
Library: vis-network
Status: Specified
Bloom Level: Analyze
Bloom Verb: attribute
Learning Objective: The learner will attribute eight problem reports from a dating-safety app to the part of the App Parts Map most likely to hold the cause, with at least six of eight correct.

Prerequisites: frontend framework, React, build tool, Express, Node.js, file storage bucket, background job, scheduled job, App Parts Map, outside service (all defined in the chapter above or in Chapter 2).

Evidence of Mastery: For each of eight problem reports, the learner clicks the one node on the map they think holds the cause and confirms. A choice is correct when it matches the "Part" column of the problem table in Content. Mastery is 6 of 8 correct on the first attempt. Clicking nodes to read their infoboxes before a problem is shown is exploration, not evidence.

Misconceptions: (1) Any problem a member sees on screen is in the front end. (2) Missing photos means the database lost them. (3) A problem that happens overnight must be in the server API. (4) Outside services never cause a wrong-looking result.

Instructional Rationale: Attributing a symptom to a part makes the learner follow the edges of the map from what the member sees back to where the work is done, which is the analysis an App Parts Map exists to support. Each report is phrased the way a member or builder would describe it, not in terms of parts.

Content:

Nodes (label, then infobox text shown on click):

Node Infobox
Member's browser Where the member uses the app. Runs the React front end.
React front end The screens, built by Vite into files the browser loads. Holds no secrets.
Express server API Routes that answer the browser, running on Node.js and written in TypeScript.
Postgres database Rows for members, scans and check results. Holds the keys of photos, not the photos.
Storage bucket Private store for photos and voice clips, saved under keys like scans/8812/photo-1.jpg.
Scan job Background job that runs about eight checks for each scan and computes the trust score.
Nightly sweep Scheduled job that removes scans and photos with no owner.
Daily cap reset Scheduled job that resets each member's scan count.
Stripe Outside service that takes payments and calls a webhook route on the server.
Outside check services AI models, image search, people search and SMS vendors called by the scan job.

Edges (from, to, label shown on hover):

From To Label
Member's browser React front end loads
React front end Express server API sends requests
Express server API Postgres database reads and writes rows
Express server API Storage bucket saves and reads files
Express server API Scan job starts
Express server API Stripe creates payments
Stripe Express server API sends webhook
Scan job Storage bucket reads photos
Scan job Outside check services calls
Scan job Postgres database writes results
Nightly sweep Postgres database finds orphaned scans
Nightly sweep Storage bucket deletes orphaned files
Daily cap reset Postgres database resets counts

Problem reports:

# Report shown to the learner Part (correct answer) Why (feedback)
1 "My scan has said Checking... for an hour." Scan job The route replied long ago; the job that finishes the scan stopped or failed.
2 "The trust score circle overlaps the text on my phone." React front end Layout is drawn in the browser by the front end.
3 "My old scan's photos show as broken images, but the scan details are there." Storage bucket The database row survived; the files it points to are missing or unreachable.
4 "Storage costs keep rising even though members delete scans." Nightly sweep Deleted scans are leaving files behind, which the sweep should remove.
5 "Since midnight, every member gets 'daily limit reached' on their first scan." Daily cap reset The counts weren't reset at the start of the day.
6 "Every scan this morning shows reverse image search as not checked." Outside check services One vendor is failing; the scan job is correctly reporting not checked.
7 "I paid, but my account still says free." Stripe The payment's webhook to the server didn't arrive or wasn't handled; start where the payment event comes from.
8 "Every page returns an error, including sign-in." Express server API Every request goes through the server; when all of them fail, start there.

Provenance: Parts and edges are from the section "Drawing Your App Parts Map" and the dating-safety app in research/seed-notes.md (React and Vite, Express, Postgres through Drizzle, private bucket, Stripe, about eight checks, not checked, sweep for orphaned scans, daily scan cap). Problem reports are illustrative and must be labeled "illustrative."

Rules: Each report has exactly one correct node. For report 7, the node Express server API is also accepted as correct, with the feedback "Also reasonable: the webhook route is on the server. Stripe's dashboard is the first place to confirm the event was sent." All other nodes are incorrect for report 7. Score counts correct first choices out of 8.

Learner Activity:

  1. The learner sees the map with all ten nodes and thirteen edges and can click any node to read its infobox.
  2. The learner presses Start. Report 1 appears.
  3. The learner clicks a node and presses Confirm. The chosen node is marked right or wrong and the Why text appears. The correct node is highlighted along with its edges.
  4. The learner repeats for reports 2 to 8.
  5. The learner should notice that only one of the eight reports lands on the front end, even though members see every one of them on screen.

Feedback: Eight reports in the order listed, one attempt each. Correct: "Right. " plus the Why text. Incorrect: "Look at [correct node]. " plus the Why text. The summary shows "n of 8 correct", "Mastery reached" at 6 or more, and the line "Seven of these eight problems showed up on screen, and only one was caused there."

Starting State: The full map, no node selected, and the prompt "Click any part to see what it does. Press Start when you're ready to find where problems come from."

Chapter Anchors: About eight outside checks per scan. Parts named in the chapter's map table: front end, server API, database, photo storage, scan job, nightly sweep, daily cap reset, payments, outside services. The bucket is private.

Making Your Own

Your agent can read the codebase for you, and your job is to check that the answer makes sense. Ask in two steps, so you can correct the list of parts before the agent draws anything.

Tell your agent

"Read this whole codebase and draft an App Parts Map. First, just list the parts: the front-end framework and build tool, the server framework, the Node.js version, the language, the package manager, the database, every storage bucket, every background job, every scheduled job, and every outside service we call. For each part, give the file or folder where it lives. Don't guess. If you can't find where something is set up, say so."

Then read the list. Does it include everything you know the app does? Is there a part you've never heard of? An unfamiliar part is worth asking about. Either the agent added something you didn't know about, or it misread something. When the list looks right, ask for the map itself. Mermaid, in the prompt below, is a way of writing a diagram as text that GitHub and most editors draw as a picture.

Tell your agent

"Now write docs/app-parts-map.md. Include a Mermaid diagram showing each part and what it talks to, and a table with these columns: part, built with, runs where, talks to, and what happens to a member if it stops. Say whether each storage bucket is public or private, and give the version where it matters, such as Node.js. Mark the parts that handle members' private data, money or sign-in. Add a line at the top with today's date, and update this file whenever we add or remove a part."

Before you call the map done, check that every background job, scheduled job and outside service is on it. The "if it stops" column should say what a member would notice. Keep the map in the repository next to the code, so the agent reads it at the start of a session. Chapter 15 covers keeping documents like this one matched to the code.

Back to the Phone Call

Neither driver could fix a car. She knew the names of the parts and roughly what each one does. That was enough to describe the noise, understand the price, and notice when an answer didn't fit.

Your App Parts Map does the same for you when you talk to your agent. Chapter 4 turns to the agent itself: how it works, why it sometimes drifts, and how to keep it on track.

You Opened the Hood

Sawyer celebrating You just named the parts under your app: the front end, the server, the runtime, the packages, the bucket, and the jobs that run when no one is watching. With your App Parts Map in the repository, you can tell your agent which part the noise is coming from.

Key Takeaways

  • Keep secrets and the rules that protect members on the server. Anyone can read what runs in React, including every VITE_ setting.
  • Write the Node.js version down in the project, so your laptop and your host run the same one.
  • Vite doesn't check types. Run type checking with npx tsc --noEmit yourself, and get the count to zero before you make the build fail on it.
  • Commit the lock file, and treat deleting it as a one-way door.
  • Know where each background job and scheduled job runs and where its failures are recorded, because nobody is watching when they fail.
  • Keep an App Parts Map next to the code, with what a member would notice if each part stopped.

See Annotated References