A modern, production-ready AI chat application built with Next.js, TypeScript, Clerk authentication, Supabase database, and OpenRouter API integration.
- π User Authentication: Secure authentication via Clerk
- π¬ Real-time Chat: Beautiful chat interface with message bubbles
- π€ AI Integration: Connect to various AI models through OpenRouter API
- π Secure API Key Storage: Encrypted API key storage in Supabase
- π± Responsive Design: Works seamlessly on desktop and mobile
- π¨ Modern UI: Beautiful gradient backgrounds and smooth animations
- β‘ Fast & Performant: Built with Next.js 15 and optimized for speed
- πΎ Message Persistence: All conversations are saved to your account
- π― Type Safety: Full TypeScript support throughout
- Frontend: Next.js 15, React 19, TypeScript
- Styling: Tailwind CSS, Framer Motion
- Authentication: Clerk
- Database: Supabase (PostgreSQL)
- AI API: OpenRouter
- Icons: Lucide React
- Encryption: CryptoJS
Before you begin, ensure you have:
- Node.js 18+ installed
- npm or yarn package manager
- Git for version control
git clone <your-repo-url>
cd e3chatnpm install
# or
yarn installCopy the example environment file:
cp .env.local.example .env.localFill in your environment variables in .env.local:
# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
CLERK_SECRET_KEY=your_clerk_secret_key
# Supabase Configuration
NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
# Encryption Key (generate a random 32-character string)
ENCRYPTION_KEY=your_32_character_encryption_key
# App Configuration
NEXT_PUBLIC_APP_URL=http://localhost:3000- Go to Clerk Dashboard
- Create a new application
- Get your publishable key and secret key
- Configure the following URLs in your Clerk dashboard:
- Homepage URL:
http://localhost:3000 - Sign in URL:
http://localhost:3000/sign-in - Sign up URL:
http://localhost:3000/sign-up - After sign in URL:
http://localhost:3000 - After sign up URL:
http://localhost:3000
- Homepage URL:
- Go to Supabase Dashboard
- Create a new project
- Get your project URL and API keys from Settings > API
- Run the database setup script:
- Go to SQL Editor in your Supabase dashboard
- Copy and paste the contents of
supabase-setup.sql - Run the script to create tables, policies, and triggers
Generate a secure 32-character encryption key:
# Using Node.js
node -e "console.log(require('crypto').randomBytes(16).toString('hex'))"
# Or use any secure random generator- Go to OpenRouter
- Sign up for an account
- Navigate to API Keys
- Create a new API key
- Users will add this key through the application interface
npm run dev
# or
yarn devVisit http://localhost:3000 to see your application!
- NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: Your Clerk application's publishable key
- CLERK_SECRET_KEY: Your Clerk application's secret key (keep this secure)
- NEXT_PUBLIC_SUPABASE_URL: Your Supabase project URL
- NEXT_PUBLIC_SUPABASE_ANON_KEY: Supabase anonymous key (for client-side operations)
- SUPABASE_SERVICE_ROLE_KEY: Service role key (for server-side operations)
- ENCRYPTION_KEY: 32-character key for encrypting user API keys
- NEXT_PUBLIC_APP_URL: Your application URL (for OpenRouter API referrer header)
The application uses three main tables:
- user_api_keys: Stores encrypted OpenRouter API keys
- chats: Stores chat sessions
- messages: Stores individual messages
All tables include Row Level Security (RLS) policies to ensure users can only access their own data.
- Users sign up/sign in via Clerk
- First-time users are prompted to add their OpenRouter API key
- API keys are encrypted before storage in Supabase
- Modern bubble-based chat design
- Distinct styling for user vs AI messages
- Animated typing indicators
- Smooth message animations
- Auto-scrolling to latest messages
- API keys encrypted using AES encryption
- Row Level Security in Supabase
- User isolation at database level
- Secure session management via Clerk
- Push your code to GitHub
- Import your repository in Vercel
- Add all environment variables in the Vercel dashboard
- Update your Clerk URLs to use your production domain
- Deploy!
Update these URLs in your production environment:
NEXT_PUBLIC_APP_URL=https://your-domain.com
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=https://your-domain.com
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=https://your-domain.com- API Key Encryption: All OpenRouter API keys are encrypted before database storage
- Row Level Security: Supabase RLS ensures users can only access their own data
- Environment Variables: Keep all secrets secure and never commit them to version control
- HTTPS: Always use HTTPS in production
- Rate Limiting: Consider implementing rate limiting for API endpoints
- "Unauthorized" errors: Check your Clerk configuration and environment variables
- Database connection errors: Verify your Supabase credentials and RLS policies
- API key validation fails: Ensure your OpenRouter API key is valid and has sufficient credits
- Build errors: Make sure all dependencies are installed and TypeScript is properly configured
Enable debug logging by setting:
DEBUG=true- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit your changes:
git commit -am 'Add feature' - Push to the branch:
git push origin feature-name - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Next.js for the amazing React framework
- Clerk for seamless authentication
- Supabase for the database and real-time features
- OpenRouter for AI model access
- Tailwind CSS for utility-first styling
- Framer Motion for beautiful animations
If you encounter any issues or have questions, please:
- Check the troubleshooting section above
- Search existing issues in the GitHub repository
- Create a new issue with detailed information about your problem
Made with β€οΈ using modern web technologies