Skip to content

envoyat/chatstudio

Β 
Β 

Repository files navigation

Chat Studio

A modern, open-source AI chat application built with Convex backend that provides access to 13+ powerful AI models including Google's Gemini, Anthropic's Claude, OpenAI's GPT, and more. Features real-time data synchronization, persistent chat history, and a beautiful responsive UI.

MIT License Next.js React TypeScript Convex

✨ Features

πŸ†“ Free AI Access

  • No API key required to get started
  • Free access to Gemini models via host-provided API keys
  • Fallback system ensures availability when user keys aren't provided

πŸ”‘ Flexible API Key Management

  • Bring your own keys for better rate limits and premium models
  • Support for 4 major AI providers with 13+ models:
    • 🟒 Google AI (Gemini 2.5 Pro, 2.5 Flash, 2.0 Flash)
    • 🟣 Anthropic (Claude 4 Sonnet, Haiku 3.5, Opus)
    • πŸ”΅ OpenAI (GPT-4.1, GPT-4.1-mini, GPT-4.1-nano, o3, o4-mini)
    • 🟠 OpenRouter (DeepSeek R1, Gemini via OpenRouter)
  • Smart fallback: User keys β†’ Host keys β†’ Error handling

πŸ’¬ Modern Chat Experience

  • Real-time streaming responses via Convex HTTP endpoints
  • Persistent chat history with Convex database
  • Dual storage modes:
    • πŸ” Authenticated: Permanent storage in Convex
    • πŸ‘€ Guest: Temporary storage in browser memory
  • Auto-generated titles using AI
  • Beautiful, responsive UI with dark/light mode
  • LaTeX math rendering support
  • Message editing and regeneration

πŸ”’ Authentication & Privacy

  • Google OAuth integration for seamless sign-in
  • Guest mode for immediate usage without account
  • Custom JWT-based authentication via Convex
  • API keys handled securely with encryption
  • Open source and transparent

πŸš€ Real-time Backend

  • Convex-powered backend for real-time data sync
  • Thread management with automatic updates
  • Message persistence across devices
  • Automatic title generation for conversations
  • Search and indexing capabilities

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ or Bun
  • Convex account (free)
  • Google AI API key (optional, for host setup)

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/chat-studio.git
    cd chat-studio
  2. Install dependencies:

    bun install
    # or
    npm install
  3. Set up Convex:

    # Start Convex development server
    bunx convex dev
  4. Configure environment variables:

    Create a .env.local file:

    # Convex Configuration (automatically set by convex dev)
    CONVEX_DEPLOYMENT=dev:your-deployment-name
    NEXT_PUBLIC_CONVEX_URL=https://your-deployment.convex.cloud
    
    # Authentication
    NEXT_PUBLIC_CLERK_FRONTEND_API_URL=https://your-clerk-instance.clerk.accounts.dev
    
    # Site Configuration
    SITE_URL=http://localhost:3000
  5. Set up host API keys (optional):

    # Provide free access to AI models for all users
    bunx convex env set HOST_GOOGLE_API_KEY your_google_api_key_here
    bunx convex env set ANTHROPIC_API_KEY your_anthropic_api_key_here
    bunx convex env set OPENAI_API_KEY your_openai_api_key_here
    bunx convex env set OPENROUTER_API_KEY your_openrouter_api_key_here
  6. Start the development server:

    bun run dev
    # or
    npm run dev
  7. Open your browser: Navigate to http://localhost:3000

πŸ“š Documentation

For detailed setup instructions, deployment guide, and API documentation:

πŸ“– Convex Setup Guide - Complete backend configuration and deployment instructions

πŸ”§ Configuration

Host API Key Setup (Recommended)

To provide free access to AI models for all users:

  1. Get API keys from providers:

  2. Set them in your Convex deployment:

    bunx convex env set HOST_GOOGLE_API_KEY AIza...your_key_here
    bunx convex env set ANTHROPIC_API_KEY sk-ant-...
    bunx convex env set OPENAI_API_KEY sk-...
    bunx convex env set OPENROUTER_API_KEY sk-or-...

Benefits of host API keys:

  • Users can chat immediately without setup
  • Fallback when user keys aren't provided
  • Free access to multiple AI models
  • Users can still add their own keys for premium features

User API Keys

Users can add their own API keys in the app settings for:

  • Better rate limits
  • Access to premium models
  • Personal usage quotas
  • Override host limitations

πŸ“ Project Structure

chat-studio/
β”œβ”€β”€ app/                    # Next.js app router
β”‚   β”œβ”€β”€ api/               # Legacy API routes
β”‚   └── page.tsx           # Main page
β”œβ”€β”€ components/            # Reusable UI components
β”œβ”€β”€ convex/                # Convex backend
β”‚   β”œβ”€β”€ ai.ts             # AI title generation
β”‚   β”œβ”€β”€ http.ts           # HTTP endpoints (/api/chat)
β”‚   β”œβ”€β”€ messages.ts       # Message operations
β”‚   β”œβ”€β”€ threads.ts        # Thread management
β”‚   β”œβ”€β”€ schema.ts         # Database schema
β”‚   β”œβ”€β”€ models.ts         # AI model configurations
β”‚   └── auth.config.ts    # Authentication config
β”œβ”€β”€ frontend/              # Frontend-specific code
β”‚   β”œβ”€β”€ components/        # React components
β”‚   β”œβ”€β”€ hooks/            # Custom React hooks
β”‚   β”œβ”€β”€ routes/           # Route components
β”‚   β”œβ”€β”€ storage/          # Local storage utilities
β”‚   └── stores/           # Zustand state management
β”œβ”€β”€ lib/                  # Shared utilities
β”œβ”€β”€ styles/               # Global styles
└── public/              # Static assets

