Sub topic 2
Capturing Design Decisions Before Code
Assume you know basic software development, Git, automated tests, and how to use a coding agent. This chapter shows how to turn accepted requirements into a design, tasks, and executable checks before implementation begins.
Capture the design
A design records decisions that requirements do not answer. It should explain the main components, data flow, state changes, failure behavior, and important security choices. Keep it short, but make decisions explicit.
For a password reset feature, the design might state:
| Decision | Choice |
|---|---|
| Token storage | Store a hashed token, issue time, and used status |
| Expiration | Reject tokens older than 30 minutes |
| Reuse | Mark a token used during successful redemption |
| Privacy | Return the same response for known and unknown emails |
Break the design into tasks
Each task should produce a small, reviewable result. Order tasks by dependency, and link each task to the requirement it satisfies. Include verification in the task rather than leaving testing until the end.
- Add a token store with issue time and used status. Covers criteria 1 and 3.
- Implement redemption checks for unknown, expired, and used tokens. Add tests first.
- Add the reset-request endpoint. Verify identical responses for known and unknown emails.
A coding agent can complete one task, run its checks, and stop at a review gate. This limits the cost of a wrong assumption.
Turn criteria into tests
Translate observable acceptance criteria into tests. Use controlled times instead of the system clock so the test is repeatable.
from datetime import datetime, timedelta, timezone
TTL = timedelta(minutes=30)
class TokenError(Exception):
pass
def redeem(issued_at, used, now):
if used or issued_at is None or now - issued_at > TTL:
raise TokenError("invalid token")
return True
start = datetime(2026, 1, 1, tzinfo=timezone.utc)
assert redeem(start, False, start + timedelta(minutes=29))
try:
redeem(start, False, start + timedelta(minutes=31))
except TokenError:
pass
else:
raise AssertionError("expired token was accepted")The test checks the requirement, while the task tells the agent where and how to implement it. Reviewers can compare both against the specification.
Exercise
What should you record when a requirement leaves multiple valid implementations?
Show answer
Record the chosen design, its reason, and the behavior or constraint that the choice protects.