create-better-t-stack 0.1.0 → 1.0.2

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 (86) hide show
  1. package/README.md +59 -49
  2. package/dist/index.js +135 -305
  3. package/package.json +19 -11
  4. package/template/base/_gitignore +2 -0
  5. package/template/base/package.json +18 -0
  6. package/template/base/packages/client/_gitignore +23 -0
  7. package/template/base/packages/client/components.json +21 -0
  8. package/template/base/packages/client/index.html +12 -0
  9. package/template/base/packages/client/package.json +49 -0
  10. package/template/base/packages/client/src/components/header.tsx +31 -0
  11. package/template/base/packages/client/src/components/loader.tsx +9 -0
  12. package/template/base/packages/client/src/components/mode-toggle.tsx +37 -0
  13. package/template/base/packages/client/src/components/theme-provider.tsx +73 -0
  14. package/template/base/packages/client/src/components/ui/button.tsx +57 -0
  15. package/template/base/packages/client/src/components/ui/card.tsx +92 -0
  16. package/template/base/packages/client/src/components/ui/checkbox.tsx +30 -0
  17. package/template/base/packages/client/src/components/ui/dropdown-menu.tsx +199 -0
  18. package/template/base/packages/client/src/components/ui/input.tsx +22 -0
  19. package/template/base/packages/client/src/components/ui/label.tsx +24 -0
  20. package/template/base/packages/client/src/components/ui/skeleton.tsx +15 -0
  21. package/template/base/packages/client/src/components/ui/sonner.tsx +29 -0
  22. package/template/base/packages/client/src/index.css +119 -0
  23. package/template/base/packages/client/src/lib/utils.ts +6 -0
  24. package/template/base/packages/client/src/main.tsx +72 -0
  25. package/template/base/packages/client/src/routes/__root.tsx +58 -0
  26. package/template/base/packages/client/src/routes/index.tsx +89 -0
  27. package/template/base/packages/client/src/utils/trpc.ts +4 -0
  28. package/template/base/packages/client/tsconfig.json +18 -0
  29. package/template/base/packages/client/vite.config.ts +14 -0
  30. package/template/base/packages/server/_gitignore +36 -0
  31. package/template/base/packages/server/package.json +27 -0
  32. package/template/base/packages/server/src/index.ts +41 -0
  33. package/template/base/packages/server/src/lib/context.ts +13 -0
  34. package/template/base/packages/server/src/lib/trpc.ts +8 -0
  35. package/template/base/packages/server/src/routers/index.ts +11 -0
  36. package/template/base/packages/server/tsconfig.json +18 -0
  37. package/template/base/turbo.json +27 -0
  38. package/template/examples/todo/packages/client/src/routes/todos.tsx +128 -0
  39. package/template/examples/todo/packages/server/src/routers/with-drizzle-todo.ts +44 -0
  40. package/template/examples/todo/packages/server/src/routers/with-prisma-todo.ts +55 -0
  41. package/template/with-auth/packages/client/src/components/auth-forms.tsx +13 -0
  42. package/template/with-auth/packages/client/src/components/header.tsx +34 -0
  43. package/template/with-auth/packages/client/src/components/sign-in-form.tsx +139 -0
  44. package/template/with-auth/packages/client/src/components/sign-up-form.tsx +164 -0
  45. package/template/with-auth/packages/client/src/components/user-menu.tsx +62 -0
  46. package/template/with-auth/packages/client/src/lib/auth-client.ts +5 -0
  47. package/template/with-auth/packages/client/src/main.tsx +78 -0
  48. package/template/with-auth/packages/client/src/routes/dashboard.tsx +36 -0
  49. package/template/with-auth/packages/client/src/routes/login.tsx +11 -0
  50. package/template/with-auth/packages/server/src/index.ts +46 -0
  51. package/template/with-auth/packages/server/src/lib/trpc.ts +24 -0
  52. package/template/with-auth/packages/server/src/routers/index.ts +19 -0
  53. package/template/with-biome/biome.json +42 -0
  54. package/template/with-drizzle-postgres/packages/server/drizzle.config.ts +10 -0
  55. package/template/with-drizzle-postgres/packages/server/src/db/index.ts +5 -0
  56. package/template/with-drizzle-postgres/packages/server/src/db/schema/auth.ts +47 -0
  57. package/template/with-drizzle-postgres/packages/server/src/db/schema/todo.ts +7 -0
  58. package/template/with-drizzle-postgres/packages/server/src/routers/todo.ts +44 -0
  59. package/template/with-drizzle-postgres/packages/server/src/with-auth-lib/auth.ts +15 -0
  60. package/template/with-drizzle-postgres/packages/server/src/with-auth-lib/context.ts +18 -0
  61. package/template/with-drizzle-postgres/packages/server/src/with-auth-lib/trpc.ts +24 -0
  62. package/template/with-drizzle-sqlite/packages/server/drizzle.config.ts +11 -0
  63. package/template/with-drizzle-sqlite/packages/server/src/db/index.ts +9 -0
  64. package/template/with-drizzle-sqlite/packages/server/src/db/schema/auth.ts +61 -0
  65. package/template/with-drizzle-sqlite/packages/server/src/db/schema/todo.ts +7 -0
  66. package/template/with-drizzle-sqlite/packages/server/src/with-auth-lib/auth.ts +15 -0
  67. package/template/with-drizzle-sqlite/packages/server/src/with-auth-lib/context.ts +18 -0
  68. package/template/with-drizzle-sqlite/packages/server/src/with-auth-lib/trpc.ts +24 -0
  69. package/template/with-husky/.husky/pre-commit +1 -0
  70. package/template/with-prisma-postgres/packages/server/prisma/index.ts +5 -0
  71. package/template/with-prisma-postgres/packages/server/prisma/schema/auth.prisma +59 -0
  72. package/template/with-prisma-postgres/packages/server/prisma/schema/schema.prisma +9 -0
  73. package/template/with-prisma-postgres/packages/server/prisma/schema/todo.prisma +7 -0
  74. package/template/with-prisma-postgres/packages/server/src/with-auth-lib/auth.ts +17 -0
  75. package/template/with-prisma-postgres/packages/server/src/with-auth-lib/context.ts +18 -0
  76. package/template/with-prisma-postgres/packages/server/src/with-auth-lib/trpc.ts +24 -0
  77. package/template/with-prisma-sqlite/packages/server/prisma/index.ts +5 -0
  78. package/template/with-prisma-sqlite/packages/server/prisma/schema/auth.prisma +59 -0
  79. package/template/with-prisma-sqlite/packages/server/prisma/schema/schema.prisma +8 -0
  80. package/template/with-prisma-sqlite/packages/server/prisma/schema/todo.prisma +7 -0
  81. package/template/with-prisma-sqlite/packages/server/src/with-auth-lib/auth.ts +17 -0
  82. package/template/with-prisma-sqlite/packages/server/src/with-auth-lib/context.ts +18 -0
  83. package/template/with-prisma-sqlite/packages/server/src/with-auth-lib/trpc.ts +24 -0
  84. package/template/with-pwa/packages/client/public/logo.png +0 -0
  85. package/template/with-pwa/packages/client/pwa-assets.config.ts +12 -0
  86. package/template/with-pwa/packages/client/vite.config.ts +35 -0
