Design
Last updated
You're the designer. Before any code, decide how the reminders fit into Pila: which modules change, what data is kept and for how long, one decision worth writing down, and what could go wrong for the mothers whose phones and babies' vaccines Pila will now know about. In this lesson you'll add a design for the feature to Pila's docs, write a decision record, and threat-model the feature.
By the end of this lesson you can
- Extend a design document with a feature’s modules and data
- Record one design decision, with the options and consequences
- Threat-model a feature that handles health information
Read the design so far
Pila's design document is short, which is how small teams keep one up to date. Read it, and its one decision record, before adding to them:
docs/design.md# Pila: design ## What it's for Patients of the barangay health centres get a queue number by text message, so they no longer wait outside from before dawn. Health workers call numbers from the counter. ## Users - **Patients**, on any phone that can send a text. Many are older, and some share a phone with their family. - **Health workers**, at the counter, on a tablet or computer. ## Parts ``` phone --text--> SMS provider (Tulay) --> sms.handle() --> Queue | phone <--reply-- SMS provider <-- gateway.send() ``` - `sms.handle()` reads the text and decides what it asks for. - `Queue` holds the rules: opening hours, one number per phone, the daily limit. - The gateway is passed in to `handle()`, so tests and the demo can use a fake one (see `adr/0001-pass-the-gateway-in.md`). - `jobs.py` says when the scheduled jobs run. ## Data | What | Kept for | Why | |---|---|---| | Phone number and its queue number | The day | To give the same phone the same number, and to call it | Nothing else about patients is stored. ## Decisions See `docs/adr/`.
docs/adr/0001-pass-the-gateway-in.md# 1. Pass the SMS gateway in Status: accepted ## Context Pila sends every reply through an SMS provider. Tests must not send real texts, and the provider may change. ## Decision `sms.handle()` takes the gateway as an argument. The only thing it uses is `gateway.send(phone, text)`. Tests pass a `FakeGateway`, the demo passes a `PrintGateway`, and production passes a `TulayGateway`. ## Consequences - Tests run without a network and without sending texts. - Changing provider means writing one new gateway class (this happened in 1.1.0). - Every caller of `handle()` has to supply a gateway.
Design the feature
Write the feature's design (lessons 4.3 and 4.5). Then save it in your repository as docs/reminders.md, using the download button, or by copying it into the file.
- A new module for reminders (not yet)
- Sent through the existing gateway (not yet)
- Says what runs it, and when (not yet)
- Says how STOP reaches it (not yet)
- The phone number (not yet)
- The vaccine and its date (not yet)
- How long it’s kept (not yet)
- No names, addresses or birthdays (done)
One decision, written down
Choose one decision the feature needs, and record it as docs/adr/0002-….md, in the same format as ADR 1 (lesson 4.9). The reference recorded how STOP reaches the reminders:
- Says what the problem is (not yet)
- At least two options (not yet)
- Names the choice (not yet)
- Gives a reason (not yet)
- At least one good and one bad (not yet)
Threat-model it
The reminders make Pila hold health information about babies (lesson 9.2), so think through what could go wrong before building it (lesson 4.7). Add the result to docs/reminders.md.
- At least three threats (not yet)
- A shared phone, or someone else reading the text (not yet)
- Someone stopping another person’s reminders, or a wrong number (not yet)
- A leak or breach (not yet)
- Says what the design does (not yet)
Here's the whole of the reference's design for the feature, threat model included:
docs/reminders.md# Vaccination reminders: design ## What changes ``` health worker --enters reminder--> ReminderBook nightly job (Mon-Fri) --> send_due() --> gateway.send() --> mother's phone mother --texts STOP--> sms.handle() --> ReminderBook.stop() ``` - `pila/reminders.py` (new): `Reminder`, `ReminderBook`, `send_due()`. - `pila/sms.py`: `handle()` takes the book, and answers STOP. - The reminder job uses `jobs.runs_on()`, like the other scheduled jobs. ## Data | What | Kept for | Why | |---|---|---| | Phone number | Until 30 days after the vaccine | To send the reminder | | Vaccine and due date | Until 30 days after the vaccine | What the reminder says | | Health centre | Until 30 days after the vaccine | Where the reminder says to go | | Phones that texted STOP | Until the mother asks to start again | So they get nothing | No names, addresses or birthdays: the reminder doesn't need them. ## Threat model | What could go wrong | How bad | What the design does | |---|---|---| | A text on a shared family phone shows a baby's vaccine to others | Minor to moderate | No names in the text, only the vaccine, day and centre | | Someone texts STOP from another phone to stop a mother's reminders | Minor | STOP only stops reminders to the phone it came from | | The database is leaked | Serious | Only the fields above; deleted after 30 days; access limited to each centre's staff | | Reminders go to the wrong phone after a typing mistake | Moderate | The health worker reads the number back to the mother before saving | ## Decisions See `adr/0002-remind-on-the-last-job-day-before.md`.
Commit your design documents on main: they're the plan the next lessons build to.
Check your design
Sources
Every claim on this page comes from these sources: the standard, the founding text of a method, a study, or the official record of a project, from the body that publishes it. Industry reports are labelled as such.
- Architectural Decision Records (adr.github.io): templates and examples of decision records
- Michael Nygard: Documenting Architecture Decisions (Cognitect, 2011): the short decision-record format Pila uses
- OWASP: Threat Modeling Cheat Sheet: what to ask, and how to record it
- National Privacy Commission: Privacy Impact Assessment (NPC Advisory 2017-03): the privacy questions to ask of a new feature