Skip to content

S01 - Spec-Based Development

Purpose: How the design is written down: the kinds of design documents, their IDs, the spec template, how a spec is split into pages, and how packages are named.

Specs are written before the code, and they are authoritative: when code and spec disagree, one of them is fixed in the same change (AGENTS.md). A spec explains why each decision was made, and leaves out how to implement it.

ID Kind Where Index
S<NN>-<slug> Spec docs/spec/ S00-indexS00-index: SpecsEvery spec, in order.
S<NN>-<MM>-<slug> Page of a spec; 00 is its overview docs/spec/S<NN>-<slug>/ S00-indexS00-index: SpecsEvery spec, in order.
C<NN>-<slug> Test cases of one area docs/tests/ C00-indexC00-index: Test casesThe test cases of each area, by test layer: unit tests, fuzz targets, and conformance checks.
FR<NN>-<slug> Functional requirement docs/requirements/ FR00-indexFR00-index: Functional requirementsWhat Wraith Box must do for the user.
NFR<NN>-<slug> Non-functional requirement docs/requirements/ NFR00-indexNFR00-index: Non-functional requirementsHow fast, how small, on which platforms, and how maintainable Wraith Box must be.
SEC<NN>-<slug> Security requirement docs/requirements/ SEC00-indexSEC00-index: Security requirementsThe security controls Wraith Box enforces.
T<NN>-<slug> Threat docs/threats/ T00-indexT00-indexboundary 6 is the host terminal stream.
X<NN>-<slug> Spike docs/spikes/ X00-indexX00-index: SpikesThe open questions that must be answered by a throwaway prototype before work builds on them, in the order they are taken up.
R<NN>-<slug> Research note docs/research/ R00-indexR00-index: Research notesBackground research that informs the design without deciding it: surveys of prior art, measurements, and reading notes.
B<NN>-<slug> Review brief, numbered after its issue docs/briefs/ B00-indexB00-index: Review briefsOne page per decision, spike result or spec change waiting for the maintainer, numbered after the GitHub issue it belongs to.
W<NN>-<slug> Campaign report, numbered after its campaign issue docs/campaigns/ W00-indexW00-index: Campaign reportsOne page per campaign, numbered after its campaign issue: what the campaign put on its train, what it spent, and what waits for the maintainer.
V<N>-<slug> Version docs/versions/ V00-indexV00-index: VersionsThe major versions of Wraith Box, each with the decisions that scope it and the milestones that deliver it.
V<N>-<NN>-<slug> Decision scoping version N its version page
V<N>-M<N>-<slug> Milestone of version N its version page
I<NN> GitHub issue GitHub
PR<NN> GitHub pull request GitHub

A spec that grows past one page of the size limits below becomes a tree. The spec moves into a directory named after it, as the overview, page 00. Its pages go next to it:

docs/spec/S07-egress-gateway/
S07-00-egress-gateway.md the overview
S07-00-egress-gateway.svg its diagram
S07-01-per-vm-policy.md a page
S07-02-packet-path.md
S07-02-packet-path.svg a page's diagram

Specs are read by people, and a page has to be short enough to review in one sitting. These limits are checked by src/plugins/structure.mjs in the docs site:

What Limit
A page 300 lines
A section, from one heading to the next 80 lines
A list two levels deep
A paragraph or list item 120 words
A sentence 40 words
  • A topic a reader might look for gets a heading, ### under ## Design. A bold lead (- **Disks.**) names an item in a list, not a section.
  • One claim per sentence. A sentence that adds a condition, a reason, and an exception becomes three sentences.
  • mise run doc:structure lists where each spec breaks a limit. The docs build fails for the specs in the file’s STRICT list. A spec goes on it once it meets the limits, and doesn’t come off.
  • In another document: the ID, then the section’s name in quotes: S07-egress-gateway, "Packet path". Once that section is a page of its own, write the page’s ID instead: S07-02-packet-path.
  • In the same document: the name in quotes, in parentheses or followed by “below” or “above”: ("Disks"), "Disks" below.
  • A section is a heading, or the bold or italic lead of a list item. The name can be cut at a comma, colon or parenthesis: “Modes” names “Modes, per host”.
  • The docs build fails on a reference to a section that its document doesn’t have (src/plugins/sections.mjs). So a renamed or moved section takes its references with it in the same change.

A spec or page has at most one diagram, at the top, as an SVG file next to it (docs/agents/review-briefs.md, “Diagrams”). It shows the design as decided: the processes, the trust boundaries and the flows that cross them. Red flows are allowed only for what a control stops. A brief’s figure of the chosen option is a good start. Remove the option letters, the figure number, and the state before the decision. Then check the drawing against the spec text. Where they differ, the text is right.

A spec states the design, as something a builder can implement and, later, as what is implemented. Review material goes in the review brief and the issue, never in the spec: what approving commits to, the controls touched, assumptions, and open decisions with their recommendations (docs/agents/review-briefs.md). Where a design relies on a property still to be measured, the spec states the design and the property, and the issue tracks the measurement.

# S<NN> - Feature Name
**Purpose:** One-line description of what this does and why
**Requirements:** The FR, NFR and SEC IDs this spec covers
**Tests:** The C pages with its test cases (S11-verification-and-spikes)
Brief: B<NN>-<slug>, when there is one
![What the diagram shows](https://github.com/wraithbox/wraithbox/blob/main/docs/spec/S<NN>-<slug>.svg)
## Design
What the design is, in the present tense, as a builder needs it.
### A topic
One `###` heading for each topic a reader might look for.
## Decisions
### A decision
What was chosen, in one sentence.
- **Why:** the reasons.
- **Rejected:** each other option, and why.
- **Decided:** the brief or issue, with the date.
## Out of scope
- What a reader could reasonably assume is included, but isn't.
**Status:** [Draft/Approved/Implemented]

Status moves from Draft to Approved when the maintainer merges it, and to Implemented when the code matches it.

The design and its reasons are kept apart. The design then reads as one description, without the history of how it was chosen. “The maintainer decided on I68I68 (closed): wb-proxyd must bind stream identity to the connection, not to wb-netd's tagsFound in the security review of #65 (X23-sandboxed-daemons result). that…” and “X was rejected, because…” go under Decisions. Nothing that was decided is dropped. A decision whose reason is one sentence can stay in the design.

Packages under packages/ are suffixed by language so each toolchain can discover what it owns:

When one feature spans languages, pick one <name> and let the suffix distinguish the implementation.

Status: Implemented