create-relkit 0.7.4 → 0.7.7

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 (238) hide show
  1. package/dist/create-capabilities.d.ts +24 -33
  2. package/dist/create-capabilities.d.ts.map +1 -1
  3. package/dist/create-capabilities.js +53 -10
  4. package/dist/create-capabilities.js.map +1 -1
  5. package/dist/create-capabilities.types.d.ts +55 -0
  6. package/dist/create-capabilities.types.d.ts.map +1 -0
  7. package/dist/create-capabilities.types.js +2 -0
  8. package/dist/create-capabilities.types.js.map +1 -0
  9. package/dist/domain-artifact.d.ts.map +1 -1
  10. package/dist/domain-artifact.js +11 -3
  11. package/dist/domain-artifact.js.map +1 -1
  12. package/dist/domain-planning.d.ts +5 -0
  13. package/dist/domain-planning.d.ts.map +1 -1
  14. package/dist/domain-planning.js +25 -16
  15. package/dist/domain-planning.js.map +1 -1
  16. package/dist/generate-deployment-manifest.d.ts +10 -0
  17. package/dist/generate-deployment-manifest.d.ts.map +1 -0
  18. package/dist/generate-deployment-manifest.js +56 -0
  19. package/dist/generate-deployment-manifest.js.map +1 -0
  20. package/dist/generate-deployment.d.ts +2 -3
  21. package/dist/generate-deployment.d.ts.map +1 -1
  22. package/dist/generate-deployment.js +6 -47
  23. package/dist/generate-deployment.js.map +1 -1
  24. package/dist/generate-examples.d.ts +11 -0
  25. package/dist/generate-examples.d.ts.map +1 -0
  26. package/dist/generate-examples.js +28 -0
  27. package/dist/generate-examples.js.map +1 -0
  28. package/dist/generate-files-utilities.d.ts +1 -8
  29. package/dist/generate-files-utilities.d.ts.map +1 -1
  30. package/dist/generate-files-utilities.js +5 -19
  31. package/dist/generate-files-utilities.js.map +1 -1
  32. package/dist/project-discovery-artifacts.d.ts +15 -0
  33. package/dist/project-discovery-artifacts.d.ts.map +1 -0
  34. package/dist/project-discovery-artifacts.js +107 -0
  35. package/dist/project-discovery-artifacts.js.map +1 -0
  36. package/dist/project-discovery-artifacts.types.d.ts +22 -0
  37. package/dist/project-discovery-artifacts.types.d.ts.map +1 -0
  38. package/dist/project-discovery-artifacts.types.js +2 -0
  39. package/dist/project-discovery-artifacts.types.js.map +1 -0
  40. package/dist/project-discovery-facts.d.ts +8 -9
  41. package/dist/project-discovery-facts.d.ts.map +1 -1
  42. package/dist/project-discovery-facts.js +29 -135
  43. package/dist/project-discovery-facts.js.map +1 -1
  44. package/dist/project-discovery-members.d.ts +16 -0
  45. package/dist/project-discovery-members.d.ts.map +1 -0
  46. package/dist/project-discovery-members.js +57 -0
  47. package/dist/project-discovery-members.js.map +1 -0
  48. package/dist/project-discovery-types.d.ts +8 -0
  49. package/dist/project-discovery-types.d.ts.map +1 -1
  50. package/dist/render-auth-database.d.ts +33 -0
  51. package/dist/render-auth-database.d.ts.map +1 -0
  52. package/dist/render-auth-database.js +69 -0
  53. package/dist/render-auth-database.js.map +1 -0
  54. package/dist/render-auth-sources.d.ts +8 -2
  55. package/dist/render-auth-sources.d.ts.map +1 -1
  56. package/dist/render-auth-sources.js +9 -3
  57. package/dist/render-auth-sources.js.map +1 -1
  58. package/dist/render-auth.d.ts +14 -11
  59. package/dist/render-auth.d.ts.map +1 -1
  60. package/dist/render-auth.js +41 -108
  61. package/dist/render-auth.js.map +1 -1
  62. package/dist/render-database-sources.d.ts +11 -1
  63. package/dist/render-database-sources.d.ts.map +1 -1
  64. package/dist/render-database-sources.js +30 -4
  65. package/dist/render-database-sources.js.map +1 -1
  66. package/dist/render-database.d.ts +7 -10
  67. package/dist/render-database.d.ts.map +1 -1
  68. package/dist/render-database.js +17 -7
  69. package/dist/render-database.js.map +1 -1
  70. package/dist/render-database.types.d.ts +15 -0
  71. package/dist/render-database.types.d.ts.map +1 -0
  72. package/dist/render-database.types.js +2 -0
  73. package/dist/render-database.types.js.map +1 -0
  74. package/dist/render-route-sources.d.ts +3 -1
  75. package/dist/render-route-sources.d.ts.map +1 -1
  76. package/dist/render-route-sources.js +4 -2
  77. package/dist/render-route-sources.js.map +1 -1
  78. package/dist/render-routes.d.ts +1 -0
  79. package/dist/render-routes.d.ts.map +1 -1
  80. package/dist/render-routes.js +2 -1
  81. package/dist/render-routes.js.map +1 -1
  82. package/dist/render-service-members.d.ts +32 -0
  83. package/dist/render-service-members.d.ts.map +1 -0
  84. package/dist/render-service-members.js +61 -0
  85. package/dist/render-service-members.js.map +1 -0
  86. package/dist/render-service-requests.d.ts +35 -0
  87. package/dist/render-service-requests.d.ts.map +1 -0
  88. package/dist/render-service-requests.js +62 -0
  89. package/dist/render-service-requests.js.map +1 -0
  90. package/dist/render-service-support.d.ts +37 -0
  91. package/dist/render-service-support.d.ts.map +1 -0
  92. package/dist/render-service-support.js +74 -0
  93. package/dist/render-service-support.js.map +1 -0
  94. package/dist/render-service.d.ts +16 -13
  95. package/dist/render-service.d.ts.map +1 -1
  96. package/dist/render-service.js +33 -149
  97. package/dist/render-service.js.map +1 -1
  98. package/dist/render-service.types.d.ts +13 -0
  99. package/dist/render-service.types.d.ts.map +1 -0
  100. package/dist/render-service.types.js +2 -0
  101. package/dist/render-service.types.js.map +1 -0
  102. package/dist/scaffold-layout.d.ts +10 -0
  103. package/dist/scaffold-layout.d.ts.map +1 -0
  104. package/dist/scaffold-layout.js +29 -0
  105. package/dist/scaffold-layout.js.map +1 -0
  106. package/dist/templates/default/README.md +1 -1
  107. package/dist/templates/default/v1/agent/.agents/skills/relkit/SKILL.md +48 -0
  108. package/dist/templates/default/v1/agent/.agents/skills/relkit/references/agent-apis.md +59 -0
  109. package/dist/templates/default/v1/agent/.agents/skills/relkit/references/cli.md +63 -0
  110. package/dist/templates/default/v1/agent/.agents/skills/relkit/references/config-environments.md +96 -0
  111. package/dist/templates/default/v1/agent/.agents/skills/relkit/references/data-apis.md +74 -0
  112. package/dist/templates/default/v1/agent/.agents/skills/relkit/references/domain-apis.md +92 -0
  113. package/dist/templates/default/v1/agent/.agents/skills/relkit/references/http-apis.md +70 -0
  114. package/dist/templates/default/v1/agent/.agents/skills/relkit/references/jobs-apis.md +49 -0
  115. package/dist/templates/default/v1/agent/.agents/skills/relkit/references/layout-migration.md +35 -0
  116. package/dist/templates/default/v1/agent/.agents/skills/relkit/references/observability-apis.md +53 -0
  117. package/dist/templates/default/v1/agent/.agents/skills/relkit/references/realtime-apis.md +98 -0
  118. package/dist/templates/default/v1/agent/.agents/skills/relkit/references/streaming-apis.md +75 -0
  119. package/dist/templates/default/v1/agent/.agents/skills/relkit/references/testing-apis.md +71 -0
  120. package/dist/templates/default/v1/agent/README.md +9 -0
  121. package/dist/templates/default/v1/agent/package.json +4 -4
  122. package/dist/templates/default/v1/agent/src/routes/hello/route.ts +2 -1
  123. package/dist/templates/default/v1/agent/src/{hello → services/hello}/agents/assistant.agent.ts +2 -1
  124. package/dist/templates/default/v1/agent/src/{hello → services/hello}/agents/review.agent.ts +1 -0
  125. package/dist/templates/default/v1/agent/src/{hello → services/hello}/functions/hello.function.ts +7 -0
  126. package/dist/templates/default/v1/agent/src/services/hello/service.ts +5 -0
  127. package/dist/templates/default/v1/agent/src/{hello → services/hello}/tools/lookup.tool.ts +2 -1
  128. package/dist/templates/default/v1/agent/tests/fixtures/lookup.tool.ts +2 -1
  129. package/dist/templates/default/v1/agent/tests/fixtures/mcp-options.ts +2 -1
  130. package/dist/templates/default/v1/agent/tests/unit/assistant.agent.test.ts +3 -2
  131. package/dist/templates/default/v1/agent/tests/unit/hello.function.test.ts +2 -1
  132. package/dist/templates/default/v1/agent/tests/unit/lookup.tool.test.ts +2 -1
  133. package/dist/templates/default/v1/agent/tests/unit/review.agent.test.ts +2 -1
  134. package/dist/templates/default/v1/agent/tsconfig.json +2 -1
  135. package/dist/templates/default/v1/api/.agents/skills/relkit/SKILL.md +48 -0
  136. package/dist/templates/default/v1/api/.agents/skills/relkit/references/agent-apis.md +59 -0
  137. package/dist/templates/default/v1/api/.agents/skills/relkit/references/cli.md +63 -0
  138. package/dist/templates/default/v1/api/.agents/skills/relkit/references/config-environments.md +96 -0
  139. package/dist/templates/default/v1/api/.agents/skills/relkit/references/data-apis.md +74 -0
  140. package/dist/templates/default/v1/api/.agents/skills/relkit/references/domain-apis.md +92 -0
  141. package/dist/templates/default/v1/api/.agents/skills/relkit/references/http-apis.md +70 -0
  142. package/dist/templates/default/v1/api/.agents/skills/relkit/references/jobs-apis.md +49 -0
  143. package/dist/templates/default/v1/api/.agents/skills/relkit/references/layout-migration.md +35 -0
  144. package/dist/templates/default/v1/api/.agents/skills/relkit/references/observability-apis.md +53 -0
  145. package/dist/templates/default/v1/api/.agents/skills/relkit/references/realtime-apis.md +98 -0
  146. package/dist/templates/default/v1/api/.agents/skills/relkit/references/streaming-apis.md +75 -0
  147. package/dist/templates/default/v1/api/.agents/skills/relkit/references/testing-apis.md +71 -0
  148. package/dist/templates/default/v1/api/README.md +10 -0
  149. package/dist/templates/default/v1/api/package.json +3 -3
  150. package/dist/templates/default/v1/api/src/routes/echo/route.ts +2 -1
  151. package/dist/templates/default/v1/api/src/routes/hello/route.ts +2 -1
  152. package/dist/templates/default/v1/api/src/routes/orders/route.ts +2 -1
  153. package/dist/templates/default/v1/api/src/{echo → services/echo}/functions/echo.function.ts +1 -0
  154. package/dist/templates/default/v1/api/src/services/echo/service.ts +5 -0
  155. package/dist/templates/default/v1/api/src/{hello → services/hello}/functions/hello.function.ts +7 -0
  156. package/dist/templates/default/v1/api/src/services/hello/service.ts +5 -0
  157. package/dist/templates/default/v1/api/src/{orders → services/orders}/functions/create-order.function.ts +2 -1
  158. package/dist/templates/default/v1/api/src/{orders → services/orders}/functions/price-order.function.ts +1 -0
  159. package/dist/templates/default/v1/api/src/services/orders/service.ts +8 -0
  160. package/dist/templates/default/v1/api/tests/unit/echo.function.test.ts +2 -1
  161. package/dist/templates/default/v1/api/tests/unit/hello.function.test.ts +2 -1
  162. package/dist/templates/default/v1/api/tests/unit/orders.function.test.ts +2 -1
  163. package/dist/templates/default/v1/api/tsconfig.json +2 -1
  164. package/dist/templates/default/v1/fullstack/.agents/skills/relkit/SKILL.md +48 -0
  165. package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/agent-apis.md +59 -0
  166. package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/cli.md +63 -0
  167. package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/config-environments.md +96 -0
  168. package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/data-apis.md +74 -0
  169. package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/domain-apis.md +92 -0
  170. package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/http-apis.md +70 -0
  171. package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/jobs-apis.md +49 -0
  172. package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/layout-migration.md +35 -0
  173. package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/observability-apis.md +53 -0
  174. package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/realtime-apis.md +98 -0
  175. package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/streaming-apis.md +75 -0
  176. package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/testing-apis.md +71 -0
  177. package/dist/templates/default/v1/fullstack/README.md +9 -0
  178. package/dist/templates/default/v1/fullstack/package.json +5 -5
  179. package/dist/templates/default/v1/fullstack/src/routes/hello/route.ts +2 -1
  180. package/dist/templates/default/v1/fullstack/src/{hello → services/hello}/agents/assistant.agent.ts +2 -1
  181. package/dist/templates/default/v1/fullstack/src/{hello → services/hello}/agents/review.agent.ts +1 -0
  182. package/dist/templates/default/v1/fullstack/src/{hello → services/hello}/functions/hello.function.ts +1 -0
  183. package/dist/templates/default/v1/fullstack/src/services/hello/service.ts +5 -0
  184. package/dist/templates/default/v1/fullstack/src/{hello → services/hello}/tools/lookup.tool.ts +2 -1
  185. package/dist/templates/default/v1/fullstack/tests/unit/assistant.agent.test.ts +3 -2
  186. package/dist/templates/default/v1/fullstack/tests/unit/hello.function.test.ts +2 -1
  187. package/dist/templates/default/v1/fullstack/tests/unit/review.agent.test.ts +2 -1
  188. package/dist/templates/default/v1/fullstack/tsconfig.json +2 -1
  189. package/dist/templates/default/v1/minimal/.agents/skills/relkit/SKILL.md +48 -0
  190. package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/agent-apis.md +59 -0
  191. package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/cli.md +63 -0
  192. package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/config-environments.md +96 -0
  193. package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/data-apis.md +74 -0
  194. package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/domain-apis.md +92 -0
  195. package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/http-apis.md +70 -0
  196. package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/jobs-apis.md +49 -0
  197. package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/layout-migration.md +35 -0
  198. package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/observability-apis.md +53 -0
  199. package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/realtime-apis.md +98 -0
  200. package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/streaming-apis.md +75 -0
  201. package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/testing-apis.md +71 -0
  202. package/dist/templates/default/v1/minimal/README.md +10 -0
  203. package/dist/templates/default/v1/minimal/package.json +3 -3
  204. package/dist/templates/default/v1/minimal/src/routes/hello/route.ts +2 -1
  205. package/dist/templates/default/v1/minimal/src/{hello → services/hello}/functions/hello.function.ts +7 -0
  206. package/dist/templates/default/v1/minimal/src/services/hello/service.ts +5 -0
  207. package/dist/templates/default/v1/minimal/tests/unit/hello.function.test.ts +2 -1
  208. package/dist/templates/default/v1/minimal/tsconfig.json +2 -1
  209. package/dist/templates/default/v1/tasks/.agents/skills/relkit/SKILL.md +48 -0
  210. package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/agent-apis.md +59 -0
  211. package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/cli.md +63 -0
  212. package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/config-environments.md +96 -0
  213. package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/data-apis.md +74 -0
  214. package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/domain-apis.md +92 -0
  215. package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/http-apis.md +70 -0
  216. package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/jobs-apis.md +49 -0
  217. package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/layout-migration.md +35 -0
  218. package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/observability-apis.md +53 -0
  219. package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/realtime-apis.md +98 -0
  220. package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/streaming-apis.md +75 -0
  221. package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/testing-apis.md +71 -0
  222. package/dist/templates/default/v1/tasks/README.md +8 -1
  223. package/dist/templates/default/v1/tasks/package.json +3 -3
  224. package/dist/templates/default/v1/tasks/src/routes/health/route.ts +2 -1
  225. package/dist/templates/default/v1/tasks/src/{orders → services/orders}/functions/health.function.ts +1 -0
  226. package/dist/templates/default/v1/tasks/src/{orders → services/orders}/jobs/export-orders.job.ts +2 -1
  227. package/dist/templates/default/v1/tasks/src/services/orders/service.ts +11 -0
  228. package/dist/templates/default/v1/tasks/src/{orders → services/orders}/tasks/export-orders.task.ts +1 -0
  229. package/dist/templates/default/v1/tasks/tests/unit/export-orders.task.test.ts +2 -1
  230. package/dist/templates/default/v1/tasks/tsconfig.json +3 -1
  231. package/package.json +3 -3
  232. package/dist/templates/default/v1/agent/src/hello/service.ts +0 -4
  233. package/dist/templates/default/v1/api/src/echo/service.ts +0 -4
  234. package/dist/templates/default/v1/api/src/hello/service.ts +0 -4
  235. package/dist/templates/default/v1/api/src/orders/service.ts +0 -7
  236. package/dist/templates/default/v1/fullstack/src/hello/service.ts +0 -4
  237. package/dist/templates/default/v1/minimal/src/hello/service.ts +0 -4
  238. package/dist/templates/default/v1/tasks/src/orders/service.ts +0 -10
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Chooses new scaffold boundaries from compiler-backed layout discovery while
3
+ * preserving existing physical service paths. Older manually supplied planning
4
+ * records use the same pure contracts rather than a second folder-depth rule.
5
+ */
6
+ import { selectApplicationLayout } from "@relkit/contracts";
7
+ import { ADD_FAILURE_CODES, AddScaffoldError } from "./add-types.js";
8
+ /**
9
+ * Locates an existing service or constructs a new boundary in the selected layout.
10
+ * @param discovery - Declaration-only project facts produced by compiler discovery.
11
+ * @param name - Validated kebab-case service directory name.
12
+ * @returns Actual existing boundary or a grouped/flat destination for a new service.
13
+ * @throws AddScaffoldError for a mixed or otherwise structurally invalid layout.
14
+ */
15
+ export function scaffoldServiceBoundary(discovery, name) {
16
+ const layout = discovery.layout ??
17
+ selectApplicationLayout(discovery.projectRoot, [
18
+ ...discovery.artifacts.map((artifact) => ({ file: artifact.path, kind: artifact.kind })),
19
+ ...discovery.services.map((service) => ({ file: service.path, kind: "service" })),
20
+ ]);
21
+ if (layout.issues.length)
22
+ throw new AddScaffoldError(ADD_FAILURE_CODES.invalidProject, layout.issues.map((issue) => `${issue.file}: ${issue.message}`).join("\n"));
23
+ const existing = discovery.services.find((service) => service.domain === name);
24
+ if (existing)
25
+ return existing.path;
26
+ const root = layout.kind === "grouped" ? "src/services" : "src";
27
+ return `${root}/${name}/service.ts`;
28
+ }
29
+ //# sourceMappingURL=scaffold-layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scaffold-layout.js","sourceRoot":"","sources":["../src/scaffold-layout.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGrE;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAC,SAA2B,EAAE,IAAY;IAC/E,MAAM,MAAM,GACV,SAAS,CAAC,MAAM;QAChB,uBAAuB,CAAC,SAAS,CAAC,WAAW,EAAE;YAC7C,GAAG,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;YACxF,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;SAClF,CAAC,CAAC;IACL,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM;QACtB,MAAM,IAAI,gBAAgB,CACxB,iBAAiB,CAAC,cAAc,EAChC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAC3E,CAAC;IACJ,MAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC;IAC/E,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC,IAAI,CAAC;IACnC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC;IAChE,OAAO,GAAG,IAAI,IAAI,IAAI,aAAa,CAAC;AACtC,CAAC"}
@@ -8,6 +8,6 @@ scaffolder:
8
8
  - `agent` — the minimal example plus a read-only tool and agent descriptor.
