Capstone: Pila 1.2 · lesson 3 of 9
Ideas in this lesson
Adocs/reminders.md4.3 and 4.5: modules and data
Bdocs/adr/0002-….md4.9: a decision record
CThreat model4.7 and 9.2: what could go wrong, and for whom

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:

How the reference does it 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/`.
How the reference does it 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.

Vaccination reminders: designKept in this browser only
  • 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)
Write each part until its checks pass.

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:

ADR 2Kept in this browser only
  • 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)
Write each part until its checks pass.

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.

Threat modelKept in this browser only
  • 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)
Write each part until its checks pass.

Here's the whole of the reference's design for the feature, threat model included:

How the reference does it 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

Why send reminders through the gateway Pila already has?
Which threat is the reason the text has no names?

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.

All sources for Simple Software Development