Your map’s trace from the last exercise follows one Small Maps order through nine steps, from the staff desk’s handler to Saved order-2. It tells you the order things run in. Grace’s requests ask something different: “Can this be changed?” To answer, you need to know which part of the shop owns the thing she wants changed.
In this lesson, you’ll turn the files your trace passed through into a system map of the shop. It names each module’s job, which modules it calls, and where the shop meets the outside world. Then you’ll use it to say where a change belongs. Start by regrouping your trace by who does what.
Give Each Module One Job
A trace lists steps in the order they run, but a request names a thing, such as the email’s wording or a shelf count. So you need a second view of the same files, grouped by the part of the shop that does each step.
The shop’s package.json sets "type": "module", so Node.js treats each of its .js files as a module. The shop groups them into folders under src/, one per part of the shop, such as src/stock/. On your map, each folder is one module of the shop.
Step 4 of your trace, createOrder(), does most of the work, and its imports name the modules it uses. Skim lines 1 to 11 of src/orders/create.js:
import { findCustomer } from '../customers/records.js';
import { chooseCode } from '../discounts/policy.js';
import { orderLines } from './catalogue.js';
import { priceOrder } from './pricing.js';
import { reserve, release } from '../stock/reservations.js';
import { payOrder } from '../payments/charges.js';
import { nextId } from '../lib/ids.js';
import { today } from '../lib/dates.js';
import { eventLog } from '../lib/logger.js';
import { queueEmail } from '../email/queue.js';
import { orderMessage } from '../email/templates.js';
Each path that starts with '../' reaches out of orders/ into another folder: customers/, discounts/, stock/, payments/, lib/, and email/. The paths on lines 3 and 4 start with './', so they stay inside orders/. Line 4 imports priceOrder(), which you read closely. src/orders/pricing.js imports findDiscount() and discountAmount() from src/discounts/codes.js.
Now start a new entry in your map, ## The shop's modules, with one line per module. For each one, write its job in a few words and the function from your trace that shows it doing that job. The folder list at the end of docs/FIRST-HOUR.md is a useful first guess.
Folder names are a first guess too. src/email/ sounds as if it writes the email files, but queueEmail() only adds the message to state.emails. Your trace’s step 7, flushOutbox() in src/storage/outbox.js, writes it to outbox/. Where a name and a function disagree, the map follows the function.
Write your lines before you compare them with this version: