domaintrail 0.3.0 → 0.5.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/README.md CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  A type-checkable domain modeling DSL shared by humans and AI.
4
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 and command
6
- contracts, never business logic.
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.
7
8
 
8
9
  ## Setup
9
10
 
@@ -17,50 +18,82 @@ npx domaintrail <command> # or run it without installing
17
18
  ## CLI
18
19
 
19
20
  ```bash
20
- dt guide # the guide: DSL, file layout, workflow, config, output and exit codes
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)
21
23
  dt -r <root> check # validate syntax, references, types and DDD rules
22
24
  dt -r <root> generate ts # generate TypeScript into <root>/generated/domain (--out to change)
23
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
24
28
  ```
25
29
 
26
30
  The package installs the same command under two names: `dt` for everyday use and `domaintrail`, its full name, for
27
31
  when `dt` clashes with another command or a script should spell it out (CI, for example).
28
32
 
29
- `<root>` defaults to the current directory; every `*.dt` file below it (except `node_modules`, `.git`, `.domaintrail`)
30
- belongs to the workspace. `dt --help` and `dt <command> --help` show the options with examples.
33
+ `<root>` defaults to the current directory; every `*.dt` file below it (except in `node_modules`, `.git`, `.domaintrail`
34
+ and what `.gitignore` ignores) belongs to the workspace, unless a `domaintrail.jsonc` says otherwise. `dt --help` and `dt <command> --help` show the options with examples.
31
35
 
32
- `check` prints diagnostics as `file:line:col - error M00X: message` and exits non-zero on errors.
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`).
33
38
  `generate ts` runs `check` first and generates nothing if there are errors.
34
39
 
35
- Try it with the example in this repository (see [Development](#development)):
40
+ Try it with the example in this repository (see [Development](#development)). [examples/shop](examples/shop/README.md)
41
+ is a complete one: the model, the generated code, and the code an AI agent writes against it — the domain
42
+ implementations and a small application layer.
36
43
 
37
44
  ```bash
38
45
  bun run dt -r examples/shop check
39
- bun run dt -r examples/shop generate ts # then examples/shop/src/order-commands.ts type-checks against it
46
+ bun run dt -r examples/shop generate ts # then examples/shop/src type-checks against it
47
+ (cd examples/shop && bun test) # passes the generated contract tests and the application's tests
48
+ (cd examples/shop && bun src/demo.ts) # a walk through the shop: orders, an invoice, a refund request
40
49
  bun run build && bun run dt -r examples/shop view
