One Platform. All AI Models.
A production-ready SaaS platform that unifies multiple AI models (GPT-4, Claude, Gemini, DeepSeek, and more) into a single, powerful chat interface.
- Multiple AI Models - Access GPT-4, Claude 3.5, Gemini 2.0, DeepSeek R1, Qwen3 Coder, and more
- Instant Model Switching - Switch between different AI models mid-conversation
- Real-time Streaming - Fast, real-time responses with streaming support
- Conversation Management - Save, organize, and revisit all your conversations
- Smart Context - AI maintains conversation context for relevant responses
- Credit System - Flexible pay-as-you-use pricing model
- Usage Analytics - Track AI usage, token consumption, and costs
- Rate Limiting - Fair usage policies with tier-based limits
- Secure Authentication - Enterprise-grade auth powered by Clerk
- Dark Theme - Beautiful dark UI with glassmorphism effects
- Modern Bento Grid - Eye-catching asymmetric layout
- Animated Components - Smooth animations with Framer Motion
- Responsive Design - Perfect on desktop, tablet, and mobile
- Premium UI - Built with shadcn/ui and Aceternity UI components
- Accessibility - WCAG compliant with keyboard navigation
- Framework: Next.js 15 with App Router
- Language: TypeScript
- Styling: Tailwind CSS
- UI Components: shadcn/ui + Aceternity UI
- Animations: Framer Motion
- Icons: Lucide React
- Authentication: Clerk
- Database: Supabase (PostgreSQL)
- AI Gateway: OpenRouter
- API: Next.js API Routes with Edge Runtime
- Hosting: Vercel
- CI/CD: GitHub Actions (optional)
- Analytics: Vercel Analytics (optional)
mi-chat/
βββ public/ # Static assets
βββ src/
β βββ app/
β β βββ (public)/ # Public landing page
β β βββ (auth)/ # Authentication pages
β β β βββ sign-in/
β β β βββ sign-up/
β β βββ (app)/ # Protected app routes
β β β βββ chat/ # Main chat interface
β β βββ api/ # API routes
β β β βββ chat/ # Streaming chat endpoint
β β β βββ webhook/ # Clerk webhooks
β β βββ layout.tsx # Root layout
β β βββ globals.css # Global styles
β βββ components/
β β βββ ui/ # shadcn/ui base components
β β β βββ button.tsx
β β β βββ card.tsx
β β β βββ dialog.tsx
β β β βββ ...
β β βββ chat/ # Chat-specific components
β β β βββ chat-input.tsx
β β β βββ chat-sidebar.tsx
β β β βββ message-item.tsx
β β β βββ message-list.tsx
β β βββ landing/ # Landing page sections
β β βββ hero.tsx
β β βββ features.tsx
β β βββ pricing.tsx
β β βββ navbar.tsx
β βββ lib/
β β βββ ai/ # AI integration
β β β βββ openrouter.ts
β β βββ db/ # Database layer
β β β βββ supabase.ts
β β β βββ queries.ts
β β βββ rate-limit.ts # Rate limiting logic
β β βββ utils.ts # Utility functions
β βββ actions/ # Server actions
β β βββ conversations.ts
β β βββ messages.ts
β βββ hooks/ # Custom React hooks
β β βββ use-chat.ts
β βββ types/ # TypeScript definitions
β β βββ index.ts
β βββ middleware.ts # Next.js middleware
βββ supabase-schema.sql # Database schema
βββ components.json # shadcn/ui config
βββ tailwind.config.ts # Tailwind configuration
βββ tsconfig.json # TypeScript configuration
βββ next.config.ts # Next.js configuration- Node.js 18.17 or later
- npm or yarn or pnpm
- Clerk Account (for authentication)
- Supabase Account (for database)
- OpenRouter Account (for AI models)
git clone https://github.com/pratham-prog861/mi-chat.git
cd mi-chatnpm install
# or
yarn install
# or
pnpm install- Go to clerk.com and create a new application
- Select Email/Password and Google as authentication methods
- Navigate to API Keys in your Clerk dashboard
- Copy your keys to
.env.local:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
CLERK_SECRET_KEY=sk_test_...
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up- Create a new project at supabase.com
- Wait for your database to be provisioned
- Go to SQL Editor in your Supabase dashboard
- Copy and run the entire contents of
supabase-schema.sql - Navigate to Settings > API to get your keys
- Copy your connection details to
.env.local:
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...Note: Keep your SUPABASE_SERVICE_ROLE_KEY secret! Never expose it in client-side code.
- Sign up at openrouter.ai
- Add credits to your account (minimum $5 recommended)
- Navigate to Keys and create a new API key
- Add to
.env.local:
OPENROUTER_API_KEY=sk-or-v1-...Create a .env.local file in the root directory:
cp .env.example .env.localUpdate all values with your actual credentials:
# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
CLERK_SECRET_KEY=sk_test_...
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
# Supabase Database
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
# OpenRouter AI
OPENROUTER_API_KEY=sk-or-v1-...
# App Configuration
NEXT_PUBLIC_APP_URL=http://localhost:3000npm run devOpen http://localhost:3000 in your browser to see the application!
npm run build
npm start| Variable | Description | Required |
|---|---|---|
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY |
Clerk publishable key | β |
CLERK_SECRET_KEY |
Clerk secret key | β |
NEXT_PUBLIC_SUPABASE_URL |
Supabase project URL | β |
NEXT_PUBLIC_SUPABASE_ANON_KEY |
Supabase anonymous key | β |
SUPABASE_SERVICE_ROLE_KEY |
Supabase service role key | β |
OPENROUTER_API_KEY |
OpenRouter API key | β |
NEXT_PUBLIC_APP_URL |
Your app URL | β |
The application uses the following tables:
- users - User accounts with credits and plan information
- conversations - Chat conversations
- messages - Individual messages in conversations
- usage_logs - Track token usage and credits
See supabase-schema.sql for the complete schema.
The platform currently supports the following free models via OpenRouter:
| Model | Provider | Description | Best For |
|---|---|---|---|
| DeepSeek R1 | DeepSeek | Advanced reasoning model | Complex problem-solving |
| Qwen3 Coder | Qwen | Specialized coding model | Programming tasks |
| Gemma 3 27B | Instruction following | General conversations | |
| GPT-OSS 120B | OpenAI OSS | Fast responses | Quick queries |
| GLM 4.5 Air | Z-AI | Lightweight & efficient | Simple tasks |
| Gemini 2.0 Flash | Ultra-fast processing | Speed-critical tasks |
Models can be easily added or modified in src/lib/ai/openrouter.ts:
export const AVAILABLE_MODELS = [
{
id: "provider/model-name:free",
name: "Model Name",
category: "Pro",
description: "Model description",
free: true,
badge: "New",
},
// Add more models...
];-
Hero Section
- Animated spotlight effects
- Sparkles particle animation
- Call-to-action buttons
- Feature badges
-
Features Section
- Modern bento grid layout (4Γ4)
- Asymmetric card sizes
- Gradient icon backgrounds
- Hover animations with glow effects
- Responsive design
-
Pricing Section
- Free and Pro tier comparison
- Credit-based pricing model
- Feature lists with checkmarks
- Glassmorphism cards
-
Conversation Sidebar
- List of all conversations
- Create new conversation
- Delete conversations
- Auto-update on changes
-
Message Display
- User and assistant messages
- Markdown rendering support
- Code syntax highlighting
- Copy message functionality
- Streaming message indicator
-
Input & Controls
- Multi-line text input
- AI model selector dropdown
- Credit balance display
- Send button with loading state
- Keyboard shortcuts (Enter to send)
| Plan | Credits | Messages/Min | Tokens/Min | Price |
|---|---|---|---|---|
| Free | 100 | 5 | 10,000 | $0 |
| Pro | 10,000/month | 50 | 100,000 | $19/month |
Credit Calculation:
- 1 credit = ~100 tokens
- Tokens used = prompt tokens + completion tokens
- Credits automatically deducted after each message
-
Authentication
- Clerk-powered auth
- Email/password & Google OAuth
- Protected API routes
- Session management
-
Database Security
- Row Level Security (RLS) policies
- Service role key for server operations
- User ownership validation
- SQL injection prevention
-
Rate Limiting
- Per-user message limits
- Token usage caps
- In-memory rate limit store
- Automatic reset after 60 seconds
-
Push to GitHub
git add . git commit -m "Initial commit" git push origin main
-
Import to Vercel
- Go to vercel.com
- Click "New Project"
- Import your GitHub repository
- Vercel will auto-detect Next.js
-
Configure Environment Variables
- Add all environment variables from
.env.local - Make sure to use production URLs and keys
- Add all environment variables from
-
Deploy
- Click "Deploy"
- Your app will be live in minutes!
-
Post-Deployment
- Update
NEXT_PUBLIC_APP_URLto your Vercel domain - Update Clerk redirect URLs
- Configure Clerk webhook to point to your domain
- Update
# Install dependencies
npm install
# Build the application
npm run build
# Start production server
npm start# Development mode
npm run dev
# Build for production
npm run build
# Start production server
npm start
# Lint code
npm run lint- API keys stored server-side only
- Row Level Security (RLS) enabled in Supabase
- User ownership validated on all queries
- Rate limiting prevents abuse
- Clerk handles authentication securely
Edit src/lib/ai/openrouter.ts:
export const AVAILABLE_MODELS = [
{
id: "provider/model-name",
name: "Model Display Name",
category: "Pro", // or "Fast", "Thinking"
description: "Brief description",
free: true, // or false for paid models
badge: "New", // or "Recommended", "Rate Limited"
},
// Add more models...
];Edit src/lib/rate-limit.ts:
export function calculateCreditsUsed(tokens: number): number {
// Change the ratio (currently 1 credit per 100 tokens)
return Math.ceil(tokens / 100);
}Edit src/types/index.ts:
export const PLAN_CONFIGS: Record<
UserPlan,
{ credits: number; rateLimit: RateLimitConfig }
> = {
free: {
credits: 100, // Initial free credits
rateLimit: {
messagesPerMinute: 5, // Max messages per minute
tokensPerMinute: 10000, // Max tokens per minute
},
},
pro: {
credits: 10000,
rateLimit: {
messagesPerMinute: 50,
tokensPerMinute: 100000,
},
},
};Edit src/app/globals.css:
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 240 10% 3.9%;
/* Modify other CSS variables... */
}
.dark {
--background: 0 0% 0%;
--foreground: 0 0% 98%;
/* Modify dark theme colors... */
}
}-
Install shadcn/ui component:
npx shadcn-ui@latest add [component-name]
-
Import and use in your files:
import { ComponentName } from "@/components/ui/component-name";
- Solution: Ensure all required env vars are set in
.env.local - Restart dev server after adding environment variables
- Check for typos in variable names
- Solution:
- Verify Supabase credentials are correct
- Ensure database schema is properly created
- Check if service role key is used for server-side operations
- Test connection in Supabase dashboard
- Solution:
- Verify Clerk API keys
- Check if redirect URLs are configured correctly
- Clear browser cookies and try again
- Ensure webhooks are properly configured
- Solution:
- Check OpenRouter API key is valid
- Verify you have credits in OpenRouter account
- Ensure Edge runtime is enabled in API route
- Check browser console for errors
- Solution:
- Wait 60 seconds for rate limit to reset
- Upgrade to Pro plan for higher limits
- Check rate limit configuration in code
- Solution:
- Clear
.nextfolder:rm -rf .next - Delete
node_modulesand reinstall:rm -rf node_modules && npm install - Check TypeScript errors:
npm run type-check - Ensure all environment variables are set
- Clear
This project is licensed under the MIT License - see the LICENSE file for details.
- shadcn/ui - Beautiful component library
- Aceternity UI - Premium UI components
- OpenRouter - AI model gateway
- Clerk - Authentication solution
- Supabase - Backend infrastructure
- Vercel - Deployment platform