domaintrail 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.ja.md +303 -0
- package/CHANGELOG.md +304 -0
- package/README.md +65 -170
- package/dist/dt.js +4457 -2630
- package/dist/web/chunk-4bbfrcw1.css +1 -0
- package/dist/web/{chunk-g3azafq4.js → chunk-64rawkq2.js} +108 -108
- package/dist/web/index.html +1 -1
- package/package.json +14 -3
- package/schema/diagnostics.schema.json +5 -0
- package/schema/domaintrail.schema.json +32 -7
- package/dist/web/chunk-cgxb04qn.css +0 -1
package/README.md
CHANGED
|
@@ -1,198 +1,93 @@
|
|
|
1
1
|
# DomainTrail
|
|
2
2
|
|
|
3
3
|
A type-checkable domain modeling DSL shared by humans and AI.
|
|
4
|
-
AI agents edit `.dt` files; humans watch the model update live in the browser and give feedback.
|
|
5
|
-
The DSL is the single source of truth for domain **structure and contracts** — it generates TypeScript types, command
|
|
6
|
-
contracts, checks of the invariants and requirements it states, and contract tests for your implementation, never
|
|
7
|
-
business logic.
|
|
8
4
|
|
|
9
|
-
|
|
5
|
+
DomainTrail models are `.dt` files that state a domain's **structure and contracts** — bounded contexts, aggregates
|
|
6
|
+
and their states, commands with what they require, change and emit, invariants — and are their single source of truth.
|
|
7
|
+
AI agents write the model and implement it; people watch it update live in the browser and give feedback on the model
|
|
8
|
+
rather than on the code. From the model, `dt` generates TypeScript types, command contracts, checks of the invariants
|
|
9
|
+
and requirements, and contract tests for your implementation — never business logic, which is written against the
|
|
10
|
+
generated types and held to the model by the compiler and the tests.
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
npm install -D domaintrail # then: npx dt <command>
|
|
15
|
-
npx domaintrail <command> # or run it without installing
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## CLI
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
dt guide [topic] # quick reference and topics; one topic (dt guide requires); --all for everything
|
|
22
|
-
dt -r <root> fmt # format .dt files in place in the canonical layout (--check for CI)
|
|
23
|
-
dt -r <root> check # validate syntax, references, types and DDD rules
|
|
24
|
-
dt -r <root> generate ts # generate TypeScript into <root>/generated/domain (--out to change)
|
|
25
|
-
dt -r <root> view # Live View at http://127.0.0.1:4321 (--port, --host); runs until Ctrl+C
|
|
26
|
-
dt lsp # language server over stdio: dt check's diagnostics, definitions, references, hover
|
|
27
|
-
dt -r <root> show <name> # one element resolved: field sets, labels, commands' contracts, who uses it
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
The package installs the same command under two names: `dt` for everyday use and `domaintrail`, its full name, for
|
|
31
|
-
when `dt` clashes with another command or a script should spell it out (CI, for example).
|
|
32
|
-
|
|
33
|
-
`<root>` defaults to the current directory; every `*.dt` file below it (except `node_modules`, `.git`, `.domaintrail`)
|
|
34
|
-
belongs to the workspace. `dt --help` and `dt <command> --help` show the options with examples.
|
|
35
|
-
|
|
36
|
-
`check` prints diagnostics as `file:line:col - error M00X: message` (with a `hint:` line on what to change, when there is
|
|
37
|
-
one) and exits non-zero on errors; `check --format json` prints them as one JSON document (`schema/diagnostics.schema.json`).
|
|
38
|
-
`generate ts` runs `check` first and generates nothing if there are errors.
|
|
12
|
+
## Quick start
|
|
39
13
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
bun run dt -r examples/shop check
|
|
44
|
-
bun run dt -r examples/shop generate ts # then examples/shop/src/order-commands.ts type-checks against it
|
|
45
|
-
(cd examples/shop && bun test) # and passes the generated contract tests
|
|
46
|
-
bun run build && bun run dt -r examples/shop view
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Guide
|
|
50
|
-
|
|
51
|
-
**[docs/guide.md](docs/guide.md)** is the reference for writing models and using the CLI. It starts with a
|
|
52
|
-
[quick reference](docs/guide.md#quick-reference) (the workflow, the DSL at a glance, the commands), and its sections are
|
|
53
|
-
**topics** that the CLI prints one at a time, so people and AI agents read only what they need without leaving the
|
|
54
|
-
terminal:
|
|
14
|
+
Requires Node.js 22.12 or later.
|
|
55
15
|
|
|
56
16
|
```bash
|
|
57
|
-
|
|
58
|
-
dt guide requires # one topic: a ## section with its ### sections, or one ### section
|
|
59
|
-
dt guide M010 # one rule and the topics that explain it
|
|
60
|
-
dt guide --all # the whole guide, the same text as docs/guide.md
|
|
17
|
+
npm i -D domaintrail
|
|
61
18
|
```
|
|
62
19
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
- [Workflow](docs/guide.md#workflow): `fmt` → `check` → `generate ts` → implement with `decide` → type-check your own
|
|
66
|
-
code (`tsc --noEmit`) → run the generated contract tests
|
|
67
|
-
- [File layout (recommended)](docs/guide.md#file-layout-recommended): `<context>/<aggregate>.dt` and
|
|
68
|
-
`<context>/context.dt` (see [ADR 0009](docs/adr/0009-file-layout.md))
|
|
69
|
-
- [DSL](docs/guide.md#dsl): contexts, aggregates, entities, values, states, commands, events, errors,
|
|
70
|
-
[domain primitives](docs/guide.md#domain-primitives), [unions](docs/guide.md#unions),
|
|
71
|
-
[shared contexts](docs/guide.md#shared-contexts), [field sets](docs/guide.md#field-sets),
|
|
72
|
-
[domain and technical fields](docs/guide.md#domain-fields-and-technical-fields),
|
|
73
|
-
[names (表示名)](docs/guide.md#names-labels-and-descriptions),
|
|
74
|
-
[invariant expressions](docs/guide.md#invariant-expressions), [command requirements](docs/guide.md#command-requirements),
|
|
75
|
-
[command changes](docs/guide.md#command-changes), [command events](docs/guide.md#command-events) and
|
|
76
|
-
[pure commands](docs/guide.md#pure-commands)
|
|
77
|
-
- [Generated TypeScript](docs/guide.md#generated-typescript): [decisions and `decide`](docs/guide.md#decisions-and-decide),
|
|
78
|
-
[what is generated and what you write](docs/guide.md#generated-code-and-your-code) (see
|
|
79
|
-
[ADR 0011](docs/adr/0011-generated-code-boundary.md)), [generated checks](docs/guide.md#generated-checks) and
|
|
80
|
-
[generated tests](docs/guide.md#generated-tests) (see [ADR 0020](docs/adr/0020-generated-checks-and-contract-tests.md)),
|
|
81
|
-
[technical metadata](docs/guide.md#technical-metadata) (see [ADR 0013](docs/adr/0013-field-sets-and-technical-metadata.md))
|
|
82
|
-
and [output directories](docs/guide.md#output-directories)
|
|
83
|
-
- [Rules](docs/guide.md#rules): M001–M021, L001–L003
|
|
84
|
-
- [Looking up one element](docs/guide.md#looking-up-one-element): `dt show`, as text or JSON
|
|
85
|
-
- [Formatting](docs/guide.md#formatting): `dt fmt`, the one canonical layout of `.dt` files
|
|
86
|
-
- [Output and exit codes](docs/guide.md#output-and-exit-codes): text, or JSON with `--format json`
|
|
87
|
-
- [Configuration](docs/guide.md#configuration): `domaintrail.jsonc` (`sources`, `generate.ts.out` /
|
|
88
|
-
`generate.ts.contexts` / `generate.ts.tests`, `view.port` / `view.host`; JSON Schema in `schema/domaintrail.schema.json`)
|
|
89
|
-
- [Language server](docs/guide.md#language-server): `dt lsp`, and how to use it from an editor or Claude Code
|
|
90
|
-
|
|
91
|
-
A taste of the DSL:
|
|
20
|
+
Write a model, e.g. `booking/reservation.dt`:
|
|
92
21
|
|
|
93
22
|
```dt
|
|
94
|
-
context
|
|
95
|
-
id
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
23
|
+
context Booking "会議室予約" {
|
|
24
|
+
id ReservationId: UUID
|
|
25
|
+
primitive Headcount "人数": Int { value in 1..50 }
|
|
26
|
+
|
|
27
|
+
aggregate Reservation "予約" {
|
|
28
|
+
id: ReservationId
|
|
29
|
+
attendees: Headcount
|
|
30
|
+
state Requested
|
|
99
31
|
state Confirmed {
|
|
100
32
|
confirmedAt: Timestamp
|
|
101
33
|
}
|
|
102
|
-
|
|
103
|
-
command
|
|
104
|
-
|
|
105
|
-
|
|
34
|
+
|
|
35
|
+
create command request(id: ReservationId, attendees: Headcount) -> Requested
|
|
36
|
+
command confirm(capacity: Headcount, at: Timestamp)
|
|
37
|
+
Requested -> Confirmed
|
|
38
|
+
requires roomFits { attendees <= capacity } else RoomTooSmall
|
|
39
|
+
emits ReservationConfirmed
|
|
106
40
|
}
|
|
107
|
-
|
|
108
|
-
|
|
41
|
+
|
|
42
|
+
event ReservationConfirmed {
|
|
43
|
+
reservationId: ReservationId
|
|
109
44
|
confirmedAt: Timestamp
|
|
110
45
|
}
|
|
46
|
+
error RoomTooSmall
|
|
111
47
|
}
|
|
112
48
|
```
|
|
113
49
|
|
|
114
|
-
|
|
115
|
-
unions ([0005](docs/adr/0005-unions.md)), persistent events ([0008](docs/adr/0008-persistent-events.md)),
|
|
116
|
-
command transitions ([0014](docs/adr/0014-command-transitions.md)), handlers per state
|
|
117
|
-
([0015](docs/adr/0015-handlers-per-state.md), superseded), collection constraints and declared invariants
|
|
118
|
-
([0016](docs/adr/0016-collection-constraints-and-declared-invariants.md)), command requirements
|
|
119
|
-
([0017](docs/adr/0017-command-requirements.md)), command events as an exact contract
|
|
120
|
-
([0018](docs/adr/0018-command-events-contract.md)), the fields a command changes and decisions
|
|
121
|
-
([0019](docs/adr/0019-command-changes-and-decisions.md)), generated checks and contract tests
|
|
122
|
-
([0020](docs/adr/0020-generated-checks-and-contract-tests.md)) and more.
|
|
123
|
-
|
|
124
|
-
## Live View
|
|
125
|
-
|
|
126
|
-
`dt view` watches the workspace, re-validates on every save and pushes updates over WebSocket.
|
|
127
|
-
The screen is laid out like an IDE; every pane is closed and opened with the icon button at its top (a closed side
|
|
128
|
-
pane leaves a narrow rail with the button that opens it) and resized by dragging (remembered per browser).
|
|
129
|
-
|
|
130
|
-
- **Explorer (left)**: model tree — shared contexts first, then each context grouped by kind; aggregates expand to
|
|
131
|
-
their states and commands — and the `.dt` files with error/warning counts. Click selects (a file too);
|
|
132
|
-
double-click opens the item in the view or inspector tab that suits it.
|
|
133
|
-
- **Main (center)**: views of the whole model, in tabs with a view-specific toolbar. Anything about one selected item
|
|
134
|
-
is in the inspector. See [ADR 0007](docs/adr/0007-pane-roles.md).
|
|
135
|
-
- *Context Map*: one node per bounded context and one edge per dependency between contexts, labeled with the
|
|
136
|
-
number of ID references and borrowed types (solid when types are borrowed). Shared contexts and contexts that
|
|
137
|
-
only declare IDs are hidden unless 「共有・外部の BC も表示」 is checked. Selecting a context lists every use in
|
|
138
|
-
the inspector (依存先 / 依存元). See [ADR 0006](docs/adr/0006-context-map.md).
|
|
139
|
-
- *Structure*: contexts, aggregate boundaries, entities, value objects, unions, `owns` / `references`. Pick bounded
|
|
140
|
-
contexts in the toolbar (any number) to draw only them, with the elements they use and the elements that use them
|
|
141
|
-
as stubs; the eye next to each other context hides its stubs and the edges to and from them (the toolbar shows how
|
|
142
|
-
many are hidden). The first row, 「すべての BC」, checks or unchecks every context and shows or hides every stub.
|
|
143
|
-
Three levels work in both, switched by the icons in the toolbar: 詳細 (every field), 概観 (the elements' names
|
|
144
|
-
only) and 集約 (only the aggregates with their descriptions, and one edge per pair of aggregates that depend on
|
|
145
|
-
each other, also through the entities, value objects and IDs they hold; shared contexts are left out, and a
|
|
146
|
-
context without aggregates stays as a frame with its description).
|
|
147
|
-
- *Catalog*: cards to look over the model, one section per kind; for now the domain primitives per context (shared
|
|
148
|
-
first) with base type, invariants and usages.
|
|
149
|
-
- **Inspector (right)**: the selected item — name, description, location (copy `file:line-line` for AI feedback),
|
|
150
|
-
diagnostics, a back button naming the item it returns to (「〇〇 に戻る」), and buttons to show it in a view. Sub-tabs: 構造 / 状態遷移 / 振る舞い / 参照 /
|
|
151
|
-
ソース. An event shows 永続化 / 非永続 next to its kind, as it does in an aggregate's 発生させる Event list;
|
|
152
|
-
persistent events have a database icon in the explorer.
|
|
153
|
-
- *状態遷移*: states and command transitions of the aggregate (`new` marks factory commands), for the aggregate
|
|
154
|
-
and its states and commands; it pans and zooms like the main canvas and shows the selected state or command.
|
|
155
|
-
- *ソース*: the whole file, read-only, syntax-coloured, diagnostics in the gutter, scrolled to the declaration;
|
|
156
|
-
clicking a declaration selects it. A selected file shows here the same way.
|
|
157
|
-
- **Problems / changes (bottom)**: diagnostics (click to locate) and additions / changes / removals since the previous model.
|
|
158
|
-
- Selecting never switches the main view by itself; the item is highlighted when the current view shows it.
|
|
159
|
-
- Added / changed elements are highlighted; removed ones appear as ghosts. On a syntax error the last diagram stays.
|
|
160
|
-
- The language of the Live View (Japanese or English) follows the browser, or is forced in the settings menu (the gear
|
|
161
|
-
at the right of the header). It covers the screen and the diagrams' own words (集約 / aggregate…); the model's names
|
|
162
|
-
and labels are shown as written, and diagnostics are in English.
|
|
163
|
-
- The theme follows the OS (自動), or is forced with ライト / ダーク in the settings menu; both choices are remembered
|
|
164
|
-
per browser.
|
|
165
|
-
- Names follow the 名前の表示 toggle in the header: ラベル (the string after a declaration's name, falling back to the
|
|
166
|
-
name), 名前 or 両方. Layouts are cached in `<root>/.domaintrail/layout.json`. The canvas is read-only.
|
|
167
|
-
|
|
168
|
-
See [docs/adr/0001-mvp-implementation-decisions.md](docs/adr/0001-mvp-implementation-decisions.md) for the design decisions.
|
|
169
|
-
|
|
170
|
-
## Development
|
|
171
|
-
|
|
172
|
-
Requires [Bun](https://bun.sh) (version pinned in `mise.toml`). `bun run dt` runs the CLI from source.
|
|
50
|
+
Check it, and watch it in the browser:
|
|
173
51
|
|
|
174
52
|
```bash
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
bun run typecheck
|
|
178
|
-
bun test # the repository's tests (bunfig.toml: test/ only)
|
|
179
|
-
bun run build # dist/: the CLI bundled for Node and the Live View page (needed by `view` and the tests)
|
|
53
|
+
npx dt check # 1 file(s) checked: 0 error(s), 0 warning(s).
|
|
54
|
+
npx dt view # the Live View at http://127.0.0.1:4321, until Ctrl+C
|
|
180
55
|
```
|
|
181
56
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
57
|
+
Then `npx dt generate ts` writes the TypeScript into `generated/domain`. The package installs the command as `dt` and
|
|
58
|
+
as `domaintrail`, its full name, for when `dt` clashes with another command.
|
|
59
|
+
|
|
60
|
+
## Where to read next
|
|
61
|
+
|
|
62
|
+
- **[Getting started](docs/getting-started.md)** ([日本語](docs/getting-started.ja.md)): working with an AI agent,
|
|
63
|
+
a first model step by step, generating, implementing and testing, and the editors.
|
|
64
|
+
- **[The guide](docs/guide.md)**, also printed by `dt guide` one topic at a time: the reference for the DSL and the
|
|
65
|
+
CLI, written for people and AI agents. Start with its [quick reference](docs/guide.md#quick-reference).
|
|
66
|
+
- **[examples/shop](examples/shop/README.md)**: a complete example — the model, the generated code and the code an AI
|
|
67
|
+
agent wrote against it, with the contract tests and a demo.
|
|
68
|
+
- **[The Live View](docs/live-view.md)**: every pane and view of `dt view`.
|
|
69
|
+
- **[Changelog](CHANGELOG.md)** ([日本語](CHANGELOG.ja.md)): what changed in each version, and how to upgrade.
|
|
70
|
+
- **[Design decisions](docs/adr)**: the ADRs behind the language.
|
|
71
|
+
|
|
72
|
+
## Features
|
|
73
|
+
|
|
74
|
+
- **The DSL**: contexts and shared contexts, aggregates with states and transitions, entities, value objects, domain
|
|
75
|
+
primitives, unions, field sets, labels (表示名) and terms; invariants, command requirements (`requires`), the fields
|
|
76
|
+
a command changes, the events it emits as an exact contract, verified types and policies.
|
|
77
|
+
- **`dt check`**: syntax, references, types and DDD rules, with a hint on what to change; text or JSON.
|
|
78
|
+
- **`dt fmt`**: one canonical layout for `.dt` files, keeping every comment.
|
|
79
|
+
- **`dt generate ts`**: types per context, command contracts and decisions for `decide`, checks of the invariants and
|
|
80
|
+
requirements, constructors of domain primitives, and contract tests with fast-check (bun, vitest, jest, node).
|
|
81
|
+
- **`dt view`**: the Live View — context map, structure, state transitions, behaviour, source and the changes since the
|
|
82
|
+
last save or a git revision, in Japanese or English.
|
|
83
|
+
- **`dt show`**: one element resolved, for people and agents, as text or JSON.
|
|
84
|
+
- **`dt lsp`**: a language server — diagnostics, definitions, references, hover, rename, formatting; a
|
|
85
|
+
[Zed extension](editors/zed) and a [tree-sitter grammar](tree-sitter-domaintrail).
|
|
86
|
+
- **`dt guide`**: the guide in the terminal, one topic at a time.
|
|
87
|
+
|
|
88
|
+
## Contributing
|
|
89
|
+
|
|
90
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for building, testing and releasing DomainTrail itself.
|
|
196
91
|
|
|
197
92
|
## License
|
|
198
93
|
|