@zerotal/arch 1.7.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.
Files changed (160) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/LICENSE +21 -0
  3. package/README.md +67 -0
  4. package/api-surface.md +283 -0
  5. package/docs/about.md +676 -0
  6. package/docs/admin/actions.md +183 -0
  7. package/docs/admin/auth.md +89 -0
  8. package/docs/admin/dashboard.md +155 -0
  9. package/docs/admin/extending-ui.md +229 -0
  10. package/docs/admin/extending.md +205 -0
  11. package/docs/admin/forms.md +155 -0
  12. package/docs/admin/index.md +144 -0
  13. package/docs/admin/operations.md +224 -0
  14. package/docs/admin/references.md +174 -0
  15. package/docs/admin/resources.md +132 -0
  16. package/docs/admin/structure.md +158 -0
  17. package/docs/admin/tables.md +185 -0
  18. package/docs/admin/testing.md +138 -0
  19. package/docs/ai.md +373 -0
  20. package/docs/application.md +435 -0
  21. package/docs/arch.md +263 -0
  22. package/docs/assets.md +755 -0
  23. package/docs/audit.md +367 -0
  24. package/docs/authentication.md +1000 -0
  25. package/docs/authorization.md +529 -0
  26. package/docs/broadcasting/channels.md +170 -0
  27. package/docs/broadcasting/client.md +108 -0
  28. package/docs/broadcasting/events.md +190 -0
  29. package/docs/broadcasting/index.md +163 -0
  30. package/docs/broadcasting/references.md +84 -0
  31. package/docs/broadcasting/testing.md +132 -0
  32. package/docs/cache.md +387 -0
  33. package/docs/carbon.md +830 -0
  34. package/docs/changelog.md +465 -0
  35. package/docs/client/auth.md +113 -0
  36. package/docs/client/errors.md +139 -0
  37. package/docs/client/files.md +118 -0
  38. package/docs/client/index.md +128 -0
  39. package/docs/client/references.md +58 -0
  40. package/docs/client/requests.md +131 -0
  41. package/docs/client/resilience.md +141 -0
  42. package/docs/client/testing.md +146 -0
  43. package/docs/commands.md +450 -0
  44. package/docs/components.md +2427 -0
  45. package/docs/config-system.md +258 -0
  46. package/docs/container.md +596 -0
  47. package/docs/context.md +579 -0
  48. package/docs/contributing.md +164 -0
  49. package/docs/controllers.md +354 -0
  50. package/docs/conventions.md +466 -0
  51. package/docs/cookies.md +101 -0
  52. package/docs/csrf.md +206 -0
  53. package/docs/database.md +476 -0
  54. package/docs/deployment.md +434 -0
  55. package/docs/devtools.md +1013 -0
  56. package/docs/email-verification.md +320 -0
  57. package/docs/encryption.md +380 -0
  58. package/docs/errors.md +317 -0
  59. package/docs/events.md +420 -0
  60. package/docs/flow/components.md +846 -0
  61. package/docs/flow/decorators.md +458 -0
  62. package/docs/flow/events.md +420 -0
  63. package/docs/flow/forms.md +551 -0
  64. package/docs/flow/index.md +568 -0
  65. package/docs/flow/layouts.md +793 -0
  66. package/docs/flow/lifecycle.md +336 -0
  67. package/docs/flow/pagination.md +402 -0
  68. package/docs/flow/performance.md +262 -0
  69. package/docs/flow/references.md +317 -0
  70. package/docs/flow/routing.md +550 -0
  71. package/docs/flow/testing.md +447 -0
  72. package/docs/getting-started.md +286 -0
  73. package/docs/health.md +269 -0
  74. package/docs/helpers.md +423 -0
  75. package/docs/i18n.md +414 -0
  76. package/docs/index.md +65 -0
  77. package/docs/inertia/build.md +95 -0
  78. package/docs/inertia/devtools.md +197 -0
  79. package/docs/inertia/index.md +267 -0
  80. package/docs/inertia/middleware.md +81 -0
  81. package/docs/inertia/props.md +507 -0
  82. package/docs/inertia/references.md +144 -0
  83. package/docs/inertia/rendering.md +189 -0
  84. package/docs/inertia/ssr.md +102 -0
  85. package/docs/inspirations.md +257 -0
  86. package/docs/lifecycle.md +331 -0
  87. package/docs/lock.md +454 -0
  88. package/docs/logger.md +517 -0
  89. package/docs/media.md +582 -0
  90. package/docs/middleware.md +509 -0
  91. package/docs/migrations.md +529 -0
  92. package/docs/monitor.md +377 -0
  93. package/docs/notifications.md +848 -0
  94. package/docs/orm/casts.md +365 -0
  95. package/docs/orm/factories.md +231 -0
  96. package/docs/orm/index.md +663 -0
  97. package/docs/orm/lifecycle.md +421 -0
  98. package/docs/orm/queries.md +692 -0
  99. package/docs/orm/relationships.md +440 -0
  100. package/docs/orm/serialization.md +251 -0
  101. package/docs/package-development.md +536 -0
  102. package/docs/pagination.md +340 -0
  103. package/docs/password-reset.md +335 -0
  104. package/docs/providers.md +447 -0
  105. package/docs/query-builder.md +465 -0
  106. package/docs/queue.md +549 -0
  107. package/docs/rate-limiting.md +253 -0
  108. package/docs/responses.md +336 -0
  109. package/docs/roles-and-2fa.md +418 -0
  110. package/docs/routing.md +1008 -0
  111. package/docs/scaffolding.md +335 -0
  112. package/docs/scheduler.md +533 -0
  113. package/docs/seeding.md +229 -0
  114. package/docs/session.md +451 -0
  115. package/docs/social.md +524 -0
  116. package/docs/storage.md +622 -0
  117. package/docs/structure.md +230 -0
  118. package/docs/support-policy.md +114 -0
  119. package/docs/telemetry.md +505 -0
  120. package/docs/tenancy.md +608 -0
  121. package/docs/testing/browser.md +153 -0
  122. package/docs/testing/console.md +130 -0
  123. package/docs/testing/database.md +238 -0
  124. package/docs/testing/flow-browser.md +216 -0
  125. package/docs/testing/http.md +441 -0
  126. package/docs/testing/index.md +240 -0
  127. package/docs/testing/mocking.md +410 -0
  128. package/docs/upgrade.md +192 -0
  129. package/docs/validator.md +549 -0
  130. package/docs/view.md +453 -0
  131. package/package.json +60 -0
  132. package/src/bin/mcp.ts +73 -0
  133. package/src/config.ts +63 -0
  134. package/src/errors.ts +27 -0
  135. package/src/index.ts +56 -0
  136. package/src/install/ArchInstallCommand.ts +189 -0
  137. package/src/install/detect.ts +98 -0
  138. package/src/install/guidelines.ts +290 -0
  139. package/src/install/markers.ts +77 -0
  140. package/src/install/mcpConfig.ts +81 -0
  141. package/src/mcp/index.ts +27 -0
  142. package/src/mcp/jsonrpc.ts +133 -0
  143. package/src/mcp/server.ts +307 -0
  144. package/src/mcp/stdio.ts +111 -0
  145. package/src/mcp/types.ts +146 -0
  146. package/src/probe/ArchProbeCommand.ts +48 -0
  147. package/src/probe/sentinel.ts +13 -0
  148. package/src/probe/topics.ts +291 -0
  149. package/src/provider/ArchProvider.ts +101 -0
  150. package/src/tools/_probe.ts +164 -0
  151. package/src/tools/apiSurface.ts +241 -0
  152. package/src/tools/appInfo.ts +88 -0
  153. package/src/tools/baselines.ts +210 -0
  154. package/src/tools/context.ts +37 -0
  155. package/src/tools/doctor.ts +93 -0
  156. package/src/tools/index.ts +50 -0
  157. package/src/tools/logs.ts +265 -0
  158. package/src/tools/routes.ts +133 -0
  159. package/src/tools/schema.ts +119 -0
  160. package/src/tools/searchDocs.ts +345 -0
