WEEK 7

Design-of-Record

Week 7 · The last document before the code

WEEK 7

Hands up

Ask the room

Who got a Project Pulse reminder this term for something they had already submitted?

WEEK 7

The tutorial recipe

flowchart LR
  S[Specification] --> A[Agent] --> C[Code]
Ask the room

What does your use case not decide?

WEEK 7

Five decisions the use case left open

  • Where is "has not submitted" computed: one shared service, or each feature on its own?
  • Which part of the code owns the scheduler?
  • May the request name the week, or does the server always compute it?
  • Send during the request, or in the background?
  • Keep a log of reminders sent?
WEEK 7

...and the shape of the code

  • Classes: which exist, which are reused.
  • Sequences: who calls whom, in what order.
  • Contract: the endpoints, their inputs, outputs, and errors.
  • Tests: what counts as done.
WEEK 7

Without a design, the agent decides

Key point

You review decisions you did not know were made, after they were built. Ask twice, get two designs.

WEEK 7

The design keeps the why

Key point

The code says what it does. Only the design says why.

WEEK 7

Eraser or sledgehammer

You can use an eraser on the drafting table or a sledgehammer on the construction site.

Attributed to Frank Lloyd Wright, American architect

WEEK 7

Where we are

The documents so far, and where the design-of-record sits

WEEK 7

Two levels of design

Architecture-of-record Design-of-record
Covers The whole system One use case area
Stops at Each component's job What the agent can safely derive
How many One One per area
Written Before any code Before this area's code
WEEK 7

Code review before there is code

  • Written first, approved first. Nobody builds from it before then.
  • Cites, never restates. The use case says what. The design says how.
  • One per area, revised in place. Not a stack of per-use-case sections.
  • Stays true. The code changed? The design changes in the same pull request.

Weeks of coding can save you hours of planning.

WEEK 7

Old idea, new author

Industry: the RFC

A proposal, reviewed and approved before it is built. IETF, Rust, Sourcegraph, Oxide.

Here: the design-of-record

Usually drafted by the agent, after your sketch. Reviewed by you. The review is the skill.

Trace: use case to design-of-record

The design's header names every use case it realizes. The traceability matrix's Design column points back.

WEEK 7

Firm the problem first

Key point

Six things the reminder's use case did not settle.

Finding The fix went to
Two definitions that disagree A new business rule
Scheduler checks the wrong week The amended FR
Emails students who cannot submit The business rule
Which week the WAR covers The use case
Half-finished peer evaluations The business rule
Foundation calls a feature The design
WEEK 7

Row one: two definitions

Where Decides "has not submitted" as
Instructor's WAR page, in the browser No activity that week
Peer evaluation report, on the server Evaluated nobody that week
Ask the room

Two places, two definitions. What could go wrong?

WEEK 7

Both are wrong, differently

  • The WAR page reads the first 200 activities and 100 students. With 77 students filing several each, people who submitted show up as missing.
  • The report counts a student as done after rating one teammate. The back end saves one rating at a time.
Key point

Nobody wrote down the answer.

WEEK 7

Read the right column

Key point

Most of what the challenge loop finds belongs in the specification, not the design.

WEEK 7

Finding the classes

  • Grammatical: nouns are classes, verbs are operations.
  • Domain: start from what the domain already has.
  • Scenario: walk a flow; whatever has no owner is a missing class.
WEEK 7

Walk the reminder: three jobs with no owner

  • Decide who owes what. SubmissionStatusService
  • Send a batch, surviving failures. ReminderService
  • Take the instructor's request. ReminderController

There are two hard things in computer science: cache invalidation and naming things. Project Pulse had two names for one fact, which is both.

WEEK 7

The class diagram: new or reused?

classDiagram
    direction LR
    class ReminderController {
        <<new>>
    }
    class SubmissionStatusService {
        <<new>>
    }
    class ReminderService {
        <<new>>
    }
    class WeeklyReminderScheduler {
        <<moved>>
    }
    class ActivityService {
        <<reused>>
    }
    class EvaluationService {
        <<reused>>
    }
    class EmailService {
        <<reused>>
    }
    class SectionService {
        <<reused>>
    }
    ReminderController --> SubmissionStatusService
    ReminderController --> ReminderService
    WeeklyReminderScheduler --> SectionService
    WeeklyReminderScheduler --> SubmissionStatusService
    WeeklyReminderScheduler --> ReminderService
    SubmissionStatusService --> ActivityService
    SubmissionStatusService --> EvaluationService
    ReminderService --> EmailService
WEEK 7

Reading a sequence diagram

Notation Means
Solid arrow A call; the caller waits
Dashed arrow A return
alt / else Exactly one branch happens
opt Happens only if its condition holds
loop Repetition
Key point

The rule this course adds: label each interaction with the use case step it implements.

WEEK 7

The reminder, step by step

sequenceDiagram
    actor I as Instructor
    participant RC as ReminderController
    participant SS as SubmissionStatusService
    participant RS as ReminderService
    participant EM as EmailService
    I->>RC: choose the item (steps 1 to 3)
    RC->>SS: who owes it, previous week
    SS-->>RC: students who owe it
    RC-->>I: list by team, and weekActive (step 4)
    alt week inactive (4a)
        Note over I: "Only for an active week", no send button
    else week active
        I->>RC: confirm (step 5)
        RC->>RS: remind them
        loop each student (step 6)
            RS->>EM: send
        end
        RS-->>RC: sent, and who failed
        RC-->>I: sent, and who failed (step 7)
    end
