Skip to content

Repository files navigation

Quorum AI

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.

Next.js React TypeScript Tailwind CSS Prisma Google Gemini


🌟 Key Features

  • ⚡ 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 (ai v7) 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.

🛠️ Tech Stack

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

📁 Directory Structure

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

🚀 Getting Started

Prerequisites

Ensure you have the following installed on your machine:

  • Node.js: v18.17.0 or higher (v20+ recommended)
  • Package Manager: bun, pnpm, or npm
  • 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

Installation & Setup

  1. Clone the repository:

    git clone https://github.com/therealshreyash/quorum.git
    cd quorum
  2. Install dependencies:

    bun install
    # or
    npm install
    # or
    pnpm install
  3. Configure Environment Variables: Copy .env.example to .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"
  4. Initialize Database & Prisma Client:

    npx prisma migrate dev --name init
    npx prisma generate
  5. Start the Development Server:

    bun dev
    # or
    npm run dev
  6. Open Application: Navigate to http://localhost:3000 in your web browser.


⚙️ Available Scripts

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

🔒 Environment Variables Reference

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)

🚢 Deployment

Deploying to Vercel

  1. Push your repository to GitHub.
  2. Import the repository into Vercel.
  3. Set the Environment Variables listed above in your Vercel Project Settings.
  4. Ensure your PostgreSQL database accepts connections from Vercel deployment IPs.
  5. Hit Deploy. Vercel will run npm run build which automatically executes prisma generate && next build.

🤝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check out the Issues page.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git checkout -b feature/AmazingFeature)
  5. Open a Pull Request

📜 License

Distributed under the MIT License. See LICENSE for more information.

Releases

Packages

Contributors

Languages