create-efforge 0.0.0-stage → 0.2.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 (239) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -2
  3. package/dist/addon.js +115 -0
  4. package/dist/bin.js +13 -0
  5. package/dist/cli.js +28 -0
  6. package/dist/commands/add.js +640 -0
  7. package/dist/commands/create.js +319 -0
  8. package/dist/commands/list.js +80 -0
  9. package/dist/diff.js +72 -0
  10. package/dist/exec.js +33 -0
  11. package/dist/generate.js +181 -0
  12. package/dist/manifest.js +14 -0
  13. package/dist/projectName.js +41 -0
  14. package/dist/prompts/flow.js +122 -0
  15. package/dist/prompts/navigable.js +193 -0
  16. package/dist/routeTree.js +7 -0
  17. package/dist/rules.js +27 -0
  18. package/dist/slots.js +116 -0
  19. package/dist/stack.js +68 -0
  20. package/dist/transforms/addAlchemyResource.js +71 -0
  21. package/dist/transforms/addArrayItem.js +31 -0
  22. package/dist/transforms/addAuthPlugin.js +77 -0
  23. package/dist/transforms/addDevVar.js +18 -0
  24. package/dist/transforms/addExport.js +46 -0
  25. package/dist/transforms/addImport.js +11 -0
  26. package/dist/transforms/addLayer.js +31 -0
  27. package/dist/transforms/addServerFnMiddleware.js +62 -0
  28. package/dist/transforms/addWorkflowSecret.js +43 -0
  29. package/dist/transforms/addWranglerBinding.js +61 -0
  30. package/dist/transforms/appendAgentsSection.js +26 -0
  31. package/dist/transforms/errors.js +7 -0
  32. package/dist/transforms/index.js +40 -0
  33. package/dist/transforms/setWranglerValue.js +40 -0
  34. package/dist/transforms/util.js +219 -0
  35. package/dist/tree.js +1 -0
  36. package/dist/versions.js +73 -0
  37. package/dist/write.js +28 -0
  38. package/package.json +63 -4
  39. package/templates/ai/effect-ai-byok/addon.json +619 -0
  40. package/templates/ai/effect-ai-byok/files/core/llm-crypto.test.ts +52 -0
  41. package/templates/ai/effect-ai-byok/files/core/llm-crypto.ts +76 -0
  42. package/templates/ai/effect-ai-byok/files/core/llm-store.ts +21 -0
  43. package/templates/ai/effect-ai-byok/files/core/llm.ts +32 -0
  44. package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/migration.sql +9 -0
  45. package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/snapshot.json +944 -0
  46. package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/migration.sql +10 -0
  47. package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/snapshot.json +1232 -0
  48. package/templates/ai/effect-ai-byok/files/routes/ai.tsx +193 -0
  49. package/templates/ai/effect-ai-byok/files/schema/d1.ts +16 -0
  50. package/templates/ai/effect-ai-byok/files/schema/pg.ts +14 -0
  51. package/templates/ai/effect-ai-byok/files/server/ai-settings.ts +129 -0
  52. package/templates/ai/effect-ai-byok/files/server/ai.ts +25 -0
  53. package/templates/ai/effect-ai-byok/files/server/llm-env.ts +48 -0
  54. package/templates/ai/effect-ai-byok/files/server/llm-orgs.ts +146 -0
  55. package/templates/ai/effect-ai-byok/files/server/llm-provider.ts +56 -0
  56. package/templates/ai/effect-ai-byok/files/server/llm-store-drizzle.ts +48 -0
  57. package/templates/ai/effect-ai-byok/files/server/llm-store-sql-d1.ts +41 -0
  58. package/templates/ai/effect-ai-byok/files/server/llm-store-sql-pg.ts +41 -0
  59. package/templates/ai/effect-ai-byok/files/sql/d1.sql +8 -0
  60. package/templates/ai/effect-ai-byok/files/sql/pg.sql +8 -0
  61. package/templates/auth/better-auth/addon.json +424 -0
  62. package/templates/auth/better-auth/files/core/Auth.ts +18 -0
  63. package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/migration.sql +51 -0
  64. package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/snapshot.json +522 -0
  65. package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/migration.sql +51 -0
  66. package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/snapshot.json +680 -0
  67. package/templates/auth/better-auth/files/lib/auth-client.ts +4 -0
  68. package/templates/auth/better-auth/files/routes/app.tsx +54 -0
  69. package/templates/auth/better-auth/files/schema/d1/auth-schema.ts +86 -0
  70. package/templates/auth/better-auth/files/schema/pg/auth-schema.ts +73 -0
  71. package/templates/auth/better-auth/files/server/auth-live.ts +47 -0
  72. package/templates/auth/better-auth/files/server/session.ts +14 -0
  73. package/templates/auth/better-auth/files/shared/components/auth-card.tsx +32 -0
  74. package/templates/auth/better-auth/files/shared/components/user-menu.tsx +44 -0
  75. package/templates/auth/better-auth/files/shared/drizzle/d1/drizzle.config.ts +7 -0
  76. package/templates/auth/better-auth/files/shared/drizzle/pg/drizzle.config.ts +10 -0
  77. package/templates/auth/better-auth/files/shared/lib/form.ts +5 -0
  78. package/templates/auth/better-auth/files/shared/lib/redirect.ts +6 -0
  79. package/templates/auth/better-auth/files/shared/routes/app/index.tsx +54 -0
  80. package/templates/auth/better-auth/files/shared/routes/sign-in.tsx +85 -0
  81. package/templates/auth/better-auth/files/shared/routes/sign-up.tsx +91 -0
  82. package/templates/auth/better-auth/files/shared/server/auth-route.ts +15 -0
  83. package/templates/auth/better-auth/files/shared/server/auth.ts +22 -0
  84. package/templates/auth/better-auth/files/shared/server/db/d1-drizzle.ts +25 -0
  85. package/templates/auth/better-auth/files/shared/server/db/d1-effect-sql.ts +17 -0
  86. package/templates/auth/better-auth/files/shared/server/db/pg-drizzle.ts +32 -0
  87. package/templates/auth/better-auth/files/shared/server/db/pg-effect-sql.ts +29 -0
  88. package/templates/auth/better-auth/files/shared/server/require-session.ts +20 -0
  89. package/templates/auth/better-auth/files/sql/d1/0002_auth.sql +13 -0
  90. package/templates/auth/better-auth/files/sql/pg/0002_auth.sql +13 -0
  91. package/templates/auth/better-auth-orgs/addon.json +463 -0
  92. package/templates/auth/better-auth-orgs/files/components/org-switcher.tsx +65 -0
  93. package/templates/auth/better-auth-orgs/files/core/Auth.ts +20 -0
  94. package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/migration.sql +88 -0
  95. package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/snapshot.json +862 -0
  96. package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/migration.sql +88 -0
  97. package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/snapshot.json +1127 -0
  98. package/templates/auth/better-auth-orgs/files/lib/auth-client.ts +5 -0
  99. package/templates/auth/better-auth-orgs/files/routes/accept-invite.$id.tsx +68 -0
  100. package/templates/auth/better-auth-orgs/files/routes/app/settings/index.tsx +27 -0
  101. package/templates/auth/better-auth-orgs/files/routes/app/settings/members.tsx +202 -0
  102. package/templates/auth/better-auth-orgs/files/routes/app/settings.tsx +30 -0
  103. package/templates/auth/better-auth-orgs/files/routes/app.tsx +58 -0
  104. package/templates/auth/better-auth-orgs/files/routes/onboarding.tsx +66 -0
  105. package/templates/auth/better-auth-orgs/files/schema/d1/auth-schema.ts +139 -0
  106. package/templates/auth/better-auth-orgs/files/schema/pg/auth-schema.ts +124 -0
  107. package/templates/auth/better-auth-orgs/files/server/auth-live.ts +52 -0
  108. package/templates/auth/better-auth-orgs/files/server/session.ts +44 -0
  109. package/templates/auth/better-auth-orgs/files/sql/d1/0002_auth.sql +27 -0
  110. package/templates/auth/better-auth-orgs/files/sql/pg/0002_auth.sql +27 -0
  111. package/templates/base/addon.json +216 -0
  112. package/templates/base/files/AGENTS.md +82 -0
  113. package/templates/base/files/CLAUDE.md +1 -0
  114. package/templates/base/files/README.md +32 -0
  115. package/templates/base/files/core/package.json +13 -0
  116. package/templates/base/files/core/src/index.ts +2 -0
  117. package/templates/base/files/core/test/core.test.ts +4 -0
  118. package/templates/base/files/core/tsconfig.json +6 -0
  119. package/templates/base/files/gitignore +11 -0
  120. package/templates/base/files/pnpm-workspace.yaml +11 -0
  121. package/templates/base/files/root/lint/effect-tests.js +45 -0
  122. package/templates/base/files/root/package.json +16 -0
  123. package/templates/base/files/root/tsconfig.base.json +19 -0
  124. package/templates/base/files/root/turbo.json +9 -0
  125. package/templates/base/files/root/vite.config.ts +86 -0
  126. package/templates/base/files/web/components.json +21 -0
  127. package/templates/base/files/web/package.json +17 -0
  128. package/templates/base/files/web/src/components/theme-provider.tsx +57 -0
  129. package/templates/base/files/web/src/components/theme-toggle.tsx +34 -0
  130. package/templates/base/files/web/src/components/ui/avatar.tsx +93 -0
  131. package/templates/base/files/web/src/components/ui/button.tsx +61 -0
  132. package/templates/base/files/web/src/components/ui/card.tsx +74 -0
  133. package/templates/base/files/web/src/components/ui/dialog.tsx +141 -0
  134. package/templates/base/files/web/src/components/ui/dropdown-menu.tsx +225 -0
  135. package/templates/base/files/web/src/components/ui/input.tsx +20 -0
  136. package/templates/base/files/web/src/components/ui/label.tsx +18 -0
  137. package/templates/base/files/web/src/components/ui/sonner.tsx +45 -0
  138. package/templates/base/files/web/src/components/widgets.tsx +4 -0
  139. package/templates/base/files/web/src/lib/utils.ts +6 -0
  140. package/templates/base/files/web/src/router.tsx +12 -0
  141. package/templates/base/files/web/src/routes/__root.tsx +42 -0
  142. package/templates/base/files/web/src/routes/app/index.tsx +27 -0
  143. package/templates/base/files/web/src/routes/app/settings.tsx +29 -0
  144. package/templates/base/files/web/src/routes/app.tsx +47 -0
  145. package/templates/base/files/web/src/routes/index.tsx +51 -0
  146. package/templates/base/files/web/src/server/greeting.ts +12 -0
  147. package/templates/base/files/web/src/server/layers.ts +10 -0
  148. package/templates/base/files/web/src/server/runtime.ts +5 -0
  149. package/templates/base/files/web/src/styles.css +81 -0
  150. package/templates/base/files/web/tsconfig.json +11 -0
  151. package/templates/base/files/web/vite.config.ts +9 -0
  152. package/templates/database/d1/addon.json +118 -0
  153. package/templates/database/d1/files/package.json +12 -0
  154. package/templates/database/d1/files/tsconfig.json +5 -0
  155. package/templates/database/postgres/addon.json +142 -0
  156. package/templates/database/postgres/files/docker-compose.yml +21 -0
  157. package/templates/database/postgres/files/package.json +12 -0
  158. package/templates/database/postgres/files/runtime.ts +12 -0
  159. package/templates/database/postgres/files/tsconfig.json +5 -0
  160. package/templates/extras/browser/addon.json +173 -0
  161. package/templates/extras/browser/files/BrowserContainer.ts +14 -0
  162. package/templates/extras/browser/files/app/Dockerfile +15 -0
  163. package/templates/extras/browser/files/app/dockerignore +1 -0
  164. package/templates/extras/browser/files/app/package-lock +605 -0
  165. package/templates/extras/browser/files/app/package.json +9 -0
  166. package/templates/extras/browser/files/app/src/server.ts +78 -0
  167. package/templates/extras/browser/files/app/src/url-policy.ts +115 -0
  168. package/templates/extras/browser/files/app/tsconfig.json +6 -0
  169. package/templates/extras/browser/files/browser.ts +34 -0
  170. package/templates/extras/browser/files/core-browser.ts +21 -0
  171. package/templates/extras/browser/files/run-browser.ts +25 -0
  172. package/templates/extras/email/addon.json +182 -0
  173. package/templates/extras/email/files/core-mailer.ts +28 -0
  174. package/templates/extras/email/files/invitation-email.ts +38 -0
  175. package/templates/extras/email/files/mailer.ts +58 -0
  176. package/templates/extras/realtime/addon.json +135 -0
  177. package/templates/extras/realtime/files/Room.ts +46 -0
  178. package/templates/extras/realtime/files/core-realtime.ts +19 -0
  179. package/templates/extras/realtime/files/realtime-demo.tsx +40 -0
  180. package/templates/extras/realtime/files/realtime-limits.test.ts +32 -0
  181. package/templates/extras/realtime/files/realtime-limits.ts +35 -0
  182. package/templates/extras/realtime/files/realtime-route.ts +39 -0
  183. package/templates/extras/realtime/files/realtime.ts +39 -0
  184. package/templates/extras/realtime/files/use-room.ts +67 -0
  185. package/templates/extras/storage/addon.json +132 -0
  186. package/templates/extras/storage/files/core-storage.ts +64 -0
  187. package/templates/extras/storage/files/storage-route.ts +50 -0
  188. package/templates/extras/storage/files/storage-security.test.ts +71 -0
  189. package/templates/extras/storage/files/storage-security.ts +92 -0
  190. package/templates/extras/storage/files/storage.ts +84 -0
  191. package/templates/extras/workflows/addon.json +95 -0
  192. package/templates/extras/workflows/files/Example.ts +42 -0
  193. package/templates/extras/workflows/files/core-jobs.ts +45 -0
  194. package/templates/extras/workflows/files/example-job.ts +36 -0
  195. package/templates/extras/workflows/files/jobs.ts +34 -0
  196. package/templates/infra/alchemy/addon.json +37 -0
  197. package/templates/infra/alchemy/files/README.md +27 -0
  198. package/templates/infra/alchemy/files/alchemy.run.ts +36 -0
  199. package/templates/infra/alchemy/files/github/deploy.yml +63 -0
  200. package/templates/infra/alchemy/files/tsconfig.json +5 -0
  201. package/templates/infra/alchemy/files/vite.config.ts +30 -0
  202. package/templates/orm/drizzle/addon.json +188 -0
  203. package/templates/orm/drizzle/files/d1/Database.ts +7 -0
  204. package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/migration.sql +10 -0
  205. package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/snapshot.json +60 -0
  206. package/templates/orm/drizzle/files/d1/drizzle.config.ts +7 -0
  207. package/templates/orm/drizzle/files/d1/layer.ts +13 -0
  208. package/templates/orm/drizzle/files/d1/migrate.ts +37 -0
  209. package/templates/orm/drizzle/files/d1/schema.ts +15 -0
  210. package/templates/orm/drizzle/files/pg/Database.ts +7 -0
  211. package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/migration.sql +10 -0
  212. package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/snapshot.json +75 -0
  213. package/templates/orm/drizzle/files/pg/drizzle.config.ts +10 -0
  214. package/templates/orm/drizzle/files/pg/layer.ts +16 -0
  215. package/templates/orm/drizzle/files/pg/migrate.ts +24 -0
  216. package/templates/orm/drizzle/files/pg/schema.ts +11 -0
  217. package/templates/orm/drizzle/files/shared/index.ts +2 -0
  218. package/templates/orm/drizzle/files/shared/notes.ts +15 -0
  219. package/templates/orm/drizzle/files/shared/page.tsx +50 -0
  220. package/templates/orm/effect-sql/addon.json +124 -0
  221. package/templates/orm/effect-sql/files/d1/layer.ts +13 -0
  222. package/templates/orm/effect-sql/files/d1/migrate.ts +20 -0
  223. package/templates/orm/effect-sql/files/d1/schema.ts +7 -0
  224. package/templates/orm/effect-sql/files/d1-sql/0001_init.sql +10 -0
  225. package/templates/orm/effect-sql/files/pg/layer.ts +16 -0
  226. package/templates/orm/effect-sql/files/pg/migrate.ts +66 -0
  227. package/templates/orm/effect-sql/files/pg/schema.ts +7 -0
  228. package/templates/orm/effect-sql/files/pg-sql/0001_init.sql +10 -0
  229. package/templates/orm/effect-sql/files/shared/Database.ts +7 -0
  230. package/templates/orm/effect-sql/files/shared/index.ts +2 -0
  231. package/templates/orm/effect-sql/files/shared/notes.ts +18 -0
  232. package/templates/orm/effect-sql/files/shared/page.tsx +50 -0
  233. package/templates/runtime/cloudflare/addon.json +52 -0
  234. package/templates/runtime/cloudflare/files/cloudflare.ts +10 -0
  235. package/templates/runtime/cloudflare/files/routes.ts +5 -0
  236. package/templates/runtime/cloudflare/files/server.ts +22 -0
  237. package/templates/runtime/cloudflare/files/tsconfig.json +12 -0
  238. package/templates/runtime/cloudflare/files/vite.config.ts +20 -0
  239. package/templates/runtime/cloudflare/files/wrangler.jsonc +8 -0