WEEK 7

When to draw a state diagram

Most objects do not need one.

Draw it where the lifecycle is where the bugs live.

stateDiagram-v2
    direction LR
    [*] --> Editable: submit
    Editable --> Editable: edit
    Editable --> ReadOnly: week ends
WEEK 7

Two sessions, one contract

Session A builds the browser side.

Session B builds the server side.

Ask the room

They never see each other's code. What do they both read?

WEEK 7

A contract row

Endpoint POST /sections/{sectionId}/reminders
Who may The course section's instructor, or the course admin
Request the item only
Success 200: number sent, who failed
Errors 403 anyone else; 400 week inactive (4a)
WEEK 7

Three things to notice

  • Every extension has an error. Or someone invents one.
  • A scheduled job is a contract too. It has a trigger and a promise.
  • What is left out is a decision. No week in the request.
Ask the room

Why does the request not carry the week?

WEEK 7

Decisions name what they rejected

Where "has not submitted" lives. One service, used by the scheduler, the reminder, and both reports. Rejected: each page computing its own list. Rejected: the report calling the new service, which makes a cycle.

WEEK 7

A pattern no requirement needs

Pitfall

Gold-plating. Ask what problem it solves in this area.

When all you have is the Gang of Four, everything looks like an AbstractSingletonProxyFactoryBean. (That is a real Spring class.)

WEEK 7

The data model change

Show only what this area adds: tables, columns, the migration.

Link the domain model; never redraw it.

The reminder adds nothing.

Rejected: a reminder log. A table, a migration, and seed data, to guard a double send the confirmation and a disabled Confirm button already guard.

Key point

"No change", with a reason, is a decision. A blank section is not.

WEEK 7

The test list, before the code

Flow Asserts
Main, peer evaluation Rated two of three: reminded. Rated all: not.
4a Week inactive: 400, no email
6a One failed send stops nothing
Last active week Its reminder still goes out
WEEK 7

When the design finds the map wrong

  • The scheduler lived in the shared foundation.
  • Deciding who owes needs the activity and evaluation features.
  • The foundation may not depend on a feature.
  • So: a new notification feature slice.
Key point

Change the architecture in the same pull request. Two maps, and the agent follows whichever it reads last.

WEEK 7

The questions test, one level down

  • A fresh session, in plan mode.
  • Give it only the use case, its rules, your crosscutting concepts, and the design.
  • Ask what it would still have to guess.
  • Each guess: fix the design, or say why a wrong guess breaks nothing.
Key point

Ready when nothing on the list could break a requirement.

WEEK 7

What it found on not.md

Found Answer
3 contradictions in the design All fixed
7 guesses worth pinning Fixed: 6 in the design, 1 in the spec
9 guesses that break nothing Kept, each with a reason
The agent

The author reads what they meant. A fresh reader reads what is on the page.

WEEK 7

Sketch first

  • You sketch the sequence and the contract. Twenty minutes.
  • The agent drafts from the template, in plan mode.
  • Compare. Decide which is right, and why.
  • Questions test, then the pull request.
The agent

It found what you missed: it goes in. You knew what it could not: fix the specification too.

WEEK 7

When the agent asks

Yours, or already in the spec

Check the use case and its rules. Then answer.

The client's

Do not pick. Fix the use case, or OPEN-ISSUES.md.

The agent

The options are its guesses. Read every one; Other is always there.

WEEK 7

The design gate

  • The design, the specification fixes, and any architecture change: one pull request.
  • The questions-test list in its description.
  • Approved by a teammate who did not write it.
  • No implementation branch until it merges.
WEEK 7

LGTM

LGTM: Let's Gamble, Trust Me.

Pitfall

A long, polished, agent-drafted design invites approval on sight.

WEEK 7

Review it with questions

  • Does every extension have a branch or a test row?
  • Does every interaction name a use case step?
  • Could two sessions build from the contract alone?
  • Does every decision name what it rejected?
  • Does anything disagree with the architecture?
  • Is every questions-test item answered?
WEEK 7

Review this

Ask the room

A design's sequence diagram has an arrow "send analytics event". No use case step mentions analytics. What do you write in the review?

WEEK 7

The proving slice

Key point

Build one use case all the way through, from the screen to the database, before building the rest. Its job is to test the architecture.

WEEK 7

Pick it by risk

Good slice

Touches the external system you are least sure of, crosses the trust boundary, or carries your hardest quality attribute.

Bad slice

The login page. A list screen. Nothing your architecture was unsure of.

The first 90 percent of the code takes the first 90 percent of the time. The remaining 10 percent takes the other 90 percent. Build the risky 10 percent first.

WEEK 7

Before week 8

  • Copy design-of-record.md to docs/design/ for your slice's area.
  • Sketch, agent draft, compare, questions test.
  • Pull request, approved by a teammate who did not write it.
  • Merged by the date on the schedule.
  • Week 8, in your team meeting: it becomes your agent's build-context.
  • Weeks 8 and 9: the agent builds it.
  • Checkpoint 2: it runs. Not described. Runs.
WEEK 7

Leave with this

Key point

What the design leaves open, the agent decides. Decide it first, and get someone else to check.

Design-of-Record

→ space PgDn
Next step or slide
← PgUp
Back
↓ S
Skip to the next slide
O
Overview of all slides
N
Speaker notes
B
Black the screen
Ctrl+P
Print / PDF handout, one slide per page