---
title: "Bun"
description: One folder, one bounded context, in Bun.
source: bun.dh.md
---
<!-- Made by dh llm from the source; nobody edits this file. -->

# Bun

**Possible, a medium change.** A context is one workspace package plus a small contract package.

## The files

```filetree
package.json  # workspaces: contexts/* and contexts/*/contract
src/
  index.ts  # api, worker, migrate
  kernel/
  generated/
    contexts.ts  (generated)  # not committed
tools/
  gen.ts  # finds the folders
  boundaries.ts  # guards layers and contexts
contexts/
  orders/
    context.yaml
    package.json
    contract/
      v1/
    src/
      register.ts
      api/
        v1/
      mcp/
      domain/
      data/
    policies.yaml
    flags.yaml
    config/
    observability/
    docs/
    tests/
      unit/
      integration/
      sit/
```

## What the tools allow

| Question | Answer | Tag |
| --- | --- | --- |
| Tests inside, with SIT | yes: 37 pass | MEASURED |
| A planted failing test | fails | MEASURED |
| Tests or docs in the Docker image | 0 found | MEASURED |
| Restart after an edit | 254 ms | MEASURED |
| Restart after a test edit | none | MEASURED |

## Adding a context

```terminal
$ scripts/new-context.sh third
$ git status --short
?? contexts/third/
$ bun install
Checked 38 installs across 85 packages (no changes) [16.00ms]
$ git status --short
 M bun.lock
?? contexts/third/
```

## What changes in the template

| Change | Count | Tag |
| --- | --- | --- |
| Files moved, consumer template | 42 of 409 | MEASURED |
| Root configs edited | 6 | MEASURED |
| Package files per context | 2 | MEASURED |
| New kernel and tool code | 1,693 lines | MEASURED |

## What does not work cleanly

- Two new contexts conflict in `bun.lock`, one hunk. `bun install` fixes it. MEASURED
- `merge=union` on that file is unsafe: the frozen install then fails. MEASURED
- No linter keeps IO out of the domain, so a 150-line checker does. MEASURED
