@hitch42/applet 0.1.1-beta.1 → 0.1.1-beta.11

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.
Files changed (178) hide show
  1. package/dist/_internal/client.js +120 -11
  2. package/dist/_internal/log-context.d.ts +34 -0
  3. package/dist/_internal/log-context.js +2 -0
  4. package/dist/_internal/server.d.ts +14 -1
  5. package/dist/_internal/server.js +122 -118
  6. package/dist/applet.js +53 -29
  7. package/dist/build-Bh_S5BUv.js +2 -0
  8. package/dist/{build-Rk3xDZV7.js → build-CEfFoIZZ.js} +30 -14
  9. package/dist/ci-BKw14X2h.js +69 -0
  10. package/dist/client.d.ts +3 -3
  11. package/dist/{contract-DMrpbaLJ.d.ts → contract-CsUpTBe0.d.ts} +1 -1
  12. package/dist/{deploy-D3BGDqgC.js → deploy-wGYjwXrx.js} +249 -35
  13. package/dist/email-DBTVhNB_.js +62 -0
  14. package/dist/{generate-CH0VQmUi.js → generate-BEIYs17x.js} +79 -25
  15. package/dist/generate-Dox-OYt6.js +2 -0
  16. package/dist/headers-DkNr9MLJ.js +17 -0
  17. package/dist/index.d.ts +123 -11
  18. package/dist/index.js +142 -26
  19. package/dist/{init-BS1Y-eNL.js → init-6oGPM46R.js} +17 -18
  20. package/dist/load-config-xEdTXs0y.js +27 -0
  21. package/dist/log-context-zu8U9Sjm.js +73 -0
  22. package/dist/login-CUx3TmFQ.js +12 -0
  23. package/dist/{logs-m00pzr_O.js → logs-DSjuEN0Q.js} +20 -22
  24. package/dist/{manifest-BQCAxATS.d.ts → manifest-C6_F4bL8.d.ts} +9 -0
  25. package/dist/{manifest-DyoJ1MIL.js → manifest-CJSL9GuC.js} +25 -3
  26. package/dist/me-BW7Paary.js +32 -0
  27. package/dist/{project-CxN-Dtc7.js → project-BRZGd6xq.js} +227 -34
  28. package/dist/prompt-ChS-grYO.js +29 -0
  29. package/dist/query-cache-CXmAyLv3.js +82 -0
  30. package/dist/react.d.ts +3 -2
  31. package/dist/react.js +98 -80
  32. package/dist/schedules-C8_Svr4h.js +42 -0
  33. package/dist/server.d.ts +9 -4
  34. package/dist/server.js +29 -8
  35. package/dist/telephony-protocol-D-nf3Gca.d.ts +76 -0
  36. package/dist/telephony.d.ts +97 -0
  37. package/dist/telephony.js +726 -0
  38. package/dist/{upload-YbRKEqR6.d.ts → upload-DKZzz5kW.d.ts} +6 -6
  39. package/dist/{variables-CP7Ce3Np.js → variables-DT5RyHdH.js} +14 -39
  40. package/dist/vite.d.ts +3 -60
  41. package/dist/vite.js +503 -34
  42. package/dist/workflow-engine-BOTzURKM.js +111 -0
  43. package/dist/{auth-DaVK0k5R.js → workspace-D0dnnlxL.js} +75 -40
  44. package/package.json +19 -6
  45. package/scaffold/.agents/skills/hitch-applets/SKILL.md +60 -15
  46. package/scaffold/.agents/skills/hitch-applets/references/email-tracking.md +49 -0
  47. package/scaffold/.agents/skills/hitch-applets/references/files.md +3 -3
  48. package/scaffold/.agents/skills/hitch-applets/references/manifest.md +29 -2
  49. package/scaffold/.agents/skills/hitch-applets/references/markdown.md +2 -0
  50. package/scaffold/.agents/skills/hitch-applets/references/performance.md +74 -0
  51. package/scaffold/.agents/skills/hitch-applets/references/records.md +32 -8
  52. package/scaffold/.agents/skills/hitch-applets/references/schedules.md +7 -2
  53. package/scaffold/.agents/skills/hitch-applets/references/server.md +0 -3
  54. package/scaffold/.agents/skills/hitch-applets/references/workflows.md +11 -3
  55. package/scaffold/.agents/skills/hitch-cli/SKILL.md +129 -0
  56. package/scaffold/.agents/skills/hitch-data/SKILL.md +52 -0
  57. package/scaffold/.agents/skills/hitch-data/references/attributes.md +127 -0
  58. package/scaffold/.agents/skills/hitch-data/references/limits.md +64 -0
  59. package/scaffold/.agents/skills/hitch-theory/SKILL.md +151 -0
  60. package/scaffold/.agents/skills/react-best-practices/SKILL.md +127 -0
  61. package/scaffold/.agents/skills/react-best-practices/rules/advanced-effect-event-deps.md +50 -0
  62. package/scaffold/.agents/skills/react-best-practices/rules/advanced-event-handler-refs.md +55 -0
  63. package/scaffold/.agents/skills/react-best-practices/rules/advanced-init-once.md +42 -0
  64. package/scaffold/.agents/skills/react-best-practices/rules/advanced-use-latest.md +39 -0
  65. package/scaffold/.agents/skills/react-best-practices/rules/async-cheap-condition-before-await.md +37 -0
  66. package/scaffold/.agents/skills/react-best-practices/rules/async-defer-await.md +82 -0
  67. package/scaffold/.agents/skills/react-best-practices/rules/async-dependencies.md +48 -0
  68. package/scaffold/.agents/skills/react-best-practices/rules/async-parallel.md +24 -0
  69. package/scaffold/.agents/skills/react-best-practices/rules/bundle-analyzable-paths.md +42 -0
  70. package/scaffold/.agents/skills/react-best-practices/rules/bundle-barrel-imports.md +39 -0
  71. package/scaffold/.agents/skills/react-best-practices/rules/bundle-conditional.md +35 -0
  72. package/scaffold/.agents/skills/react-best-practices/rules/bundle-defer-third-party.md +46 -0
  73. package/scaffold/.agents/skills/react-best-practices/rules/bundle-dynamic-imports.md +38 -0
  74. package/scaffold/.agents/skills/react-best-practices/rules/bundle-preload.md +40 -0
  75. package/scaffold/.agents/skills/react-best-practices/rules/client-event-listeners.md +78 -0
  76. package/scaffold/.agents/skills/react-best-practices/rules/client-localstorage-schema.md +74 -0
  77. package/scaffold/.agents/skills/react-best-practices/rules/client-passive-event-listeners.md +48 -0
  78. package/scaffold/.agents/skills/react-best-practices/rules/js-batch-dom-css.md +110 -0
  79. package/scaffold/.agents/skills/react-best-practices/rules/js-cache-function-results.md +58 -0
  80. package/scaffold/.agents/skills/react-best-practices/rules/js-cache-property-access.md +28 -0
  81. package/scaffold/.agents/skills/react-best-practices/rules/js-cache-storage.md +56 -0
  82. package/scaffold/.agents/skills/react-best-practices/rules/js-combine-iterations.md +32 -0
  83. package/scaffold/.agents/skills/react-best-practices/rules/js-early-exit.md +50 -0
  84. package/scaffold/.agents/skills/react-best-practices/rules/js-flatmap-filter.md +51 -0
  85. package/scaffold/.agents/skills/react-best-practices/rules/js-hoist-regexp.md +45 -0
  86. package/scaffold/.agents/skills/react-best-practices/rules/js-index-maps.md +37 -0
  87. package/scaffold/.agents/skills/react-best-practices/rules/js-length-check-first.md +50 -0
  88. package/scaffold/.agents/skills/react-best-practices/rules/js-min-max-loop.md +82 -0
  89. package/scaffold/.agents/skills/react-best-practices/rules/js-request-idle-callback.md +104 -0
  90. package/scaffold/.agents/skills/react-best-practices/rules/js-set-map-lookups.md +24 -0
  91. package/scaffold/.agents/skills/react-best-practices/rules/js-tosorted-immutable.md +57 -0
  92. package/scaffold/.agents/skills/react-best-practices/rules/rendering-activity.md +26 -0
  93. package/scaffold/.agents/skills/react-best-practices/rules/rendering-animate-svg-wrapper.md +38 -0
  94. package/scaffold/.agents/skills/react-best-practices/rules/rendering-conditional-render.md +32 -0
  95. package/scaffold/.agents/skills/react-best-practices/rules/rendering-content-visibility.md +38 -0
  96. package/scaffold/.agents/skills/react-best-practices/rules/rendering-hoist-jsx.md +36 -0
  97. package/scaffold/.agents/skills/react-best-practices/rules/rendering-resource-hints.md +81 -0
  98. package/scaffold/.agents/skills/react-best-practices/rules/rendering-script-defer-async.md +36 -0
  99. package/scaffold/.agents/skills/react-best-practices/rules/rendering-svg-precision.md +28 -0
  100. package/scaffold/.agents/skills/react-best-practices/rules/rendering-usetransition-loading.md +43 -0
  101. package/scaffold/.agents/skills/react-best-practices/rules/rerender-defer-reads.md +39 -0
  102. package/scaffold/.agents/skills/react-best-practices/rules/rerender-dependencies.md +45 -0
  103. package/scaffold/.agents/skills/react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
  104. package/scaffold/.agents/skills/react-best-practices/rules/rerender-derived-state.md +29 -0
  105. package/scaffold/.agents/skills/react-best-practices/rules/rerender-functional-setstate.md +77 -0
  106. package/scaffold/.agents/skills/react-best-practices/rules/rerender-lazy-state-init.md +56 -0
  107. package/scaffold/.agents/skills/react-best-practices/rules/rerender-memo-with-default-value.md +36 -0
  108. package/scaffold/.agents/skills/react-best-practices/rules/rerender-memo.md +44 -0
  109. package/scaffold/.agents/skills/react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
  110. package/scaffold/.agents/skills/react-best-practices/rules/rerender-no-inline-components.md +75 -0
  111. package/scaffold/.agents/skills/react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
  112. package/scaffold/.agents/skills/react-best-practices/rules/rerender-split-combined-hooks.md +64 -0
  113. package/scaffold/.agents/skills/react-best-practices/rules/rerender-transitions.md +40 -0
  114. package/scaffold/.agents/skills/react-best-practices/rules/rerender-use-deferred-value.md +59 -0
  115. package/scaffold/.agents/skills/react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
  116. package/scaffold/.agents/skills/tanstack-query/SKILL.md +136 -0
  117. package/scaffold/.agents/skills/tanstack-query/references/compositions/automatic-invalidation-after-mutations.md +124 -0
  118. package/scaffold/.agents/skills/tanstack-query/references/compositions/broadcast-realtime-and-multi-tab-synchronization.md +150 -0
  119. package/scaffold/.agents/skills/tanstack-query/references/compositions/compose-query-with-tanstack-router-and-start.md +248 -0
  120. package/scaffold/.agents/skills/tanstack-query/references/compositions/enforce-query-best-practices-with-eslint.md +167 -0
  121. package/scaffold/.agents/skills/tanstack-query/references/compositions/persist-offline-and-restore-caches.md +181 -0
  122. package/scaffold/.agents/skills/tanstack-query/references/compositions/query-data-and-forms.md +156 -0
  123. package/scaffold/.agents/skills/tanstack-query/references/core/build-query-abstractions.md +130 -0
  124. package/scaffold/.agents/skills/tanstack-query/references/core/cancel-queries-and-consume-abort-signals.md +176 -0
  125. package/scaffold/.agents/skills/tanstack-query/references/core/concurrent-optimistic-updates.md +135 -0
  126. package/scaffold/.agents/skills/tanstack-query/references/core/coordinate-query-execution.md +188 -0
  127. package/scaffold/.agents/skills/tanstack-query/references/core/design-query-keys-and-options.md +182 -0
  128. package/scaffold/.agents/skills/tanstack-query/references/core/fetch-and-observe-queries.md +193 -0
  129. package/scaffold/.agents/skills/tanstack-query/references/core/implement-optimistic-updates-and-cache-writes.md +168 -0
  130. package/scaffold/.agents/skills/tanstack-query/references/core/paginate-and-build-infinite-queries.md +188 -0
  131. package/scaffold/.agents/skills/tanstack-query/references/core/seed-placeholder-select-and-transform-data.md +188 -0
  132. package/scaffold/.agents/skills/tanstack-query/references/core/selectors-and-derived-state.md +145 -0
  133. package/scaffold/.agents/skills/tanstack-query/references/core/tune-defaults-freshness-retries-and-refetching.md +172 -0
  134. package/scaffold/.agents/skills/tanstack-query/references/core/understand-query-internals-and-observers.md +104 -0
  135. package/scaffold/.agents/skills/tanstack-query/references/core/write-mutations-and-invalidate-related-queries.md +183 -0
  136. package/scaffold/.agents/skills/tanstack-query/references/framework/debug-with-devtools.md +169 -0
  137. package/scaffold/.agents/skills/tanstack-query/references/framework/handle-status-and-errors.md +119 -0
  138. package/scaffold/.agents/skills/tanstack-query/references/framework/shape-data-and-render-efficiently.md +184 -0
  139. package/scaffold/.agents/skills/tanstack-query/references/framework/use-framework-adapter-reactivity.md +185 -0
  140. package/scaffold/.agents/skills/tanstack-query/references/framework/use-suspense-and-error-boundaries.md +208 -0
  141. package/scaffold/.agents/skills/tanstack-query/references/lifecycle/migrate-major-versions-and-codemods.md +169 -0
  142. package/scaffold/.agents/skills/tanstack-query/references/lifecycle/prefetch-and-remove-request-waterfalls.md +228 -0
  143. package/scaffold/.agents/skills/tanstack-query/references/lifecycle/setup-query-client-and-providers.md +161 -0
  144. package/scaffold/.agents/skills/tanstack-query/references/lifecycle/ssr-hydration-and-streaming.md +209 -0
  145. package/scaffold/.agents/skills/tanstack-query/references/lifecycle/test-query-code.md +160 -0
  146. package/scaffold/.agents/skills/tanstack-router/SKILL.md +134 -0
  147. package/scaffold/.agents/skills/tanstack-router/references/compositions/router-query.md +412 -0
  148. package/scaffold/.agents/skills/tanstack-router/references/react-router.md +495 -0
  149. package/scaffold/.agents/skills/tanstack-router/references/router-core/auth-and-guards.md +495 -0
  150. package/scaffold/.agents/skills/tanstack-router/references/router-core/code-splitting.md +318 -0
  151. package/scaffold/.agents/skills/tanstack-router/references/router-core/data-loading.md +490 -0
  152. package/scaffold/.agents/skills/tanstack-router/references/router-core/index.md +158 -0
  153. package/scaffold/.agents/skills/tanstack-router/references/router-core/navigation.md +433 -0
  154. package/scaffold/.agents/skills/tanstack-router/references/router-core/not-found-and-errors.md +436 -0
  155. package/scaffold/.agents/skills/tanstack-router/references/router-core/path-params.md +383 -0
  156. package/scaffold/.agents/skills/tanstack-router/references/router-core/search-params.md +343 -0
  157. package/scaffold/.agents/skills/tanstack-router/references/router-core/ssr.md +462 -0
  158. package/scaffold/.agents/skills/tanstack-router/references/router-core/type-safety.md +493 -0
  159. package/scaffold/.agents/skills/tanstack-router/references/router-plugin.md +250 -0
  160. package/scaffold/.agents/skills/tanstack-router/references/virtual-file-routes.md +215 -0
  161. package/scaffold/.agents/skills/web-design-guidelines/SKILL.md +184 -0
  162. package/scaffold/.github/workflows/hitch.yml +15 -0
  163. package/scaffold/AGENTS.md +2 -2
  164. package/scaffold/applet/src/client/components/ui/alert.tsx +1 -1
  165. package/scaffold/applet/src/client/components/ui/button.tsx +1 -1
  166. package/scaffold/applet/src/client/components/ui/checkbox.tsx +1 -1
  167. package/scaffold/applet/src/client/components/ui/dialog.tsx +2 -2
  168. package/scaffold/applet/src/client/components/ui/dropdown-menu.tsx +2 -2
  169. package/scaffold/applet/src/client/components/ui/input-group.tsx +2 -2
  170. package/scaffold/applet/src/client/components/ui/select.tsx +2 -2
  171. package/scaffold/applet/src/client/components/ui/sheet.tsx +2 -2
  172. package/scaffold/applet/src/client/components/ui/spinner.tsx +2 -1
  173. package/scaffold/applet/src/client/components/ui/tabs.tsx +1 -1
  174. package/scaffold/applet/src/client/lib/utils.ts +1 -6
  175. package/scaffold/applet/src/client/styles/globals.css +2 -0
  176. package/dist/build-CEku1lyb.js +0 -2
  177. package/dist/generate-6Nbt7uii.js +0 -2
  178. package/dist/load-config-BnxocLAQ.js +0 -56
