├── src ├── app │ ├── favicon.ico │ ├── fonts │ │ ├── GeistVF.woff │ │ └── GeistMonoVF.woff │ ├── api │ │ ├── auth │ │ │ └── [...all] │ │ │ │ └── route.ts │ │ └── chat │ │ │ └── route.ts │ ├── chat │ │ ├── layout.tsx │ │ └── page.tsx │ ├── admin │ │ ├── users │ │ │ ├── actions.ts │ │ │ ├── page.tsx │ │ │ └── user-management-table.tsx │ │ ├── layout.tsx │ │ └── page.tsx │ ├── layout.tsx │ ├── globals.css │ ├── sign-in │ │ └── page.tsx │ ├── sign-up │ │ └── page.tsx │ └── page.tsx ├── lib │ ├── utils.ts │ ├── auth-client.ts │ ├── prisma.ts │ └── auth.ts ├── utils │ └── supabase.ts └── components │ ├── ui │ ├── collapsible.tsx │ ├── shadcn-io │ │ ├── ai │ │ │ ├── image.tsx │ │ │ ├── suggestion.tsx │ │ │ ├── actions.tsx │ │ │ ├── conversation.tsx │ │ │ ├── message.tsx │ │ │ ├── source.tsx │ │ │ ├── loader.tsx │ │ │ ├── task.tsx │ │ │ ├── code-block.tsx │ │ │ ├── tool.tsx │ │ │ ├── reasoning.tsx │ │ │ ├── branch.tsx │ │ │ ├── prompt-input.tsx │ │ │ ├── web-preview.tsx │ │ │ ├── inline-citation.tsx │ │ │ └── response.tsx │ │ └── code-block │ │ │ ├── server.tsx │ │ │ └── index.tsx │ ├── label.tsx │ ├── textarea.tsx │ ├── input.tsx │ ├── tooltip.tsx │ ├── badge.tsx │ ├── hover-card.tsx │ ├── avatar.tsx │ ├── scroll-area.tsx │ ├── button.tsx │ ├── card.tsx │ ├── table.tsx │ ├── select.tsx │ ├── carousel.tsx │ └── dropdown-menu.tsx │ ├── Footer.tsx │ ├── AdminGuard.tsx │ └── Navbar.tsx ├── prisma ├── migrations │ ├── migration_lock.toml │ └── 20251011081631_add_roles_and_better_auth │ │ └── migration.sql └── schema.prisma ├── postcss.config.mjs ├── .env.example ├── next.config.mjs ├── components.json ├── .eslintrc.json ├── .gitignore ├── .editorconfig ├── tsconfig.json ├── scripts ├── README.md └── make-admin.ts ├── tailwind.config.ts ├── package.json └── README.md /src/app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sugarforever/nextjs-boilerplate/main/src/app/favicon.ico -------------------------------------------------------------------------------- /src/app/fonts/GeistVF.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sugarforever/nextjs-boilerplate/main/src/app/fonts/GeistVF.woff -------------------------------------------------------------------------------- /src/app/fonts/GeistMonoVF.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sugarforever/nextjs-boilerplate/main/src/app/fonts/GeistMonoVF.woff -------------------------------------------------------------------------------- /prisma/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "postgresql" -------------------------------------------------------------------------------- /postcss.config.mjs: -------------------------------------------------------------------------------- 1 | /** @type {import('postcss-load-config').Config} */ 2 | const config = { 3 | plugins: { 4 | tailwindcss: {}, 5 | }, 6 | }; 7 | 8 | export default config; 9 | -------------------------------------------------------------------------------- /src/app/api/auth/[...all]/route.ts: -------------------------------------------------------------------------------- 1 | import { auth } from "@/lib/auth"; 2 | import { toNextJsHandler } from "better-auth/next-js"; 3 | 4 | export const { GET, POST } = toNextJsHandler(auth); 5 | -------------------------------------------------------------------------------- /src/lib/utils.ts: -------------------------------------------------------------------------------- 1 | import { clsx, type ClassValue } from "clsx" 2 | import { twMerge } from "tailwind-merge" 3 | 4 | export function cn(...inputs: ClassValue[]) { 5 | return twMerge(clsx(inputs)) 6 | } 7 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgresql://localhost:5432/boilerplate 2 | BETTER_AUTH_SECRET=your-secret-key-here 3 | NEXT_PUBLIC_APP_URL=http://localhost:3000 4 | 5 | # OpenAI API Key for AI Chat functionality 6 | OPENAI_API_KEY=your-openai-api-key-here -------------------------------------------------------------------------------- /src/utils/supabase.ts: -------------------------------------------------------------------------------- 1 | import { createClient } from '@supabase/supabase-js' 2 | 3 | const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL! 4 | const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY! 5 | 6 | export const supabase = createClient(supabaseUrl, supabaseAnonKey) -------------------------------------------------------------------------------- /src/app/chat/layout.tsx: -------------------------------------------------------------------------------- 1 | export default function ChatLayout({ 2 | children, 3 | }: { 4 | children: React.ReactNode; 5 | }) { 6 | // Full viewport height since navbar is hidden on chat page 7 | return ( 8 |
9 | {children} 10 |
11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /src/components/ui/collapsible.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as CollapsiblePrimitive from "@radix-ui/react-collapsible" 4 | 5 | const Collapsible = CollapsiblePrimitive.Root 6 | 7 | const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger 8 | 9 | const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent 10 | 11 | export { Collapsible, CollapsibleTrigger, CollapsibleContent } 12 | -------------------------------------------------------------------------------- /next.config.mjs: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = { 3 | env: { 4 | GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID, 5 | GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET, 6 | NEXTAUTH_URL: process.env.NEXTAUTH_URL, 7 | NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET, 8 | DATABASE_URL: process.env.DATABASE_URL, 9 | } 10 | }; 11 | 12 | export default nextConfig; 13 | -------------------------------------------------------------------------------- /src/lib/auth-client.ts: -------------------------------------------------------------------------------- 1 | import { createAuthClient } from "better-auth/react"; 2 | import { inferAdditionalFields } from "better-auth/client/plugins"; 3 | import type { auth } from "./auth"; 4 | 5 | export const authClient = createAuthClient({ 6 | baseURL: process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000", 7 | plugins: [inferAdditionalFields()], 8 | }); 9 | 10 | export const { 11 | signIn, 12 | signUp, 13 | signOut, 14 | useSession, 15 | } = authClient; 16 | -------------------------------------------------------------------------------- /components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://ui.shadcn.com/schema.json", 3 | "style": "new-york", 4 | "rsc": true, 5 | "tsx": true, 6 | "tailwind": { 7 | "config": "tailwind.config.ts", 8 | "css": "src/app/globals.css", 9 | "baseColor": "zinc", 10 | "cssVariables": true, 11 | "prefix": "" 12 | }, 13 | "aliases": { 14 | "components": "@/components", 15 | "utils": "@/lib/utils", 16 | "ui": "@/components/ui", 17 | "lib": "@/lib", 18 | "hooks": "@/hooks" 19 | } 20 | } -------------------------------------------------------------------------------- /src/lib/prisma.ts: -------------------------------------------------------------------------------- 1 | import { PrismaClient } from '@prisma/client' 2 | 3 | const prismaClientSingleton = () => { 4 | return new PrismaClient() 5 | } 6 | 7 | type PrismaClientSingleton = ReturnType 8 | 9 | const globalForPrisma = globalThis as unknown as { 10 | prisma: PrismaClientSingleton | undefined 11 | } 12 | 13 | const prisma = globalForPrisma.prisma ?? prismaClientSingleton() 14 | 15 | export default prisma 16 | 17 | if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma -------------------------------------------------------------------------------- /src/app/admin/users/actions.ts: -------------------------------------------------------------------------------- 1 | 'use server'; 2 | 3 | import prisma from '@/lib/prisma'; 4 | import { revalidatePath } from 'next/cache'; 5 | 6 | export async function updateUserRole(userId: string, role: 'USER' | 'ADMIN') { 7 | try { 8 | await prisma.user.update({ 9 | where: { id: userId }, 10 | data: { role }, 11 | }); 12 | revalidatePath('/admin/users'); 13 | return { success: true }; 14 | } catch (error) { 15 | console.error('Failed to update user role:', error); 16 | throw new Error('Failed to update user role'); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/components/Footer.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | 3 | import { usePathname } from 'next/navigation'; 4 | 5 | const Footer = () => { 6 | const pathname = usePathname(); 7 | 8 | // Hide footer on chat page 9 | if (pathname === '/chat') { 10 | return null; 11 | } 12 | 13 | return ( 14 |
15 |
16 |

© {new Date().getFullYear()}

17 |
18 |
19 | ); 20 | }; 21 | 22 | export default Footer; 23 | -------------------------------------------------------------------------------- /src/app/api/chat/route.ts: -------------------------------------------------------------------------------- 1 | import { openai } from '@ai-sdk/openai'; 2 | import { streamText, UIMessage, convertToModelMessages } from 'ai'; 3 | 4 | export const maxDuration = 30; 5 | 6 | export async function POST(req: Request) { 7 | const { messages }: { messages: UIMessage[] } = await req.json(); 8 | 9 | const result = streamText({ 10 | model: openai('gpt-4o-mini'), 11 | system: 'You are a helpful assistant. Be concise and clear in your responses.', 12 | messages: convertToModelMessages(messages), 13 | }); 14 | 15 | return result.toUIMessageStreamResponse(); 16 | } 17 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "next/core-web-vitals", 4 | "next/typescript", 5 | "plugin:@typescript-eslint/recommended", 6 | "prettier" 7 | ], 8 | "plugins": ["@typescript-eslint"], 9 | "parser": "@typescript-eslint/parser", 10 | "rules": { 11 | "@typescript-eslint/no-empty-object-type": "off", 12 | "react/react-in-jsx-scope": "off", 13 | "react/prop-types": "off", 14 | "@typescript-eslint/explicit-module-boundary-types": "off", 15 | "@typescript-eslint/no-explicit-any": "warn", 16 | "no-unused-vars": "off", 17 | "@typescript-eslint/no-unused-vars": ["error"] 18 | } 19 | } -------------------------------------------------------------------------------- /src/components/ui/shadcn-io/ai/image.tsx: -------------------------------------------------------------------------------- 1 | import { cn } from '@/lib/utils'; 2 | import type { Experimental_GeneratedImage } from 'ai'; 3 | 4 | export type ImageProps = Experimental_GeneratedImage & { 5 | className?: string; 6 | alt?: string; 7 | }; 8 | 9 | export const Image = ({ 10 | base64, 11 | uint8Array, 12 | mediaType, 13 | ...props 14 | }: ImageProps) => ( 15 | {props.alt} 24 | ); 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | .yarn/install-state.gz 8 | 9 | # testing 10 | /coverage 11 | 12 | # next.js 13 | /.next/ 14 | /out/ 15 | 16 | # production 17 | /build 18 | 19 | # misc 20 | .DS_Store 21 | *.pem 22 | 23 | # debug 24 | npm-debug.log* 25 | yarn-debug.log* 26 | yarn-error.log* 27 | 28 | # local env files 29 | .env*.local 30 | .env 31 | 32 | # vercel 33 | .vercel 34 | 35 | # typescript 36 | *.tsbuildinfo 37 | next-env.d.ts 38 | 39 | # env files 40 | .env*.local 41 | 42 | .claude 43 | .specify 44 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | charset = utf-8 11 | trim_trailing_whitespace = true 12 | 13 | # TypeScript and JavaScript files 14 | [*.{ts,tsx,js,jsx,mjs}] 15 | indent_style = space 16 | indent_size = 2 17 | 18 | # JSON files 19 | [*.json] 20 | indent_style = space 21 | indent_size = 2 22 | 23 | # CSS, SCSS files 24 | [*.{css,scss}] 25 | indent_style = space 26 | indent_size = 2 27 | 28 | # Markdown files 29 | [*.md] 30 | trim_trailing_whitespace = false 31 | 32 | # YAML files 33 | [*.{yml,yaml}] 34 | indent_style = space 35 | indent_size = 2 -------------------------------------------------------------------------------- /src/app/admin/users/page.tsx: -------------------------------------------------------------------------------- 1 | import prisma from '@/lib/prisma'; 2 | import { UserManagementTable } from './user-management-table'; 3 | 4 | export default async function UsersPage() { 5 | const users = await prisma.user.findMany({ 6 | orderBy: { createdAt: 'desc' }, 7 | select: { 8 | id: true, 9 | name: true, 10 | email: true, 11 | role: true, 12 | emailVerified: true, 13 | createdAt: true, 14 | }, 15 | }); 16 | 17 | return ( 18 |
19 |
20 |