@@ -0,0 +1,335 @@
1
+ ---
2
+ title: Scaffolding
3
+ description: Generate typed boilerplate files at conventional paths with the make:* commands instead of writing them by hand.
4
+ ---
5
+
6
+ # Scaffolding
7
+
8
+ Zerotal's `make:*` commands generate boilerplate files so you spend time on logic,
9
+ not structure. Each generator writes a typed stub to the conventional path and
10
+ reports what it created.
11
+
12
+ ```bash
13
+ # in your project root
14
+ bun zt make:<type> <Name> [flags]
15
+ ```
16
+
17
+ Every generator is idempotent: if the target file already exists it reports
18
+ `File already exists: <path>` and writes nothing, so it never overwrites your work.
19
+
20
+ ## Generators at a glance
21
+
22
+ | Command | Creates | Notes |
23
+ | --------------------- | --------------------------------- | ------------------------------------------ |
24
+ | `make:controller` | `app/controllers/<Name>.ts` | `--resource` adds CRUD stubs |
25
+ | `make:middleware` | `app/middleware/<Name>.ts` | Pass-through `Pipe<HttpContext>` stub |
26
+ | `make:command` | `app/commands/<Name>.ts` | CLI command extending `Command` |
27
+ | `make:request` | `app/requests/<Name>.ts` | `FormRequest` with `rules()` |
28
+ | `make:notification` | `app/notifications/<Name>.ts` | Extends `Notification` |
29
+ | `make:job` | `app/jobs/<Name>.ts` | Queue `Job`, self-registers |
30
+ | `make:event` | `app/events/<Name>.ts` | `--broadcast` extends `BroadcastingEvent` |
31
+ | `make:listener` | `app/listeners/<Name>.ts` | `handle(event)` method |
32
+ | `make:observer` | `app/observers/<Name>.ts` | `--model` sets the target model |
33
+ | `make:policy` | `app/policies/<Name>.ts` | `--model` sets the target model |
34
+ | `make:resource` | `app/resources/<Name>.ts` | API resource transformer |
35
+ | `make:admin-resource` | `app/admin/<Name>Resource.ts` | Admin panel resource for a model |
36
+ | `make:provider` | `app/providers/<Name>Provider.ts` | Auto-registers in `bootstrap/providers.ts` |
37
+ | `make:package` | `packages/<name>/…` | Full `@zerotal/*` package skeleton |
38
+
39
+ ## make:controller
40
+
41
+ ```bash
42
+ # in your project root
43
+ bun zt make:controller PostController
44
+ # Created: app/controllers/PostController.ts
45
+
46
+ bun zt make:controller PostController --resource
47
+ # Created: app/controllers/PostController.ts (with index/show/store/update/destroy stubs)
48
+ ```
49
+
50
+ The basic stub has a single `index` action; `--resource` adds the full CRUD set:
51
+ `index`, `show`, `store`, `update`, and `destroy`.
52
+
53
+ | Flag | Type | Description |
54
+ | ------------ | ------- | --------------------- |
55
+ | `--resource` | boolean | Add CRUD action stubs |
56
+
57
+ ## make:middleware
58
+
59
+ ```bash
60
+ # in your project root
61
+ bun zt make:middleware RequireAdminMiddleware
62
+ # Created: app/middleware/RequireAdminMiddleware.ts
63
+ ```
64
+
65
+ The stub implements `Pipe<HttpContext>` with a `handle(ctx, next)` method that calls
66
+ `next()`, plus a commented example of short-circuiting with a `Response`.
67
+
68
+ ## make:command
69
+
70
+ ```bash
71
+ # in your project root
72
+ bun zt make:command SendDailyReport
73
+ # Created: app/commands/SendDailyReport.ts
74
+ ```
75
+
76
+ The stub includes `static commandName` (kebab-cased from the class name),
77
+ `static description`, `static needsApp`, placeholder `args` and `flags` arrays,
78
+ and an async `run()` method.
79
+
80
+ ## make:request
81
+
82
+ Form requests centralise validation rules away from controller bodies.
83
+
84
+ ```bash
85
+ # in your project root
86
+ bun zt make:request StorePostRequest
87
+ # Created: app/requests/StorePostRequest.ts
88
+ ```
89
+
90
+ The stub extends `FormRequest` from `@zerotal/validator` with a `rules(r)` method
91
+ that returns a `Record<string, FieldRule>`.
92
+
93
+ ## make:notification
94
+
95
+ ```bash
96
+ # in your project root
97
+ bun zt make:notification OrderShipped
98
+ # Created: app/notifications/OrderShipped.ts
99
+ ```
100
+
101
+ The stub extends `Notification` and ships with a `channels()` method (defaulting to
102
+ `['database']`) and a `toDatabase()` method.
103
+
104
+ ## make:job
105
+
106
+ ```bash
107
+ # in your project root
108
+ bun zt make:job ProcessPayment
109
+ # Created: app/jobs/ProcessPayment.ts
110
+ ```
111
+
112
+ The stub extends `Job` from `@zerotal/queue`, sets a `default` queue, and calls
113
+ `JobRegistry.register(...)` at the bottom of the file so the job is dispatchable.
114
+
115
+ ## make:event
116
+
117
+ ```bash
118
+ # in your project root
119
+ bun zt make:event UserRegistered
120
+ # Created: app/events/UserRegistered.ts
121
+
122
+ bun zt make:event OrderShipped --broadcast
123
+ # Created: app/events/OrderShipped.ts (extends BroadcastingEvent)
124
+ ```
125
+
126
+ By default the stub is a plain class with constructor parameters commented as
127
+ examples. With `--broadcast` (`-b`) it instead extends `BroadcastingEvent` and
128
+ includes `broadcastOn()` and `broadcastWith()` methods.
129
+
130
+ | Flag | Type | Description |
131
+ | ------------- | ------- | ----------------------------------------------- |
132
+ | `--broadcast` | boolean | Generate a broadcastable event (`-b` for short) |
133
+
134
+ > **Tip** — See [Broadcasting](/docs/broadcasting) for channels and authorization
135
+ > rules used by broadcastable events.
136
+
137
+ ## make:listener
138
+
139
+ ```bash
140
+ # in your project root
141
+ bun zt make:listener SendWelcomeEmail
142
+ # Created: app/listeners/SendWelcomeEmail.ts
143
+ ```
144
+
145
+ The stub has a `handle(event: unknown)` method you narrow to the correct event type.
146
+
147
+ ## make:observer
148
+
149
+ ```bash
150
+ # in your project root
151
+ bun zt make:observer UserObserver
152
+ # Created: app/observers/UserObserver.ts
153
+
154
+ bun zt make:observer UserObserver --model User
155
+ # Same path; stub names its parameters after the model
156
+ ```
157
+
158
+ The stub implements `ModelObserver` from `@zerotal/orm` with `creating`/`created`,
159
+ `updating`/`updated`, and `deleting`/`deleted` hooks. When `--model` is omitted the
160
+ model name is inferred by stripping the `Observer` suffix.
161
+
162
+ | Flag | Type | Description |
163
+ | ---------------- | ------ | --------------------------------- |
164
+ | `--model` (`-m`) | string | Model class this observer targets |
165
+
166
+ ## make:policy
167
+
168
+ ```bash
169
+ # in your project root
170
+ bun zt make:policy PostPolicy
171
+ # Created: app/policies/PostPolicy.ts
172
+
173
+ bun zt make:policy PostPolicy --model Post
174
+ # Same path; stub references Post in commented imports
175
+ ```
176
+
177
+ The stub extends `Policy` from `@zerotal/auth` with `view`, `create`, `update`,
178
+ and `delete` methods. When `--model` is omitted the model name is inferred by
179
+ stripping the `Policy` suffix.
180
+
181
+ | Flag | Type | Description |
182
+ | ---------------- | ------ | ----------------------- |
183
+ | `--model` (`-m`) | string | Model the policy is for |
184
+
185
+ ## make:resource
186
+
187
+ API resource transformers shape model data before it leaves the controller.
188
+
189
+ ```bash
190
+ # in your project root
191
+ bun zt make:resource UserResource
192
+ # Created: app/resources/UserResource.ts
193
+ ```
194
+
195
+ The stub extends `Resource<Model>` with a `toArray()` method and includes commented
196
+ usage examples for single models and paginated `ResourceCollection`s.
197
+
198
+ ## make:provider
199
+
200
+ ```bash
201
+ # in your project root
202
+ bun zt make:provider Payment
203
+ # Created: app/providers/PaymentProvider.ts
204
+ # Registered in bootstrap/providers.ts
205
+
206
+ bun zt make:provider Payment --no-register
207
+ # Created: app/providers/PaymentProvider.ts (no codemod)
208
+ ```
209
+
210
+ The name is suffixed with `Provider` if it isn't already. The stub extends
211
+ `ServiceProvider` with `onRegister`, `onBooting`, and `onBooted` hooks ready to fill
212
+ in.
213
+
214
+ Unless `--no-register` is passed, a codemod appends the provider import and class
215
+ name to the default export array in `bootstrap/providers.ts`. It is idempotent:
216
+ rerunning reports `Already registered in bootstrap/providers.ts` rather than
217
+ duplicating the entry. If `bootstrap/providers.ts` is missing, it warns and leaves
218
+ the file for you to wire up manually.
219
+
220
+ | Flag | Type | Description |
221
+ | --------------- | ------- | --------------------------------------- |
222
+ | `--no-register` | boolean | Skip modifying `bootstrap/providers.ts` |
223
+
224
+ ## make:package
225
+
226
+ Scaffolds a complete, conformant `@zerotal/<name>` package under `packages/`.
227
+
228
+ ```bash
229
+ # in your project root
230
+ bun zt make:package billing
231
+ # Created @zerotal/billing
232
+ # ./packages/billing/package.json
233
+ # ./packages/billing/src/index.ts
234
+ # ./packages/billing/src/config.ts
235
+ # ./packages/billing/src/BillingManager.ts
236
+ # ./packages/billing/src/provider/BillingProvider.ts
237
+ # ./packages/billing/src/facades/Billing.ts
238
+ # ./packages/billing/src/Billing.test.ts
239
+ ```
240
+
241
+ The generated package follows the Zerotal package conventions: a manager class, a
242
+ service provider (with a container binding and config wiring), a facade, a
243
+ `XxxConfig()` factory, and a test file. The package name is normalised to a
244
+ kebab-case token, and class names are derived in PascalCase.
245
+
246
+ By default the package is written under `./packages`; pass a second argument to
247
+ choose a different base directory:
248
+
249
+ ```bash
250
+ # in your project root
251
+ bun zt make:package billing ./vendor
252
+ ```
253
+
254
+ After generation, register the new provider and verify the package passes the
255
+ structural checks:
256
+
257
+ ```bash
258
+ # in your project root
259
+ bun zt make:provider Billing # adds BillingProvider to bootstrap/providers.ts
260
+ bun zt lint:packages # verify the package passes structural checks
261
+ ```
262
+
263
+ > **Note** — See [Package Development](/docs/package-development) for the full
264
+ > package conventions the scaffold conforms to.
265
+
266
+ ## Codemod helpers
267
+
268
+ The underlying codemod utilities are exported from `zerotal` for use in your
269
+ own generators, install scripts, or migration tools. Each is idempotent — a no-op
270
+ when the change is already present.
271
+
272
+ ```ts
273
+ // in your own generator or script
274
+ import {
275
+ addImport,
276
+ addToDefaultArrayExport,
277
+ registerProvider,
278
+ type RegisterProviderOptions,
279
+ type RegisterResult,
280
+ } from "zerotal/build";
281
+
282
+ // Add an import after the last existing import (deduped):
283
+ const withImport = addImport(
284
+ src,
285
+ `import { BillingProvider } from "./providers/BillingProvider.ts";`,
286
+ );
287
+
288
+ // Append an identifier to the `export default [ ... ]` array literal:
289
+ const withEntry = addToDefaultArrayExport(src, "BillingProvider");
290
+
291
+ // Combined: add the import AND register in bootstrap/providers.ts on disk:
292
+ const result: RegisterResult = await registerProvider({
293
+ className: "BillingProvider",
294
+ importPath: "../app/providers/BillingProvider.ts",
295
+ // bootstrapPath defaults to "bootstrap/providers.ts"
296
+ });
297
+ ```
298
+
299
+ > **Note** — These live on the `zerotal/build` subpath rather than the
300
+ > root barrel: they are build-time tooling for generators, and an application
301
+ > never calls them at runtime.
302
+
303
+ > **Warning** — `registerProvider` reads and writes a file on disk. `addImport` and
304
+ > `addToDefaultArrayExport` are pure string transforms — they take source text and
305
+ > return the transformed text, leaving the file untouched.
306
+
307
+ ## References
308
+
309
+ | Function | Signature | Description |
310
+ | ------------------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------ |
311
+ | `addImport` | `(source: string, importStatement: string) => string` | Insert an import after the last existing import; no-op if already there. |
312
+ | `addToDefaultArrayExport` | `(source: string, identifier: string) => string` | Append an identifier to an `export default [ … ]` array literal. |
313
+ | `registerProvider` | `(options: RegisterProviderOptions) => Promise<RegisterResult>` | Add the import and register a provider in the bootstrap file on disk. |
314
+
315
+ `RegisterProviderOptions`:
316
+
317
+ | Field | Required | Default | Description |
318
+ | --------------- | -------- | -------------------------- | --------------------------------------------------------------------------- |
319
+ | `className` | yes | — | Provider class name to import and register. |
320
+ | `importPath` | yes | — | Import specifier, e.g. `../app/providers/FooProvider.ts` or `@zerotal/foo`. |
321
+ | `bootstrapPath` | no | `"bootstrap/providers.ts"` | Path to the bootstrap providers file. |
322
+
323
+ `RegisterResult` is `'added' | 'exists' | 'missing'`:
324
+
325
+ | Value | Meaning |
326
+ | ----------- | ----------------------------------------------------------- |
327
+ | `'added'` | Provider was written and registered. |
328
+ | `'exists'` | Already registered; no change made. |
329
+ | `'missing'` | `bootstrap/providers.ts` not found; nothing was registered. |
330
+
331
+ ## Next steps
332
+
333
+ - [Commands](/docs/commands) — built-in commands and writing your own.
334
+ - [Service Providers](/docs/providers) — provider lifecycle and what to put in each hook.
335
+ - [Directory Structure](/docs/structure) — where generated files live.