A full-stack, production-ready AI Chat application modeled after ChatGPT, built with Next.js 16 (App Router), React 19, Vercel AI SDK, Google Gemini, Better Auth, and Prisma ORM with PostgreSQL.
- ⚡ Instant-Start New Chat: Deferred database creation—chats are created in Postgres only when the user sends their first message, resulting in zero DB bloat and zero page redirect flashes.
- 💬 Real-Time AI Streaming: Powered by Vercel AI SDK (
aiv7) and Google Gemini (gemini-3.6-flash). - 🎨 Streamdown Markdown & Math: Rich response rendering including syntax-highlighted code blocks, inline & block LaTeX math equations (
@streamdown/math), and interactive Mermaid flowcharts/diagrams (@streamdown/mermaid). - 📌 Conversation Management:
- Pin important conversations to the sidebar header.
- Archive inactive threads.
- Auto-generated conversation titles based on content.
- Custom system prompts and model selection per thread.
- 🔑 Secure Authentication: Better Auth (
better-auth) integration supporting GitHub OAuth, session management, and cookies. - 🌗 Dark / Light Mode: Beautiful UI built with Tailwind CSS v4, Radix UI, Base UI, Lucide & HugeIcons, and
next-themes. - 📱 Responsive Sidebar UI: Collapsible sidebar with instant search, user account popover, pinned threads, and history grouping.
| Domain | Technology |
|---|---|
| Framework | Next.js 16 (App Router) & React 19 |
| Language | TypeScript |
| AI Integration | Vercel AI SDK, @ai-sdk/google, Google Gemini API |
| Authentication | Better Auth with GitHub OAuth |
| Database & ORM | PostgreSQL, Prisma ORM 7 |
| Styling & Components | Tailwind CSS v4, Radix UI, Base UI, Lucide Icons, HugeIcons |
| Markdown Rendering | Streamdown (streamdown, @streamdown/code, @streamdown/math, @streamdown/mermaid) |
| State & Data Fetching | TanStack React Query v5 |
chatgpt-clone/
├── prisma/
│ ├── schema.prisma # Database schema (User, Conversation, Message, Session, Account)
│ └── migrations/ # PostgreSQL migrations
├── src/
│ ├── app/
│ │ ├── (auth)/ # Authentication routes (Sign-in page)
│ │ ├── (protected)/ # Protected application routes (/chat, /c/[id])
│ │ ├── api/ # API routes (/api/chat streaming, /api/auth)
│ │ ├── globals.css # Tailwind CSS v4 configuration and styles
│ │ └── layout.tsx # Root layout with theme and auth providers
│ ├── components/
│ │ ├── ai-elements/ # Custom AI chat components (Message, Loader, Conversation)
│ │ ├── providers/ # Context & theme providers
│ │ └── ui/ # Shadcn & custom UI components
│ ├── features/
│ │ ├── ai/ # AI SDK configuration, model utils & chat persistence
│ │ ├── auth/ # Authentication actions & client state
│ │ ├── conversation/ # Sidebar, ChatComposer, ChatMessages, NewChatView
│ │ └── home/ # Home page components and actions
│ ├── lib/
│ │ ├── auth.ts # Better Auth setup with Prisma adapter
│ │ └── db.ts # Prisma Client instance setup
│ └── generated/
│ └── prisma/ # Generated Prisma Client output
├── .env.example # Template for required environment variables
├── package.json # Project dependencies and scripts
└── tsconfig.json # TypeScript configuration
Ensure you have the following installed on your machine:
- Node.js: v18.17.0 or higher (v20+ recommended)
- Package Manager:
bun,pnpm, ornpm - PostgreSQL Database: A local or hosted PostgreSQL instance (e.g. Supabase, Neon, Railway)
- Google AI API Key: Get one from Google AI Studio
- GitHub OAuth App: Create one in GitHub Developer Settings
-
Clone the repository:
git clone https://github.com/therealshreyash/quorum.git cd quorum -
Install dependencies:
bun install # or npm install # or pnpm install
-
Configure Environment Variables: Copy
.env.exampleto.env:cp .env.example .env
Fill in the required values in
.env:# PostgreSQL Database URL DATABASE_URL="postgresql://user:password@localhost:5432/chatgpt_clone?schema=public" # Secret key for Better Auth (Generate using: openssl rand -base64 32) BETTER_AUTH_SECRET="your-32-byte-secret" # GitHub OAuth Credentials GITHUB_CLIENT_ID="your-github-client-id" GITHUB_CLIENT_SECRET="your-github-client-secret" # Google Gemini API Key GOOGLE_GENERATIVE_AI_API_KEY="your-google-ai-api-key" # Application Base URL NEXT_PUBLIC_APP_URL="http://localhost:3000"
-
Initialize Database & Prisma Client:
npx prisma migrate dev --name init npx prisma generate
-
Start the Development Server:
bun dev # or npm run dev -
Open Application: Navigate to http://localhost:3000 in your web browser.
| Command | Description |
|---|---|
bun dev / npm run dev |
Runs the development server on http://localhost:3000 |
bun run build / npm run build |
Generates Prisma client and builds the application for production |
bun run start / npm run start |
Starts the production server after building |
bun run lint / npm run lint |
Runs ESLint to check for code quality issues |
npx prisma studio |
Opens Prisma Studio to inspect and edit database records visually |
| Variable | Required | Description |
|---|---|---|
DATABASE_URL |
Yes | PostgreSQL connection string |
BETTER_AUTH_SECRET |
Yes | 32+ character random string for session token encryption |
GITHUB_CLIENT_ID |
Yes | OAuth Client ID from your GitHub Developer Portal |
GITHUB_CLIENT_SECRET |
Yes | OAuth Client Secret from your GitHub Developer Portal |
GOOGLE_GENERATIVE_AI_API_KEY |
Yes | Gemini API key from Google AI Studio |
NEXT_PUBLIC_APP_URL |
Yes | Public app URL (http://localhost:3000 for local dev) |
- Push your repository to GitHub.
- Import the repository into Vercel.
- Set the Environment Variables listed above in your Vercel Project Settings.
- Ensure your PostgreSQL database accepts connections from Vercel deployment IPs.
- Hit Deploy. Vercel will run
npm run buildwhich automatically executesprisma generate && next build.
Contributions, issues, and feature requests are welcome! Feel free to check out the Issues page.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git checkout -b feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.