Users Management

21 |

Manage user accounts and permissions

22 |
23 | 24 |
25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /src/lib/auth.ts: -------------------------------------------------------------------------------- 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: "postgresql", 8 | }), 9 | emailAndPassword: { 10 | enabled: true, 11 | requireEmailVerification: false, 12 | }, 13 | user: { 14 | additionalFields: { 15 | role: { 16 | type: "string", 17 | defaultValue: "USER", 18 | input: false, 19 | }, 20 | }, 21 | }, 22 | session: { 23 | expiresIn: 60 * 60 * 24 * 7, // 7 days 24 | updateAge: 60 * 60 * 24, // 1 day 25 | }, 26 | }); 27 | 28 | export type Session = typeof auth.$Infer.Session.session; 29 | export type User = typeof auth.$Infer.Session.user; 30 | -------------------------------------------------------------------------------- /src/components/ui/label.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as LabelPrimitive from "@radix-ui/react-label" 5 | import { cva, type VariantProps } from "class-variance-authority" 6 | 7 | import { cn } from "@/lib/utils" 8 | 9 | const labelVariants = cva( 10 | "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" 11 | ) 12 | 13 | const Label = React.forwardRef< 14 | React.ElementRef, 15 | React.ComponentPropsWithoutRef & 16 | VariantProps 17 | >(({ className, ...props }, ref) => ( 18 | 23 | )) 24 | Label.displayName = LabelPrimitive.Root.displayName 25 | 26 | export { Label } 27 | -------------------------------------------------------------------------------- /src/components/ui/textarea.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | 3 | import { cn } from "@/lib/utils" 4 | 5 | export interface TextareaProps 6 | extends React.TextareaHTMLAttributes {} 7 | 8 | const Textarea = React.forwardRef( 9 | ({ className, ...props }, ref) => { 10 | return ( 11 |