@ddd-tool/domain-designer-cli 0.1.0-beta.9 → 0.3.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 +12 -20
- package/bin/domain-designer-cli.cjs +19145 -18666
- package/package.json +40 -23
- package/packages/playground/.env +1 -0
- package/packages/playground/node_modules/.vite/deps/_metadata.json +34 -0
- package/packages/playground/node_modules/.vite/deps/chunk-F4TQRHS6.js +2147 -0
- package/packages/playground/node_modules/.vite/deps/chunk-F4TQRHS6.js.map +7 -0
- package/packages/playground/node_modules/.vite/deps/chunk-MFAKUPMY.js +12787 -0
- package/packages/playground/node_modules/.vite/deps/chunk-MFAKUPMY.js.map +7 -0
- package/packages/playground/node_modules/.vite/deps/package.json +3 -0
- package/packages/playground/node_modules/.vite/deps/primevue_button.js +1215 -0
- package/packages/playground/node_modules/.vite/deps/primevue_button.js.map +7 -0
- package/packages/playground/node_modules/.vite/deps/primevue_dock.js +1236 -0
- package/packages/playground/node_modules/.vite/deps/primevue_dock.js.map +7 -0
- package/packages/playground/node_modules/.vite/deps/vue.js +346 -0
- package/packages/playground/node_modules/.vite/deps/vue.js.map +7 -0
- package/packages/playground/node_modules/.vue-global-types/vue_3.5_0.d.ts +136 -0
- package/packages/playground/package.json +21 -0
- package/{src → packages/playground/src}/App.vue +12 -12
- package/{src → packages/playground/src}/main.ts +27 -27
- package/{src → packages/playground/src}/views/Index.vue +1 -1
- package/packages/playground/src/views/complex-example-detail/book.ts +383 -0
- package/packages/playground/src/views/complex-example-detail/common.ts +4 -0
- package/packages/playground/src/views/complex-example-detail/user.ts +66 -0
- package/packages/playground/src/views/complex-example.ts +4 -0
- package/{src → packages/playground/src}/views/design-en.ts +25 -14
- package/{src → packages/playground/src}/views/design-zh.ts +10 -4
- package/packages/playground/src/views/index.ts +19 -0
- package/packages/playground/src/views/simple-example.ts +103 -0
- package/packages/playground/tsconfig.json +32 -0
- package/packages/playground/vite-env.d.ts +12 -0
- package/packages/playground/vite.config.ts +21 -0
- package/scripts/ai-assist-worker.cjs +7123 -0
- package/scripts/sync-version.mjs +22 -0
- package/templates/CLAUDE.md +276 -0
- package/templates/README.md +97 -0
- package/templates/complex-example-detail/book.ts +383 -0
- package/templates/complex-example-detail/common.ts +4 -0
- package/templates/complex-example-detail/user.ts +66 -0
- package/templates/complex-example.ts +4 -0
- package/templates/node_modules/@ddd-tool/domain-designer-core/actor.d.ts +2 -2
- package/templates/node_modules/@ddd-tool/domain-designer-core/agg.d.ts +2 -2
- package/templates/node_modules/@ddd-tool/domain-designer-core/command.d.ts +3 -3
- package/templates/node_modules/@ddd-tool/domain-designer-core/common.d.ts +79 -80
- package/templates/node_modules/@ddd-tool/domain-designer-core/event.d.ts +2 -2
- package/templates/node_modules/@ddd-tool/domain-designer-core/index.d.ts +4 -4
- package/templates/node_modules/@ddd-tool/domain-designer-core/info.d.ts +2 -2
- package/templates/node_modules/@ddd-tool/domain-designer-core/note.d.ts +2 -2
- package/templates/node_modules/@ddd-tool/domain-designer-core/policy.d.ts +2 -2
- package/templates/node_modules/@ddd-tool/domain-designer-core/read-model.d.ts +2 -2
- package/templates/node_modules/@ddd-tool/domain-designer-core/service.d.ts +2 -2
- package/templates/node_modules/@ddd-tool/domain-designer-core/system.d.ts +2 -2
- package/templates/node_modules/@ddd-tool/domain-designer-core/{define.d.ts → types.d.ts} +326 -307
- package/templates/node_modules/version.txt +1 -1
- package/templates/simple-example.ts +103 -0
- package/templates//345/244/215/346/235/202/346/250/241/345/235/227/346/267/273/345/212/240-detail/345/220/216/347/274/200 +2 -0
- package/tsconfig.json +19 -6
- package/scripts/sync-ver.mjs +0 -0
- package/src/views/index.ts +0 -15
- package/templates/example-agg.ts +0 -31
- package/templates/example.ts +0 -91
- package/vite.config.ts +0 -16
- /package/{index.html → packages/playground/index.html} +0 -0
- /package/{src → packages/playground/src}/assets/logo.svg +0 -0
- /package/{src → packages/playground/src}/assets/main.css +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
function syncVersion() {
|
|
5
|
+
const rootPath = path.resolve(import.meta.dirname, '..')
|
|
6
|
+
const packageInfo = JSON.parse(fs.readFileSync(path.join(rootPath, 'package.json'), 'utf-8'))
|
|
7
|
+
const version = packageInfo.version
|
|
8
|
+
if (!version) {
|
|
9
|
+
console.error('version not found')
|
|
10
|
+
process.exit(1)
|
|
11
|
+
}
|
|
12
|
+
fs.readdirSync(path.resolve(rootPath, 'packages')).forEach((pkgName) => {
|
|
13
|
+
const pkgPath = path.resolve(rootPath, 'packages', pkgName)
|
|
14
|
+
if (fs.existsSync(path.join(pkgPath, 'package.json'))) {
|
|
15
|
+
const pkgInfo = JSON.parse(fs.readFileSync(path.join(pkgPath, 'package.json'), 'utf-8'))
|
|
16
|
+
pkgInfo.version = version
|
|
17
|
+
fs.writeFileSync(path.join(pkgPath, 'package.json'), JSON.stringify(pkgInfo, null, 2) + '\n', 'utf-8')
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
syncVersion()
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when helping with domain modeling in this workspace.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
This workspace uses **Domain Designer CLI** - a Domain-Driven Design (DDD) modeling tool that enables developers to design domains using TypeScript code. The tool generates visualizations (event storming UML, user stories, workflow animations) and can produce code in multiple languages (Java, Kotlin, C#, Go).
|
|
8
|
+
|
|
9
|
+
## Current Workspace
|
|
10
|
+
|
|
11
|
+
This is a **user workspace** initialized with `domain-designer-cli init`. The workspace contains example models that demonstrate how to use the tool.
|
|
12
|
+
|
|
13
|
+
## Core API
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createDomainDesigner } from '@ddd-tool/domain-designer-core'
|
|
17
|
+
|
|
18
|
+
const d = createDomainDesigner()
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Available Methods
|
|
22
|
+
|
|
23
|
+
| Method | Purpose |
|
|
24
|
+
| --------------------- | ---------------------------------------------------- |
|
|
25
|
+
| `d.actor()` | Create actors (users/systems that initiate commands) |
|
|
26
|
+
| `d.command()` | Create commands (intent to change state) |
|
|
27
|
+
| `d.facadeCmd()` | Create facade commands |
|
|
28
|
+
| `d.agg()` | Create aggregates (domain boundaries) |
|
|
29
|
+
| `d.event()` | Create events (facts that have happened) |
|
|
30
|
+
| `d.policy()` | Create policies (business rules) |
|
|
31
|
+
| `d.service()` | Create domain services |
|
|
32
|
+
| `d.system()` | Create external systems |
|
|
33
|
+
| `d.readModel()` | Create read models (query models) |
|
|
34
|
+
| `d.startWorkflow()` | Start defining a workflow |
|
|
35
|
+
| `d.defineUserStory()` | Group workflows by user intent |
|
|
36
|
+
| `d.note()` | Create documentation notes |
|
|
37
|
+
|
|
38
|
+
## Workflow Builder Pattern
|
|
39
|
+
|
|
40
|
+
Workflows define the sequence of interactions in the domain:
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// Start a workflow
|
|
44
|
+
const workflowName = d.startWorkflow('CreateOrder')
|
|
45
|
+
|
|
46
|
+
// Chain the interactions: actor → command → aggregate → event → ...
|
|
47
|
+
actor.command(createOrder).agg(orderAgg).event(orderCreated)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Complete Example
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { createDomainDesigner } from '@ddd-tool/domain-designer-core'
|
|
54
|
+
|
|
55
|
+
const d = createDomainDesigner()
|
|
56
|
+
|
|
57
|
+
// Create value objects (infos)
|
|
58
|
+
const orderId = d.info.id('订单号')
|
|
59
|
+
const userId = d.info.id('用户id')
|
|
60
|
+
const orderTime = d.info.version('下单时间')
|
|
61
|
+
|
|
62
|
+
// Create events
|
|
63
|
+
const orderCreated = d.event('下单成功', [orderId, userId, orderTime])
|
|
64
|
+
const paymentSuccess = d.event('支付成功', [orderId])
|
|
65
|
+
|
|
66
|
+
// Create commands
|
|
67
|
+
const createOrder = d.command('创建订单', [orderId, userId, orderTime])
|
|
68
|
+
const makePayment = d.command('支付', [orderId])
|
|
69
|
+
|
|
70
|
+
// Create aggregates
|
|
71
|
+
const orderAgg = d.agg('订单聚合', [orderId])
|
|
72
|
+
orderAgg.event(orderCreated)
|
|
73
|
+
|
|
74
|
+
// Create actors
|
|
75
|
+
const customer = d.actor('用户')
|
|
76
|
+
|
|
77
|
+
// Create workflow
|
|
78
|
+
d.startWorkflow('创建订单并支付')
|
|
79
|
+
customer
|
|
80
|
+
.command(createOrder)
|
|
81
|
+
.agg(orderAgg)
|
|
82
|
+
.event(orderCreated)
|
|
83
|
+
.command(makePayment)
|
|
84
|
+
.agg(orderAgg)
|
|
85
|
+
.event(paymentSuccess)
|
|
86
|
+
|
|
87
|
+
// Create user story
|
|
88
|
+
d.defineUserStory('用户下单购物', ['创建订单并支付'])
|
|
89
|
+
|
|
90
|
+
export default d
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## File Organization
|
|
94
|
+
|
|
95
|
+
### Single-File Mode (simple-example.ts)
|
|
96
|
+
|
|
97
|
+
For small domains, put everything in one file:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { createDomainDesigner } from '@ddd-tool/domain-designer-core'
|
|
101
|
+
|
|
102
|
+
const d = createDomainDesigner()
|
|
103
|
+
|
|
104
|
+
// ... all definitions
|
|
105
|
+
|
|
106
|
+
export default d
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Multi-File Mode (complex-example.ts)
|
|
110
|
+
|
|
111
|
+
For larger domains, split into modules:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
// common.ts - Shared setup
|
|
115
|
+
import { createDomainDesigner } from '@ddd-tool/domain-designer-core'
|
|
116
|
+
export const d = createDomainDesigner({ moduleName: 'my-domain' })
|
|
117
|
+
|
|
118
|
+
// user.ts - User domain
|
|
119
|
+
import { d } from './common'
|
|
120
|
+
const user = d.actor('用户')
|
|
121
|
+
// ... more definitions
|
|
122
|
+
|
|
123
|
+
// book.ts - Book domain
|
|
124
|
+
import { d } from './common'
|
|
125
|
+
const book = d.agg('图书')
|
|
126
|
+
// ... more definitions
|
|
127
|
+
|
|
128
|
+
// index.ts - Main entry
|
|
129
|
+
import { d } from './common'
|
|
130
|
+
import './user'
|
|
131
|
+
import './book'
|
|
132
|
+
export default d
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Value Object Types
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
d.info.id('name') // ID type
|
|
139
|
+
d.info.document('name') // Document type
|
|
140
|
+
d.info.func('name') // Function type
|
|
141
|
+
d.info.valueObj('name') // Value Object type
|
|
142
|
+
d.info.version('name') // Version type
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Modeling Guidelines
|
|
146
|
+
|
|
147
|
+
### 1. Start with User Intent
|
|
148
|
+
|
|
149
|
+
Use **User Stories** to group workflows by user intent:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
d.defineUserStory('用户注册账号', ['注册用户', '发送验证邮件'])
|
|
153
|
+
d.defineUserStory('用户下单', ['创建订单', '支付'])
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### 2. Define Aggregates as Boundaries
|
|
157
|
+
|
|
158
|
+
Aggregates represent consistency boundaries:
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
const orderAgg = d.agg('订单聚合', [
|
|
162
|
+
d.info.id('订单号'),
|
|
163
|
+
d.info.document('商品列表'),
|
|
164
|
+
d.info.version('状态'),
|
|
165
|
+
])
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### 3. Events Represent Facts
|
|
169
|
+
|
|
170
|
+
Events are things that **have happened** (past tense):
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
const orderCreated = d.event('订单已创建') // Good
|
|
174
|
+
const creatingOrder = d.event('创建订单') // Also acceptable
|
|
175
|
+
const createOrder = d.event('创建订单') // Avoid - sounds like a command
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 4. Commands Represent Intent
|
|
179
|
+
|
|
180
|
+
Commands are things someone **wants to happen**:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
const createOrder = d.command('创建订单') // Good
|
|
184
|
+
const orderCreated = d.command('订单已创建') // Avoid - sounds like an event
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Common Patterns
|
|
188
|
+
|
|
189
|
+
### Policy Pattern
|
|
190
|
+
|
|
191
|
+
Policies automate business rules:
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
const paymentPolicy = d.policy('支付超时取消规则')
|
|
195
|
+
const cancelOrder = d.command('取消订单')
|
|
196
|
+
|
|
197
|
+
// When payment timeout event occurs, trigger cancellation
|
|
198
|
+
paymentTimeout.event(cancelOrder)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### External Systems
|
|
202
|
+
|
|
203
|
+
Integrate with external systems:
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
const emailSystem = d.system('邮件系统')
|
|
207
|
+
orderCreated.event(emailSystem)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Read Models
|
|
211
|
+
|
|
212
|
+
Define query models:
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
const orderSummary = d.readModel('订单汇总读模型', [
|
|
216
|
+
d.info.id('订单号'),
|
|
217
|
+
d.info.document('商品信息'),
|
|
218
|
+
d.info.version('订单状态'),
|
|
219
|
+
])
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Testing the Model
|
|
223
|
+
|
|
224
|
+
### Visualize
|
|
225
|
+
|
|
226
|
+
Run the web server to see visualizations:
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
.\RunWeb.bat # Windows
|
|
230
|
+
./RunWeb.sh # Linux/macOS
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Visualizations include:
|
|
234
|
+
|
|
235
|
+
- Event Storming UML diagram
|
|
236
|
+
- User story workflows
|
|
237
|
+
- Workflow animations
|
|
238
|
+
- Completeness analysis
|
|
239
|
+
|
|
240
|
+
### Generate Code
|
|
241
|
+
|
|
242
|
+
Generate implementation code:
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
.\GenCode.bat # Windows
|
|
246
|
+
./GenCode.sh # Linux/macOS
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Supported languages: Java, Kotlin, C#, Go
|
|
250
|
+
|
|
251
|
+
## Tips for AI Assistants
|
|
252
|
+
|
|
253
|
+
When helping with domain modeling:
|
|
254
|
+
|
|
255
|
+
1. **Ask clarifying questions** about the business domain
|
|
256
|
+
2. **Start with actors and user stories** to understand user intent
|
|
257
|
+
3. **Identify aggregates** by looking for consistency boundaries
|
|
258
|
+
4. **Use Chinese** for domain concepts if the user prefers (the tool supports it)
|
|
259
|
+
5. **Always define workflows** to show how elements interact
|
|
260
|
+
6. **Group related workflows** into user stories for better organization
|
|
261
|
+
7. **Keep aggregates small** - one aggregate per root entity
|
|
262
|
+
8. **Use value objects** to give meaning to primitive types
|
|
263
|
+
|
|
264
|
+
## Error Handling
|
|
265
|
+
|
|
266
|
+
If you see errors like:
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
The requested module does not provide an export named 'X'
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
This typically means the `@ddd-tool/domain-designer-core` package needs to be rebuilt. If this is a development environment, run:
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
pnpm --filter @ddd-tool/domain-designer-core build
|
|
276
|
+
```
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# 领域建模工作空间
|
|
2
|
+
|
|
3
|
+
这是一个使用 [Domain Designer CLI](https://github.com/ddd-tool/domain-designer-cli-node) 创建的领域驱动设计(DDD)建模工作空间。
|
|
4
|
+
|
|
5
|
+
## 快速开始
|
|
6
|
+
|
|
7
|
+
### 1. 查看可视化
|
|
8
|
+
|
|
9
|
+
运行以下命令启动 Web 服务,实时查看领域模型的可视化效果:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Windows
|
|
13
|
+
.\RunWeb.bat
|
|
14
|
+
|
|
15
|
+
# Linux / macOS
|
|
16
|
+
./RunWeb.sh
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 2. 生成代码
|
|
20
|
+
|
|
21
|
+
运行以下命令根据领域模型生成代码:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Windows
|
|
25
|
+
.\GenCode.bat
|
|
26
|
+
|
|
27
|
+
# Linux / macOS
|
|
28
|
+
./GenCode.sh
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 项目结构
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
.
|
|
35
|
+
├── simple-example.ts # 简单示例(单文件模式)
|
|
36
|
+
├── complex-example.ts # 复杂示例(模块化模式)
|
|
37
|
+
├── complex-example-detail/ # 复杂示例的详细模块
|
|
38
|
+
│ ├── common.ts # 公共定义
|
|
39
|
+
│ ├── user.ts # 用户领域
|
|
40
|
+
│ └── book.ts # 图书领域
|
|
41
|
+
├── node_modules/ # 类型定义(仅包含 .d.ts 文件)
|
|
42
|
+
├── RunWeb.bat / RunWeb.sh # 启动 Web 可视化服务
|
|
43
|
+
├── GenCode.bat / GenCode.sh # 代码生成脚本
|
|
44
|
+
└── README.md # 本文件
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 编写领域模型
|
|
48
|
+
|
|
49
|
+
### 数据源规则
|
|
50
|
+
|
|
51
|
+
**只有**位于工作空间根目录且**默认导出**了 `DomainDesigner` 实例的 TypeScript 文件才会被识别为数据源。
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { createDomainDesigner } from '@ddd-tool/domain-designer-core'
|
|
55
|
+
|
|
56
|
+
const d = createDomainDesigner()
|
|
57
|
+
|
|
58
|
+
// ... 定义领域模型
|
|
59
|
+
|
|
60
|
+
export default d // 必须默认导出
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 单文件模式 vs 模块化模式
|
|
64
|
+
|
|
65
|
+
**单文件模式**(参考 `simple-example.ts`):
|
|
66
|
+
|
|
67
|
+
- 适合小型领域模型
|
|
68
|
+
- 所有定义在一个文件中
|
|
69
|
+
- 快速上手,简单直接
|
|
70
|
+
|
|
71
|
+
**模块化模式**(参考 `complex-example.ts`):
|
|
72
|
+
|
|
73
|
+
- 适合大型、复杂的领域模型
|
|
74
|
+
- 将不同领域拆分到不同文件中
|
|
75
|
+
- 更好的代码组织和可维护性
|
|
76
|
+
|
|
77
|
+
### 实时预览
|
|
78
|
+
|
|
79
|
+
- 修改 `.ts` 文件后,刷新浏览器页面即可看到更新
|
|
80
|
+
- 新增或删除 `.ts` 文件后,需要重新运行 `RunWeb` 脚本
|
|
81
|
+
|
|
82
|
+
## 使用 AI 辅助建模
|
|
83
|
+
|
|
84
|
+
本项目提供了 `CLAUDE.md` 文件,专门用于指导 Claude Code 等 AI 工具辅助你进行领域建模。
|
|
85
|
+
|
|
86
|
+
启用 AI 辅助的方法:
|
|
87
|
+
|
|
88
|
+
1. 在 VS Code 中安装 [Claude Code](https://claude.ai/code) 扩展
|
|
89
|
+
2. 在工作空间中直接与 Claude 对话,例如:
|
|
90
|
+
- "帮我创建一个用户注册的聚合"
|
|
91
|
+
- "为订单添加支付事件"
|
|
92
|
+
- "检查我的领域模型是否完整"
|
|
93
|
+
|
|
94
|
+
## 相关资源
|
|
95
|
+
|
|
96
|
+
- [Domain Designer CLI GitHub](https://github.com/ddd-tool/domain-designer-cli-node)
|
|
97
|
+
- [领域驱动设计(DDD)入门指南](https://martinfowler.com/tags/domain%20driven%20design.html)
|