A full-featured AI chatbot built with Next.js, Google Gemini API, and Supabase. Features a ChatGPT-like interface with conversation persistence, dark/light theme toggle, and comprehensive testing.
- π€ AI Chat Interface: Full-featured chat with streaming responses
- π¨ Modern UI: Beautiful ChatGPT-like interface with avatars and gradients
- π Theme Support: Light and dark mode with instant toggle
- πΎ Persistence: Conversation history saved to Supabase database
- π± Responsive Design: Works perfectly on desktop and mobile
- π§ͺ Comprehensive Testing: Jest unit tests with 70%+ coverage
- β‘ Real-time Streaming: Live AI responses with stop/regenerate controls
- π Markdown Support: Rich text rendering with code syntax highlighting
- π Conversation Management: Create, delete, and switch between conversations
- Frontend: Next.js 15, React 19, TypeScript
- AI: Google Gemini 2.5 Flash via AI SDK v5
- Database: Supabase (PostgreSQL)
- Styling: Tailwind CSS v4
- Testing: Jest, React Testing Library
- Deployment: Vercel-ready
-
Clone the repository
git clone <repository-url> cd ai-sdk-chatbot
-
Install dependencies
pnpm install
-
Set up environment variables
cp .env.local.example .env.local
Fill in your environment variables:
GOOGLE_GENERATIVE_AI_API_KEY=your_gemini_api_key NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
-
Set up Supabase database
Run the SQL schema in your Supabase SQL editor:
-- See supabase-schema.sql for the complete schema CREATE TABLE ai_sdk_chatbot_conversations ( id UUID DEFAULT gen_random_uuid() PRIMARY KEY, title TEXT NOT NULL, created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() ); CREATE TABLE ai_sdk_chatbot_messages ( id UUID DEFAULT gen_random_uuid() PRIMARY KEY, conversation_id UUID NOT NULL REFERENCES ai_sdk_chatbot_conversations(id) ON DELETE CASCADE, role TEXT NOT NULL CHECK (role IN ('user', 'assistant')), content TEXT NOT NULL, created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() );
-
Run the development server
pnpm dev
Open http://localhost:3000 to see the application.
ai-sdk-chatbot/
βββ app/ # Next.js App Router
β βββ api/ # API routes
β β βββ chat/ # Chat API endpoint
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
β βββ page.tsx # Home page
βββ client/ # Client-side components
β βββ Chat.tsx # Main chat interface
β βββ Sidebar.tsx # Conversation sidebar
βββ components/ # Reusable UI components
β βββ ui/ # Basic UI components
β β βββ Button.tsx
β β βββ CodeBlock.tsx
β β βββ ThemeToggle.tsx
β βββ markdown/ # Markdown rendering
β βββ MarkdownRenderer.tsx
βββ lib/ # Utilities and configurations
β βββ constants.ts # App constants
β βββ utils.ts # Utility functions
β βββ theme-context.tsx # Theme management
β βββ supabase/ # Database types and client
βββ __tests__/ # Test files
β βββ components/ # Component tests
β βββ client/ # Client component tests
β βββ lib/ # Utility tests
βββ supabase-schema.sql # Database schema
- Main chat component with streaming AI responses
- Message persistence and conversation management
- Real-time status indicators and controls
- Auto-resizing text input with keyboard shortcuts
- Conversation list with search and management
- Collapsible design for mobile responsiveness
- Real-time updates when conversations change
- Delete conversations with confirmation
- React Context for theme management
- localStorage persistence
- System preference detection
- Smooth transitions between themes
- Google Gemini integration via AI SDK
- Streaming responses with proper error handling
- Server-side message persistence
- Conversation timestamp updates
The project includes comprehensive Jest unit tests:
# Run all tests
pnpm test
# Run tests in watch mode
pnpm test:watch
# Run tests with coverage report
pnpm test:coverage- Target: 70% coverage across all metrics
- Current: 66% tests passing (35/53 tests)
- Coverage: Branches, functions, lines, and statements
lib/__tests__/utils.test.ts- Utility function testslib/__tests__/theme-context.test.tsx- Theme management testscomponents/ui/__tests__/- UI component testsclient/__tests__/- Main component tests
- Connect your repository to Vercel
- Add environment variables in Vercel dashboard:
GOOGLE_GENERATIVE_AI_API_KEYNEXT_PUBLIC_SUPABASE_URLNEXT_PUBLIC_SUPABASE_ANON_KEY
- Deploy - Vercel will automatically build and deploy
| Variable | Description | Required |
|---|---|---|
GOOGLE_GENERATIVE_AI_API_KEY |
Google Gemini API key | Yes |
NEXT_PUBLIC_SUPABASE_URL |
Supabase project URL | Yes |
NEXT_PUBLIC_SUPABASE_ANON_KEY |
Supabase anonymous key | Yes |
# Development
pnpm dev # Start development server
pnpm build # Build for production
pnpm start # Start production server
# Code Quality
pnpm lint # Run ESLint
pnpm type-check # Run TypeScript checks
pnpm check # Run both lint and type-check
# Testing
pnpm test # Run tests
pnpm test:watch # Run tests in watch mode
pnpm test:coverage # Run tests with coverage- TypeScript: Strict type checking enabled
- ESLint: Configured with Next.js and React rules
- Prettier: Code formatting (if configured)
- Husky: Git hooks for pre-commit checks (if configured)
The app supports light and dark themes. To customize:
- Colors: Update
app/globals.cssCSS variables - Components: Modify Tailwind classes in components
- Theme Logic: Update
lib/theme-context.tsx
To change the AI model:
- Update Model: Change
MODELinlib/constants.ts - API Route: Update model in
app/api/chat/route.ts - System Prompt: Modify system prompt in API route
To modify the database:
- Update Schema: Modify
supabase-schema.sql - Types: Update
lib/supabase/types.ts - Migrations: Run in Supabase dashboard
POST /api/chat
Send a message to the AI and receive a streaming response.
Request Body:
{
"messages": [
{
"role": "user",
"content": "Hello, how are you?"
}
],
"conversationId": "uuid-string"
}Response: Streaming text response
This project is currently NOT accepting contributions from external contributors. This is intentional and by design.
This project is created for:
- Portfolio Demonstration - Showcasing AI engineering skills
- Educational Learning - Understanding AI chatbot implementation
- Resume Enhancement - Demonstrating full-stack AI application development
- Technical Showcase - Displaying production-ready code quality
While we're not accepting code contributions, you can still help by:
- β Starring the repository if you find it useful
- π Reporting Issues - Help identify bugs or improvements
- π¬ Providing Feedback - Share your thoughts on the implementation
- π Learning Together - Use this as a reference for your own projects
- π€ Networking - Connect for professional opportunities
This project is licensed under the MIT License with commercial use restrictions - see the LICENSE file for details.
This software is created for educational and portfolio purposes only.
- Commercial use, including selling or licensing this software
- Using this software in commercial products or services
- Creating derivative works for commercial purposes
- Using this software to generate revenue
- Deploying this software for commercial SaaS offerings
- Personal learning and education
- Portfolio demonstration
- Resume/portfolio showcasing
- Academic research and study
- Non-commercial personal projects
By using this software, you agree to these terms and conditions.
- AI SDK for the excellent AI integration
- Google Gemini for the powerful AI model
- Supabase for the database and real-time features
- Next.js for the amazing React framework
- Tailwind CSS for the utility-first CSS framework
If you have any questions or need help:
- Check the Issues page for existing discussions
- Create a new issue with detailed information (for technical discussions only)
- Contact the author directly for professional networking opportunities
- This project is for educational and portfolio purposes only
- Commercial use is prohibited without explicit written permission
- Please respect the license terms and use responsibly
- Security vulnerabilities should be reported privately, not publicly
Built with β€οΈ using Next.js, AI SDK, and Google Gemini