41
50
  ```
42
51
 
43
52
  ## Guide
44
53
 
45
- **[docs/guide.md](docs/guide.md)** is the reference for writing models and using the CLI, and `dt guide` prints the
46
- same text, so people and AI agents get it without leaving the terminal:
54
+ **[docs/guide.md](docs/guide.md)** is the reference for writing models and using the CLI. It starts with a
55
+ [quick reference](docs/guide.md#quick-reference) (the workflow, the DSL at a glance, the commands), and its sections are
56
+ **topics** that the CLI prints one at a time, so people and AI agents read only what they need without leaving the
57
+ terminal:
47
58
 
48
- - [Workflow](docs/guide.md#workflow): `check` → `generate ts` → type-check your own code (`tsc --noEmit`)
49
- - [Output and exit codes](docs/guide.md#output-and-exit-codes)
50
- - [Configuration](docs/guide.md#configuration): `domaintrail.jsonc` (`sources`, `generate.ts.out` /
51
- `generate.ts.contexts`, `view.port` / `view.host`; JSON Schema in `schema/domaintrail.schema.json`)
59
+ ```bash
60
+ dt guide # the quick reference and the list of topics (about one screen)
61
+ dt guide requires # one topic: a ## section with its ### sections, or one ### section
62
+ dt guide M010 # one rule and the topics that explain it
63
+ dt guide --all # the whole guide, the same text as docs/guide.md
64
+ ```
65
+
66
+ The sections, in the guide's order:
67
+
68
+ - [Workflow](docs/guide.md#workflow): `fmt` → `check` → `generate ts` → implement with `decide` → type-check your own
69
+ code (`tsc --noEmit`) → run the generated contract tests
52
70
  - [File layout (recommended)](docs/guide.md#file-layout-recommended): `<context>/<aggregate>.dt` and
53
71
  `<context>/context.dt` (see [ADR 0009](docs/adr/0009-file-layout.md))
54
72
  - [DSL](docs/guide.md#dsl): contexts, aggregates, entities, values, states, commands, events, errors,
55
73
  [domain primitives](docs/guide.md#domain-primitives), [unions](docs/guide.md#unions),
56
74
  [shared contexts](docs/guide.md#shared-contexts), [field sets](docs/guide.md#field-sets),
57
75
  [domain and technical fields](docs/guide.md#domain-fields-and-technical-fields),
58
- [names (表示名)](docs/guide.md#names-labels-and-descriptions)
59
- and [invariant expressions](docs/guide.md#invariant-expressions)
60
- - [Rules](docs/guide.md#rules) (M001–M017, L001–L003) and [Generated TypeScript](docs/guide.md#generated-typescript):
76
+ [names (表示名)](docs/guide.md#names-labels-and-descriptions),
77
+ [invariant expressions](docs/guide.md#invariant-expressions), [command requirements](docs/guide.md#command-requirements),
78
+ [command changes](docs/guide.md#command-changes), [command events](docs/guide.md#command-events),
79
+ [pure commands](docs/guide.md#pure-commands), [verified types](docs/guide.md#verified-types) (the evidence of a
80
+ check outside the aggregate, as a command's parameter) and [reactions to events](docs/guide.md#reactions-to-events-policies)
81
+ (policies: when an event happens, a command eventually runs; see [ADR 0022](docs/adr/0022-policy-declarations.md))
82
+ - [Generated TypeScript](docs/guide.md#generated-typescript): [decisions and `decide`](docs/guide.md#decisions-and-decide),
61
83
  [what is generated and what you write](docs/guide.md#generated-code-and-your-code) (see
62
- [ADR 0011](docs/adr/0011-generated-code-boundary.md)), [output directories](docs/guide.md#output-directories) and
84
+ [ADR 0011](docs/adr/0011-generated-code-boundary.md)), [generated checks](docs/guide.md#generated-checks) and
85
+ [generated tests](docs/guide.md#generated-tests) (see [ADR 0020](docs/adr/0020-generated-checks-and-contract-tests.md)),
63
86
  [technical metadata](docs/guide.md#technical-metadata) (see [ADR 0013](docs/adr/0013-field-sets-and-technical-metadata.md))
87
+ and [output directories](docs/guide.md#output-directories)
88
+ - [Rules](docs/guide.md#rules): M001–M024, L001–L003
89
+ - [Looking up one element](docs/guide.md#looking-up-one-element): `dt show`, as text or JSON
90
+ - [Formatting](docs/guide.md#formatting): `dt fmt`, the one canonical layout of `.dt` files
91
+ - [Output and exit codes](docs/guide.md#output-and-exit-codes): text, or JSON with `--format json`
92
+ - [Configuration](docs/guide.md#configuration): `domaintrail.jsonc` (`sources`, `generate.ts.out` /
93
+ `generate.ts.contexts` / `generate.ts.tests`, `view.port` / `view.host`; JSON Schema in `schema/domaintrail.schema.json`)
94
+ - [Language server](docs/guide.md#language-server): `dt lsp`, and how to use it from an editor or Claude Code
95
+ - [Editors](docs/guide.md#editors): the Zed extension in `editors/zed` (tree-sitter highlighting, outline, `dt lsp`),
96
+ other editors through `dt lsp` and the tree-sitter grammar in `tree-sitter-domaintrail`
64
97
 
65
98
  A taste of the DSL:
66
99
 
@@ -70,18 +103,32 @@ context Sales "販売" {
70
103
  aggregate Order "注文" {
71
104
  id: OrderId
72
105
  state Draft
73
- state Confirmed { confirmedAt: Timestamp }
74
- create command place() -> Draft
75
- command confirm(at: Timestamp) Draft -> Confirmed emits OrderConfirmed
106
+ state Confirmed {
107
+ confirmedAt: Timestamp
108
+ }
109
+ create command place(id: OrderId) -> Draft
110
+ command confirm(at: Timestamp)
111
+ Draft -> Confirmed
112
+ emits OrderConfirmed
113
+ }
114
+ persistent event OrderConfirmed {
115
+ orderId: OrderId
116
+ confirmedAt: Timestamp
76
117
  }
77
- persistent event OrderConfirmed { orderId: OrderId confirmedAt: Timestamp }
78
118
  }
79
119
  ```
