better-ts-stack 2.0.2 → 2.1.1

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 (68) hide show
  1. package/README.md +114 -113
  2. package/dist/args.js +27 -20
  3. package/dist/builder/buildPlanner.js +1 -1
  4. package/dist/builder/configGenerator.js +4 -6
  5. package/dist/builder/index.js +15 -3
  6. package/dist/builder/moduleSelector.js +6 -2
  7. package/dist/builder/readmeGenerator.js +107 -0
  8. package/dist/builder/templateContext.js +53 -0
  9. package/dist/index.js +7 -1
  10. package/dist/output/nextSteps.js +23 -22
  11. package/dist/prompts/index.js +5 -2
  12. package/dist/prompts/stack.js +23 -2
  13. package/dist/types/index.js +2 -0
  14. package/dist/ui/messages.js +3 -1
  15. package/dist/validators/index.js +5 -2
  16. package/package.json +3 -3
  17. package/templates/backend/express/config.json +42 -40
  18. package/templates/backend/express/gitignore +3 -0
  19. package/templates/backend/express/src/env.ts.hbs +39 -0
  20. package/templates/backend/express/src/index.ts.hbs +111 -75
  21. package/templates/backend/nestjs/config.json +43 -41
  22. package/templates/backend/nestjs/gitignore +3 -0
  23. package/templates/backend/nestjs/src/app.module.ts.hbs +13 -0
  24. package/templates/backend/nestjs/src/env.ts.hbs +39 -0
  25. package/templates/backend/nestjs/src/health/{health.controller.ts → health.controller.ts.hbs} +8 -0
  26. package/templates/backend/nestjs/src/main.ts +3 -2
  27. package/templates/frontend/nextjs/app/page.tsx.hbs +98 -97
  28. package/templates/frontend/nextjs/config.json +12 -14
  29. package/templates/frontend/nextjs/gitignore +3 -0
  30. package/templates/frontend/tanstack/config.json +16 -16
  31. package/templates/frontend/tanstack/gitignore +3 -0
  32. package/templates/frontend/tanstack/src/routes/index.tsx.hbs +102 -101
  33. package/templates/frontend/tanstack/vite.config.ts +23 -14
  34. package/templates/modules/auth/express/config.json +20 -20
  35. package/templates/modules/auth/express/src/middleware/requireAuth.ts.hbs +1 -2
  36. package/templates/modules/auth/express/src/routes/auth.ts.hbs +27 -19
  37. package/templates/modules/auth/nestjs/config.json +20 -20
  38. package/templates/modules/auth/nestjs/src/auth/{auth.controller.ts → auth.controller.ts.hbs} +15 -0
  39. package/templates/modules/auth/nextjs/config.json +4 -4
  40. package/templates/{frontend/nextjs/proxy.ts.hbs → modules/auth/nextjs/proxy.ts} +1 -8
  41. package/templates/modules/auth/tanstack/config.json +4 -4
  42. package/templates/modules/auth/tanstack/src/components/auth/sign-in-form.tsx +132 -134
  43. package/templates/modules/auth/tanstack/src/components/auth/sign-out-button.tsx +46 -48
  44. package/templates/modules/auth/tanstack/src/components/auth/sign-up-form.tsx +150 -152
  45. package/templates/modules/ci/.github/workflows/ci.yml.hbs +43 -0
  46. package/templates/modules/ci/config.json +10 -0
  47. package/templates/modules/docker/.dockerignore +2 -0
  48. package/templates/modules/docker/Dockerfile.hbs +147 -136
  49. package/templates/modules/docker/docker-compose.yml.hbs +97 -2
  50. package/templates/modules/drizzle/express/config.json +3 -3
  51. package/templates/modules/drizzle/nestjs/config.json +3 -3
  52. package/templates/modules/drizzle/nextjs/config.json +3 -3
  53. package/templates/modules/drizzle/tanstack/config.json +3 -3
  54. package/templates/modules/mongoose/express/config.json +2 -2
  55. package/templates/modules/mongoose/nestjs/config.json +1 -1
  56. package/templates/modules/mongoose/nextjs/config.json +2 -2
  57. package/templates/modules/mongoose/tanstack/config.json +2 -2
  58. package/templates/modules/prisma/express/config.json +4 -4
  59. package/templates/modules/prisma/express/prisma.config.ts +4 -2
  60. package/templates/modules/prisma/nestjs/config.json +4 -4
  61. package/templates/modules/prisma/nestjs/prisma.config.ts +4 -2
  62. package/templates/modules/prisma/nextjs/config.json +4 -4
  63. package/templates/modules/prisma/nextjs/prisma.config.ts +4 -2
  64. package/templates/modules/prisma/tanstack/config.json +4 -4
  65. package/templates/modules/prisma/tanstack/prisma.config.ts +4 -2
  66. package/templates/modules/rate-limit/express/config.json +12 -0
  67. package/templates/modules/rate-limit/express/src/middleware/rateLimit.ts +23 -0
  68. package/templates/modules/rate-limit/nestjs/config.json +12 -0
