create-thexjs-app 0.1.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 (115) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1026 -0
  3. package/dist/index.js +224 -0
  4. package/package.json +30 -0
  5. package/templates/basic/components.json +21 -0
  6. package/templates/basic/content/blog/hello.md +8 -0
  7. package/templates/basic/public/favicon.ico +0 -0
  8. package/templates/basic/src/actions/dashboard/greet.ts +3 -0
  9. package/templates/basic/src/api/auth/login.ts +30 -0
  10. package/templates/basic/src/api/auth/logout.ts +12 -0
  11. package/templates/basic/src/api/placeholder/comments.ts +17 -0
  12. package/templates/basic/src/api/placeholder/posts.ts +20 -0
  13. package/templates/basic/src/api/placeholder/todos.ts +21 -0
  14. package/templates/basic/src/api/placeholder/users.ts +12 -0
  15. package/templates/basic/src/components/Head.tsx +21 -0
  16. package/templates/basic/src/components/Image.tsx +27 -0
  17. package/templates/basic/src/components/Link.tsx +16 -0
  18. package/templates/basic/src/components/ui/badge.tsx +49 -0
  19. package/templates/basic/src/components/ui/button.tsx +58 -0
  20. package/templates/basic/src/components/ui/card.tsx +88 -0
  21. package/templates/basic/src/components/ui/input.tsx +20 -0
  22. package/templates/basic/src/layouts/main.tsx +38 -0
  23. package/templates/basic/src/lib/auth.ts +70 -0
  24. package/templates/basic/src/lib/migrations/001_create_sessions.sql +9 -0
  25. package/templates/basic/src/lib/placeholder-data.ts +176 -0
  26. package/templates/basic/src/lib/utils.ts +6 -0
  27. package/templates/basic/src/pages/_404.tsx +17 -0
  28. package/templates/basic/src/pages/about.tsx +22 -0
  29. package/templates/basic/src/pages/blog.tsx +41 -0
  30. package/templates/basic/src/pages/dashboard/_middleware.ts +16 -0
  31. package/templates/basic/src/pages/dashboard/index.tsx +84 -0
  32. package/templates/basic/src/pages/index.tsx +54 -0
  33. package/templates/basic/src/pages/login.tsx +85 -0
  34. package/templates/basic/src/pages/placeholder.tsx +194 -0
  35. package/templates/basic/src/pages/posts/[id].tsx +17 -0
  36. package/templates/basic/src/styles/globals.css +90 -0
  37. package/templates/basic/src/x-routes.ts +29 -0
  38. package/templates/basic/tsconfig.json +11 -0
  39. package/templates/basic/x.config.ts +10 -0
  40. package/templates/blog/components.json +20 -0
  41. package/templates/blog/content/posts/getting-started.md +38 -0
  42. package/templates/blog/content/posts/hello-world.md +21 -0
  43. package/templates/blog/content/posts/tailwind-v4.md +31 -0
  44. package/templates/blog/public/favicon.ico +0 -0
  45. package/templates/blog/src/components/ui/avatar.tsx +91 -0
  46. package/templates/blog/src/components/ui/badge.tsx +49 -0
  47. package/templates/blog/src/components/ui/button.tsx +58 -0
  48. package/templates/blog/src/components/ui/card.tsx +88 -0
  49. package/templates/blog/src/components/ui/input.tsx +20 -0
  50. package/templates/blog/src/layouts/blog.tsx +46 -0
  51. package/templates/blog/src/layouts/main.tsx +32 -0
  52. package/templates/blog/src/lib/utils.ts +5 -0
  53. package/templates/blog/src/pages/about.tsx +36 -0
  54. package/templates/blog/src/pages/blog/[slug].tsx +56 -0
  55. package/templates/blog/src/pages/blog/index.tsx +70 -0
  56. package/templates/blog/src/pages/index.tsx +70 -0
  57. package/templates/blog/src/styles/globals.css +90 -0
  58. package/templates/blog/src/x-routes.ts +20 -0
  59. package/templates/blog/tsconfig.json +5 -0
  60. package/templates/blog/x.config.ts +6 -0
  61. package/templates/landing/components.json +20 -0
  62. package/templates/landing/public/favicon.ico +0 -0
  63. package/templates/landing/src/components/code-block.tsx +24 -0
  64. package/templates/landing/src/components/ui/avatar.tsx +91 -0
  65. package/templates/landing/src/components/ui/badge.tsx +49 -0
  66. package/templates/landing/src/components/ui/button.tsx +58 -0
  67. package/templates/landing/src/components/ui/card.tsx +88 -0
  68. package/templates/landing/src/components/ui/input.tsx +20 -0
  69. package/templates/landing/src/layouts/main.tsx +48 -0
  70. package/templates/landing/src/lib/syntax.tsx +366 -0
  71. package/templates/landing/src/lib/utils.ts +5 -0
  72. package/templates/landing/src/pages/contact.tsx +95 -0
  73. package/templates/landing/src/pages/docs/_layout.tsx +109 -0
  74. package/templates/landing/src/pages/docs/api-routes.tsx +113 -0
  75. package/templates/landing/src/pages/docs/build-deploy.tsx +124 -0
  76. package/templates/landing/src/pages/docs/configuration.tsx +121 -0
  77. package/templates/landing/src/pages/docs/content-collections.tsx +130 -0
  78. package/templates/landing/src/pages/docs/data-layer.tsx +142 -0
  79. package/templates/landing/src/pages/docs/getting-started.tsx +119 -0
  80. package/templates/landing/src/pages/docs/index.tsx +123 -0
  81. package/templates/landing/src/pages/docs/layouts.tsx +114 -0
  82. package/templates/landing/src/pages/docs/middleware.tsx +124 -0
  83. package/templates/landing/src/pages/docs/pages.tsx +135 -0
  84. package/templates/landing/src/pages/docs/routing.tsx +123 -0
  85. package/templates/landing/src/pages/docs/server-functions.tsx +123 -0
  86. package/templates/landing/src/pages/features.tsx +129 -0
  87. package/templates/landing/src/pages/index.tsx +175 -0
  88. package/templates/landing/src/styles/globals.css +100 -0
  89. package/templates/landing/src/x-routes.ts +31 -0
  90. package/templates/landing/tsconfig.json +5 -0
  91. package/templates/landing/x.config.ts +2 -0
  92. package/templates/saas/components.json +20 -0
  93. package/templates/saas/public/favicon.ico +0 -0
  94. package/templates/saas/src/actions/dashboard.ts +3 -0
  95. package/templates/saas/src/components/ui/avatar.tsx +91 -0
  96. package/templates/saas/src/components/ui/badge.tsx +49 -0
  97. package/templates/saas/src/components/ui/button.tsx +58 -0
  98. package/templates/saas/src/components/ui/card.tsx +88 -0
  99. package/templates/saas/src/components/ui/input.tsx +20 -0
  100. package/templates/saas/src/layouts/dashboard.tsx +67 -0
  101. package/templates/saas/src/layouts/main.tsx +38 -0
  102. package/templates/saas/src/lib/auth.ts +70 -0
  103. package/templates/saas/src/lib/migrations/001_create_sessions.sql +9 -0
  104. package/templates/saas/src/lib/utils.ts +5 -0
  105. package/templates/saas/src/pages/dashboard/_middleware.ts +9 -0
  106. package/templates/saas/src/pages/dashboard/analytics.tsx +68 -0
  107. package/templates/saas/src/pages/dashboard/index.tsx +86 -0
  108. package/templates/saas/src/pages/dashboard/settings.tsx +105 -0
  109. package/templates/saas/src/pages/index.tsx +110 -0
  110. package/templates/saas/src/pages/login.tsx +67 -0
  111. package/templates/saas/src/pages/pricing.tsx +121 -0
  112. package/templates/saas/src/styles/globals.css +90 -0
  113. package/templates/saas/src/x-routes.ts +22 -0
  114. package/templates/saas/tsconfig.json +5 -0
  115. package/templates/saas/x.config.ts +7 -0