80
120
 
81
121
  The design decisions behind the DSL are in [docs/adr](docs/adr): shared contexts ([0004](docs/adr/0004-shared-contexts.md)),
82
122
  unions ([0005](docs/adr/0005-unions.md)), persistent events ([0008](docs/adr/0008-persistent-events.md)),
83
123
  command transitions ([0014](docs/adr/0014-command-transitions.md)), handlers per state
84
- ([0015](docs/adr/0015-handlers-per-state.md)) and more.
124
+ ([0015](docs/adr/0015-handlers-per-state.md), superseded), collection constraints and declared invariants
125
+ ([0016](docs/adr/0016-collection-constraints-and-declared-invariants.md)), command requirements
126
+ ([0017](docs/adr/0017-command-requirements.md)), command events as an exact contract
127
+ ([0018](docs/adr/0018-command-events-contract.md)), the fields a command changes and decisions
128
+ ([0019](docs/adr/0019-command-changes-and-decisions.md)), generated checks and contract tests
129
+ ([0020](docs/adr/0020-generated-checks-and-contract-tests.md)), event and error fields named after their source
130
+ ([0021](docs/adr/0021-payload-field-names.md)), policy declarations ([0022](docs/adr/0022-policy-declarations.md)),
131
+ verified types ([0023](docs/adr/0023-verified-types.md)) and more.
85
132
 
86
133
  ## Live View
87
134
 
@@ -137,7 +184,9 @@ Requires [Bun](https://bun.sh) (version pinned in `mise.toml`). `bun run dt` run
137
184
  bun install
138
185
  bun run langium:generate # after editing src/language/domain.langium
139
186
  bun run typecheck
140
- bun test
187
+ bun run lint # oxlint --type-aware, no narrowing casts without a reason (after `bun run dt -r examples/shop generate ts`)
188
+ bun run fmt # oxfmt (`fmt:check` in CI); the .dt files are formatted by `dt fmt`
189
+ bun test # the repository's tests (bunfig.toml: test/ only)
141
190
  bun run build # dist/: the CLI bundled for Node and the Live View page (needed by `view` and the tests)
142
191
  ```
143
192
 
@@ -152,7 +201,7 @@ See [docs/releasing.md](docs/releasing.md).
152
201
  | `src/language` | Langium grammar, generated parser/AST, scoping |
153
202
  | `src/core` | analyzer, diagnostics, validation rules (`checker/`) |
154
203
  | `src/model` | Typed Model (serializable, resolved) |
155
- | `src/generator` | TypeScript generator and naming |
204
+ | `src/generator` | TypeScript generator and naming, generated checks (`checks.ts`) and contract tests (`tests.ts`, `testing/`) |
156
205
  | `src/graph`, `src/layout` | Graph IR, diff, ELK layout |
157
206
  | `src/server`, `web` | Live View server and React + tldraw client |
158
207