@aigne/doc-smith 0.7.2 → 0.8.1

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.
@@ -1,48 +1,957 @@
1
1
  - 使用 d2 图表解释复杂的概念 (```d2``` format),让页面内容展示形式更丰富
2
- - 使用 d2 展示架构关系、流程与组件交互,节点与连线文案保持简洁
3
- - d2 代码块必须完整且可渲染,避免使用未闭合的语法与奇异字符
4
- - d2 图表使用补充说明:
5
- - 示例:
6
- {% include "diy-examples.md" %}
7
- - 官方示例:
8
- {% include "official-examples.md" %}
9
- - 其他注意事项:
10
- - 图表应简洁明了,节点和连线命名准确。
11
- - 每个 d2 代码块必须完整闭合,避免语法错误。
12
- - 不要添加注释说明,因为生成的图片无法进行交互。
13
- - 不要随意更改节点和连线的颜色,这样会破坏配置好的主题。
14
- - 节点的名称尽量使用 " 进行包裹,避免出现异常。
15
- - bad: `SDK: @blocklet/js-sdk`
16
- - good: `SDK: "@blocklet/js-sdk"`
17
- - d2 中的 `shape` 只有这些值: `rectangle`, `square`, `page`, `parallelogram`, `document`, `cylinder`, `queue`, `package`, `step`, `callout`, `stored_data`, `person`, `diamond`, `oval`, `circle`, `hexagon`, `cloud`, `c4-person`,不要随意创建其他的 shape,会导致图表报错
18
- - 页面的整体布局使用 `direction: down`,这样能确保图表适合在网页中进行阅读;子图中可以根据情况来使用其他的方向布局,需要确保图表的整体效果看起来不会太宽
19
- - 如果一个对象中的元素太多了(超过3个),请使用 `grid-columns` 限制一下单行的列数,`grid-columns` 的值不要超过 3,例如
20
- ```d2
21
- "Instance": {
2
+ - 使用的 d2 的版本是 0.7.x,d2 官方的文档请查看 https://d2lang.com/tour/intro/
3
+ - 图表应简洁明了,节点和连线命名准确,节点与连线文案保持简洁,不要太长
4
+ - bad
5
+ ```d2
6
+ "TokenService": {
7
+ label: "TokenService (Handles token storage & refresh)"
8
+ shape: class
9
+ }
10
+ ```
11
+ - good
12
+ ```d2
13
+ "TokenService": {
14
+ label: "TokenService"
15
+ shape: class
16
+ }
17
+ ```
18
+ - 使用 d2 展示架构关系、流程与组件交互
19
+ - d2 代码块必须完整且可渲染,避免使用未闭合的语法与奇异字符,避免语法错误
20
+ - 不要为节点添加 `tooltip`,保持简单即可
21
+ - bad
22
+ ```d2
23
+ "AuthService": {
24
+ label: "AuthService"
25
+ tooltip: "Manages user profiles, privacy, and authentication actions"
26
+ shape: class
27
+ }
28
+ ```
29
+ - good
30
+ ```d2
31
+ "AuthService": {
32
+ label: "AuthService"
33
+ shape: class
34
+ }
35
+ ```
36
+ - 节点的名称尽量使用 `"` 进行包裹,避免出现渲染异常
37
+ - bad: `SDK: @blocklet/js-sdk`
38
+ - good: `SDK: "@blocklet/js-sdk"`
39
+ - 不要随意给节点填充颜色,除非节点有明确的 yes/no 的状态,此时可以给节点 fill `error`, `warning`, `success` 之类的颜色
40
+ - bad
41
+ ```d2
42
+ "TokenService" {
43
+ shape: class
44
+ style.fill: "#fffbe6"
45
+ }
46
+ ```
47
+ - good
48
+ ```d2
49
+ "TokenService" {
50
+ shape: class
51
+ }
52
+ ```
53
+ - 对于单个节点和连线,可以使用 `animate: true` 可以让图表增加动画效果,看起来效果更好
54
+ - 对于节点 shape 的选择,可以参考
55
+ {% include "shape-rules.md" %}
56
+ - 页面的整体布局使用 `direction: down`,这样能确保图表适合在网页中进行阅读;子图中可以根据情况来使用其他的方向布局,需要确保图表的整体效果看起来不会太宽
57
+ - bad:
58
+ ```d2
59
+ direction: right
60
+
61
+ "online": {
62
+ shape: circle
63
+ style.fill: "#52c41a"
64
+ }
65
+
66
+ "offline": {
67
+ shape: circle
68
+ style.fill: "#faad14"
69
+ }
70
+
71
+ "expired": {
72
+ shape: circle
73
+ style.fill: "#ff4d4f"
74
+ }
75
+
76
+ "New Login" -> "online": "User authenticates"
77
+ "online" -> "offline": "User closes app/browser"
78
+ "online" -> "expired": "Token expires"
79
+ "offline" -> "online": "User returns"
80
+ "offline" -> "expired": "Extended inactivity"
81
+ ```
82
+ - good:
83
+ ```d2
84
+ direction: down
85
+
86
+ "online": {
87
+ shape: circle
88
+ style.fill: "#52c41a"
89
+ }
90
+
91
+ "offline": {
92
+ shape: circle
93
+ style.fill: "#faad14"
94
+ }
95
+
96
+ "expired": {
97
+ shape: circle
98
+ style.fill: "#ff4d4f"
99
+ }
100
+
101
+ "New Login" -> "online": "User authenticates"
102
+ "online" -> "offline": "User closes app/browser"
103
+ "online" -> "expired": "Token expires"
104
+ "offline" -> "online": "User returns"
105
+ "offline" -> "expired": "Extended inactivity"
106
+ ```
107
+ - 如果一个节点中的字节点太多了(超过3个),请使用 `grid-columns` 限制一下单行的列数,`grid-columns` 的值优先使用2,最大不要超过 3,例如
108
+ - good:
109
+ ```d2
110
+ "Instance": {
111
+ grid-columns: 3
112
+ "A": "A"
113
+ "B": "B"
114
+ "C": "C"
115
+ "D": "D"
116
+ "E": "E"
117
+ }
118
+ ```
119
+ ```d2
120
+ "Instance": {
121
+ grid-columns: 2
122
+ "A": "A"
123
+ "B": "B"
124
+ "C": "C"
125
+ "D": "D"
126
+ }
127
+ ```
128
+ - 每一个容器节点中,最好设置 `grid-columns`
129
+ - bad:
130
+ ```d2
131
+ direction: down
132
+
133
+ "SDK": "@blocklet/js-sdk" {
134
+ shape: package
135
+
136
+ "Core Instance": {
137
+ shape: rectangle
138
+ "BlockletSDK": "Main SDK Class"
139
+ }
140
+
141
+ "Services": {
142
+ grid-columns: 3
143
+ "AuthService": "User Authentication" {
144
+ shape: class
145
+ }
146
+ "TokenService": "Token Management" {
147
+ shape: class
148
+ }
149
+ "UserSessionService": "Session Management" {
150
+ shape: class
151
+ }
152
+ "BlockletService": "Blocklet Metadata" {
153
+ shape: class
154
+ }
155
+ "FederatedService": "Federated Login" {
156
+ shape: class
157
+ }
158
+ }
159
+
160
+ "HTTP Clients": {
161
+ grid-columns: 2
162
+ "createAxios": "Axios-based Client" {
163
+ shape: rectangle
164
+ }
165
+ "createFetch": "Fetch-based Client" {
166
+ shape: rectangle
167
+ }
168
+ }
169
+ }
170
+
171
+ "Your App": "Application Code" {
172
+ shape: rectangle
173
+ }
174
+
175
+ "Blocklet Services": "Remote APIs" {
176
+ shape: cylinder
177
+ }
178
+
179
+ "Your App" -> "SDK": "Import & Use"
180
+ "SDK" -> "Blocklet Services": "Authenticated Requests"
181
+ "Blocklet Services" -> "SDK": "Responses & Tokens"
182
+ ```
183
+ - good:
184
+ ```d2
185
+ direction: down
186
+
187
+ "SDK": "@blocklet/js-sdk" {
188
+ shape: package
189
+ grid-columns: 1
190
+
191
+ "Core Instance": {
192
+ shape: rectangle
193
+ "BlockletSDK": "Main SDK Class"
194
+ }
195
+
196
+ "Services": {
197
+ grid-columns: 3
198
+ "AuthService": "User Authentication" {
199
+ shape: class
200
+ }
201
+ "TokenService": "Token Management" {
202
+ shape: class
203
+ }
204
+ "UserSessionService": "Session Management" {
205
+ shape: class
206
+ }
207
+ "BlockletService": "Blocklet Metadata" {
208
+ shape: class
209
+ }
210
+ "FederatedService": "Federated Login" {
211
+ shape: class
212
+ }
213
+ }
214
+
215
+ "HTTP Clients": {
216
+ grid-columns: 2
217
+ "createAxios": "Axios-based Client" {
218
+ shape: rectangle
219
+ }
220
+ "createFetch": "Fetch-based Client" {
221
+ shape: rectangle
222
+ }
223
+ }
224
+ }
225
+
226
+ "Your App": "Application Code" {
227
+ shape: rectangle
228
+ }
229
+
230
+ "Blocklet Services": "Remote APIs" {
231
+ shape: cylinder
232
+ }
233
+
234
+ "Your App" -> "SDK": "Import & Use"
235
+ "SDK" -> "Blocklet Services": "Authenticated Requests"
236
+ "Blocklet Services" -> "SDK": "Responses & Tokens"
237
+ ```
238
+ - 必须保证一个图中,所有的节点都是有关联的,不需要为图表设置 legend,如果就是有节点不存在关联性,则应该移除这些节点,或者拆分成多个独立的图表
239
+ - bad:
240
+ ```d2
241
+ direction: down
242
+
243
+ "Your App": {
244
+ shape: rectangle
245
+ }
246
+
247
+ "SDK Request Helper": {
248
+ label: "@blocklet/js-sdk (createAxios / createFetch)"
249
+ shape: package
250
+ }
251
+
252
+ "Blocklet Service": {
253
+ shape: cylinder
254
+ }
255
+
256
+ "Token Refresh Endpoint": {
257
+ label: "/api/did/refreshSession"
258
+ shape: rectangle
259
+ }
260
+
261
+ "Your App" -> "SDK Request Helper": "1. Make API Call (e.g., /api/profile)"
262
+
263
+ "SDK Request Helper" -> "Blocklet Service": "2. Adds Auth Header & Sends Request" {
264
+ style {
265
+ stroke-dash: 2
266
+ }
267
+ }
268
+
269
+ "Success Path": {
270
+ style.stroke: "#52c41a"
271
+
272
+ "Blocklet Service" -> "SDK Request Helper": "3a. 200 OK (Token Valid)"
273
+ "SDK Request Helper" -> "Your App": "4a. Returns Data"
274
+ }
275
+
276
+
277
+ "Token Renewal Path": {
278
+ style.stroke: "#faad14"
279
+
280
+ "Blocklet Service" -> "SDK Request Helper": "3b. 401 Unauthorized (Token Expired)"
281
+ "SDK Request Helper" -> "Token Refresh Endpoint": "4b. Request New Token"
282
+ "Token Refresh Endpoint" -> "SDK Request Helper": "5b. New Tokens"
283
+ "SDK Request Helper" -> "Blocklet Service": "6b. Retry Original Request"
284
+ "Blocklet Service" -> "SDK Request Helper": "7b. 200 OK" {
285
+ style.stroke: "#52c41a"
286
+ }
287
+ "SDK Request Helper" -> "Your App": "8b. Returns Data Transparently" {
288
+ style.stroke: "#52c41a"
289
+ }
290
+ }
291
+ ```
292
+ - good:
293
+ ```d2
294
+ direction: down
295
+
296
+ "Your App": {
297
+ shape: rectangle
298
+ }
299
+
300
+ "SDK Request Helper": {
301
+ label: "@blocklet/js-sdk (createAxios / createFetch)"
302
+ shape: package
303
+ }
304
+
305
+ "Blocklet Service": {
306
+ shape: cylinder
307
+ }
308
+
309
+ "Token Refresh Endpoint": {
310
+ label: "/api/did/refreshSession"
311
+ shape: rectangle
312
+ }
313
+
314
+ "Your App" -> "SDK Request Helper": "1. Make API Call (e.g., /api/profile)"
315
+
316
+ "SDK Request Helper" -> "Blocklet Service": "2. Adds Auth Header & Sends Request" {
317
+ style {
318
+ stroke-dash: 2
319
+ }
320
+ }
321
+ ```
322
+ ```d2
323
+ "Success Path": {
324
+ style.stroke: "#52c41a"
325
+
326
+ "Blocklet Service" -> "SDK Request Helper": "3a. 200 OK (Token Valid)"
327
+ "SDK Request Helper" -> "Your App": "4a. Returns Data"
328
+ }
329
+ ```
330
+ ```d2
331
+ "Token Renewal Path": {
332
+ style.stroke: "#faad14"
333
+
334
+ "Blocklet Service" -> "SDK Request Helper": "3b. 401 Unauthorized (Token Expired)"
335
+ "SDK Request Helper" -> "Token Refresh Endpoint": "4b. Request New Token"
336
+ "Token Refresh Endpoint" -> "SDK Request Helper": "5b. New Tokens"
337
+ "SDK Request Helper" -> "Blocklet Service": "6b. Retry Original Request"
338
+ "Blocklet Service" -> "SDK Request Helper": "7b. 200 OK" {
339
+ style.stroke: "#52c41a"
340
+ }
341
+ "SDK Request Helper" -> "Your App": "8b. Returns Data Transparently" {
342
+ style.stroke: "#52c41a"
343
+ }
344
+ }
345
+ ```
346
+ - 必须确保每个节点和子节点是有名称的
347
+ - bad:
348
+ ```d2
349
+ "SDK Core Instance": {
350
+ shape: package
351
+ "TokenService": "Manages session and refresh tokens"
352
+ "Services": {
353
+ grid-columns: 2
354
+ "AuthService": ""
355
+ "BlockletService": ""
356
+ }
357
+ }
358
+ ```
359
+ - good:
360
+ ```d2
361
+ "SDK Core Instance": {
362
+ shape: package
363
+ "TokenService": "Manages session and refresh tokens"
364
+ "Services": {
365
+ grid-columns: 2
366
+ "AuthService": "AuthService"
367
+ "BlockletService": "BlockletService"
368
+ }
369
+ }
370
+ ```
371
+ - 当有关联关系的节点,处于一个节点内部时,则它们的关联关系也应该写在节点内部
372
+ - bad
373
+ ```d2
374
+ direction: down
375
+
376
+ "@blocklet/js-sdk": {
377
+ shape: package
378
+
379
+ "Main SDK Instance": {
380
+ shape: rectangle
381
+ "BlockletSDK Class": "Main entry point"
382
+ "getBlockletSDK()": "Singleton factory"
383
+ }
384
+
385
+ "HTTP Clients": {
386
+ shape: rectangle
387
+ grid-columns: 2
388
+ "createAxios()": "Axios-based client"
389
+ "createFetch()": "Fetch-based client"
390
+ }
391
+
392
+ "Core Services": {
393
+ shape: rectangle
394
+ grid-columns: 3
395
+ "AuthService": "User authentication"
396
+ "TokenService": "Token management"
397
+ "BlockletService": "Blocklet metadata"
398
+ "UserSessionService": "Session management"
399
+ "FederatedService": "Federated login"
400
+ "ComponentService": "Component utilities"
401
+ }
402
+ }
403
+
404
+ "Main SDK Instance" -> "HTTP Clients": "Uses for requests"
405
+ "Main SDK Instance" -> "Core Services": "Provides access to"
406
+ "HTTP Clients" -> "Core Services": "Configured with"
407
+ ```
408
+ - good
409
+ ```d2
410
+ direction: down
411
+
412
+ "@blocklet/js-sdk": {
413
+ shape: package
414
+
415
+ "Main SDK Instance": {
416
+ shape: rectangle
417
+ "BlockletSDK Class": "Main entry point"
418
+ "getBlockletSDK()": "Singleton factory"
419
+ }
420
+
421
+ "HTTP Clients": {
422
+ shape: rectangle
423
+ grid-columns: 2
424
+ "createAxios()": "Axios-based client"
425
+ "createFetch()": "Fetch-based client"
426
+ }
427
+
428
+ "Core Services": {
429
+ shape: rectangle
22
430
  grid-columns: 3
23
- "A": "A"
24
- "B": "B"
25
- "C": "C"
26
- "D": "D"
27
- "E": "E"
28
- }
29
- ```
30
- - 尽量保证一个图中,只有一个关联所有元素的图,不要产生多个没有任何连接的子图
31
- - 确保 `style` 中的值都是可用的,错误的字段会导致图片生成失败
32
- - 尽量确保每个子元素是有名称的
33
- - bad:
34
- ```d2
35
- "SDK Core Instance": {
36
- shape: package
37
- "TokenService": "Manages session and refresh tokens"
38
- "Services": {
39
- grid-columns: 2
40
- "AuthService": ""
41
- "BlockletService": ""
42
- "FederatedService": ""
43
- "UserSessionService": ""
44
- }
45
- }
46
- ```
47
- - 使用 animate: true 可以让图表增加动画效果,看起来效果更好
48
- - 针对节点的状态(yes or no),可以给定不同的颜色(error,warning,success)来增强表现力
431
+ "AuthService": "User authentication"
432
+ "TokenService": "Token management"
433
+ "BlockletService": "Blocklet metadata"
434
+ "UserSessionService": "Session management"
435
+ "FederatedService": "Federated login"
436
+ "ComponentService": "Component utilities"
437
+ }
438
+
439
+ "Main SDK Instance" -> "HTTP Clients": "Uses for requests"
440
+ "Main SDK Instance" -> "Core Services": "Provides access to"
441
+ "HTTP Clients" -> "Core Services": "Configured with"
442
+ }
443
+ ```
444
+ - bad:
445
+ ```d2
446
+ direction: down
447
+
448
+ "Your App": {
449
+ shape: rectangle
450
+ }
451
+
452
+ "SDK Request Helper": {
453
+ label: "@blocklet/js-sdk (createAxios / createFetch)"
454
+ shape: package
455
+ }
456
+
457
+ "Blocklet Service": {
458
+ shape: cylinder
459
+ }
460
+
461
+
462
+ "Your App" -> "SDK Request Helper": "1. Make API Call (e.g., /api/profile)"
463
+
464
+ "SDK Request Helper" -> "Blocklet Service": "2. Adds Auth Header & Sends Request" {
465
+ style {
466
+ stroke-dash: 2
467
+ }
468
+ }
469
+
470
+ "Token Renewal Path": {
471
+ style.stroke: "#faad14"
472
+
473
+ "Blocklet Service" -> "SDK Request Helper": "3. 401 Unauthorized (Token Expired)"
474
+ "SDK Request Helper" -> "Token Refresh Endpoint": "4. Request New Token"
475
+ "Token Refresh Endpoint" -> "SDK Request Helper": "5. New Tokens Received"
476
+ "SDK Request Helper" -> "Blocklet Service": "6. Retry Original Request with New Token"
477
+ "Blocklet Service" -> "SDK Request Helper": "7. 200 OK" {
478
+ style.stroke: "#52c41a"
479
+ }
480
+ "SDK Request Helper" -> "Your App": "8. Returns Data Transparently" {
481
+ style.stroke: "#52c41a"
482
+ }
483
+ }
484
+ ```
485
+ - good:
486
+ ```d2
487
+ direction: down
488
+
489
+ "Your App": {
490
+ shape: rectangle
491
+ }
492
+
493
+ "SDK Request Helper": {
494
+ label: "@blocklet/js-sdk (createAxios / createFetch)"
495
+ shape: package
496
+ }
497
+
498
+ "Blocklet Service": {
499
+ shape: cylinder
500
+ }
501
+
502
+
503
+ "Your App" -> "SDK Request Helper": "1. Make API Call (e.g., /api/profile)"
504
+
505
+ "SDK Request Helper" -> "Blocklet Service": "2. Adds Auth Header & Sends Request" {
506
+ style {
507
+ stroke-dash: 2
508
+ }
509
+ }
510
+
511
+ "Blocklet Service" -> "SDK Request Helper": "3. 401 Unauthorized (Token Expired)"
512
+ "SDK Request Helper" -> "Token Refresh Endpoint": "4. Request New Token"
513
+ "Token Refresh Endpoint" -> "SDK Request Helper": "5. New Tokens Received"
514
+ "SDK Request Helper" -> "Blocklet Service": "6. Retry Original Request with New Token"
515
+ "Blocklet Service" -> "SDK Request Helper": "7. 200 OK" {
516
+ style.stroke: "#52c41a"
517
+ }
518
+ "SDK Request Helper" -> "Your App": "8. Returns Data Transparently" {
519
+ style.stroke: "#52c41a"
520
+ }
521
+ ```
522
+ - 如果整个图表只有一个容器节点,就不要增加这个容器节点,直接将内部的节点放在最外层
523
+ - bad:
524
+ ```d2
525
+ direction: down
526
+
527
+ "User Sessions Flow": {
528
+ shape: package
529
+ grid-columns: 1
530
+
531
+ "User Login": {
532
+ shape: person
533
+ style.fill: "#e6f7ff"
534
+ }
535
+
536
+ "Session Creation": {
537
+ shape: rectangle
538
+ style.fill: "#f6ffed"
539
+ }
540
+
541
+ "Session Storage": {
542
+ shape: cylinder
543
+ style.fill: "#fff7e6"
544
+ }
545
+
546
+ "Multi-Device Access": {
547
+ shape: package
548
+ grid-columns: 3
549
+ "Web Browser": {
550
+ shape: rectangle
551
+ }
552
+ "Mobile App": {
553
+ shape: rectangle
554
+ }
555
+ "Desktop App": {
556
+ shape: rectangle
557
+ }
558
+ }
559
+ "User Login" -> "Session Creation": "Authenticate"
560
+ "Session Creation" -> "Session Storage": "Store session"
561
+ "Session Storage" -> "Multi-Device Access": "Access from devices"
562
+ }
563
+ ```
564
+ - good:
565
+ ```d2
566
+ direction: down
567
+
568
+ "User Login": {
569
+ shape: person
570
+ style.fill: "#e6f7ff"
571
+ }
572
+
573
+ "Session Creation": {
574
+ shape: rectangle
575
+ style.fill: "#f6ffed"
576
+ }
577
+
578
+ "Session Storage": {
579
+ shape: cylinder
580
+ style.fill: "#fff7e6"
581
+ }
582
+
583
+ "Multi-Device Access": {
584
+ shape: package
585
+ grid-columns: 3
586
+ "Web Browser": {
587
+ shape: rectangle
588
+ }
589
+ "Mobile App": {
590
+ shape: rectangle
591
+ }
592
+ "Desktop App": {
593
+ shape: rectangle
594
+ }
595
+ }
596
+ "User Login" -> "Session Creation": "Authenticate"
597
+ "Session Creation" -> "Session Storage": "Store session"
598
+ "Session Storage" -> "Multi-Device Access": "Access from devices"
599
+ ```
600
+ - 某些情况下,单纯的设置 `direction: down` 还无法控制图表的整体方向,可以再结合 `grid-columns: 1` 来进行设置
601
+ - bad:
602
+ ```d2
603
+ direction: down
604
+
605
+ "Your Application": {
606
+ shape: rectangle
607
+ }
608
+
609
+ "@blocklet/js-sdk": {
610
+ shape: package
611
+ grid-columns: 1
612
+
613
+ "AuthService": {
614
+ shape: class
615
+ }
616
+ }
617
+
618
+ "Blocklet API Endpoints": {
619
+ shape: cylinder
620
+ grid-columns: 2
621
+ "/api/user/profile": {}
622
+ "/api/user/privacy/config": {}
623
+ "/api/user/notification/config": {}
624
+ "/api/user/logout": {}
625
+ "/api/user/follow/{did}": {}
626
+ "/api/user": {}
627
+ }
628
+
629
+ "Your Application" -> "@blocklet/js-sdk".AuthService: "e.g., sdk.auth.getProfile()"
630
+ "@blocklet/js-sdk".AuthService -> "Blocklet API Endpoints": "Makes authenticated API calls"
631
+ ```
632
+ - good:
633
+ ```d2
634
+ direction: down
635
+ grid-columns: 1
636
+
637
+ "Your Application": {
638
+ shape: rectangle
639
+ }
640
+
641
+ "@blocklet/js-sdk": {
642
+ shape: package
643
+ grid-columns: 1
644
+
645
+ "AuthService": {
646
+ shape: class
647
+ }
648
+ }
649
+
650
+ "Blocklet API Endpoints": {
651
+ shape: cylinder
652
+ grid-columns: 2
653
+ "/api/user/profile": {}
654
+ "/api/user/privacy/config": {}
655
+ "/api/user/notification/config": {}
656
+ "/api/user/logout": {}
657
+ "/api/user/follow/{did}": {}
658
+ "/api/user": {}
659
+ }
660
+
661
+ "Your Application" -> "@blocklet/js-sdk".AuthService: "e.g., sdk.auth.getProfile()"
662
+ "@blocklet/js-sdk".AuthService -> "Blocklet API Endpoints": "Makes authenticated API calls"
663
+ ```
664
+ - 当节点中子节点个数与 `grid-columns` 值相同时,则应该去掉 `grid-columns` 字段
665
+ - bad:
666
+ ```d2
667
+ "@blocklet/js-sdk": {
668
+ shape: package
669
+ grid-columns: 1
670
+
671
+ "AuthService": {
672
+ shape: class
673
+ }
674
+ }
675
+ ```
676
+ - good:
677
+ ```d2
678
+ "@blocklet/js-sdk": {
679
+ shape: package
680
+
681
+ "AuthService": {
682
+ shape: class
683
+ }
684
+ }
685
+ ```
686
+ - bad:
687
+ ```d2
688
+ "Browser Storage": {
689
+ shape: package
690
+ grid-columns: 2
691
+
692
+ "Cookies": {
693
+ shape: document
694
+ "Session Token": {}
695
+ }
696
+
697
+ "LocalStorage": {
698
+ shape: stored_data
699
+ "Refresh Token": {}
700
+ }
701
+ }
702
+ ```
703
+ - good:
704
+ ```d2
705
+ "Browser Storage": {
706
+ shape: package
707
+
708
+ "Cookies": {
709
+ shape: document
710
+ "Session Token": {}
711
+ }
712
+
713
+ "LocalStorage": {
714
+ shape: stored_data
715
+ "Refresh Token": {}
716
+ }
717
+ }
718
+ ```
719
+ - 当一个容器节点外部有节点与当前容器节点内部节点相互关联时,应该将这些节点放在同一层级
720
+ - bad:
721
+ ```d2
722
+ direction: down
723
+
724
+ "Federated Login Group": {
725
+ shape: package
726
+
727
+ "Master App": {
728
+ shape: rectangle
729
+ style.stroke: "#0052cc"
730
+ style.stroke-width: 2
731
+ "Provides central authentication"
732
+ }
733
+
734
+ "Member App 1 (Current App)": {
735
+ shape: rectangle
736
+ "User interacts here"
737
+ }
738
+
739
+ "Member App 2": {
740
+ shape: rectangle
741
+ }
742
+
743
+ "Master App" -> "Member App 1 (Current App)": "Shares user session"
744
+ "Master App" -> "Member App 2": "Shares user session"
745
+ }
746
+
747
+ User: {
748
+ shape: person
749
+ }
750
+
751
+ User -> "Member App 1 (Current App)": "Logs in via Master App"
752
+ ```
753
+ - good:
754
+ ```d2
755
+ direction: down
756
+
757
+ "Federated Login Group": {
758
+ shape: package
759
+
760
+ "Master App": {
761
+ shape: rectangle
762
+ style.stroke: "#0052cc"
763
+ style.stroke-width: 2
764
+ "Provides central authentication"
765
+ }
766
+
767
+ "Member App 1 (Current App)": {
768
+ shape: rectangle
769
+ "User interacts here"
770
+ }
771
+
772
+ "Member App 2": {
773
+ shape: rectangle
774
+ }
775
+
776
+ "Master App" -> "Member App 1 (Current App)": "Shares user session"
777
+ "Master App" -> "Member App 2": "Shares user session"
778
+
779
+ User: {
780
+ shape: person
781
+ }
782
+
783
+ User -> "Member App 1 (Current App)": "Logs in via Master App"
784
+ }
785
+
786
+ ```
787
+ - 当存在多层容器节点嵌套时,外层的容器节点应该使用 `grid-columns: 1`,这一点非常重要
788
+ - bad:
789
+ ```d2
790
+ direction: down
791
+
792
+ "User Account": {
793
+ shape: person
794
+ }
795
+
796
+ "Sessions": {
797
+ shape: package
798
+ grid-columns: 3
799
+
800
+ "Web Browser Session": {
801
+ shape: rectangle
802
+ "IP: 192.168.1.10"
803
+ "UA: Chrome on macOS"
804
+ "Status: online"
805
+ }
806
+
807
+ "iOS App Session": {
808
+ shape: rectangle
809
+ "IP: 10.0.0.5"
810
+ "UA: MyApp/1.2 iOS"
811
+ "Status: online"
812
+ }
813
+
814
+ "Old Laptop Session": {
815
+ shape: rectangle
816
+ "IP: 172.16.0.20"
817
+ "UA: Firefox on Windows"
818
+ "Status: expired"
819
+ }
820
+ }
821
+
822
+ "User Account" -> "Sessions": "Has multiple"
823
+ ```
824
+ - good:
825
+ ```d2
826
+ direction: down
827
+
828
+ "User Account": {
829
+ shape: person
830
+ }
831
+
832
+ "Sessions": {
833
+ shape: package
834
+ grid-columns: 1
835
+
836
+ "Web Browser Session": {
837
+ shape: rectangle
838
+ "IP: 192.168.1.10"
839
+ "UA: Chrome on macOS"
840
+ "Status: online"
841
+ }
842
+
843
+ "iOS App Session": {
844
+ shape: rectangle
845
+ "IP: 10.0.0.5"
846
+ "UA: MyApp/1.2 iOS"
847
+ "Status: online"
848
+ }
849
+
850
+ "Old Laptop Session": {
851
+ shape: rectangle
852
+ "IP: 172.16.0.20"
853
+ "UA: Firefox on Windows"
854
+ "Status: expired"
855
+ }
856
+ }
857
+
858
+ "User Account" -> "Sessions": "Has multiple"
859
+ ```
860
+ - 当一个节点容器中包含了其他的节点容器,建议使用 `grid-gap` 来增加各个节点容器的距离,尽量大于 100
861
+ - bad:
862
+ ```d2
863
+ direction: down
864
+
865
+ "Your Application": {
866
+ shape: rectangle
867
+ }
868
+
869
+ "SDK: @blocklet/js-sdk": {
870
+ shape: package
871
+ grid-columns: 1
872
+
873
+ "HTTP Clients": {
874
+ shape: rectangle
875
+ grid-columns: 2
876
+ "createAxios()": "Axios-based client"
877
+ "createFetch()": "Fetch-based client"
878
+ }
879
+
880
+ "Core Services": {
881
+ shape: rectangle
882
+ grid-columns: 3
883
+ "AuthService": "User & Auth"
884
+ "TokenService": "Token Management"
885
+ "UserSessionService": "Session Data"
886
+ "BlockletService": "Blocklet Metadata"
887
+ "FederatedService": "Federated Login"
888
+ }
889
+
890
+ "HTTP Clients" -> "Core Services".TokenService: "Uses for auth tokens"
891
+ }
892
+
893
+ "Blocklet Services": {
894
+ shape: cylinder
895
+ "Remote APIs"
896
+ }
897
+
898
+ "Your Application" -> "SDK: @blocklet/js-sdk": "Imports & Initializes"
899
+ "SDK: @blocklet/js-sdk" -> "Blocklet Services": "Makes authenticated requests"
900
+ ```
901
+ - bad:
902
+ ```d2
903
+ direction: down
904
+
905
+ "Your Application": {
906
+ shape: rectangle
907
+ }
908
+
909
+ "SDK: @blocklet/js-sdk": {
910
+ shape: package
911
+ grid-columns: 1
912
+ grid-gap: 100
913
+
914
+ "HTTP Clients": {
915
+ shape: rectangle
916
+ grid-columns: 2
917
+ "createAxios()": "Axios-based client"
918
+ "createFetch()": "Fetch-based client"
919
+ }
920
+
921
+ "Core Services": {
922
+ shape: rectangle
923
+ grid-columns: 3
924
+ "AuthService": "User & Auth"
925
+ "TokenService": "Token Management"
926
+ "UserSessionService": "Session Data"
927
+ "BlockletService": "Blocklet Metadata"
928
+ "FederatedService": "Federated Login"
929
+ }
930
+
931
+ "HTTP Clients" -> "Core Services".TokenService: "Uses for auth tokens"
932
+ }
933
+
934
+ "Blocklet Services": {
935
+ shape: cylinder
936
+ "Remote APIs"
937
+ }
938
+
939
+ "Your Application" -> "SDK: @blocklet/js-sdk": "Imports & Initializes"
940
+ "SDK: @blocklet/js-sdk" -> "Blocklet Services": "Makes authenticated requests"
941
+ ```
942
+ - 如果节点的 `shape: person`,则不要加任何其他内部的文字
943
+ - bad:
944
+ ```d2
945
+ "User Account": {
946
+ shape: person
947
+ "did:z... (John Doe)"
948
+ }
949
+ ```
950
+ - good:
951
+ ```d2
952
+ "User Account": {
953
+ shape: person
954
+ }
955
+ ```
956
+ - 示例参考:
957
+ {% include "diy-examples.md" %}