@@ -0,0 +1,91 @@
1
+ import { Avatar as AvatarPrimitive } from "@base-ui/react/avatar";
2
+ import type * as React from "react";
3
+
4
+ import { cn } from "@/lib/utils";
5
+
6
+ function Avatar({
7
+ className,
8
+ size = "default",
9
+ ...props
10
+ }: AvatarPrimitive.Root.Props & {
11
+ size?: "default" | "sm" | "lg";
12
+ }) {
13
+ return (
14
+ <AvatarPrimitive.Root
15
+ data-slot="avatar"
16
+ data-size={size}
17
+ className={cn(
18
+ "group/avatar relative flex size-8 shrink-0 rounded-full select-none after:absolute after:inset-0 after:rounded-full after:border after:border-border after:mix-blend-darken data-[size=lg]:size-10 data-[size=sm]:size-6 dark:after:mix-blend-lighten",
19
+ className,
20
+ )}
21
+ {...props}
22
+ />
23
+ );
24
+ }
25
+
26
+ function AvatarImage({ className, ...props }: AvatarPrimitive.Image.Props) {
27
+ return (
28
+ <AvatarPrimitive.Image
29
+ data-slot="avatar-image"
30
+ className={cn("aspect-square size-full rounded-full object-cover", className)}
31
+ {...props}
32
+ />
33
+ );
34
+ }
35
+
36
+ function AvatarFallback({ className, ...props }: AvatarPrimitive.Fallback.Props) {
37
+ return (
38
+ <AvatarPrimitive.Fallback
39
+ data-slot="avatar-fallback"
40
+ className={cn(
41
+ "flex size-full items-center justify-center rounded-full bg-muted text-sm text-muted-foreground group-data-[size=sm]/avatar:text-xs",
42
+ className,
43
+ )}
44
+ {...props}
45
+ />
46
+ );
47
+ }
48
+
49
+ function AvatarBadge({ className, ...props }: React.ComponentProps<"span">) {
50
+ return (
51
+ <span
52
+ data-slot="avatar-badge"
53
+ className={cn(
54
+ "absolute right-0 bottom-0 z-10 inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground bg-blend-color ring-2 ring-background select-none",
55
+ "group-data-[size=sm]/avatar:size-2 group-data-[size=sm]/avatar:[&>svg]:hidden",
56
+ "group-data-[size=default]/avatar:size-2.5 group-data-[size=default]/avatar:[&>svg]:size-2",
57
+ "group-data-[size=lg]/avatar:size-3 group-data-[size=lg]/avatar:[&>svg]:size-2",
58
+ className,
59
+ )}
60
+ {...props}
61
+ />
62
+ );
63
+ }
64
+
65
+ function AvatarGroup({ className, ...props }: React.ComponentProps<"div">) {
66
+ return (
67
+ <div
68
+ data-slot="avatar-group"
69
+ className={cn(
70
+ "group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-background",
71
+ className,
72
+ )}
73
+ {...props}
74
+ />
75
+ );
76
+ }
77
+
78
+ function AvatarGroupCount({ className, ...props }: React.ComponentProps<"div">) {
79
+ return (
80
+ <div
81
+ data-slot="avatar-group-count"
82
+ className={cn(
83
+ "relative flex size-8 shrink-0 items-center justify-center rounded-full bg-muted text-sm text-muted-foreground ring-2 ring-background group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3",
84
+ className,
85
+ )}
86
+ {...props}
87
+ />
88
+ );
89
+ }
90
+
91
+ export { Avatar, AvatarImage, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarBadge };
@@ -0,0 +1,49 @@
1
+ import { mergeProps } from "@base-ui/react/merge-props";
2
+ import { useRender } from "@base-ui/react/use-render";
3
+ import { type VariantProps, cva } from "class-variance-authority";
4
+
5
+ import { cn } from "@/lib/utils";
6
+
7
+ const badgeVariants = cva(
8
+ "group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-all focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3!",
9
+ {
10
+ variants: {
11
+ variant: {
12
+ default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
13
+ secondary: "bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
14
+ destructive:
15
+ "bg-destructive/10 text-destructive focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:focus-visible:ring-destructive/40 [a]:hover:bg-destructive/20",
16
+ outline: "border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
17
+ ghost: "hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",
18
+ link: "text-primary underline-offset-4 hover:underline",
19
+ },
20
+ },
21
+ defaultVariants: {
22
+ variant: "default",
23
+ },
24
+ },
25
+ );
26
+
27
+ function Badge({
28
+ className,
29
+ variant = "default",
30
+ render,
31
+ ...props
32
+ }: useRender.ComponentProps<"span"> & VariantProps<typeof badgeVariants>) {
33
+ return useRender({
34
+ defaultTagName: "span",
35
+ props: mergeProps<"span">(
36
+ {
37
+ className: cn(badgeVariants({ variant }), className),
38
+ },
39
+ props,
40
+ ),
41
+ render,
42
+ state: {
43
+ slot: "badge",
44
+ variant,
45
+ },
46
+ });
47
+ }
48
+
49
+ export { Badge, badgeVariants };
@@ -0,0 +1,58 @@
1
+ import { Button as ButtonPrimitive } from "@base-ui/react/button";
2
+ import { type VariantProps, cva } from "class-variance-authority";
3
+
4
+ import { cn } from "@/lib/utils";
5
+
6
+ const buttonVariants = cva(
7
+ "group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
8
+ {
9
+ variants: {
10
+ variant: {
11
+ default: "bg-primary text-primary-foreground hover:bg-primary/80",
12
+ outline:
13
+ "border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
14
+ secondary:
15
+ "bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
16
+ ghost:
17
+ "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
18
+ destructive:
19
+ "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
20
+ link: "text-primary underline-offset-4 hover:underline",
21
+ },
22
+ size: {
23
+ default:
24
+ "h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
25
+ xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
26
+ sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
27
+ lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
28
+ icon: "size-8",
29
+ "icon-xs":
30
+ "size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
31
+ "icon-sm":
32
+ "size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg",
33
+ "icon-lg": "size-9",
34
+ },
35
+ },
36
+ defaultVariants: {
37
+ variant: "default",
38
+ size: "default",
39
+ },
40
+ },
41
+ );
42
+
43
+ function Button({
44
+ className,
45
+ variant = "default",
46
+ size = "default",
47
+ ...props
48
+ }: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>) {
49
+ return (
50
+ <ButtonPrimitive
51
+ data-slot="button"
52
+ className={cn(buttonVariants({ variant, size, className }))}
53
+ {...props}
54
+ />
55
+ );
56
+ }
57
+
58
+ export { Button, buttonVariants };
@@ -0,0 +1,88 @@
1
+ import type * as React from "react";
2
+
3
+ import { cn } from "@/lib/utils";
4
+
5
+ function Card({
6
+ className,
7
+ size = "default",
8
+ ...props
9
+ }: React.ComponentProps<"div"> & { size?: "default" | "sm" }) {
10
+ return (
11
+ <div
12
+ data-slot="card"
13
+ data-size={size}
14
+ className={cn(
15
+ "group/card flex flex-col gap-(--card-spacing) overflow-hidden rounded-xl bg-card py-(--card-spacing) text-sm text-card-foreground ring-1 ring-foreground/10 [--card-spacing:--spacing(4)] has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(3)] data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl",
16
+ className,
17
+ )}
18
+ {...props}
19
+ />
20
+ );
21
+ }
22
+
23
+ function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
24
+ return (
25
+ <div
26
+ data-slot="card-header"
27
+ className={cn(
28
+ "group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-xl px-(--card-spacing) has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-(--card-spacing)",
29
+ className,
30
+ )}
31
+ {...props}
32
+ />
33
+ );
34
+ }
35
+
36
+ function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
37
+ return (
38
+ <div
39
+ data-slot="card-title"
40
+ className={cn(
41
+ "text-base leading-snug font-medium group-data-[size=sm]/card:text-sm",
42
+ className,
43
+ )}
44
+ {...props}
45
+ />
46
+ );
47
+ }
48
+
49
+ function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
50
+ return (
51
+ <div
52
+ data-slot="card-description"
53
+ className={cn("text-sm text-muted-foreground", className)}
54
+ {...props}
55
+ />
56
+ );
57
+ }
58
+
59
+ function CardAction({ className, ...props }: React.ComponentProps<"div">) {
60
+ return (
61
+ <div
62
+ data-slot="card-action"
63
+ className={cn("col-start-2 row-span-2 row-start-1 self-start justify-self-end", className)}
64
+ {...props}
65
+ />
66
+ );
67
+ }
68
+
69
+ function CardContent({ className, ...props }: React.ComponentProps<"div">) {
70
+ return (
71
+ <div data-slot="card-content" className={cn("px-(--card-spacing)", className)} {...props} />
72
+ );
73
+ }
74
+
75
+ function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
76
+ return (
77
+ <div
78
+ data-slot="card-footer"
79
+ className={cn(
80
+ "flex items-center rounded-b-xl border-t bg-muted/50 p-(--card-spacing)",
81
+ className,
82
+ )}
83
+ {...props}
84
+ />
85
+ );
86
+ }
87
+
88
+ export { Card, CardHeader, CardFooter, CardTitle, CardAction, CardDescription, CardContent };
@@ -0,0 +1,20 @@
1
+ import { Input as InputPrimitive } from "@base-ui/react/input";
2
+ import type * as React from "react";
3
+
4
+ import { cn } from "@/lib/utils";
5
+
6
+ function Input({ className, type, ...props }: React.ComponentProps<"input">) {
7
+ return (
8
+ <InputPrimitive
9
+ type={type}
10
+ data-slot="input"
11
+ className={cn(
12
+ "h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
13
+ className,
14
+ )}
15
+ {...props}
16
+ />
17
+ );
18
+ }
19
+
20
+ export { Input };
@@ -0,0 +1,67 @@
1
+ import { BarChart3, LayoutDashboard, Settings, User } from "lucide-react";
2
+ import type { ReactNode } from "react";
3
+ import { cn } from "../lib/utils";
4
+
5
+ interface LayoutProps {
6
+ children: ReactNode;
7
+ page?: string;
8
+ }
9
+
10
+ const sidebarLinks = [
11
+ { href: "/dashboard", label: "Dashboard", icon: LayoutDashboard },
12
+ { href: "/dashboard/analytics", label: "Analytics", icon: BarChart3 },
13
+ { href: "/dashboard/settings", label: "Settings", icon: Settings },
14
+ ];
15
+
16
+ export default function DashboardLayout({ children, page }: LayoutProps) {
17
+ return (
18
+ <div className="flex h-screen overflow-hidden bg-background">
19
+ <aside className="flex w-64 flex-col border-r border-border bg-sidebar">
20
+ <div className="flex h-16 items-center gap-2 border-b border-sidebar-border px-6">
21
+ <div className="flex h-8 w-8 items-center justify-center rounded-lg bg-sidebar-primary text-sidebar-primary-foreground text-sm font-bold">
22
+ S
23
+ </div>
24
+ <span className="text-lg font-bold text-sidebar-foreground">SaaS</span>
25
+ </div>
26
+ <nav className="flex-1 space-y-1 p-4">
27
+ {sidebarLinks.map((link) => {
28
+ const Icon = link.icon;
29
+ const isActive = page === link.label;
30
+ return (
31
+ <a
32
+ key={link.href}
33
+ href={link.href}
34
+ className={cn(
35
+ "flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium transition-colors",
36
+ isActive
37
+ ? "bg-sidebar-accent text-sidebar-accent-foreground"
38
+ : "text-sidebar-foreground/70 hover:bg-sidebar-accent/50 hover:text-sidebar-foreground",
39
+ )}
40
+ >
41
+ <Icon className="h-4 w-4" />
42
+ {link.label}
43
+ </a>
44
+ );
45
+ })}
46
+ </nav>
47
+ <div className="border-t border-sidebar-border p-4">
48
+ <div className="flex items-center gap-3 rounded-lg px-3 py-2">
49
+ <div className="flex h-8 w-8 items-center justify-center rounded-full bg-muted">
50
+ <User className="h-4 w-4 text-muted-foreground" />
51
+ </div>
52
+ <div className="flex flex-col">
53
+ <span className="text-sm font-medium text-sidebar-foreground">John Doe</span>
54
+ <span className="text-xs text-sidebar-foreground/60">john@example.com</span>
55
+ </div>
56
+ </div>
57
+ </div>
58
+ </aside>
59
+ <div className="flex flex-1 flex-col overflow-hidden">
60
+ <header className="flex h-16 items-center border-b border-border bg-background px-8">
61
+ <h1 className="text-lg font-semibold text-foreground">{page || "Dashboard"}</h1>
62
+ </header>
63
+ <main className="flex-1 overflow-y-auto p-8">{children}</main>
64
+ </div>
65
+ </div>
66
+ );
67
+ }
@@ -0,0 +1,38 @@
1
+ import type { ReactNode } from "react";
2
+ import { cn } from "../lib/utils";
3
+
4
+ interface LayoutProps {
5
+ children: ReactNode;
6
+ }
7
+
8
+ const navLinks = [
9
+ { href: "/#features", label: "Features" },
10
+ { href: "/pricing", label: "Pricing" },
11
+ { href: "/login", label: "Login" },
12
+ ];
13
+
14
+ export default function MainLayout({ children }: LayoutProps) {
15
+ return (
16
+ <div className="min-h-screen bg-background">
17
+ <nav className="sticky top-0 z-50 bg-background/80 backdrop-blur-sm border-b border-border">
18
+ <div className="mx-auto flex h-16 max-w-7xl items-center justify-between px-4 sm:px-6 lg:px-8">
19
+ <a href="/" className="text-xl font-bold tracking-tight text-foreground">
20
+ SaaS
21
+ </a>
22
+ <div className="flex items-center gap-8">
23
+ {navLinks.map((link) => (
24
+ <a
25
+ key={link.href}
26
+ href={link.href}
27
+ className="text-sm font-medium text-muted-foreground transition-colors hover:text-foreground"
28
+ >
29
+ {link.label}
30
+ </a>
31
+ ))}
32
+ </div>
33
+ </div>
34
+ </nav>
35
+ <main>{children}</main>
36
+ </div>
37
+ );
38
+ }
@@ -0,0 +1,70 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { join } from "node:path";
3
+ import { connectSQLite, runSQLiteMigrations } from "@thexjs/core";
4
+
5
+ const SESSION_COOKIE = "x_session";
6
+ const SESSION_MAX_AGE = 60 * 60 * 24 * 7;
7
+
8
+ export interface Session {
9
+ id: string;
10
+ token: string;
11
+ user_id: string;
12
+ username: string;
13
+ }
14
+
15
+ function getDb() {
16
+ const dbPath = join(import.meta.dir, "..", "..", "data", "dev.db");
17
+ const db = connectSQLite({ path: dbPath });
18
+ runSQLiteMigrations(db, join(import.meta.dir, "migrations"));
19
+ return db;
20
+ }
21
+
22
+ export function createSession(username: string): Session {
23
+ const db = getDb();
24
+ const id = randomUUID();
25
+ const token = randomUUID();
26
+ const userId = `user_${randomUUID().slice(0, 8)}`;
27
+
28
+ db.run("INSERT INTO sessions (id, token, user_id, username) VALUES (?1, ?2, ?3, ?4)", [
29
+ id,
30
+ token,
31
+ userId,
32
+ username,
33
+ ] as unknown as string[]);
34
+
35
+ return { id, token, user_id: userId, username };
36
+ }
37
+
38
+ export function getSession(token: string | undefined): Session | null {
39
+ if (!token) return null;
40
+ const db = getDb();
41
+ const row = db
42
+ .prepare("SELECT id, token, user_id, username FROM sessions WHERE token = ?1")
43
+ .get(token) as { id: string; token: string; user_id: string; username: string } | null;
44
+ if (!row) return null;
45
+ return { id: row.id, token: row.token, user_id: row.user_id, username: row.username };
46
+ }
47
+
48
+ export function deleteSession(token: string): void {
49
+ const db = getDb();
50
+ db.run("DELETE FROM sessions WHERE token = ?1", [token] as unknown as string[]);
51
+ }
52
+
53
+ export function parseSessionCookie(cookieHeader: string | null): string | undefined {
54
+ if (!cookieHeader) return undefined;
55
+ for (const part of cookieHeader.split(";")) {
56
+ const trimmed = part.trim();
57
+ if (trimmed.startsWith(`${SESSION_COOKIE}=`)) {
58
+ return trimmed.slice(SESSION_COOKIE.length + 1);
59
+ }
60
+ }
61
+ return undefined;
62
+ }
63
+
64
+ export function setSessionCookie(token: string): string {
65
+ return `${SESSION_COOKIE}=${token}; HttpOnly; SameSite=Lax; Path=/; Max-Age=${SESSION_MAX_AGE}`;
66
+ }
67
+
68
+ export function clearSessionCookie(): string {
69
+ return `${SESSION_COOKIE}=; HttpOnly; SameSite=Lax; Path=/; Max-Age=0`;
70
+ }
@@ -0,0 +1,9 @@
1
+ CREATE TABLE IF NOT EXISTS sessions (
2
+ id TEXT PRIMARY KEY,
3
+ token TEXT NOT NULL UNIQUE,
4
+ user_id TEXT NOT NULL,
5
+ username TEXT NOT NULL,
6
+ created_at TEXT DEFAULT (datetime('now'))
7
+ );
8
+
9
+ CREATE INDEX IF NOT EXISTS idx_sessions_token ON sessions(token);
@@ -0,0 +1,5 @@
1
+ import { type ClassValue, clsx } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+ export function cn(...inputs: ClassValue[]) {
4
+ return twMerge(clsx(inputs));
5
+ }
@@ -0,0 +1,9 @@
1
+ import type { MiddlewareContext, MiddlewareNext } from "@thexjs/core";
2
+ import { getSession, parseSessionCookie } from "../../lib/auth";
3
+
4
+ export default async function middleware(ctx: MiddlewareContext, next: MiddlewareNext) {
5
+ const token = parseSessionCookie(ctx.request.headers.get("Cookie"));
6
+ const session = getSession(token);
7
+ if (!session) return new Response(null, { status: 302, headers: { Location: "/login" } });
8
+ return next();
9
+ }
@@ -0,0 +1,68 @@
1
+ import type { LoaderArgs, RouteProps } from "@thexjs/core";
2
+ import { BarChart3, PieChart, TrendingUp } from "lucide-react";
3
+
4
+ export async function loader({ request }: LoaderArgs) {
5
+ const { parseSessionCookie, getSession } = await import("../../lib/auth");
6
+ const token = parseSessionCookie(request.headers.get("Cookie"));
7
+ const session = getSession(token);
8
+ return { username: session?.username ?? "User" };
9
+ }
10
+
11
+ const charts = [
12
+ { icon: BarChart3, title: "Monthly Revenue", colors: "from-blue-500/20 to-purple-500/20" },
13
+ { icon: TrendingUp, title: "User Growth", colors: "from-emerald-500/20 to-teal-500/20" },
14
+ { icon: PieChart, title: "Traffic Sources", colors: "from-orange-500/20 to-pink-500/20" },
15
+ ];
16
+
17
+ export default function AnalyticsPage({ loaderData }: RouteProps) {
18
+ return (
19
+ <div className="space-y-8">
20
+ <div>
21
+ <h2 className="text-2xl font-bold tracking-tight text-foreground">Analytics</h2>
22
+ <p className="mt-1 text-sm text-muted-foreground">Track your performance metrics</p>
23
+ </div>
24
+
25
+ <div className="grid gap-6 lg:grid-cols-3">
26
+ {charts.map((chart) => {
27
+ const Icon = chart.icon;
28
+ return (
29
+ <div
30
+ key={chart.title}
31
+ className="group rounded-2xl border border-border bg-card p-6 transition-all hover:border-primary/50 hover:shadow-lg hover:shadow-primary/5"
32
+ >
33
+ <div className="flex items-center gap-3">
34
+ <div className="flex h-10 w-10 items-center justify-center rounded-xl bg-primary/10 text-primary transition-colors group-hover:bg-primary/20">
35
+ <Icon className="h-5 w-5" />
36
+ </div>
37
+ <h3 className="text-lg font-semibold text-card-foreground">{chart.title}</h3>
38
+ </div>
39
+ <div
40
+ className={`mt-6 flex h-48 items-center justify-center rounded-xl bg-gradient-to-br ${chart.colors} border border-border/50`}
41
+ >
42
+ <p className="text-sm text-muted-foreground">Chart placeholder</p>
43
+ </div>
44
+ </div>
45
+ );
46
+ })}
47
+ </div>
48
+
49
+ <div className="rounded-2xl border border-border bg-card p-6">
50
+ <h3 className="text-lg font-semibold text-card-foreground mb-4">Summary</h3>
51
+ <div className="grid gap-4 sm:grid-cols-3">
52
+ <div className="rounded-xl border border-border bg-background p-4">
53
+ <p className="text-sm text-muted-foreground">Total Page Views</p>
54
+ <p className="mt-1 text-2xl font-bold text-foreground">1,234,567</p>
55
+ </div>
56
+ <div className="rounded-xl border border-border bg-background p-4">
57
+ <p className="text-sm text-muted-foreground">Conversion Rate</p>
58
+ <p className="mt-1 text-2xl font-bold text-foreground">3.42%</p>
59
+ </div>
60
+ <div className="rounded-xl border border-border bg-background p-4">
61
+ <p className="text-sm text-muted-foreground">Avg. Session</p>
62
+ <p className="mt-1 text-2xl font-bold text-foreground">4m 32s</p>
63
+ </div>
64
+ </div>
65
+ </div>
66
+ </div>
67
+ );
68
+ }
@@ -0,0 +1,86 @@
1
+ import type { LoaderArgs, RouteProps } from "@thexjs/core";
2
+ import { Activity, DollarSign, TrendingUp, Users } from "lucide-react";
3
+
4
+ export async function loader({ request }: LoaderArgs) {
5
+ const { parseSessionCookie, getSession } = await import("../../lib/auth");
6
+ const token = parseSessionCookie(request.headers.get("Cookie"));
7
+ const session = getSession(token);
8
+ return { username: session?.username ?? "User" };
9
+ }
10
+
11
+ const stats = [
12
+ { label: "Total Users", value: "24,563", change: "+12.5%", icon: Users, trend: "up" },
13
+ { label: "Revenue", value: "$48,290", change: "+8.2%", icon: DollarSign, trend: "up" },
14
+ { label: "Active Now", value: "1,429", change: "+3.1%", icon: Activity, trend: "up" },
15
+ { label: "Growth", value: "23.4%", change: "+2.4%", icon: TrendingUp, trend: "up" },
16
+ ];
17
+
18
+ const recentActivity = [
19
+ { user: "Sarah Chen", action: "created a new project", time: "2 minutes ago" },
20
+ { user: "Mike Johnson", action: "upgraded to Pro plan", time: "15 minutes ago" },
21
+ { user: "Emily Davis", action: "invited 3 team members", time: "1 hour ago" },
22
+ { user: "Alex Kim", action: "completed onboarding", time: "3 hours ago" },
23
+ { user: "Lisa Park", action: "exported analytics report", time: "5 hours ago" },
24
+ ];
25
+
26
+ export default function DashboardPage({ loaderData }: RouteProps) {
27
+ return (
28
+ <div className="space-y-8">
29
+ <div>
30
+ <h2 className="text-2xl font-bold tracking-tight text-foreground">Dashboard</h2>
31
+ <p className="mt-1 text-sm text-muted-foreground">
32
+ Welcome back, {loaderData?.username as string}!
33
+ </p>
34
+ </div>
35
+
36
+ <div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-4">
37
+ {stats.map((stat) => {
38
+ const Icon = stat.icon;
39
+ return (
40
+ <div
41
+ key={stat.label}
42
+ className="group rounded-2xl border border-border bg-card p-6 transition-all hover:border-primary/50 hover:shadow-lg hover:shadow-primary/5"
43
+ >
44
+ <div className="flex items-center justify-between">
45
+ <span className="text-sm font-medium text-muted-foreground">{stat.label}</span>
46
+ <div className="flex h-10 w-10 items-center justify-center rounded-xl bg-primary/10 text-primary transition-colors group-hover:bg-primary/20">
47
+ <Icon className="h-5 w-5" />
48
+ </div>
49
+ </div>
50
+ <p className="mt-4 text-3xl font-bold tracking-tight text-card-foreground">
51
+ {stat.value}
52
+ </p>
53
+ <p className="mt-1 text-sm text-emerald-400">{stat.change} this month</p>
54
+ </div>
55
+ );
56
+ })}
57
+ </div>
58
+
59
+ <div className="rounded-2xl border border-border bg-card">
60
+ <div className="border-b border-border px-6 py-4">
61
+ <h3 className="text-lg font-semibold text-card-foreground">Recent Activity</h3>
62
+ </div>
63
+ <div className="divide-y divide-border">
64
+ {recentActivity.map((item) => (
65
+ <div
66
+ key={item.user + item.time}
67
+ className="flex items-center justify-between px-6 py-4"
68
+ >
69
+ <div className="flex items-center gap-3">
70
+ <div className="flex h-8 w-8 items-center justify-center rounded-full bg-primary/10 text-xs font-medium text-primary">
71
+ {item.user.charAt(0)}
72
+ </div>
73
+ <div>
74
+ <p className="text-sm text-card-foreground">
75
+ <span className="font-medium">{item.user}</span> {item.action}
76
+ </p>
77
+ </div>
78
+ </div>
79
+ <span className="text-xs text-muted-foreground">{item.time}</span>
80
+ </div>
81
+ ))}
82
+ </div>
83
+ </div>
84
+ </div>
85
+ );
86
+ }