πŸ› οΈ Technology Stack

Backend

  • Database: Convex (real-time database)
  • API: Convex HTTP actions
  • Authentication: Custom JWT with Google OAuth
  • AI Integration: Vercel AI SDK

Frontend

  • Framework: Next.js 15 with App Router
  • Frontend: React 18, TypeScript
  • Routing: React Router (client-side)
  • Styling: Tailwind CSS + shadcn/ui
  • State Management: Zustand
  • Local Storage: Browser memory (guest mode)
  • Package Manager: Bun

🎯 Supported AI Models

Google AI (Gemini)

  • βœ… Gemini 2.5 Pro (gemini-2.5-pro-preview-05-06)
  • βœ… Gemini 2.5 Flash (gemini-2.5-flash-preview-04-17)
  • βœ… Gemini 2.5 Flash-Lite Preview (gemini-2.5-flash-lite-preview-06-17)

OpenAI (GPT)

  • βœ… GPT-4.1 (gpt-4.1)
  • βœ… GPT-4.1-mini (gpt-4.1-mini)
  • βœ… GPT-4.1-nano (gpt-4.1-nano)
  • βœ… o3 (o3)
  • βœ… o4-mini (o4-mini)

Anthropic (Claude)

  • βœ… Claude 4 Sonnet (claude-4-sonnet-20250514)
  • βœ… Claude Haiku 3.5 (claude-3-5-haiku-20241022)
  • βœ… Claude 4 Opus (claude-4-opus-20250514)

OpenRouter

  • βœ… DeepSeek R1 (deepseek/deepseek-r1-0528:free)
  • βœ… Gemini 2.0 Flash (google/gemini-2.0-flash-exp:free)

πŸš€ Deployment

Production Deployment

  1. Deploy Convex backend:

    bunx convex deploy --prod
  2. Set production environment variables:

    bunx convex env set HOST_GOOGLE_API_KEY your_key_here --prod
    bunx convex env set ANTHROPIC_API_KEY your_key_here --prod
    bunx convex env set OPENAI_API_KEY your_key_here --prod
    bunx convex env set OPENROUTER_API_KEY your_key_here --prod
    bunx convex env set SITE_URL https://your-domain.com --prod
  3. Deploy frontend (Vercel recommended):

    • Connect your repository to Vercel
    • Set environment variables:
      CONVEX_DEPLOYMENT=prod:your-production-deployment
      NEXT_PUBLIC_CONVEX_URL=https://your-production.convex.cloud
      NEXT_PUBLIC_CLERK_FRONTEND_API_URL=https://your-auth-domain
      
    • Deploy!

Other Platforms

The frontend can be deployed on platforms supporting Next.js:

  • Netlify
  • Railway
  • DigitalOcean App Platform
  • Self-hosted with Docker

Note: Backend always runs on Convex Cloud for optimal performance.

πŸ—οΈ Architecture

Dual Storage System

  • Authenticated Users: Data stored in Convex database
  • Guest Users: Data stored in browser memory
  • Seamless Migration: Guest data can be saved when signing in

Authentication Flow

  1. Guest Mode: Immediate access, temporary storage
  2. Google Sign-In: OAuth flow via custom JWT system
  3. Data Persistence: Conversations saved to Convex
  4. Cross-Device Sync: Access chat history anywhere

API Key Management

User API Key β†’ Host API Key β†’ Error Handling
     ↓              ↓              ↓
  Premium        Free Access    Clear Error
   Models         to AI         Message

🀝 Contributing

We welcome contributions! Please see our contributing guidelines:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Development Guidelines

  • Use TypeScript for all new code
  • Follow the existing code style
  • Test both authenticated and guest modes
  • Update Convex schema if needed
  • Add tests for new features
  • Update documentation as needed

πŸ“ API Keys & Providers

Getting API Keys

Provider Get API Key Key Format Models Available
Google AI AI Studio AIza... Gemini 2.5 Pro/Flash, 2.0 Flash
Anthropic Console sk-ant-... Claude 4 Sonnet/Opus, Haiku 3.5
OpenAI Platform sk-... GPT-4.1, o3, o4-mini
OpenRouter Dashboard sk-or-... DeepSeek R1, Gemini (free tier)

Cost & Rate Limits

  • Host keys: Shared usage, free for users, managed by host
  • User keys: Personal quotas, user controls costs and limits
  • Fallback system: Ensures service availability
  • OpenRouter: Often includes free tier models

πŸ”’ Privacy & Security

Data Storage

  • Authenticated: Conversations stored securely in Convex
  • Guest Mode: Temporary storage in browser memory only
  • No Server Logging: Host doesn't log conversation contents
  • User Control: Delete conversations anytime

API Key Security

  • User Keys: Encrypted and stored locally in browser
  • Host Keys: Server-side only, never exposed to client
  • Transmission: All communications use HTTPS
  • Isolation: User and host keys kept separate

Authentication

  • Google OAuth: Secure authentication flow
  • Custom JWT: Convex-managed authentication tokens
  • No Password Storage: OAuth-only authentication
  • Session Management: Secure token handling

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support


Made with ❀️ by Johannes du Plessis

About

AI Chat Application for Hackathon

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 97.0%
  • CSS 2.8%
  • JavaScript 0.2%