octobot/skills/engineering/bdd/deep-modules-r.md
Lukasz Boryn feb12b1586 feat(skills): port codebase-design vocabulary skill from upstream
Adds engineering/codebase-design/ — shared vocabulary for designing deep
modules (module, interface, seam, adapter, depth, leverage, locality).
Three files: SKILL.md (glossary + principles + R+Py testability examples +
rejected framings); DEEPENING.md (4 dependency categories, seam discipline,
replace-don't-layer); DESIGN-IT-TWICE.md (parallel sub-agent pattern for
exploring 3+ radically different interface designs).

Retargets existing bdd siblings as language-flavored leaves:
- bdd/SKILL.md gains a Vocabulary anchor pointing at codebase-design
- interface-design-{r,py}.md and deep-modules-r.md get "vocab lives
  upstream" headers; "deep modules" mention dropped from the py
  interface-design description (codebase-design owns it now)
- mocking-{r,py}.md swap "boundary" -> "seam" throughout — upstream
  rejects "boundary" as overloaded with DDD's bounded context
- refactoring-r.md cross-links Shallow-modules to DEEPENING.md

Cross-references added in sieve/SKILL.md (Minimal invokes depth),
winnow/SKILL.md (deletion test formalised there), diagnose/SKILL.md
(seam definition for Phase 5's "no correct seam" finding),
domain-modeling/SKILL.md (sibling — vocabulary for solution structure
vs problem domain). README gains a codebase-design bullet.

Source: mattpocock/skills@main engineering/codebase-design/. R+Py
testability examples replace upstream TS originals.
2026-06-19 00:37:37 +02:00

76 lines
2.3 KiB
Markdown

# Deep modules in R
Vocabulary and principles in [`../codebase-design/SKILL.md`](../codebase-design/SKILL.md).
This file shows what deep / shallow look like with `box::use` — the R lever
for controlling the interface.
In R you control the interface with `box::use` (or NAMESPACE/`@export` in a
package). The interface is whatever a caller writes after `box::use(...)`.
## Shallow — bad
```r
# R/modb/client.R — exports eight thin helpers
box::export(
build_url, build_headers, parse_token, refresh_token,
page_request, paged_collect, validate_dataset_id, query_dataset
)
```
A caller writes:
```r
box::use(R/modb/client[
build_url, build_headers, parse_token, refresh_token,
page_request, paged_collect, validate_dataset_id, query_dataset
])
tok <- refresh_token(parse_token(Sys.getenv("MODB_TOKEN")))
url <- build_url("DS001")
hdr <- build_headers(tok)
rows <- paged_collect(page_request(url, hdr))
```
Every refactor that splits, renames, or merges a helper breaks every caller
and every test. The tests reach into internals because the internals *are*
the interface.
## Deep — good
```r
# R/modb/client.R — one exported entry point, everything else internal
box::export(query_dataset)
```
A caller writes:
```r
box::use(R/modb/client[query_dataset])
rows <- query_dataset("DS001")
```
`query_dataset()` handles tokens, paging, retries, and validation
internally. Tests target the contract ("returns a tibble of expected rows
for DS001"; "raises `modb_auth_error` on bad token"). Internal helpers can
be renamed or replaced freely.
## Design questions before exporting
For every name you are about to `box::export()` or `@export`:
1. **Does a caller need this?** If only other internals call it, keep it
unexported.
2. **Could two of these collapse?** `build_url` + `build_headers` may want
to become an internal `prepare_request()`.
3. **Could a parameter swallow a helper?** A `paginate = TRUE` argument on
`query_dataset()` can remove `page_request` + `paged_collect` from the
surface.
4. **Is this a leaky abstraction?** Returning a `httr2::request` object
forces every caller (and test) to know `httr2`. Return a tibble or a
typed result instead.
## Heuristic
If the count of exports from a module changes every PR, the module is
shallow. Deep modules export one or two names and stay stable for months.