@@ -0,0 +1,25 @@
1
+ import { drizzleAdapter } from "better-auth/adapters/drizzle"
2
+ import { drizzle } from "drizzle-orm/d1"
3
+ import { Context, Effect, Layer } from "effect"
4
+ import { D1 } from "effect-cf"
5
+ import * as schema from "@repo/db"
6
+ import type { AuthSettings } from "./auth"
7
+
8
+ /** The `DB` binding, read for Better Auth's own client. */
9
+ class AuthD1 extends D1.Service<AuthD1>()("AuthD1", { binding: "DB" }) {}
10
+
11
+ /**
12
+ * Better Auth's database. It is promise-based, so it gets plain `drizzle-orm/d1` over the D1
13
+ * binding rather than the Effect-flavoured `Database` client.
14
+ */
15
+ export class AuthDatabase extends Context.Service<
16
+ AuthDatabase,
17
+ { readonly database: AuthSettings["database"] }
18
+ >()("AuthDatabase") {}
19
+
20
+ export const AuthDatabaseLayer = Layer.effect(
21
+ AuthDatabase,
22
+ Effect.map(AuthD1, (d1) => ({
23
+ database: drizzleAdapter(drizzle(d1), { provider: "sqlite", schema }),
24
+ })),
25
+ ).pipe(Layer.provide(AuthD1.layer))
@@ -0,0 +1,17 @@
1
+ import { Context, Effect, Layer } from "effect"
2
+ import { D1 } from "effect-cf"
3
+ import type { AuthSettings } from "./auth"
4
+
5
+ /** The `DB` binding, read for Better Auth's own client. */
6
+ class AuthD1 extends D1.Service<AuthD1>()("AuthD1", { binding: "DB" }) {}
7
+
8
+ /** Better Auth's database. It queries through Kysely, which has a built-in D1 dialect, so the binding is passed as is. */
9
+ export class AuthDatabase extends Context.Service<
10
+ AuthDatabase,
11
+ { readonly database: AuthSettings["database"] }
12
+ >()("AuthDatabase") {}
13
+
14
+ export const AuthDatabaseLayer = Layer.effect(
15
+ AuthDatabase,
16
+ Effect.map(AuthD1, (d1) => ({ database: d1 })),
17
+ ).pipe(Layer.provide(AuthD1.layer))
@@ -0,0 +1,32 @@
1
+ import { drizzleAdapter } from "better-auth/adapters/drizzle"
2
+ import { drizzle } from "drizzle-orm/node-postgres"
3
+ import { Context, Effect, Layer } from "effect"
4
+ import { Hyperdrive } from "effect-cf"
5
+ import { Pool } from "pg"
6
+ import * as schema from "@repo/db"
7
+ import type { AuthSettings } from "./auth"
8
+
9
+ /** The `HYPERDRIVE` binding, read for Better Auth's own connection. */
10
+ class AuthHyperdrive extends Hyperdrive.Tag<AuthHyperdrive>()("AuthHyperdrive") {}
11
+
12
+ /**
13
+ * Better Auth's database. It is promise-based, so it gets plain `drizzle-orm/node-postgres` over a
14
+ * `pg` pool on the Hyperdrive connection string rather than the Effect-flavoured `Database` client.
15
+ * The pool lives as long as the layer, which on Postgres is one request.
16
+ */
17
+ export class AuthDatabase extends Context.Service<
18
+ AuthDatabase,
19
+ { readonly database: AuthSettings["database"] }
20
+ >()("AuthDatabase") {}
21
+
22
+ export const AuthDatabaseLayer = Layer.effect(
23
+ AuthDatabase,
24
+ Effect.gen(function* () {
25
+ const { connectionString } = yield* AuthHyperdrive
26
+ const pool = yield* Effect.acquireRelease(
27
+ Effect.sync(() => new Pool({ connectionString, max: 1 })),
28
+ (opened) => Effect.promise(() => opened.end()),
29
+ )
30
+ return { database: drizzleAdapter(drizzle({ client: pool }), { provider: "pg", schema }) }
31
+ }),
32
+ ).pipe(Layer.provide(AuthHyperdrive.layer({ binding: "HYPERDRIVE" })))
@@ -0,0 +1,29 @@
1
+ import { Context, Effect, Layer } from "effect"
2
+ import { Hyperdrive } from "effect-cf"
3
+ import { Pool } from "pg"
4
+ import type { AuthSettings } from "./auth"
5
+
6
+ /** The `HYPERDRIVE` binding, read for Better Auth's own connection. */
7
+ class AuthHyperdrive extends Hyperdrive.Tag<AuthHyperdrive>()("AuthHyperdrive") {}
8
+
9
+ /**
10
+ * Better Auth's database. It is promise-based and queries through Kysely, which takes a `pg` pool
11
+ * directly, so it connects with its own pool on the Hyperdrive connection string. The pool lives
12
+ * as long as the layer, which on Postgres is one request.
13
+ */
14
+ export class AuthDatabase extends Context.Service<
15
+ AuthDatabase,
16
+ { readonly database: AuthSettings["database"] }
17
+ >()("AuthDatabase") {}
18
+
19
+ export const AuthDatabaseLayer = Layer.effect(
20
+ AuthDatabase,
21
+ Effect.gen(function* () {
22
+ const { connectionString } = yield* AuthHyperdrive
23
+ const pool = yield* Effect.acquireRelease(
24
+ Effect.sync(() => new Pool({ connectionString, max: 1 })),
25
+ (opened) => Effect.promise(() => opened.end()),
26
+ )
27
+ return { database: pool }
28
+ }),
29
+ ).pipe(Layer.provide(AuthHyperdrive.layer({ binding: "HYPERDRIVE" })))
@@ -0,0 +1,20 @@
1
+ import { Auth } from "@repo/core/Auth"
2
+ import { createMiddleware } from "@tanstack/react-start"
3
+ import { Effect } from "effect"
4
+ import { runtime } from "./runtime"
5
+
6
+ /**
7
+ * Server-function middleware: rejects the call unless someone is signed in. Add it with
8
+ * `createServerFn(...).middleware([requireSession])`; `efforge` extras (browser, workflows, AI)
9
+ * are wired this way when the project has auth. The session is also passed on as `context.session`.
10
+ */
11
+ export const requireSession = createMiddleware({ type: "function" }).server(({ next }) =>
12
+ runtime
13
+ .runPromise(
14
+ Effect.gen(function* () {
15
+ const auth = yield* Auth
16
+ return yield* auth.currentSession
17
+ }),
18
+ )
19
+ .then((session) => next({ context: { session } })),
20
+ )
@@ -0,0 +1,13 @@
1
+ create table "user" ("id" text not null primary key, "name" text not null, "email" text not null unique, "emailVerified" integer not null, "image" text, "createdAt" date not null, "updatedAt" date not null);
2
+
3
+ create table "session" ("id" text not null primary key, "expiresAt" date not null, "token" text not null unique, "createdAt" date not null, "updatedAt" date not null, "ipAddress" text, "userAgent" text, "userId" text not null references "user" ("id") on delete cascade);
4
+
5
+ create table "account" ("id" text not null primary key, "accountId" text not null, "providerId" text not null, "userId" text not null references "user" ("id") on delete cascade, "accessToken" text, "refreshToken" text, "idToken" text, "accessTokenExpiresAt" date, "refreshTokenExpiresAt" date, "scope" text, "password" text, "createdAt" date not null, "updatedAt" date not null);
6
+
7
+ create table "verification" ("id" text not null primary key, "identifier" text not null, "value" text not null, "expiresAt" date not null, "createdAt" date not null, "updatedAt" date not null);
8
+
9
+ create index "session_userId_idx" on "session" ("userId");
10
+
11
+ create index "account_userId_idx" on "account" ("userId");
12
+
13
+ create index "verification_identifier_idx" on "verification" ("identifier");
@@ -0,0 +1,13 @@
1
+ create table "user" ("id" text not null primary key, "name" text not null, "email" text not null unique, "emailVerified" boolean not null, "image" text, "createdAt" timestamptz default CURRENT_TIMESTAMP not null, "updatedAt" timestamptz default CURRENT_TIMESTAMP not null);
2
+
3
+ create table "session" ("id" text not null primary key, "expiresAt" timestamptz not null, "token" text not null unique, "createdAt" timestamptz default CURRENT_TIMESTAMP not null, "updatedAt" timestamptz not null, "ipAddress" text, "userAgent" text, "userId" text not null references "user" ("id") on delete cascade);
4
+
5
+ create table "account" ("id" text not null primary key, "accountId" text not null, "providerId" text not null, "userId" text not null references "user" ("id") on delete cascade, "accessToken" text, "refreshToken" text, "idToken" text, "accessTokenExpiresAt" timestamptz, "refreshTokenExpiresAt" timestamptz, "scope" text, "password" text, "createdAt" timestamptz default CURRENT_TIMESTAMP not null, "updatedAt" timestamptz not null);
6
+
7
+ create table "verification" ("id" text not null primary key, "identifier" text not null, "value" text not null, "expiresAt" timestamptz not null, "createdAt" timestamptz default CURRENT_TIMESTAMP not null, "updatedAt" timestamptz default CURRENT_TIMESTAMP not null);
8
+
9
+ create index "session_userId_idx" on "session" ("userId");
10
+
11
+ create index "account_userId_idx" on "account" ("userId");
12
+
13
+ create index "verification_identifier_idx" on "verification" ("identifier");
@@ -0,0 +1,463 @@
1
+ {
2
+ "id": "auth/better-auth-orgs",
3
+ "title": "Better Auth with organizations",
4
+ "description": "Email and password sign-in with Better Auth, plus organizations: an org switcher, member management and invite links.",
5
+ "files": [
6
+ {
7
+ "path": "files/core/Auth.ts",
8
+ "target": "packages/core/src/Auth.ts"
9
+ },
10
+ {
11
+ "path": "../better-auth/files/shared/server/auth.ts",
12
+ "target": "apps/web/src/server/auth.ts"
13
+ },
14
+ {
15
+ "path": "files/server/auth-live.ts",
16
+ "target": "apps/web/src/server/auth-live.ts"
17
+ },
18
+ {
19
+ "path": "../better-auth/files/shared/server/auth-route.ts",
20
+ "target": "apps/web/src/server/auth-route.ts"
21
+ },
22
+ {
23
+ "path": "files/server/session.ts",
24
+ "target": "apps/web/src/server/session.ts"
25
+ },
26
+ {
27
+ "path": "../better-auth/files/shared/server/require-session.ts",
28
+ "target": "apps/web/src/server/require-session.ts"
29
+ },
30
+ {
31
+ "path": "files/lib/auth-client.ts",
32
+ "target": "apps/web/src/lib/auth-client.ts"
33
+ },
34
+ {
35
+ "path": "../better-auth/files/shared/lib/redirect.ts",
36
+ "target": "apps/web/src/lib/redirect.ts"
37
+ },
38
+ {
39
+ "path": "../better-auth/files/shared/lib/form.ts",
40
+ "target": "apps/web/src/lib/form.ts"
41
+ },
42
+ {
43
+ "path": "../better-auth/files/shared/components/auth-card.tsx",
44
+ "target": "apps/web/src/components/auth-card.tsx"
45
+ },
46
+ {
47
+ "path": "../better-auth/files/shared/components/user-menu.tsx",
48
+ "target": "apps/web/src/components/user-menu.tsx"
49
+ },
50
+ {
51
+ "path": "../better-auth/files/shared/routes/sign-in.tsx",
52
+ "target": "apps/web/src/routes/sign-in.tsx"
53
+ },
54
+ {
55
+ "path": "../better-auth/files/shared/routes/sign-up.tsx",
56
+ "target": "apps/web/src/routes/sign-up.tsx"
57
+ },
58
+ {
59
+ "path": "../better-auth/files/shared/routes/app/index.tsx",
60
+ "target": "apps/web/src/routes/app/index.tsx"
61
+ },
62
+ {
63
+ "path": "files/routes/app.tsx",
64
+ "target": "apps/web/src/routes/app.tsx"
65
+ },
66
+ {
67
+ "path": "files/routes/onboarding.tsx",
68
+ "target": "apps/web/src/routes/onboarding.tsx"
69
+ },
70
+ {
71
+ "path": "files/routes/accept-invite.$id.tsx",
72
+ "target": "apps/web/src/routes/accept-invite.$id.tsx"
73
+ },
74
+ {
75
+ "path": "files/routes/app/settings.tsx",
76
+ "target": "apps/web/src/routes/app/settings.tsx"
77
+ },
78
+ {
79
+ "path": "files/routes/app/settings/index.tsx",
80
+ "target": "apps/web/src/routes/app/settings/index.tsx"
81
+ },
82
+ {
83
+ "path": "files/routes/app/settings/members.tsx",
84
+ "target": "apps/web/src/routes/app/settings/members.tsx"
85
+ },
86
+ {
87
+ "path": "files/components/org-switcher.tsx",
88
+ "target": "apps/web/src/components/org-switcher.tsx"
89
+ },
90
+ {
91
+ "path": "../better-auth/files/shared/server/db/pg-drizzle.ts",
92
+ "target": "apps/web/src/server/auth-database.ts",
93
+ "when": {
94
+ "database": [
95
+ "postgres"
96
+ ],
97
+ "orm": [
98
+ "drizzle"
99
+ ]
100
+ }
101
+ },
102
+ {
103
+ "path": "../better-auth/files/shared/server/db/pg-effect-sql.ts",
104
+ "target": "apps/web/src/server/auth-database.ts",
105
+ "when": {
106
+ "database": [
107
+ "postgres"
108
+ ],
109
+ "orm": [
110
+ "effect-sql"
111
+ ]
112
+ }
113
+ },
114
+ {
115
+ "path": "files/schema/pg/auth-schema.ts",
116
+ "target": "packages/db/src/auth-schema.ts",
117
+ "when": {
118
+ "database": [
119
+ "postgres"
120
+ ],
121
+ "orm": [
122
+ "drizzle"
123
+ ]
124
+ }
125
+ },
126
+ {
127
+ "path": "../better-auth/files/shared/drizzle/pg/drizzle.config.ts",
128
+ "target": "packages/db/drizzle.config.ts",
129
+ "when": {
130
+ "database": [
131
+ "postgres"
132
+ ],
133
+ "orm": [
134
+ "drizzle"
135
+ ]
136
+ }
137
+ },
138
+ {
139
+ "path": "files/drizzle/pg/20261018161055_auth/migration.sql",
140
+ "target": "packages/db/drizzle/20261018161055_auth/migration.sql",
141
+ "when": {
142
+ "database": [
143
+ "postgres"
144
+ ],
145
+ "orm": [
146
+ "drizzle"
147
+ ]
148
+ }
149
+ },
150
+ {
151
+ "path": "files/drizzle/pg/20261018161055_auth/snapshot.json",
152
+ "target": "packages/db/drizzle/20261018161055_auth/snapshot.json",
153
+ "when": {
154
+ "database": [
155
+ "postgres"
156
+ ],
157
+ "orm": [
158
+ "drizzle"
159
+ ]
160
+ }
161
+ },
162
+ {
163
+ "path": "files/sql/pg/0002_auth.sql",
164
+ "target": "packages/db/migrations/0002_auth.sql",
165
+ "when": {
166
+ "database": [
167
+ "postgres"
168
+ ],
169
+ "orm": [
170
+ "effect-sql"
171
+ ]
172
+ }
173
+ },
174
+ {
175
+ "path": "../better-auth/files/shared/server/db/d1-drizzle.ts",
176
+ "target": "apps/web/src/server/auth-database.ts",
177
+ "when": {
178
+ "database": [
179
+ "d1"
180
+ ],
181
+ "orm": [
182
+ "drizzle"
183
+ ]
184
+ }
185
+ },
186
+ {
187
+ "path": "../better-auth/files/shared/server/db/d1-effect-sql.ts",
188
+ "target": "apps/web/src/server/auth-database.ts",
189
+ "when": {
190
+ "database": [
191
+ "d1"
192
+ ],
193
+ "orm": [
194
+ "effect-sql"
195
+ ]
196
+ }
197
+ },
198
+ {
199
+ "path": "files/schema/d1/auth-schema.ts",
200
+ "target": "packages/db/src/auth-schema.ts",
201
+ "when": {
202
+ "database": [
203
+ "d1"
204
+ ],
205
+ "orm": [
206
+ "drizzle"
207
+ ]
208
+ }
209
+ },
210
+ {
211
+ "path": "../better-auth/files/shared/drizzle/d1/drizzle.config.ts",
212
+ "target": "packages/db/drizzle.config.ts",
213
+ "when": {
214
+ "database": [
215
+ "d1"
216
+ ],
217
+ "orm": [
218
+ "drizzle"
219
+ ]
220
+ }
221
+ },
222
+ {
223
+ "path": "files/drizzle/d1/20261018161055_auth/migration.sql",
224
+ "target": "packages/db/drizzle/20261018161055_auth/migration.sql",
225
+ "when": {
226
+ "database": [
227
+ "d1"
228
+ ],
229
+ "orm": [
230
+ "drizzle"
231
+ ]
232
+ }
233
+ },
234
+ {
235
+ "path": "files/drizzle/d1/20261018161055_auth/snapshot.json",
236
+ "target": "packages/db/drizzle/20261018161055_auth/snapshot.json",
237
+ "when": {
238
+ "database": [
239
+ "d1"
240
+ ],
241
+ "orm": [
242
+ "drizzle"
243
+ ]
244
+ }
245
+ },
246
+ {
247
+ "path": "files/sql/d1/0002_auth.sql",
248
+ "target": "packages/db/migrations/0002_auth.sql",
249
+ "when": {
250
+ "database": [
251
+ "d1"
252
+ ],
253
+ "orm": [
254
+ "effect-sql"
255
+ ]
256
+ }
257
+ }
258
+ ],
259
+ "dependencies": {
260
+ "apps/web": [
261
+ "better-auth"
262
+ ]
263
+ },
264
+ "devDependencies": {},
265
+ "envVars": [
266
+ {
267
+ "name": "BETTER_AUTH_SECRET",
268
+ "example": "change-me-to-a-long-random-string",
269
+ "description": "Signs sessions and cookies (local: .dev.vars; production: wrangler secret put BETTER_AUTH_SECRET)"
270
+ },
271
+ {
272
+ "name": "BETTER_AUTH_URL",
273
+ "example": "http://localhost:5173",
274
+ "description": "Public origin of the app, used for redirects and trusted origins (a Worker var in production)"
275
+ }
276
+ ],
277
+ "requires": [],
278
+ "conflicts": [],
279
+ "transforms": [
280
+ {
281
+ "name": "addDevVar",
282
+ "args": {
283
+ "name": "BETTER_AUTH_SECRET",
284
+ "value": "dev-only-secret-replace-me-with-openssl-rand-base64-32"
285
+ }
286
+ },
287
+ {
288
+ "name": "addDevVar",
289
+ "args": {
290
+ "name": "BETTER_AUTH_URL",
291
+ "value": "http://localhost:5173"
292
+ }
293
+ },
294
+ {
295
+ "name": "addExport",
296
+ "args": {
297
+ "file": "packages/core/src/index.ts",
298
+ "export": "*",
299
+ "from": "./Auth"
300
+ }
301
+ },
302
+ {
303
+ "name": "addImport",
304
+ "args": {
305
+ "file": "apps/web/src/server/layers.ts",
306
+ "import": "AuthLive",
307
+ "from": "./auth-live"
308
+ }
309
+ },
310
+ {
311
+ "name": "addLayer",
312
+ "args": {
313
+ "file": "apps/web/src/server/layers.ts",
314
+ "import": "AuthLive",
315
+ "from": "./auth-live",
316
+ "layer": "AuthLive"
317
+ }
318
+ },
319
+ {
320
+ "name": "addArrayItem",
321
+ "args": {
322
+ "file": "apps/web/src/server/routes.ts",
323
+ "name": "workerRoutes",
324
+ "item": "authRoute",
325
+ "import": "authRoute",
326
+ "from": "./auth-route"
327
+ }
328
+ },
329
+ {
330
+ "name": "addExport",
331
+ "args": {
332
+ "file": "packages/db/src/index.ts",
333
+ "export": "*",
334
+ "from": "./auth-schema.ts"
335
+ },
336
+ "when": {
337
+ "orm": [
338
+ "drizzle"
339
+ ]
340
+ }
341
+ },
342
+ {
343
+ "name": "addAuthPlugin",
344
+ "args": {
345
+ "import": "organization",
346
+ "from": "better-auth/plugins",
347
+ "call": "organization()"
348
+ }
349
+ },
350
+ {
351
+ "name": "addImport",
352
+ "args": {
353
+ "file": "infra/alchemy.run.ts",
354
+ "import": "* as Config",
355
+ "from": "effect/Config"
356
+ },
357
+ "when": {
358
+ "infra": [
359
+ "alchemy"
360
+ ]
361
+ }
362
+ },
363
+ {
364
+ "name": "addAlchemyResource",
365
+ "args": {
366
+ "name": "betterAuthSecret",
367
+ "code": "const betterAuthSecret = yield* Config.Redacted(\"BETTER_AUTH_SECRET\")",
368
+ "binding": "BETTER_AUTH_SECRET"
369
+ },
370
+ "when": {
371
+ "infra": [
372
+ "alchemy"
373
+ ]
374
+ }
375
+ },
376
+ {
377
+ "name": "addAlchemyResource",
378
+ "args": {
379
+ "name": "betterAuthUrl",
380
+ "code": "// the public origin; empty lets Better Auth infer it from each request (right for PR previews)\nconst betterAuthUrl = yield* Config.String(\"BETTER_AUTH_URL\").pipe(Config.withDefault(\"\"))",
381
+ "binding": "BETTER_AUTH_URL"
382
+ },
383
+ "when": {
384
+ "infra": [
385
+ "alchemy"
386
+ ]
387
+ }
388
+ },
389
+ {
390
+ "name": "addWorkflowSecret",
391
+ "args": {
392
+ "name": "BETTER_AUTH_SECRET"
393
+ },
394
+ "when": {
395
+ "infra": [
396
+ "alchemy"
397
+ ]
398
+ }
399
+ },
400
+ {
401
+ "name": "appendAgentsSection",
402
+ "args": {
403
+ "id": "auth",
404
+ "content": "## Auth (Better Auth)\n\n- Server: `apps/web/src/server/auth.ts` builds the Better Auth instance (`makeAuth`); `auth-live.ts` provides it and the `Auth` service from `@repo/core`. Read the session in Effect code through `Auth.currentSession`, never from cookies directly.\n- `/api/auth/*` is served by `auth-route.ts` (a `workerRoutes` entry). Client: `authClient` in `apps/web/src/lib/auth-client.ts`.\n- Route guard: `routes/app.tsx` redirects signed-out visitors to `/sign-in?redirect=...`; build redirects with `safeRedirect`, never from raw input."
405
+ }
406
+ },
407
+ {
408
+ "name": "appendAgentsSection",
409
+ "args": {
410
+ "id": "auth-schema",
411
+ "content": "- Auth tables are in `packages/db/src/auth-schema.ts` (Drizzle); after changing Better Auth plugins regenerate the schema and generate a new migration in `packages/db/drizzle/`, never edit applied ones."
412
+ },
413
+ "when": {
414
+ "orm": [
415
+ "drizzle"
416
+ ]
417
+ }
418
+ },
419
+ {
420
+ "name": "appendAgentsSection",
421
+ "args": {
422
+ "id": "auth-schema",
423
+ "content": "- Auth tables are plain SQL in `packages/db/migrations/0002_auth.sql`; after changing Better Auth plugins add a new migration file, never edit applied ones."
424
+ },
425
+ "when": {
426
+ "orm": [
427
+ "effect-sql"
428
+ ]
429
+ }
430
+ },
431
+ {
432
+ "name": "appendAgentsSection",
433
+ "args": {
434
+ "id": "auth-secret",
435
+ "content": "- `BETTER_AUTH_SECRET` signs sessions: set it as a Worker secret (`.dev.vars` locally, `wrangler secret put BETTER_AUTH_SECRET` in production). Never log or return it. `BETTER_AUTH_URL` is the public origin; when unset Better Auth infers it from the request."
436
+ },
437
+ "when": {
438
+ "infra": [
439
+ "none"
440
+ ]
441
+ }
442
+ },
443
+ {
444
+ "name": "appendAgentsSection",
445
+ "args": {
446
+ "id": "auth-secret",
447
+ "content": "- `BETTER_AUTH_SECRET` signs sessions: Alchemy passes it to the Worker from `.env` locally and from the deploy workflow secret in CI. Never log or return it. `BETTER_AUTH_URL` is the public origin; when unset Better Auth infers it from the request."
448
+ },
449
+ "when": {
450
+ "infra": [
451
+ "alchemy"
452
+ ]
453
+ }
454
+ },
455
+ {
456
+ "name": "appendAgentsSection",
457
+ "args": {
458
+ "id": "organizations",
459
+ "content": "## Organizations\n\n- The `organization()` plugin is enabled: members, roles (`owner`, `admin`, `member`) and invitations live in the `organization`, `member` and `invitation` tables.\n- The session carries `activeOrganizationId`; new users are sent to `/onboarding` to create their first organization. Scope data by it.\n- Member management is at `/app/settings/members`; invitations are accepted at `/accept-invite/$id` (the invite link is shown to the inviter, and with the `email` extra it is also emailed).\n- Check roles on the server before changing another member's data; the UI hides controls but does not enforce permissions."
460
+ }
461
+ }
462
+ ]
463
+ }