@@ -0,0 +1,7 @@
1
+ model Todo {
2
+ id Int @id @default(autoincrement())
3
+ text String
4
+ completed Boolean @default(false)
5
+
6
+ @@map("todo")
7
+ }
@@ -0,0 +1,17 @@
1
+ import { betterAuth } from "better-auth";
2
+ import { prismaAdapter } from "better-auth/adapters/prisma";
3
+ import prisma from "../../prisma";
4
+
5
+ export const auth = betterAuth({
6
+ database: prismaAdapter(prisma, {
7
+ provider: "pg",
8
+ }),
9
+ trustedOrigins: [process.env.CORS_ORIGIN || ""],
10
+ emailAndPassword: { enabled: true },
11
+ advanced: {
12
+ defaultCookieAttributes: {
13
+ sameSite: "none",
14
+ secure: true,
15
+ },
16
+ },
17
+ });
@@ -0,0 +1,18 @@
1
+ import type { Context as HonoContext } from "hono";
2
+ import { auth } from "./auth";
3
+
4
+ export type CreateContextOptions = {
5
+ hono: HonoContext;
6
+ };
7
+
8
+ export async function createContext({ hono }: CreateContextOptions) {
9
+ const session = await auth.api.getSession({
10
+ headers: hono.req.raw.headers,
11
+ });
12
+
13
+ return {
14
+ session,
15
+ };
16
+ }
17
+
18
+ export type Context = Awaited<ReturnType<typeof createContext>>;
@@ -0,0 +1,24 @@
1
+ import { initTRPC, TRPCError } from "@trpc/server";
2
+ import type { Context } from "./context";
3
+
4
+ export const t = initTRPC.context<Context>().create();
5
+
6
+ export const router = t.router;
7
+
8
+ export const publicProcedure = t.procedure;
9
+
10
+ export const protectedProcedure = t.procedure.use(({ ctx, next }) => {
11
+ if (!ctx.session) {
12
+ throw new TRPCError({
13
+ code: "UNAUTHORIZED",
14
+ message: "Authentication required",
15
+ cause: "No session",
16
+ });
17
+ }
18
+ return next({
19
+ ctx: {
20
+ ...ctx,
21
+ session: ctx.session,
22
+ },
23
+ });
24
+ });
@@ -0,0 +1,5 @@
1
+ import { PrismaClient } from "@prisma/client";
2
+
3
+ let prisma = new PrismaClient();
4
+
5
+ export default prisma;
@@ -0,0 +1,59 @@
1
+ model User {
2
+ id String @id @map("_id")
3
+ name String
4
+ email String
5
+ emailVerified Boolean
6
+ image String?
7
+ createdAt DateTime
8
+ updatedAt DateTime
9
+ sessions Session[]
10
+ accounts Account[]
11
+
12
+ @@unique([email])
13
+ @@map("user")
14
+ }
15
+
16
+ model Session {
17
+ id String @id @map("_id")
18
+ expiresAt DateTime
19
+ token String
20
+ createdAt DateTime
21
+ updatedAt DateTime
22
+ ipAddress String?
23
+ userAgent String?
24
+ userId String
25
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
26
+
27
+ @@unique([token])
28
+ @@map("session")
29
+ }
30
+
31
+ model Account {
32
+ id String @id @map("_id")
33
+ accountId String
34
+ providerId String
35
+ userId String
36
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
37
+ accessToken String?
38
+ refreshToken String?
39
+ idToken String?
40
+ accessTokenExpiresAt DateTime?
41
+ refreshTokenExpiresAt DateTime?
42
+ scope String?
43
+ password String?
44
+ createdAt DateTime
45
+ updatedAt DateTime
46
+
47
+ @@map("account")
48
+ }
49
+
50
+ model Verification {
51
+ id String @id @map("_id")
52
+ identifier String
53
+ value String
54
+ expiresAt DateTime
55
+ createdAt DateTime?
56
+ updatedAt DateTime?
57
+
58
+ @@map("verification")
59
+ }
@@ -0,0 +1,8 @@
1
+ generator client {
2
+ provider = "prisma-client-js"
3
+ }
4
+
5
+ datasource db {
6
+ provider = "sqlite"
7
+ url = "file:../local.db"
8
+ }
@@ -0,0 +1,7 @@
1
+ model Todo {
2
+ id Int @id @default(autoincrement())
3
+ text String
4
+ completed Boolean @default(false)
5
+
6
+ @@map("todo")
7
+ }
@@ -0,0 +1,17 @@
1
+ import { betterAuth } from "better-auth";
2
+ import { prismaAdapter } from "better-auth/adapters/prisma";
3
+ import prisma from "../../prisma";
4
+
5
+ export const auth = betterAuth({
6
+ database: prismaAdapter(prisma, {
7
+ provider: "sqlite",
8
+ }),
9
+ trustedOrigins: [process.env.CORS_ORIGIN || ""],
10
+ emailAndPassword: { enabled: true },
11
+ advanced: {
12
+ defaultCookieAttributes: {
13
+ sameSite: "none",
14
+ secure: true,
15
+ },
16
+ },
17
+ });
@@ -0,0 +1,18 @@
1
+ import type { Context as HonoContext } from "hono";
2
+ import { auth } from "./auth";
3
+
4
+ export type CreateContextOptions = {
5
+ hono: HonoContext;
6
+ };
7
+
8
+ export async function createContext({ hono }: CreateContextOptions) {
9
+ const session = await auth.api.getSession({
10
+ headers: hono.req.raw.headers,
11
+ });
12
+
13
+ return {
14
+ session,
15
+ };
16
+ }
17
+
18
+ export type Context = Awaited<ReturnType<typeof createContext>>;
@@ -0,0 +1,24 @@
1
+ import { initTRPC, TRPCError } from "@trpc/server";
2
+ import type { Context } from "./context";
3
+
4
+ export const t = initTRPC.context<Context>().create();
5
+
6
+ export const router = t.router;
7
+
8
+ export const publicProcedure = t.procedure;
9
+
10
+ export const protectedProcedure = t.procedure.use(({ ctx, next }) => {
11
+ if (!ctx.session) {
12
+ throw new TRPCError({
13
+ code: "UNAUTHORIZED",
14
+ message: "Authentication required",
15
+ cause: "No session",
16
+ });
17
+ }
18
+ return next({
19
+ ctx: {
20
+ ...ctx,
21
+ session: ctx.session,
22
+ },
23
+ });
24
+ });
@@ -0,0 +1,12 @@
1
+ import {
2
+ defineConfig,
3
+ minimal2023Preset as preset,
4
+ } from "@vite-pwa/assets-generator/config";
5
+
6
+ export default defineConfig({
7
+ headLinkOptions: {
8
+ preset: "2023",
9
+ },
10
+ preset,
11
+ images: ["public/logo.png"],
12
+ });
@@ -0,0 +1,35 @@
1
+ import tailwindcss from "@tailwindcss/vite";
2
+ import { TanStackRouterVite } from "@tanstack/router-plugin/vite";
3
+ import react from "@vitejs/plugin-react";
4
+ import path from "node:path";
5
+ import { defineConfig } from "vite";
6
+ import { VitePWA } from "vite-plugin-pwa";
7
+
8
+ export default defineConfig({
9
+ plugins: [
10
+ tailwindcss(),
11
+ TanStackRouterVite({}),
12
+ react(),
13
+ VitePWA({
14
+ registerType: "autoUpdate",
15
+ manifest: {
16
+ name: "My App",
17
+ short_name: "My App ",
18
+ description: "My App",
19
+ theme_color: "#0c0c0c",
20
+ },
21
+ pwaAssets: {
22
+ disabled: false,
23
+ config: true,
24
+ },
25
+ devOptions: {
26
+ enabled: true,
27
+ },
28
+ }),
29
+ ],
30
+ resolve: {
31
+ alias: {
32
+ "@": path.resolve(__dirname, "./src"),
33
+ },
34
+ },
35
+ });