9
9
 
10
10
  Each variant is self-contained and can be copied as a project root. It uses
11
- the current checked-in RelKit package version (`0.7.4`), Bun `1.3.10`, and
11
+ the current checked-in RelKit package version (`0.7.7`), Bun `1.3.10`, and
12
12
  TypeScript `5.9.3`. The generator owns project-name substitution and later
13
13
  installation/Git behavior.
@@ -0,0 +1,48 @@
1
+ ---
2
+ name: relkit
3
+ description: Build or extend a RELKIT CLI-generated application using its installed scaffolding and project commands. Use for application config, environments, services, functions, routes, auth, database, jobs, providers, and related app work.
4
+ ---
5
+
6
+ # Work in a RELKIT application
7
+
8
+ Run commands from the generated application's root, where `relkit.config.ts` and `package.json` live. Use `bun run relkit` to invoke the project's installed CLI. Check `bun run relkit <command> --help` before relying on an option, especially after a dependency upgrade.
9
+
10
+ ## Source placement
11
+
12
+ New projects place every generic, database, and auth boundary at `src/services/<name>/service.ts`. Keep its functions, events, tasks, jobs, tools, agents, channels, schemas, resources, helpers, and assets under that service. Routes live at `src/routes`; configuration support and environment contracts live at `src/platform`. Application descriptors use plain TypeScript and supported public APIs; Effect imports are not required.
13
+
14
+ Existing flat projects with `src/<name>/service.ts` remain supported. `relkit add` preserves the detected layout; empty projects default to grouped. Never mix flat and grouped boundaries or add an aggregate `src/services/service.ts`. Across services and from routes, import only the destination's `service.ts`; Platform cannot import services or Routes. Ordinary helpers do not become independently discovered descriptors.
15
+
16
+ Read [layout migration](references/layout-migration.md) before moving an existing app. Keep logical IDs, exposure, provider profiles, and durable contract versions stable during a source-only move.
17
+
18
+ ## Add application artifacts
19
+
20
+ Inspect the existing `src/` tree and `relkit.config.ts` before scaffolding. Prefer `relkit add` for supported artifacts, then edit the generated source for the required behavior. An interactive terminal can prompt for missing choices; scripts and noninteractive runs should provide the kind, name, service, route mode, and mappings explicitly.
21
+
22
+ Read [the CLI reference](references/cli.md) for commands and option patterns covering services, functions, routes, auth, database, and the other add kinds.
23
+
24
+ ## Authoring API references
25
+
26
+ Read only the reference relevant to the requested change. These examples describe the template's public APIs; check the installed package's TypeScript declarations when an exact option or signature matters.
27
+
28
+ - [Application configuration and environments](references/config-environments.md)
29
+ - [Functions, services, events, and errors](references/domain-apis.md)
30
+ - [HTTP routes and request policy](references/http-apis.md)
31
+ - [Streaming responses](references/streaming-apis.md)
32
+ - [Tasks and jobs](references/jobs-apis.md)
33
+ - [Agents, tools, and prompts](references/agent-apis.md)
34
+ - [Database, auth, cache, and storage](references/data-apis.md)
35
+ - [Realtime channels](references/realtime-apis.md)
36
+ - [Observability and tracing](references/observability-apis.md)
37
+ - [Testing functions, routes, and providers](references/testing-apis.md)
38
+
39
+ ## Working conventions
40
+
41
+ - Generic domain services own callable functions and public event contracts. Other domains and routes should import a service's public members through its `service.ts`.
42
+ - A service route maps HTTP methods to existing public callable members. A raw route is a standalone handler. The CLI will not overwrite an existing route file.
43
+ - Database and auth are singletons under `src/services/database` and `src/services/auth`; extend an existing one instead of creating another. Auth may create a database baseline if none exists. Scaffolding does not run migrations, create secrets, or provision cloud resources.
44
+ - Preserve existing application configuration, environment fields, service members, routes, and user changes when specializing generated files.
45
+
46
+ ## Verify the result
47
+
48
+ Review the CLI's created and updated files, warnings, and next steps. Run `bun run check`, `bun run typecheck`, and focused tests after editing. For HTTP work, exercise the route itself; a direct function test does not cover request mapping. Database and auth work also needs the reported environment and migration steps before runtime verification.
@@ -0,0 +1,59 @@
1
+ # Agents, tools, and prompts
2
+
3
+ | API | Import | Role |
4
+ | ----------------------------------------------- | -------------------- | ------------------------------------ |
5
+ | `defineAgent`, `defineGraph`, `defineGraphNode` | `@relkit/app/agents` | Model-driven agent or explicit graph |
6
+ | `defineTool` | `@relkit/app/tools` | Policy-controlled view of a function |
7
+ | `definePrompt` | `@relkit/app` | Reusable instructions |
8
+ | `z` | `@relkit/app/schema` | Agent and tool schemas |
9
+
10
+ ## `defineAgent`
11
+
12
+ Use `defineAgent` when a model should choose among tools. The agent template provides an executable offline LangChain model example. This shortened form uses the same public options:
13
+
14
+ ```ts
15
+ import { defineAgent } from "@relkit/app/agents";
16
+ import { z } from "@relkit/app/schema";
17
+ import { FakeToolCallingModel } from "langchain";
18
+ import lookup from "@app/services/hello/tools/lookup.tool.js";
19
+ export default defineAgent({
20
+ id: "hello.assistant",
21
+ input: z.object({ message: z.string().min(1) }),
22
+ output: z.object({ answer: z.string() }),
23
+ model: new FakeToolCallingModel({
24
+ toolCalls: [[{ name: "relkit_output", args: { value: { answer: "Hello!" } }, id: "output-1" }]],
25
+ }),
26
+ instructions: "Answer greeting questions with the available tools.",
27
+ tools: [lookup],
28
+ limits: { maxSteps: 4, maxToolCalls: 4, timeoutMs: 10_000 },
29
+ });
30
+ ```
31
+
32
+ Other generated projects may need a native model package and application-owned provider configuration. `limits` requires positive `maxSteps`, `maxToolCalls`, and `timeoutMs`. `instructions` can be text or a `definePrompt` descriptor. A model can call only tools listed in the agent's `tools` array. A fixed sequence can be a function; a stateful explicit workflow can use `defineGraph` and `defineGraphNode`.
33
+
34
+ ## `defineTool` and `definePrompt`
35
+
36
+ A RELKIT tool wraps a callable function without duplicating its schemas:
37
+
38
+ ```ts
39
+ import { defineTool } from "@relkit/app/tools";
40
+ import lookup from "@app/services/orders/functions/lookup.function.js";
41
+ export default defineTool({
42
+ id: "orders.lookup",
43
+ target: lookup,
44
+ description: "Look up an order by ID",
45
+ sideEffect: "read",
46
+ approval: "never",
47
+ timeoutMs: 2_000,
48
+ });
49
+ ```
50
+
51
+ ```ts
52
+ import { definePrompt } from "@relkit/app";
53
+ export default definePrompt("Answer using the available tools.", {
54
+ id: "hello.assistant-instructions",
55
+ });
56
+ ```
57
+
58
+ `lookup.asTool({ ... })` is the alternate tool form. Choose accurate `sideEffect` (`none`, `read`, `write`, or `external`) and `approval` (`never`, `on-write`, or `always`) policies. Tools are available to MCP by default; set `mcp: false` when a tool should remain inside the app. Permission checks belong in application logic.
59
+ If a browser client needs an agent, configure its explicit `client` contract. Keep provider credentials and native model instances on the server. A typed agent run uses a stable thread ID; resume the same thread instead of creating a replacement run.
@@ -0,0 +1,63 @@
1
+ # CLI commands in a generated project
2
+
3
+ These examples use the local binary through `bun run relkit`. The installed CLI's `--help` is authoritative if its version differs from the template.
4
+
5
+ ## Service and HTTP scaffolding
6
+
7
+ | Goal | Command |
8
+ | ---------------------------------------------- | ---------------------------------------------------------------------------------------------- |
9
+ | Create a domain with a public example function | `bun run relkit add service Billing` |
10
+ | Select extra domain artifacts | `bun run relkit add service Billing --include function --include error` |
11
+ | Create the full domain bundle | `bun run relkit add service Billing --full` |
12
+ | Add a public callable function | `bun run relkit add function "Send Receipt" --service billing` |
13
+ | Add a standalone GET handler | `bun run relkit add route '/status' --mode route` |
14
+ | Map an existing public member to HTTP | `bun run relkit add route '/billing' --mode service-route --service billing --map GET=example` |
15
+
16
+ `--include` is repeatable and exclusive with `--full`. `--service` selects an existing generic domain; `--create-service` creates it while adding an artifact. Use `--internal` on a function or event that should stay out of the public service API. A service route needs one or more `--map METHOD=member` values in noninteractive use; the member must be a public callable function. Quote paths containing `*` or `?`.
17
+
18
+ ## Database and auth
19
+
20
+ | Goal | Command |
21
+ | -------------------------------------------- | ------------------------------------------------------------------------- |
22
+ | Scaffold a SQLite Drizzle service | `bun run relkit add database --orm drizzle --dialect sqlite` |
23
+ | Scaffold Better Auth and its catch-all route | `bun run relkit add auth --adapter better-auth --database-dialect sqlite` |
24
+
25
+ Database `--dialect` and auth `--database-dialect` also accept `postgresql` and `mysql`. Auth's `--base-path` changes the default `/api/auth` mount. The CLI adds dependencies and an environment example as needed, but it does not apply database migrations or populate secrets. Follow the scaffold's reported next steps after reviewing the schema and environment values.
26
+
27
+ ## Other add kinds
28
+
29
+ Run `bun run relkit add <kind> --help` for each kind's flags and requirements:
30
+
31
+ | Area | Kinds |
32
+ | --------------- | ---------------------------------------- |
33
+ | Domain behavior | `function`, `task`, `error`, `constants` |
34
+ | Events and work | `event`, `event-function`, `job` |
35
+ | Providers | `cache`, `bucket` |
36
+ | AI | `tool`, `prompt`, `agent` |
37
+ | HTTP | `middleware`, `transform`, `route` |
38
+
39
+ For example, jobs need a target task, tools need an existing or newly created function, and agents need a prompt or inline instructions. Check the existing service and profile before selecting one. `--no-install` skips installing newly required packages and may skip verification; `--project-root <directory>` targets another app. `bun run relkit --json add ...` disables prompts and emits structured results for automation.
40
+
41
+ There is no `relkit add channel` or `relkit add observability` kind. Author channels with `defineChannel` and configure observability in `defineApp({ telemetry })`; see the [realtime](realtime-apis.md) and [observability](observability-apis.md) references.
42
+
43
+ For streaming responses, scaffold a function and route, then edit the function's output to `streamOf(itemSchema)` and the route's `stream` option; see the [streaming reference](streaming-apis.md).
44
+
45
+ ## Inspect and run the app
46
+
47
+ | Goal | Command |
48
+ | --------------------------------------- | ----------------------------------- |
49
+ | Validate the application graph | `bun run check` |
50
+ | Typecheck and test | `bun run typecheck`, `bun run test` |
51
+ | Start app, inspector, and API reference | `bun run dev` |
52
+ | Inspect the graph | `bun run relkit graph print` |
53
+ | Inspect environment value status | `bun run relkit env list` |
54
+ | Validate active environment values | `bun run relkit env check` |
55
+ | Explain one environment declaration | `bun run relkit env explain NAME` |
56
+ | Render a safe environment example | `bun run relkit env example` |
57
+ | Check local prerequisites | `bun run relkit doctor` |
58
+ | Inspect local service status | `bun run relkit local status` |
59
+ | Build or start a built app | `bun run build`, `bun run start` |
60
+
61
+ Use `bun run relkit --help` to discover additional `graph`, `env`, `local`, `jobs`, `client`, and deployment commands. Start Docker-backed local services with `bun run relkit local up --detach` only when the app actually declares and needs them. Deployment commands require a configured deployment target.
62
+
63
+ For optional flat-to-grouped migration, use `bun run relkit migrate layout` for preview, `--write` for validated publication, and `--rollback <receipt>` for guarded restoration. See [layout migration](layout-migration.md). After `--no-install`, install dependencies and run `bun run relkit dev --prepare` before evaluating prepared-start readiness.
@@ -0,0 +1,96 @@
1
+ # Application configuration and environments
2
+
3
+ A generated application has two authoring files at its root: `relkit.config.ts` declares topology and runtime policy with `defineApp`, and `src/platform/env.ts` declares application environment values with `defineEnv`. Extend these existing files rather than creating a second application or environment contract.
4
+
5
+ ## `defineEnv`: values for handlers
6
+
7
+ In `src/platform/env.ts`:
8
+
9
+ ```ts
10
+ import { defineEnv, env } from "@relkit/app/config";
11
+
12
+ export default defineEnv({
13
+ LOG_LEVEL: env.literal("debug", "info", "warn", "error").default("info"),
14
+ DATABASE_PATH: env.string().default(".relkit/app.sqlite"),
15
+ BETTER_AUTH_SECRET: env.secret().requiredIn("production"),
16
+ PUBLIC_ORIGIN: env.url().optional(),
17
+ });
18
+ ```
19
+
20
+ Builders include `string`, `secret`, `number`, `boolean`, `port`, `url`, `json`, and `literal(...)`. Use `.default(value)` only for intentional safe defaults, `.optional()` for absent values, `.requiredIn("production")` for environment-specific requirements, and `.description(text)` or `.example(value)` for safe metadata. A URL field resolves to a `URL`, a number field to a number, and a Boolean field to a boolean. Do not declare `PORT` or `RELKIT_ENV`; RELKIT reserves them.
21
+
22
+ Pass the definition into `defineApp({ env })`. Functions read the resolved, typed values through `context.env`:
23
+
24
+ ```ts
25
+ import { defineFunction } from "@relkit/app/functions";
26
+ import { z } from "@relkit/app/schema";
27
+
28
+ export default defineFunction({
29
+ input: z.object({}),
30
+ output: z.object({ level: z.string() }),
31
+ handler: async (_input, context) => ({ level: context.env.LOG_LEVEL }),
32
+ });
33
+ ```
34
+
35
+ Mark credentials with `env.secret()`; keep actual values outside source control. Secret metadata enables redaction in generated output, diagnostics, telemetry, and Inspector data. Avoid placeholder production secrets or logging resolved secrets.
36
+
37
+ ## `defineApp`: topology and policy
38
+
39
+ In `relkit.config.ts`, the baseline application contains the environment contract, telemetry redaction, backend settings, and Inspector settings:
40
+
41
+ ```ts
42
+ import { defineApp } from "@relkit/app/config";
43
+ import env from "@app/platform/env.js";
44
+
45
+ export default defineApp({
46
+ env,
47
+ telemetry: { redaction: { mode: "development-redacted", maxBytes: 65_536 } },
48
+ server: { port: 3000, maxBodyBytes: 1_048_576 },
49
+ inspector: { port: 3210 },
50
+ });
51
+ ```
52
+
53
+ `defineApp` also accepts `id`, `defaults`, `deployment`, and provider capabilities `bucket`, `cache`, `jobs`, `event`, `model`, `realtime`, and `"agent-state"`. A capability can have one `default` profile or a named profile map. `defaults.<capability>` must name a configured profile. The `jobs` key is the public spelling for the job provider. Add only providers the app uses; the base template has none. Public creation currently certifies only the minimal starter with examples, no jobs, no cloud, and no deployment. API, agent, fullstack, jobs, and AWS/Pulumi creation tuples are internal candidates and must remain rejected until their exact release evidence is certified. Configure an existing app's optional integrations only when the installed version supports them and the task requires them.
54
+
55
+ For a one-machine realtime provider and a named Docker-backed cache profile, the complete configuration shape is:
56
+
57
+ ```ts
58
+ import { defineApp, env as binding } from "@relkit/app/config";
59
+ import { docker } from "@relkit/docker";
60
+ import { localRealtime } from "@relkit/local";
61
+ import { redis } from "@relkit/redis";
62
+ import env from "@app/platform/env.js";
63
+
64
+ export default defineApp({
65
+ env,
66
+ cache: {
67
+ requests: docker(redis({ url: binding.secret("REQUESTS_REDIS_URL") })),
68
+ },
69
+ realtime: localRealtime(),
70
+ defaults: { cache: "requests", realtime: "default" },
71
+ telemetry: { redaction: { mode: "development-redacted", maxBytes: 65_536 } },
72
+ server: { port: 3000, maxBodyBytes: 1_048_576 },
73
+ inspector: { port: 3210 },
74
+ });
75
+ ```
76
+
77
+ Merge only the needed capabilities into the existing `defineApp`, preserving its other settings. Install the optional integration packages before importing them. `binding.secret("REQUESTS_REDIS_URL")` is a value-free provider binding; it is not a `context.env` field unless `defineEnv` declares that name too. Stable topology belongs in source; machine, stack, and secret values belong in environment bindings.
78
+
79
+ Platform fragments may explicitly export server, Inspector, telemetry, deployment, or provider settings and be imported by `relkit.config.ts`. Unimported files are not autoloaded. Keep provider acquisition in supported lazy factories and compose one `defineApp`.
80
+
81
+ CLI `--environment` selects provider configuration; `RELKIT_ENV` selects the application environment. `.env` and `.env.local` supply runtime values according to existing CLI loading; `.env.example` is informational and is not loaded as credentials.
82
+
83
+ ## Inspect and verify environment values
84
+
85
+ From the generated project root:
86
+
87
+ ```sh
88
+ bun run relkit env check
89
+ bun run relkit env list
90
+ bun run relkit env explain BETTER_AUTH_SECRET
91
+ bun run relkit env example
92
+ ```
93
+
94
+ `check` validates active values, `list` shows presence/status without printing secrets, `explain` describes one declaration, and `example` renders a safe template. `env example --write --path .env.example` writes it when requested. Use `--environment <name>` with environment-aware CLI commands to select provider configuration; it does not define an application env field. Run `bun run check` and `bun run typecheck` after changing the contract, then exercise the affected runtime path. Run `bun run relkit local status` before using Docker-backed providers.
95
+
96
+ For observability settings, see [Observability and tracing](observability-apis.md); for realtime provider behavior, see [Realtime channels](realtime-apis.md).
@@ -0,0 +1,74 @@
1
+ # Database, authentication, cache, and storage
2
+
3
+ For the full `defineApp`, `defineEnv`, provider profile, and environment binding workflow, read [Application configuration and environments](config-environments.md).
4
+
5
+ The database and auth integrations are specialized services, separate from `defineService` domain maps. `relkit add database` creates the Drizzle baseline in `src/services/database`; `relkit add auth` creates `src/services/auth` and its recognized `ALL` handler route. There should be one of each. Extend an existing one while preserving schema exports, environment fields, and routes.
6
+
7
+ ## `defineEnv` and `defineDrizzleService`
8
+
9
+ ```ts
10
+ import { defineEnv, env as envFactory } from "@relkit/app/config";
11
+
12
+ export default defineEnv({
13
+ DATABASE_PATH: envFactory.string().default(".relkit/app.sqlite"),
14
+ BETTER_AUTH_SECRET: envFactory.secret(),
15
+ });
16
+ ```
17
+
18
+ ```ts
19
+ import { Database } from "bun:sqlite";
20
+ import { defineDrizzleService } from "@relkit/drizzle";
21
+ import { drizzle } from "drizzle-orm/bun-sqlite";
22
+ import * as schema from "./schema/index.js";
23
+
24
+ export default defineDrizzleService({
25
+ schema,
26
+ client: ({ env }) => drizzle({ client: new Database(env.DATABASE_PATH, { create: true }) }),
27
+ dispose: (database) => database.$client.close(),
28
+ });
29
+ ```
30
+
31
+ Open the native connection in the `client({ env })` factory and close it with `dispose` when needed. Discovery does not run the factory. Generate and review migrations with the installed Drizzle tooling; service creation does not create tables or apply migrations. After `bun run check`, generated context declarations provide typed `context.database`.
32
+
33
+ ## `defineBetterAuthService`
34
+
35
+ ```ts
36
+ import { defineBetterAuthService } from "@relkit/better-auth";
37
+
38
+ export default defineBetterAuthService({
39
+ baseURL: process.env.BETTER_AUTH_URL ?? "http://127.0.0.1:3000",
40
+ emailAndPassword: { enabled: true },
41
+ });
42
+ ```
43
+
44
+ Better Auth uses the same Drizzle connection and needs its tables in that schema. Mount `auth.handler` directly with `export const ALL = defineRoute({ handler: auth.handler })` under the auth base path. Supply a stable server-side `BETTER_AUTH_SECRET` and correct public `BETTER_AUTH_URL`; the scaffold only adds environment examples. Protect application routes and enforce ownership separately from signing in.
45
+
46
+ ## `defineCache` and `defineBucket`
47
+
48
+ ```ts
49
+ import { defineCache } from "@relkit/app/cache";
50
+ import { z } from "@relkit/app/schema";
51
+
52
+ export default defineCache({
53
+ id: "orders.prices",
54
+ profile: "requests",
55
+ key: z.object({ sku: z.string() }),
56
+ value: z.number().int().nonnegative(),
57
+ defaultTtlMs: 60_000,
58
+ maxTtlMs: 300_000,
59
+ });
60
+ ```
61
+
62
+ ```ts
63
+ import { defineBucket } from "@relkit/app/buckets";
64
+
65
+ export default defineBucket({
66
+ id: "assets.objects",
67
+ profile: "assets",
68
+ visibility: "private",
69
+ maxObjectBytes: 5_000_000,
70
+ allowedContentTypes: ["application/json", "image/*"],
71
+ });
72
+ ```
73
+
74
+ Configure compatible profiles in `relkit.config.ts` and declare each resource in a function's `dependencies` before using its checked context client. A profile selects a provider; the descriptor does not create Redis, S3, or credentials. Use `bun run relkit local status` to inspect Docker-backed resources.
@@ -0,0 +1,92 @@
1
+ # Functions, services, events, and errors
2
+
3
+ Generated projects map `@app/*` to `src/*`; keep the `.js` suffix on source imports. Use the installed package types when an exact signature matters, and run `bun run check` to validate the discovered graph.
4
+
5
+ ## `defineFunction` and `defineService`
6
+
7
+ Put domain behavior in `src/services/<domain>/functions/*.function.ts`. A function validates input before its handler and validates the returned output:
8
+
9
+ ```ts
10
+ import { defineFunction } from "@relkit/app/functions";
11
+ import { z } from "@relkit/app/schema";
12
+
13
+ const greet = defineFunction({
14
+ id: "hello.greet",
15
+ input: z.object({ name: z.string().min(1) }),
16
+ output: z.object({ message: z.string() }),
17
+ handler: async ({ name }) => ({ message: `Hello, ${name}!` }),
18
+ });
19
+
20
+ export default greet;
21
+ ```
22
+
23
+ Expose selected functions from `src/services/<domain>/service.ts`:
24
+
25
+ ```ts
26
+ import { defineService } from "@relkit/app/services";
27
+ import greet from "@app/services/hello/functions/greet.function.js";
28
+
29
+ export default defineService({ functions: { greet } });
30
+ ```
31
+
32
+ The service also accepts `events`, `tasks`, and `jobs` maps. Its members appear directly as `service.greet`; there is no `service.functions.greet` namespace. Membership makes a function available across domains, but does not create an HTTP route or grant authorization.
33
+
34
+ Within a domain, import a sibling function directly. Across domains and from routes, import the other domain's `service.ts`. Invoke a function descriptor with `await service.greet.invoke(input)`; do not call its handler directly. Leave an internal function out of the service map. Tools, agents, caches, buckets, and event-only functions are not service members.
35
+
36
+ ## `defineEvent` and `defineEventFunction`
37
+
38
+ Declare an event payload in `src/services/<domain>/events/*.event.ts`:
39
+
40
+ ```ts
41
+ import { defineEvent } from "@relkit/app/events";
42
+ import { z } from "@relkit/app/schema";
43
+
44
+ const orderCreated = defineEvent({
45
+ id: "orders.created",
46
+ version: 1,
47
+ input: z.object({ orderId: z.string() }),
48
+ });
49
+
50
+ declare global {
51
+ namespace Relkit {
52
+ interface EventRegistry {
53
+ readonly "orders.created": typeof orderCreated;
54
+ }
55
+ }
56
+ }
57
+
58
+ export default orderCreated;
59
+ ```
60
+
61
+ Expose it through `defineService({ events: { orderCreated } })` when other domains need it. A publisher declares the exact ID in `publishes: ["orders.created"]` and calls `await context.events["orders.created"].publish({ orderId })`.
62
+
63
+ An event-only consumer reacts without returning a result to its publisher:
64
+
65
+ ```ts
66
+ import { defineEventFunction } from "@relkit/app/events";
67
+
68
+ export default defineEventFunction({
69
+ id: "orders.confirmation",
70
+ event: "orders.created",
71
+ handler: async ({ orderId }, context) => {
72
+ context.log.info("Order created", { orderId });
73
+ },
74
+ });
75
+ ```
76
+
77
+ ## `defineError`
78
+
79
+ ```ts
80
+ import { defineError } from "@relkit/app/functions";
81
+ import { z } from "@relkit/app/schema";
82
+
83
+ export default defineError({
84
+ id: "orders.not-found",
85
+ data: z.object({ orderId: z.string() }),
86
+ message: ({ orderId }) => `Order ${orderId} was not found`,
87
+ http: { status: 404 },
88
+ retry: { kind: "later", afterMs: 1_000 },
89
+ });
90
+ ```
91
+
92
+ Declare only expected failures callers should handle on a function. Use the route layer for HTTP-specific request mapping and middleware.
@@ -0,0 +1,70 @@
1
+ # HTTP routes and request policy
2
+
3
+ Routes live under `src/routes/**/route.ts`. The file path supplies the URL, and named exports supply methods. Import route APIs from `@relkit/app/routes`. Use a public service function as the target for ordinary application endpoints.
4
+
5
+ ## `defineRoute`: one function-backed method
6
+
7
+ In `src/routes/hello/route.ts`, this exposes the service's public `hello` function as `GET /hello`:
8
+
9
+ ```ts
10
+ import { defineRoute } from "@relkit/app/routes";
11
+ import hello from "@app/services/hello/service.js";
12
+
13
+ export const GET = defineRoute({ target: hello.hello });
14
+ ```
15
+
16
+ A function-backed route can also set `successStatus`, `request`, `responses`, `rateLimit`, and `timeoutMs` when needed. The target must be a public callable function; jobs, events, agents, and tools are not route targets. Ordinary JSON request and response schemas are inferred from the target unless you supply explicit mapping.
17
+
18
+ ## `defineRoute`: raw Web handler
19
+
20
+ Use `handler` instead of `target` for a standalone Web `Request`/`Response` handler:
21
+
22
+ ```ts
23
+ import { defineRoute } from "@relkit/app/routes";
24
+
25
+ export const GET = defineRoute({
26
+ handler: async () => Response.json({ ok: true }),
27
+ });
28
+ ```
29
+
30
+ A raw handler has a generic OpenAPI response. The recognized Better Auth mount also uses a raw route:
31
+
32
+ ```ts
33
+ import { defineRoute } from "@relkit/app/routes";
34
+ import auth from "@app/services/auth/service.js";
35
+
36
+ export const ALL = defineRoute({ handler: auth.handler });
37
+ ```
38
+
39
+ ## `defineServiceRoutes`: methods on one service
40
+
41
+ ```ts
42
+ import { defineServiceRoutes } from "@relkit/app/routes";
43
+ import orders from "@app/services/orders/service.js";
44
+
45
+ export const { GET, POST } = defineServiceRoutes(orders, {
46
+ GET: "listOrders",
47
+ POST: { member: "createOrder", successStatus: 201 },
48
+ });
49
+ ```
50
+
51
+ `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, and `OPTIONS` are supported service-route exports. `ALL` is for raw handlers. Do not add a `path` or `method` option to `defineRoute`; the filesystem and export determine both. The CLI can scaffold either form through `add route --mode route` or `--mode service-route`. It will not overwrite an existing route file; edit it directly to add a method.
52
+
53
+ Use `request` mapping only when inference cannot express headers, cookies, names, or nesting; it replaces the inferred mapping. Use `responses` only when you need an explicit response contract. `defineMiddleware(path, handler)` is for HTTP policy, and `defineTransform({ schema })` is for request transforms:
54
+
55
+ ```ts
56
+ import { defineMiddleware } from "@relkit/app/routes";
57
+
58
+ export default defineMiddleware("/orders/*", async (_context, next) => {
59
+ await next();
60
+ });
61
+ ```
62
+
63
+ ```ts
64
+ import { defineTransform } from "@relkit/app/routes";
65
+ import { z } from "@relkit/app/schema";
66
+
67
+ export default defineTransform({ schema: z.string() });
68
+ ```
69
+
70
+ Application authorization must be enforced in the relevant route or function logic. After changing a route, run `bun run check` and `bun run typecheck`, exercise the HTTP endpoint, and inspect `/_relkit/v1/api-reference` while `bun run dev` is running.
@@ -0,0 +1,49 @@
1
+ # Tasks and jobs
2
+
3
+ Use a task for work that must outlive its initiating request; a function remains a request- or event-scoped operation.
4
+
5
+ ## `defineTask`
6
+
7
+ ```ts
8
+ import { defineTask } from "@relkit/app/tasks";
9
+ import { z } from "@relkit/app/schema";
10
+
11
+ export default defineTask({
12
+ id: "orders.export-orders",
13
+ version: "1",
14
+ execution: "durable",
15
+ input: z.object({ orderIds: z.array(z.string()) }),
16
+ output: z.object({ exported: z.number().int().nonnegative() }),
17
+ progress: z.object({ completed: z.number().int().nonnegative() }),
18
+ handler: async ({ orderIds }, context) => {
19
+ await context.progress.emit({ completed: orderIds.length });
20
+ return { exported: orderIds.length };
21
+ },
22
+ });
23
+ ```
24
+
25
+ ## `defineJob`
26
+
27
+ Bind the task to a public job name and an explicit client policy in `src/services/orders/jobs/export-orders.job.ts`:
28
+
29
+ ```ts
30
+ import { defineJob } from "@relkit/app/jobs";
31
+ import exportOrders from "@app/services/orders/tasks/export-orders.task.js";
32
+
33
+ export default defineJob({
34
+ id: "orders.export-orders-job",
35
+ name: "exportOrders",
36
+ task: exportOrders,
37
+ client: {
38
+ public: true,
39
+ operations: ["trigger", "get", "list", "watch"],
40
+ fields: ["status", "progress", "output"],
41
+ },
42
+ });
43
+ ```
44
+
45
+ Expose the task and job through the owning service's `tasks` and `jobs` maps. Keep the task ID and version stable; change the version for an intentional incompatible task contract. Make side effects idempotent because work may retry or resume.
46
+
47
+ The app's `relkit.config.ts` selects a compatible jobs provider. Run `bun run relkit jobs capabilities` to inspect its actual guarantees; a durable task needs a binding that supports durable execution. `relkit add task` and `relkit add job --target <task-id>` scaffold the pair without running a worker or provisioning a provider.
48
+
49
+ A trigger admits work and returns a run handle, not the task's output. Keep its `runId` and `operationId`, then read or watch the run; a typed client alone does not authorize a caller. A raw HTTP trigger can return the accepted handle with status `202`. Use `bun run relkit local status` to inspect local provider state before exercising a Docker-backed job.
@@ -0,0 +1,35 @@
1
+ # Optional flat layout migration
2
+
3
+ Flat `src/<name>/service.ts` applications remain supported. Migrate only when grouped placement helps the app. Preview from the application root:
4
+
5
+ ```sh
6
+ bun run relkit migrate layout
7
+ bun run relkit --json migrate layout
8
+ ```
9
+
10
+ The deterministic plan moves complete service roots to `src/services/<name>`, including helpers and assets. It reports import, test, tooling, documentation, and local guidance rewrites, conflicts, and references needing manual action. Preview leaves authored files, lockfiles, generated output, persistent state, migration history, and credentials unchanged.
11
+
12
+ Stop the app's active development session and resolve touched tracked changes, occupied destinations, mixed boundaries, symlinks, and ambiguous/computed references before applying:
13
+
14
+ ```sh
15
+ bun run relkit migrate layout --write
16
+ ```
17
+
18
+ Write stages the candidate with installed dependencies and requires baseline/candidate check, typecheck, logical graph, and offline deployment compatibility before publication. It does not install packages, run database migrations or seeds, provision providers, or edit global skills. Publication is coordinated across files; the restricted local receipt retains exact before/after bytes and permissions for failure or crash recovery. Keep that receipt private.
19
+
20
+ Rollback with the exact path returned by the write result:
21
+
22
+ ```sh
23
+ bun run relkit migrate layout --rollback .relkit/migrations/RECEIPT_ID/receipt.json
24
+ ```
25
+
26
+ Rollback refuses later edits or occupied original locations instead of overwriting them. Recovery conflicts preserve user bytes and require inspection of the retained receipt. Successful migration or restoration needs fresh preparation:
27
+
28
+ ```sh
29
+ bun run check
30
+ bun run typecheck
31
+ bun run relkit dev --prepare
32
+ bun run dev
33
+ ```
34
+
35
+ Compare actual application responses and durable runs after the move. Logical service/function/task/job/channel/agent IDs and versions remain unchanged; diagnostic and editor paths point at their real grouped sources.