@@ -1,102 +1,103 @@
1
- import { createFileRoute{{#if useAuth}}, Link{{/if}} } from "@tanstack/react-router";
2
- import { ArrowRight } from "lucide-react";
3
-
4
- import { buttonVariants } from "~/components/ui/button";
5
- import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card";
6
- import { cn } from "~/lib/utils";
7
-
8
- export const Route = createFileRoute("/")({
9
- component: Home,
10
- });
11
-
12
- const featureList = [
13
- "TanStack Start SSR",
14
- "TanStack Router and Query",
15
- "React 19 and TypeScript",
16
- "Tailwind CSS v4",
17
- {{#if useAuth}}"Better Auth-ready session flow",{{/if}}
18
- {{#if (eq database "prisma")}}"Prisma database tooling",{{/if}}
19
- {{#if (eq database "drizzle")}}"Drizzle database tooling",{{/if}}
20
- ];
21
-
22
- function Home() {
23
- return (
24
- <main className="min-h-screen bg-background text-foreground">
25
- <div className="mx-auto flex min-h-screen max-w-6xl flex-col justify-center gap-12 px-6 py-16 sm:px-10 lg:px-12">
26
- <section className="grid gap-10 lg:grid-cols-[1.2fr_0.8fr] lg:items-center">
27
- <div className="space-y-6">
28
- <span className="inline-flex w-fit items-center rounded-full border border-border bg-card px-3 py-1 text-xs font-medium uppercase tracking-[0.24em] text-muted-foreground shadow-sm">
29
- Created with better-ts-stack
30
- </span>
31
- <div className="space-y-4">
32
- <h1 className="max-w-3xl text-4xl font-semibold tracking-tight sm:text-5xl">
33
- Ship your stack faster with a polished TypeScript foundation.
34
- </h1>
35
- <p className="max-w-2xl text-base leading-7 text-muted-foreground sm:text-lg">
36
- Your project already includes the core app shell, database wiring,
37
- and a shadcn-compatible UI foundation so you can keep building
38
- instead of setting up boilerplate.
39
- </p>
40
- </div>
41
- <div className="flex flex-col gap-3 sm:flex-row">
42
- {{#if useAuth}}
43
- <Link
44
- to="/sign-up"
45
- className={cn(buttonVariants({ size: "lg" }), "gap-2")}
46
- >
47
- Create an account
48
- <ArrowRight className="size-4" />
49
- </Link>
50
- <Link
51
- to="/sign-in"
52
- className={buttonVariants({ variant: "outline", size: "lg" })}
53
- >
54
- Login
55
- </Link>
56
- {{else}}
57
- <a
58
- href="https://github.com/Abdullah-dev0/better-ts-stack"
59
- target="_blank"
60
- rel="noreferrer"
61
- className={cn(buttonVariants({ size: "lg" }), "gap-2")}
62
- >
63
- Explore the docs
64
- <ArrowRight className="size-4" />
65
- </a>
66
- <a
67
- href="https://tanstack.com/start/latest"
68
- target="_blank"
69
- rel="noreferrer"
70
- className={buttonVariants({ variant: "outline", size: "lg" })}
71
- >
72
- TanStack guide
73
- </a>
74
- {{/if}}
75
- </div>
76
- </div>
77
-
78
- <Card className="border-border bg-card shadow-sm">
79
- <CardHeader>
80
- <CardTitle>Included in this starter</CardTitle>
81
- </CardHeader>
82
- <CardContent className="space-y-4">
83
- <ul className="space-y-3 text-sm text-muted-foreground">
84
- {featureList.map((feature) => (
85
- <li key={feature} className="flex items-center gap-3">
86
- <span className="size-2 rounded-full bg-primary" />
87
- <span>{feature}</span>
88
- </li>
89
- ))}
90
- </ul>
91
- <div className="rounded-2xl border border-border bg-muted px-4 py-3 text-sm text-muted-foreground">
92
- Start editing{" "}
93
- <code className="font-mono">src/routes/index.tsx</code> and
94
- shape the project around your product instead of setup chores.
95
- </div>
96
- </CardContent>
97
- </Card>
98
- </section>
99
- </div>
100
- </main>
101
- );
1
+ import { createFileRoute{{#if useAuth}}, Link{{/if}} } from "@tanstack/react-router";
2
+ import { ArrowRight } from "lucide-react";
3
+
4
+ import { buttonVariants } from "~/components/ui/button";
5
+ import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card";
6
+ import { cn } from "~/lib/utils";
7
+
8
+ export const Route = createFileRoute("/")({
9
+ component: Home,
10
+ });
11
+
12
+ const featureList = [
13
+ "TanStack Start SSR",
14
+ "TanStack Router and Query",
15
+ "React 19 and TypeScript",
16
+ "Tailwind CSS v4",
17
+ {{#if useAuth}}"Better Auth-ready session flow",{{/if}}
18
+ {{#if (eq database "prisma")}}"Prisma database tooling",{{/if}}
19
+ {{#if (eq database "drizzle")}}"Drizzle database tooling",{{/if}}
20
+ {{#if (eq database "mongoose")}}"Mongoose database tooling",{{/if}}
21
+ ];
22
+
23
+ function Home() {
24
+ return (
25
+ <main className="min-h-screen bg-background text-foreground">
26
+ <div className="mx-auto flex min-h-screen max-w-6xl flex-col justify-center gap-12 px-6 py-16 sm:px-10 lg:px-12">
27
+ <section className="grid gap-10 lg:grid-cols-[1.2fr_0.8fr] lg:items-center">
28
+ <div className="space-y-6">
29
+ <span className="inline-flex w-fit items-center rounded-full border border-border bg-card px-3 py-1 text-xs font-medium uppercase tracking-[0.24em] text-muted-foreground shadow-sm">
30
+ Created with better-ts-stack
31
+ </span>
32
+ <div className="space-y-4">
33
+ <h1 className="max-w-3xl text-4xl font-semibold tracking-tight sm:text-5xl">
34
+ Ship your stack faster with a polished TypeScript foundation.
35
+ </h1>
36
+ <p className="max-w-2xl text-base leading-7 text-muted-foreground sm:text-lg">
37
+ Your project already includes the core app shell, database wiring,
38
+ and a shadcn-compatible UI foundation so you can keep building
39
+ instead of setting up boilerplate.
40
+ </p>
41
+ </div>
42
+ <div className="flex flex-col gap-3 sm:flex-row">
43
+ {{#if useAuth}}
44
+ <Link
45
+ to="/sign-up"
46
+ className={cn(buttonVariants({ size: "lg" }), "gap-2")}
47
+ >
48
+ Create an account
49
+ <ArrowRight className="size-4" />
50
+ </Link>
51
+ <Link
52
+ to="/sign-in"
53
+ className={buttonVariants({ variant: "outline", size: "lg" })}
54
+ >
55
+ Login
56
+ </Link>
57
+ {{else}}
58
+ <a
59
+ href="https://better-ts-stack.abdullahtech.me/docs"
60
+ target="_blank"
61
+ rel="noreferrer"
62
+ className={cn(buttonVariants({ size: "lg" }), "gap-2")}
63
+ >
64
+ Explore the docs
65
+ <ArrowRight className="size-4" />
66
+ </a>
67
+ <a
68
+ href="https://tanstack.com/start/latest"
69
+ target="_blank"
70
+ rel="noreferrer"
71
+ className={buttonVariants({ variant: "outline", size: "lg" })}
72
+ >
73
+ TanStack guide
74
+ </a>
75
+ {{/if}}
76
+ </div>
77
+ </div>
78
+
79
+ <Card className="border-border bg-card shadow-sm">
80
+ <CardHeader>
81
+ <CardTitle>Included in this starter</CardTitle>
82
+ </CardHeader>
83
+ <CardContent className="space-y-4">
84
+ <ul className="space-y-3 text-sm text-muted-foreground">
85
+ {featureList.map((feature) => (
86
+ <li key={feature} className="flex items-center gap-3">
87
+ <span className="size-2 rounded-full bg-primary" />
88
+ <span>{feature}</span>
89
+ </li>
90
+ ))}
91
+ </ul>
92
+ <div className="rounded-2xl border border-border bg-muted px-4 py-3 text-sm text-muted-foreground">
93
+ Start editing{" "}
94
+ <code className="font-mono">src/routes/index.tsx</code> and
95
+ shape the project around your product instead of setup chores.
96
+ </div>
97
+ </CardContent>
98
+ </Card>
99
+ </section>
100
+ </div>
101
+ </main>
102
+ );
102
103
  }
@@ -1,14 +1,23 @@
1
- import { tanstackStart } from "@tanstack/react-start/plugin/vite";
2
- import tailwindcss from "@tailwindcss/vite";
3
- import viteReact from "@vitejs/plugin-react";
4
- import { defineConfig } from "vite";
5
-
6
- export default defineConfig({
7
- server: {
8
- port: 3000,
9
- },
10
- resolve: {
11
- tsconfigPaths: true,
12
- },
13
- plugins: [tanstackStart({ srcDirectory: "src" }), tailwindcss(), viteReact()],
14
- });
1
+ import { tanstackStart } from "@tanstack/react-start/plugin/vite";
2
+ import tailwindcss from "@tailwindcss/vite";
3
+ import viteReact from "@vitejs/plugin-react";
4
+ import { nitro } from "nitro/vite";
5
+ import { defineConfig } from "vite";
6
+
7
+ export default defineConfig(({ command, isPreview }) => ({
8
+ server: {
9
+ port: 3000,
10
+ },
11
+ resolve: {
12
+ tsconfigPaths: true,
13
+ },
14
+ plugins: [
15
+ tanstackStart({ srcDirectory: "src" }),
16
+ tailwindcss(),
17
+ viteReact(),
18
+ // Nitro builds the production server in .output/ (run with node) and serves
19
+ // it for `vite preview`. It is left out of `vite dev`, where TanStack Start's
20
+ // own dev server is steadier
21
+ (command === "build" || isPreview) && nitro(),
22
+ ],
23
+ }));
@@ -1,20 +1,20 @@
1
- {
2
- "id": "auth",
3
- "name": "JWT Auth",
4
- "description": "JWT authentication with bcrypt password hashing",
5
- "type": "feature",
6
- "dependencies": {
7
- "bcrypt": "^6.0.0",
8
- "jsonwebtoken": "^9.0.3",
9
- "zod": "^4.6.5"
10
- },
11
- "devDependencies": {
12
- "@types/bcrypt": "^6.0.0",
13
- "@types/jsonwebtoken": "^9.0.10"
14
- },
15
- "scripts": {},
16
- "envVars": {
17
- "JWT_SECRET": "please-change-me",
18
- "JWT_EXPIRES_IN": "1h"
19
- }
20
- }
1
+ {
2
+ "id": "auth",
3
+ "name": "JWT Auth",
4
+ "description": "JWT authentication with bcrypt password hashing",
5
+ "type": "feature",
6
+ "dependencies": {
7
+ "bcrypt": "^6.0.0",
8
+ "jsonwebtoken": "^9.0.3",
9
+ "zod": "^4.6.7"
10
+ },
11
+ "devDependencies": {
12
+ "@types/bcrypt": "^6.0.0",
13
+ "@types/jsonwebtoken": "^9.0.10"
14
+ },
15
+ "scripts": {},
16
+ "envVars": {
17
+ "JWT_SECRET": "please-change-me",
18
+ "JWT_EXPIRES_IN": "1h"
19
+ }
20
+ }
@@ -19,8 +19,7 @@ export function requireAuth(req: AuthenticatedRequest, res: Response, next: Next
19
19
  const payload = verifyToken(token);
20
20
  req.user = payload;
21
21
  next();
22
- } catch (error) {
23
- console.error('JWT verification failed:', error);
22
+ } catch {
24
23
  res.status(401).json({ error: 'Invalid or expired token' });
25
24
  }
26
25
  }
@@ -1,19 +1,27 @@
1
- import { Request, Response, NextFunction, Router } from 'express';
2
- import { login, me, register } from '../controllers/authController';
3
- import { requireAuth } from '../middleware/requireAuth';
4
-
5
- const router: Router = Router();
6
-
7
- function asyncHandler(
8
- fn: (req: Request, res: Response, next: NextFunction) => Promise<void>
9
- ): (req: Request, res: Response, next: NextFunction) => void {
10
- return (req, res, next) => {
11
- void fn(req, res, next).catch(next);
12
- };
13
- }
14
-
15
- router.post('/register', asyncHandler(register));
16
- router.post('/login', asyncHandler(login));
17
- router.get('/me', requireAuth, me);
18
-
19
- export default router;
1
+ import { Request, Response, NextFunction, Router } from 'express';
2
+ import { login, me, register } from '../controllers/authController';
3
+ {{#if useRateLimit}}
4
+ import { authLimiter } from '../middleware/rateLimit';
5
+ {{/if}}
6
+ import { requireAuth } from '../middleware/requireAuth';
7
+
8
+ const router: Router = Router();
9
+
10
+ function asyncHandler(
11
+ fn: (req: Request, res: Response, next: NextFunction) => Promise<void>
12
+ ): (req: Request, res: Response, next: NextFunction) => void {
13
+ return (req, res, next) => {
14
+ void fn(req, res, next).catch(next);
15
+ };
16
+ }
17
+
18
+ {{#if useRateLimit}}
19
+ router.post('/register', authLimiter, asyncHandler(register));
20
+ router.post('/login', authLimiter, asyncHandler(login));
21
+ {{else}}
22
+ router.post('/register', asyncHandler(register));
23
+ router.post('/login', asyncHandler(login));
24
+ {{/if}}
25
+ router.get('/me', requireAuth, me);
26
+
27
+ export default router;
@@ -1,20 +1,20 @@
1
- {
2
- "id": "auth",
3
- "name": "JWT Auth",
4
- "description": "JWT authentication for NestJS with bcrypt password hashing",
5
- "type": "feature",
6
- "dependencies": {
7
- "bcrypt": "^6.0.0",
8
- "jsonwebtoken": "^9.0.3",
9
- "zod": "^4.6.5"
10
- },
11
- "devDependencies": {
12
- "@types/bcrypt": "^6.0.0",
13
- "@types/jsonwebtoken": "^9.0.10"
14
- },
15
- "scripts": {},
16
- "envVars": {
17
- "JWT_SECRET": "please-change-me",
18
- "JWT_EXPIRES_IN": "1h"
19
- }
20
- }
1
+ {
2
+ "id": "auth",
3
+ "name": "JWT Auth",
4
+ "description": "JWT authentication for NestJS with bcrypt password hashing",
5
+ "type": "feature",
6
+ "dependencies": {
7
+ "bcrypt": "^6.0.0",
8
+ "jsonwebtoken": "^9.0.3",
9
+ "zod": "^4.6.7"
10
+ },
11
+ "devDependencies": {
12
+ "@types/bcrypt": "^6.0.0",
13
+ "@types/jsonwebtoken": "^9.0.10"
14
+ },
15
+ "scripts": {},
16
+ "envVars": {
17
+ "JWT_SECRET": "please-change-me",
18
+ "JWT_EXPIRES_IN": "1h"
19
+ }
20
+ }
@@ -7,6 +7,9 @@ import {
7
7
  Req,
8
8
  UseGuards,
9
9
  } from "@nestjs/common";
10
+ {{#if useRateLimit}}
11
+ import { Throttle } from "@nestjs/throttler";
12
+ {{/if}}
10
13
 
11
14
  import { type AuthenticatedRequest, AuthGuard } from "./auth.guard.js";
12
15
  import {
@@ -19,11 +22,20 @@ import { type AuthResponse, AuthService } from "./auth.service.js";
19
22
  import type { AuthTokenPayload } from "./jwt.js";
20
23
  import { ZodValidationPipe } from "./zod-validation.pipe.js";
21
24
 
25
+ {{#if useRateLimit}}
26
+ // Sign-up and login: 10 attempts per client IP in 15 minutes, against
27
+ // password guessing
28
+ const AUTH_LIMIT = { default: { ttl: 15 * 60 * 1000, limit: 10 } };
29
+
30
+ {{/if}}
22
31
  @Controller("auth")
23
32
  export class AuthController {
24
33
  constructor(private readonly authService: AuthService) {}
25
34
 
26
35
  @Post("register")
36
+ {{#if useRateLimit}}
37
+ @Throttle(AUTH_LIMIT)
38
+ {{/if}}
27
39
  register(
28
40
  @Body(new ZodValidationPipe(registerSchema)) body: RegisterInput
29
41
  ): Promise<AuthResponse> {
@@ -32,6 +44,9 @@ export class AuthController {
32
44
 
33
45
  @Post("login")
34
46
  @HttpCode(200)
47
+ {{#if useRateLimit}}
48
+ @Throttle(AUTH_LIMIT)
49
+ {{/if}}
35
50
  login(
36
51
  @Body(new ZodValidationPipe(loginSchema)) body: LoginInput
37
52
  ): Promise<AuthResponse> {
@@ -4,10 +4,10 @@
4
4
  "description": "Better Auth for Next.js with optional Prisma or Drizzle adapter",
5
5
  "type": "feature",
6
6
  "dependencies": {
7
- "@hookform/resolvers": "^5.9.1",
8
- "better-auth": "^1.7.3",
9
- "react-hook-form": "^7.87.0",
10
- "zod": "^4.6.5"
7
+ "@hookform/resolvers": "^5.9.2",
8
+ "better-auth": "^1.7.14",
9
+ "react-hook-form": "^7.91.0",
10
+ "zod": "^4.6.7"
11
11
  },
12
12
  "devDependencies": {},
13
13
  "scripts": {},
@@ -1,8 +1,6 @@
1
+ import { getSessionCookie } from "better-auth/cookies";
1
2
  import { NextResponse } from "next/server";
2
-
3
- {{#if useAuth}}
4
3
  import type { NextRequest } from "next/server";
5
- import { getSessionCookie } from "better-auth/cookies";
6
4
 
7
5
  export function proxy(request: NextRequest) {
8
6
  const sessionCookie = getSessionCookie(request);
@@ -17,8 +15,3 @@ export function proxy(request: NextRequest) {
17
15
  export const config = {
18
16
  matcher: ["/dashboard/:path*"],
19
17
  };
20
- {{else}}
21
- export function proxy() {
22
- return NextResponse.next();
23
- }
24
- {{/if}}
@@ -4,11 +4,11 @@
4
4
  "description": "Better Auth for TanStack Start with optional Prisma, Drizzle, or MongoDB adapter",
5
5
  "type": "feature",
6
6
  "dependencies": {
7
- "@hookform/resolvers": "^5.9.1",
8
- "better-auth": "^1.7.3",
7
+ "@hookform/resolvers": "^5.9.2",
8
+ "better-auth": "^1.7.14",
9
9
  "dotenv": "^17.4.2",
10
- "react-hook-form": "^7.87.0",
11
- "zod": "^4.6.5"
10
+ "react-hook-form": "^7.91.0",
11
+ "zod": "^4.6.7"
12
12
  },
13
13
  "devDependencies": {},
14
14
  "scripts": {},