@@ -0,0 +1,151 @@
1
+ ---
2
+ name: hitch-theory
3
+ description: The mental model of Hitch. Read before you design, review, or explain anything that touches Hitch data, applets, access, or query cost. Use when a decision depends on what Hitch is for, what Hitch handles versus what an applet handles, how attributes and references model data, how changesets and releases move together, or who a call acts as. Pairs with hitch-applets, which holds the build procedure.
4
+ ---
5
+
6
+ # Theory of Hitch
7
+
8
+ This skill explains how Hitch works and why. For the build procedure, read the `hitch-applets` skill.
9
+
10
+ ## 1. What Hitch is
11
+
12
+ Hitch is a platform for internal applications. It is not a CRM, a rostering product, a reporting product, or any other vertical. An organization builds its own rostering, job, or invoice applets on Hitch.
13
+
14
+ Hitch is two layers:
15
+
16
+ 1. A durable data system that the organization owns: objects, attributes, records, files, identity, and grants.
17
+ 2. A governed runtime for replaceable software: applets that Hitch builds, releases, hosts, and runs.
18
+
19
+ ## 2. What an applet is
20
+
21
+ An applet is not an app. An app is the whole machine from the old days of software: its own authentication, its own database, its own permissions, a frontend, a server, caches, a deployment pipeline, and monitoring. Every app rebuilds that machine from scratch. Every app then spends most of its life on the machine, not on the work. The organization never wanted the machine. It wanted the business logic.
22
+
23
+ AI has changed the economics of software. Code is now cheap to write and cheap to change, so software can be personal to one organization, one team, and one workflow. Hitch is built for that world. Hitch flips the model. Instead of one monolithic app designed to serve many unrelated users, an organization gets a set of many applets, completely custom and personalised to its needs. An applet is the closest thing to pure business logic: one workflow, the screens it needs, and the rules that make it correct. Hitch handles everything underneath: the data and its schema, identity, permissions, files, immutable releases, hosting, schedules, and durable workflows. The author never touches the machine. The author builds only what matters to the user.
24
+
25
+ Hitch takes the machine away for correctness and trust as much as for speed. Authentication, access control, schema validation, and release safety are the parts an agent gets wrong, and the parts an organization cannot afford to have wrong. Hitch handles them, so your organisation has the confidence it needs to fully adopt vibe coded software and move off of legacy SaaS systems.
26
+
27
+ In practice an applet is a client-only, server-only, or full-stack application that Hitch builds, releases, hosts, and runs inside the platform trust boundary. It is not a third-party plugin.
28
+
29
+ Every organization has its own tenant on Hitch. Its data, its users, its grants, and its applets all live there. When Hitch runs an applet, it runs it inside that tenant, the way AWS runs a workload inside a customer's account: the provider operates the infrastructure, but the account, the identities, and the data are the customer's. An applet sees its organization's tenant and nothing else.
30
+
31
+ Applets can be used standalone via their `.app` URL or within the Hitch shell. Standalone and embedded operation use the same identity, release, routes, and theme.
32
+
33
+ ## 3. What Hitch handles and what an applet handles
34
+
35
+ | Hitch handles | The applet handles |
36
+ | --------------------------------------------------------------- | --------------------------------------------- |
37
+ | Canonical organization records and files | One focused workflow and its presentation |
38
+ | Object and attribute schema, and references | Domain-specific UI composition |
39
+ | Validation, normalization, constraints, versions, audit | External API adapters and translation |
40
+ | Organization identity, authentication, grants | User interactions and app-specific validation |
41
+ | Immutable releases, schedules, the workflow engine, the runtime | Derived views and deliberate derived records |
42
+ | Theme delivery and platform navigation | Ephemeral client state |
43
+
44
+ ## 4. Why code and data are separate
45
+
46
+ The organization's Hitch data is the single source of truth. An applet reads and writes that data. It does not keep its own copy.
47
+
48
+ The data layer stands on its own so that every way of using it is a client of the same thing. An applet, the `hitch` command line, an MCP server for an AI agent, an API key in a script, and an import all speak to the same objects, the same schema, and the same permissions. None of them is a bridge bolted on later. The CLI and applet doors are generated from the organization's own schema. The MCP door has a fixed set of record tools and reads each object's live schema at runtime with `get_object_schema`. Each one acts as the person or applet behind it, so it sees exactly what that caller may see. The result is that a person in a browser, an agent in a chat window, and a script in a terminal all work on the same records under the same rules, and each gets the interface that suits them. Software stops being one product with one screen and becomes your organizational data with many doors.
49
+
50
+ The boundary gives you:
51
+
52
+ - One source of truth that many applets share.
53
+ - One set of schema and integrity rules for every writer: applets, API keys, imports, and future code.
54
+ - Central permissions that applet UI code cannot weaken.
55
+ - Independent applet release and rollback with no data fork.
56
+ - Direct user-scoped reads from the browser, with no applet server proxy.
57
+ - One place for integrations: sync an external system into Hitch once, then let other applets use the same data.
58
+
59
+ Consequences:
60
+
61
+ - Do not add an applet-owned database, a parallel cache, or a copied object set. If an applet seems to need its own storage, Hitch has a gap. Raise the gap instead.
62
+ - Code rollback is not data recovery. A release switch never moves or restores records.
63
+ - When you install, upgrade, or remove an applet, the canonical data stays where it is.
64
+ - A domain rule can live in applet code when it controls one workflow. If the rule must hold for every writer, express it in the schema, so Hitch enforces it for every applet, API key, and import.
65
+ - Data normalization and UI hierarchy are separate decisions. Model distinct concepts as objects plus references when their lifecycle or permissions differ. Group them on one screen when that matches the user. Do not invent child objects to solve navigation.
66
+
67
+ ## 5. Attributes are schema
68
+
69
+ An attribute is schema, not a free JSON field. Hitch validates each value against its type and configuration, normalizes it, stores it in the record, and indexes it when asked. A value that should be a select or a reference, but is stored as free text, cannot be grouped or filtered well later.
70
+
71
+ - Types: text, rich text, integer, decimal, currency, checkbox, date, datetime, time, domain, url, email, phone, select, reference, user, organisation, attachment.
72
+ - Cardinality is configuration, not a type. Text, select, reference, user, and attachment can be multi-value. A multi-value is an ordered array.
73
+ - An empty attribute reads as null. A required multi-value attribute rejects an empty array.
74
+ - Uniqueness is a real constraint, per attribute, per organization.
75
+ - Advanced filters and sorting are opt-in per attribute with the `indexed` flag. New attributes default to off. Every attribute still supports equality and not-empty filters. Aggregating or grouping by an attribute needs no flag. Type rules still apply: a reference, user, attachment, rich text, or multi-value attribute never sorts. Do not turn the flag on for every attribute. Turn it on for the attributes a query needs.
76
+
77
+ References model relationships:
78
+
79
+ - A reference attribute names a target object. Cardinality on each side comes from the single or multi setting of each face.
80
+ - A reference can expose an inverse face on the target object. One face owns and stores the edges. The other face is derived. Write the owner face only.
81
+ - Hitch keeps the links typed, clears inbound links when a target is deleted, applies grants through the inverse, and lets you filter through either face. Do not invent a join object for a plain relationship. Use a join object only when the relationship needs its own fields or lifecycle.
82
+
83
+ Special cases:
84
+
85
+ - A user attribute points at a membership in the same organization. Removal of the member sweeps those values.
86
+ - An organisation attribute points at a connected organisation; null means internal only; at most one exists per object.
87
+ - An attachment attribute holds file IDs. Files live outside records, in their own storage. Create the file, upload it, then store the ID on the record.
88
+
89
+ ## 6. Changesets and releases move together
90
+
91
+ All schema mutations go through a changeset: an ordered list of object and attribute operations with a stored evaluation.
92
+
93
+ - A hard blocker means invalid schema or data. Examples: a unique constraint that finds duplicates, a required attribute with empty records, a tightened range with violators.
94
+ - A soft blocker means a dependency. Examples: applets, grant conditions, or delegations that depend on the object or attribute.
95
+ - Any blocker stops the apply. A submit with a blocker stages a pending changeset. The apply succeeds after the blocker is resolved.
96
+
97
+ An applet release can bind to a pending changeset. Hitch checks the manifest against the schema the changeset will produce. A mismatch is a deploy warning, not a denial. The unresolved warning becomes a hard blocker on the changeset. A bound release does not go live on deploy. When the changeset applies, the schema and the newest bound release of each applet become active together. Schema and code change together.
98
+
99
+ Adoption folds one pending changeset into another and abandons the source. The source must have no bound releases.
100
+
101
+ The applet manifest lists the objects the applet uses, with create and delete flags, read-only attributes, and read-write attributes. That list is the access declaration. It caps what the applet identity can do: the object actions, and the attributes it can update. It does not change what a user can see.
102
+
103
+ ## 7. Identity and access
104
+
105
+ Hitch enforces access control on every Hitch API call. An applet never re-implements it. A UI filter or a hidden control is convenience, never a boundary. An applet's own server procedure is applet code, so it must check the business rules it introduces. Every call carries a principal and Hitch applies that principal's grants.
106
+
107
+ Principals:
108
+
109
+ - A person, through a session or a personal API key. A personal API key inherits the member's capabilities.
110
+ - An impersonated person. The target's capabilities must be a proper subset of the caller's.
111
+ - An applet. The applet identity has no role and no bypass. Its authority is exactly the grants projected from its manifest.
112
+
113
+ The organization roles are member and owner. There is no admin role. The owner holds every capability, bypasses every grant, and cannot be removed or impersonated. Capabilities are ten named org-wide powers: manage members, teams, objects, permissions, applets, and the organization; read all records; write all records; use applets; impersonate members. A capability grant goes to a team only, never to a person or to everyone. When one person needs a capability, put them in a one-person team. A caller can grant only a capability the caller holds.
114
+
115
+ Object grants are the matrix: one row per object and grantee with create, read, update, and delete flags. A grantee is a team, an applet, or the default row that every member holds. A member's access is the union of the default row and their team rows. The read-all and write-all capabilities bypass object grants. Object grants set the verbs. Conditions narrow rows. Attribute grants restrict updates to protected attributes and applet writes. Reads are never masked per attribute.
116
+
117
+ An object grant can delegate through one single-valued owner reference. The linked record then uses the same grantee's grant on the target object.
118
+
119
+ Grant conditions scope rows to the current user. A condition path is a user attribute on the object, or one reference followed by a user attribute on the target object. A record whose user attribute is empty is invisible to that grant. An invisible record behaves as missing. A condition applies to read, update, and delete, never to create. A condition cannot compare a value, such as "where status equals X".
120
+
121
+ Who a call acts as:
122
+
123
+ - A client applet call acts as the current user. The manifest grants do not apply.
124
+ - A schedule run acts as the applet, capped by the manifest.
125
+ - A workflow run acts as whoever started it: the invoking user, or the applet when a schedule started it.
126
+
127
+ Because Hitch enforces access, a client applet needs no server proxy for filtering or access control. Add a server only for secrets, external systems, schedules, workflows, or bounded fan-in.
128
+
129
+ ## 8. What makes a good applet
130
+
131
+ A good applet:
132
+
133
+ - Solves one related workflow for one clear group of users.
134
+ - Uses the organization's existing Hitch data, not a private copy.
135
+ - Presents the smallest useful set of decisions and actions. It does not reproduce a legacy product screen for screen.
136
+ - Uses Hitch primitives before custom infrastructure.
137
+ - Feels native through semantic theme tokens, shared interaction patterns, useful empty, loading, and error states, and viewport-safe layouts.
138
+ - Has explicit access, performance, failure, and recovery behavior.
139
+ - Can be replaced or rolled back with no move or rewrite of the canonical data.
140
+
141
+ Split an applet when workflows, audiences, privileges, release cadence, or failure modes differ. Do not split because the UI has another page. A sync applet and a reporting applet are a good split. Ingestion has secrets, schedules, broad write grants, retries, and external failure modes. Reports read already-synced data with narrow grants.
142
+
143
+ ## 9. Product-design principles
144
+
145
+ - Build to user outcomes, not to the screens or tables of an older system.
146
+ - Start with the important nouns, relationships, permissions, and failure cases. Design screens after that.
147
+ - Simplify critically. Defer speculative channels and infrastructure.
148
+ - Ship the smallest complete workflow. Add nothing unrequested.
149
+ - Treat thresholds, status rules, timing, channels, and recipients as product decisions for the user.
150
+ - Confirm destructive or external writes. Show the target, the intended change, the stale-source check, and the outcome. A Hitch mutation and a mutation of an external source are not equivalent.
151
+ - Record rejected designs and the reason. Do not rebuild what was deliberately cut.
@@ -0,0 +1,127 @@
1
+ ---
2
+ name: react-best-practices
3
+ description: Client React performance guidelines. Use when writing, reviewing, or refactoring React components, client data fetching, bundles, rendering, or browser performance.
4
+ license: MIT
5
+ metadata:
6
+ version: "1.0.0"
7
+ ---
8
+
9
+ # React Best Practices
10
+
11
+ Performance guidance for client React applications. The rules focus on browser behavior, client data fetching, bundles, rendering, and re-renders.
12
+
13
+ ## When to Apply
14
+
15
+ Reference these guidelines when:
16
+
17
+ - Writing new React components
18
+ - Implementing client data fetching
19
+ - Reviewing code for performance issues
20
+ - Refactoring existing React code
21
+ - Optimizing bundle size or load times
22
+
23
+ ## Rule Categories by Priority
24
+
25
+ | Priority | Category | Impact | Prefix |
26
+ | -------- | ------------------------- | ----------- | ------------ |
27
+ | 1 | Eliminating Waterfalls | CRITICAL | `async-` |
28
+ | 2 | Bundle Size Optimization | CRITICAL | `bundle-` |
29
+ | 3 | Client-Side Data Fetching | MEDIUM-HIGH | `client-` |
30
+ | 4 | Re-render Optimization | MEDIUM | `rerender-` |
31
+ | 5 | Rendering Performance | MEDIUM | `rendering-` |
32
+ | 6 | JavaScript Performance | LOW-MEDIUM | `js-` |
33
+ | 7 | Advanced Patterns | LOW | `advanced-` |
34
+
35
+ ## Quick Reference
36
+
37
+ ### 1. Eliminating Waterfalls (CRITICAL)
38
+
39
+ - `async-cheap-condition-before-await` - Check cheap sync conditions before awaiting flags or remote values
40
+ - `async-defer-await` - Move await into branches where actually used
41
+ - `async-parallel` - Use Promise.all() for independent operations
42
+ - `async-dependencies` - Use better-all for partial dependencies
43
+
44
+ ### 2. Bundle Size Optimization (CRITICAL)
45
+
46
+ - `bundle-barrel-imports` - Import directly, avoid barrel files
47
+ - `bundle-analyzable-paths` - Prefer statically analyzable imports
48
+ - `bundle-dynamic-imports` - Use React.lazy for heavy components
49
+ - `bundle-defer-third-party` - Split non-critical libraries from the initial bundle
50
+ - `bundle-conditional` - Load modules only when feature is activated
51
+ - `bundle-preload` - Preload on hover/focus for perceived speed
52
+
53
+ ### 3. Client-Side Data Fetching (MEDIUM-HIGH)
54
+
55
+ - `client-event-listeners` - Deduplicate global event listeners
56
+ - `client-passive-event-listeners` - Use passive listeners for scroll
57
+ - `client-localstorage-schema` - Version and minimize localStorage data
58
+
59
+ ### 4. Re-render Optimization (MEDIUM)
60
+
61
+ - `rerender-defer-reads` - Don't subscribe to state only used in callbacks
62
+ - `rerender-memo` - Extract expensive work into memoized components
63
+ - `rerender-memo-with-default-value` - Hoist default non-primitive props
64
+ - `rerender-dependencies` - Use primitive dependencies in effects
65
+ - `rerender-derived-state` - Subscribe to derived booleans, not raw values
66
+ - `rerender-derived-state-no-effect` - Derive state during render, not effects
67
+ - `rerender-functional-setstate` - Use functional setState for stable callbacks
68
+ - `rerender-lazy-state-init` - Pass function to useState for expensive values
69
+ - `rerender-simple-expression-in-memo` - Avoid memo for simple primitives
70
+ - `rerender-split-combined-hooks` - Split hooks with independent dependencies
71
+ - `rerender-move-effect-to-event` - Put interaction logic in event handlers
72
+ - `rerender-transitions` - Use startTransition for non-urgent updates
73
+ - `rerender-use-deferred-value` - Defer expensive renders to keep input responsive
74
+ - `rerender-use-ref-transient-values` - Use refs for transient frequent values
75
+ - `rerender-no-inline-components` - Don't define components inside components
76
+
77
+ ### 5. Rendering Performance (MEDIUM)
78
+
79
+ - `rendering-animate-svg-wrapper` - Animate div wrapper, not SVG element
80
+ - `rendering-content-visibility` - Use content-visibility for long lists
81
+ - `rendering-hoist-jsx` - Extract static JSX outside components
82
+ - `rendering-svg-precision` - Reduce SVG coordinate precision
83
+ - `rendering-activity` - Use Activity component for show/hide
84
+ - `rendering-conditional-render` - Use ternary, not && for conditionals
85
+ - `rendering-usetransition-loading` - Track async action pending state with useTransition
86
+ - `rendering-resource-hints` - Use React DOM resource hints for preloading
87
+ - `rendering-script-defer-async` - Use defer or async on script tags
88
+
89
+ ### 6. JavaScript Performance (LOW-MEDIUM)
90
+
91
+ - `js-batch-dom-css` - Group CSS changes via classes or cssText
92
+ - `js-index-maps` - Build Map for repeated lookups
93
+ - `js-cache-property-access` - Cache object properties in loops
94
+ - `js-cache-function-results` - Cache function results in module-level Map
95
+ - `js-cache-storage` - Cache localStorage/sessionStorage reads
96
+ - `js-combine-iterations` - Combine multiple filter/map into one loop
97
+ - `js-length-check-first` - Check array length before expensive comparison
98
+ - `js-early-exit` - Return early from functions
99
+ - `js-hoist-regexp` - Hoist RegExp creation outside loops
100
+ - `js-min-max-loop` - Use loop for min/max instead of sort
101
+ - `js-set-map-lookups` - Use Set/Map for O(1) lookups
102
+ - `js-tosorted-immutable` - Use toSorted() for immutability
103
+ - `js-flatmap-filter` - Use flatMap to map and filter in one pass
104
+ - `js-request-idle-callback` - Defer non-critical work to browser idle time
105
+
106
+ ### 7. Advanced Patterns (LOW)
107
+
108
+ - `advanced-effect-event-deps` - Don't put `useEffectEvent` results in effect deps
109
+ - `advanced-event-handler-refs` - Store event handlers in refs
110
+ - `advanced-init-once` - Initialize app once per app load
111
+ - `advanced-use-latest` - useLatest for stable callback refs
112
+
113
+ ## How to Use
114
+
115
+ Read individual rule files for detailed explanations and code examples:
116
+
117
+ ```
118
+ rules/async-parallel.md
119
+ rules/bundle-barrel-imports.md
120
+ ```
121
+
122
+ Each rule file contains:
123
+
124
+ - Brief explanation of why it matters
125
+ - Incorrect code example with explanation
126
+ - Correct code example with explanation
127
+ - Additional context and references
@@ -0,0 +1,50 @@
1
+ ---
2
+ title: Do Not Put Effect Events in Dependency Arrays
3
+ impact: LOW
4
+ impactDescription: avoids unnecessary effect re-runs and lint errors
5
+ tags: advanced, hooks, useEffectEvent, dependencies, effects
6
+ ---
7
+
8
+ ## Do Not Put Effect Events in Dependency Arrays
9
+
10
+ Effect Event functions do not have a stable identity. Their identity intentionally changes on every render. Do not include the function returned by `useEffectEvent` in a `useEffect` dependency array. Keep the actual reactive values as dependencies and call the Effect Event from inside the effect body or subscriptions created by that effect.
11
+
12
+ **Incorrect (Effect Event added as a dependency):**
13
+
14
+ ```tsx
15
+ import { useEffect, useEffectEvent } from "react";
16
+
17
+ function ChatRoom({ roomId, onConnected }: { roomId: string; onConnected: () => void }) {
18
+ const handleConnected = useEffectEvent(onConnected);
19
+
20
+ useEffect(() => {
21
+ const connection = createConnection(roomId);
22
+ connection.on("connected", handleConnected);
23
+ connection.connect();
24
+
25
+ return () => connection.disconnect();
26
+ }, [roomId, handleConnected]);
27
+ }
28
+ ```
29
+
30
+ Including the Effect Event in dependencies makes the effect re-run every render and triggers the React Hooks lint rule.
31
+
32
+ **Correct (depend on reactive values, not the Effect Event):**
33
+
34
+ ```tsx
35
+ import { useEffect, useEffectEvent } from "react";
36
+
37
+ function ChatRoom({ roomId, onConnected }: { roomId: string; onConnected: () => void }) {
38
+ const handleConnected = useEffectEvent(onConnected);
39
+
40
+ useEffect(() => {
41
+ const connection = createConnection(roomId);
42
+ connection.on("connected", handleConnected);
43
+ connection.connect();
44
+
45
+ return () => connection.disconnect();
46
+ }, [roomId]);
47
+ }
48
+ ```
49
+
50
+ Reference: [React useEffectEvent: Effect Event in deps](https://react.dev/reference/react/useEffectEvent#effect-event-in-deps)
@@ -0,0 +1,55 @@
1
+ ---
2
+ title: Store Event Handlers in Refs
3
+ impact: LOW
4
+ impactDescription: stable subscriptions
5
+ tags: advanced, hooks, refs, event-handlers, optimization
6
+ ---
7
+
8
+ ## Store Event Handlers in Refs
9
+
10
+ Store callbacks in refs when used in effects that shouldn't re-subscribe on callback changes.
11
+
12
+ **Incorrect (re-subscribes on every render):**
13
+
14
+ ```tsx
15
+ function useWindowEvent(event: string, handler: (e) => void) {
16
+ useEffect(() => {
17
+ window.addEventListener(event, handler);
18
+ return () => window.removeEventListener(event, handler);
19
+ }, [event, handler]);
20
+ }
21
+ ```
22
+
23
+ **Correct (stable subscription):**
24
+
25
+ ```tsx
26
+ function useWindowEvent(event: string, handler: (e) => void) {
27
+ const handlerRef = useRef(handler);
28
+ useEffect(() => {
29
+ handlerRef.current = handler;
30
+ }, [handler]);
31
+
32
+ useEffect(() => {
33
+ const listener = (e) => handlerRef.current(e);
34
+ window.addEventListener(event, listener);
35
+ return () => window.removeEventListener(event, listener);
36
+ }, [event]);
37
+ }
38
+ ```
39
+
40
+ **Alternative: use `useEffectEvent` if you're on latest React:**
41
+
42
+ ```tsx
43
+ import { useEffectEvent } from "react";
44
+
45
+ function useWindowEvent(event: string, handler: (e) => void) {
46
+ const onEvent = useEffectEvent(handler);
47
+
48
+ useEffect(() => {
49
+ window.addEventListener(event, onEvent);
50
+ return () => window.removeEventListener(event, onEvent);
51
+ }, [event]);
52
+ }
53
+ ```
54
+
55
+ `useEffectEvent` reads the latest handler without re-subscribing. The Effect Event function does not have a stable identity.
@@ -0,0 +1,42 @@
1
+ ---
2
+ title: Initialize App Once, Not Per Mount
3
+ impact: LOW-MEDIUM
4
+ impactDescription: avoids duplicate init in development
5
+ tags: initialization, useEffect, app-startup, side-effects
6
+ ---
7
+
8
+ ## Initialize App Once, Not Per Mount
9
+
10
+ Do not put app-wide initialization that must run once per app load inside `useEffect([])` of a component. Components can remount and effects will re-run. Use a module-level guard or top-level init in the entry module instead.
11
+
12
+ **Incorrect (runs twice in dev, re-runs on remount):**
13
+
14
+ ```tsx
15
+ function Comp() {
16
+ useEffect(() => {
17
+ loadFromStorage();
18
+ checkAuthToken();
19
+ }, []);
20
+
21
+ // ...
22
+ }
23
+ ```
24
+
25
+ **Correct (once per app load):**
26
+
27
+ ```tsx
28
+ let didInit = false;
29
+
30
+ function Comp() {
31
+ useEffect(() => {
32
+ if (didInit) return;
33
+ didInit = true;
34
+ loadFromStorage();
35
+ checkAuthToken();
36
+ }, []);
37
+
38
+ // ...
39
+ }
40
+ ```
41
+
42
+ Reference: [Initializing the application](https://react.dev/learn/you-might-not-need-an-effect#initializing-the-application)
@@ -0,0 +1,39 @@
1
+ ---
2
+ title: useEffectEvent for Stable Callback Refs
3
+ impact: LOW
4
+ impactDescription: prevents effect re-runs
5
+ tags: advanced, hooks, useEffectEvent, refs, optimization
6
+ ---
7
+
8
+ ## useEffectEvent for Stable Callback Refs
9
+
10
+ Access latest values in callbacks without adding them to dependency arrays. Prevents effect re-runs while avoiding stale closures.
11
+
12
+ **Incorrect (effect re-runs on every callback change):**
13
+
14
+ ```tsx
15
+ function SearchInput({ onSearch }: { onSearch: (q: string) => void }) {
16
+ const [query, setQuery] = useState("");
17
+
18
+ useEffect(() => {
19
+ const timeout = setTimeout(() => onSearch(query), 300);
20
+ return () => clearTimeout(timeout);
21
+ }, [query, onSearch]);
22
+ }
23
+ ```
24
+
25
+ **Correct (using React's useEffectEvent):**
26
+
27
+ ```tsx
28
+ import { useEffectEvent } from "react";
29
+
30
+ function SearchInput({ onSearch }: { onSearch: (q: string) => void }) {
31
+ const [query, setQuery] = useState("");
32
+ const onSearchEvent = useEffectEvent(onSearch);
33
+
34
+ useEffect(() => {
35
+ const timeout = setTimeout(() => onSearchEvent(query), 300);
36
+ return () => clearTimeout(timeout);
37
+ }, [query]);
38
+ }
39
+ ```
@@ -0,0 +1,37 @@
1
+ ---
2
+ title: Check Cheap Conditions Before Async Flags
3
+ impact: HIGH
4
+ impactDescription: avoids unnecessary async work when a synchronous guard already fails
5
+ tags: async, await, feature-flags, short-circuit, conditional
6
+ ---
7
+
8
+ ## Check Cheap Conditions Before Async Flags
9
+
10
+ When a branch uses `await` for a flag or remote value and also requires a **cheap synchronous** condition (local props, request metadata, already-loaded state), evaluate the cheap condition **first**. Otherwise you pay for the async call even when the compound condition can never be true.
11
+
12
+ This is a specialization of [Defer Await Until Needed](./async-defer-await.md) for `flag && cheapCondition` style checks.
13
+
14
+ **Incorrect:**
15
+
16
+ ```typescript
17
+ const someFlag = await getFlag();
18
+
19
+ if (someFlag && someCondition) {
20
+ // ...
21
+ }
22
+ ```
23
+
24
+ **Correct:**
25
+
26
+ ```typescript
27
+ if (someCondition) {
28
+ const someFlag = await getFlag();
29
+ if (someFlag) {
30
+ // ...
31
+ }
32
+ }
33
+ ```
34
+
35
+ This matters when `getFlag` hits the network, a feature-flag service, or `React.cache` / DB work: skipping it when `someCondition` is false removes that cost on the cold path.
36
+
37
+ Keep the original order if `someCondition` is expensive, depends on the flag, or you must run side effects in a fixed order.
@@ -0,0 +1,82 @@
1
+ ---
2
+ title: Defer Await Until Needed
3
+ impact: HIGH
4
+ impactDescription: avoids blocking unused code paths
5
+ tags: async, await, conditional, optimization
6
+ ---
7
+
8
+ ## Defer Await Until Needed
9
+
10
+ Move `await` operations into the branches where they're actually used to avoid blocking code paths that don't need them.
11
+
12
+ **Incorrect (blocks both branches):**
13
+
14
+ ```typescript
15
+ async function handleRequest(userId: string, skipProcessing: boolean) {
16
+ const userData = await fetchUserData(userId);
17
+
18
+ if (skipProcessing) {
19
+ // Returns immediately but still waited for userData
20
+ return { skipped: true };
21
+ }
22
+
23
+ // Only this branch uses userData
24
+ return processUserData(userData);
25
+ }
26
+ ```
27
+
28
+ **Correct (only blocks when needed):**
29
+
30
+ ```typescript
31
+ async function handleRequest(userId: string, skipProcessing: boolean) {
32
+ if (skipProcessing) {
33
+ // Returns immediately without waiting
34
+ return { skipped: true };
35
+ }
36
+
37
+ // Fetch only when needed
38
+ const userData = await fetchUserData(userId);
39
+ return processUserData(userData);
40
+ }
41
+ ```
42
+
43
+ **Another example (early return optimization):**
44
+
45
+ ```typescript
46
+ // Incorrect: always fetches permissions
47
+ async function updateResource(resourceId: string, userId: string) {
48
+ const permissions = await fetchPermissions(userId);
49
+ const resource = await getResource(resourceId);
50
+
51
+ if (!resource) {
52
+ return { error: "Not found" };
53
+ }
54
+
55
+ if (!permissions.canEdit) {
56
+ return { error: "Forbidden" };
57
+ }
58
+
59
+ return await updateResourceData(resource, permissions);
60
+ }
61
+
62
+ // Correct: fetches only when needed
63
+ async function updateResource(resourceId: string, userId: string) {
64
+ const resource = await getResource(resourceId);
65
+
66
+ if (!resource) {
67
+ return { error: "Not found" };
68
+ }
69
+
70
+ const permissions = await fetchPermissions(userId);
71
+
72
+ if (!permissions.canEdit) {
73
+ return { error: "Forbidden" };
74
+ }
75
+
76
+ return await updateResourceData(resource, permissions);
77
+ }
78
+ ```
79
+
80
+ This optimization is especially valuable when the skipped branch is frequently taken, or when the deferred operation is expensive.
81
+
82
+ For `await getFlag()` combined with a cheap synchronous guard (`flag && someCondition`), see [Check Cheap Conditions Before Async Flags](./async-cheap-condition-before-await.md).
@@ -0,0 +1,48 @@
1
+ ---
2
+ title: Dependency-Based Parallelization
3
+ impact: CRITICAL
4
+ impactDescription: 2-10× improvement
5
+ tags: async, parallelization, dependencies, better-all
6
+ ---
7
+
8
+ ## Dependency-Based Parallelization
9
+
10
+ For operations with partial dependencies, use `better-all` to maximize parallelism. It automatically starts each task at the earliest possible moment.
11
+
12
+ **Incorrect (profile waits for config unnecessarily):**
13
+
14
+ ```typescript
15
+ const [user, config] = await Promise.all([fetchUser(), fetchConfig()]);
16
+ const profile = await fetchProfile(user.id);
17
+ ```
18
+
19
+ **Correct (config and profile run in parallel):**
20
+
21
+ ```typescript
22
+ import { all } from "better-all";
23
+
24
+ const { user, config, profile } = await all({
25
+ async user() {
26
+ return fetchUser();
27
+ },
28
+ async config() {
29
+ return fetchConfig();
30
+ },
31
+ async profile() {
32
+ return fetchProfile((await this.$.user).id);
33
+ },
34
+ });
35
+ ```
36
+
37
+ **Alternative without extra dependencies:**
38
+
39
+ We can also create all the promises first, and do `Promise.all()` at the end.
40
+
41
+ ```typescript
42
+ const userPromise = fetchUser();
43
+ const profilePromise = userPromise.then((user) => fetchProfile(user.id));
44
+
45
+ const [user, config, profile] = await Promise.all([userPromise, fetchConfig(), profilePromise]);
46
+ ```
47
+
48
+ Reference: [https://github.com/shuding/better-all](https://github.com/shuding/better-all)
@@ -0,0 +1,24 @@
1
+ ---
2
+ title: Promise.all() for Independent Operations
3
+ impact: CRITICAL
4
+ impactDescription: 2-10× improvement
5
+ tags: async, parallelization, promises, waterfalls
6
+ ---
7
+
8
+ ## Promise.all() for Independent Operations
9
+
10
+ When async operations have no interdependencies, execute them concurrently using `Promise.all()`.
11
+
12
+ **Incorrect (sequential execution, 3 round trips):**
13
+
14
+ ```typescript
15
+ const user = await fetchUser();
16
+ const posts = await fetchPosts();
17
+ const comments = await fetchComments();
18
+ ```
19
+
20
+ **Correct (parallel execution, 1 round trip):**
21
+
22
+ ```typescript
23
+ const [user, posts, comments] = await Promise.all([fetchUser(), fetchPosts(), fetchComments()]);
24
+ ```