A production-ready, full-stack AI chat application built with Next.js 14, Supabase, OpenAI & NextAuth.
- 🔐 Authentication — Secure login with NextAuth + Google OAuth
- 💬 AI Chat — Real-time conversations powered by OpenAI GPT-4o
- 🧠 Auto Sessions — Chat sessions auto-generated from first message
- 🗄️ Persistent Storage — Full chat & message history stored in Supabase
- ⭐ Favourites — Bookmark and revisit important conversations
- 🚫 Rate Limiting — Per-user request limits to prevent abuse
- ⚡ Server Actions — Next.js server actions for secure backend logic
- 🎨 Modern UI — Clean, responsive design with Tailwind CSS + ShadCN
| Category | Technology |
|---|---|
| Framework | Next.js 14 (App Router) |
| AI | OpenAI GPT-4o (AI SDK) |
| Database | Supabase / PostgreSQL |
| Auth | NextAuth + Google OAuth |
| Styling | Tailwind CSS + ShadCN UI |
| Deployment | Vercel |
git clone https://github.com/Anurag13075/ai-chat-platform.git
cd ai-chat-platformnpm installCreate a .env.local file in the root:
# NextAuth
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-secret-key
# OpenAI
OPENAI_API_KEY=your-openai-key
# Supabase
SUPABASE_URL=https://xxxxx.supabase.co
SUPABASE_ANON_KEY=your-public-anon-key
SUPABASE_SERVICE_KEY=your-service-role-key
# Rate Limiting
RATE_LIMIT=5npm run devVisit http://localhost:3000 🎉
git add .
git commit -m "Deploy to Vercel"
git push origin main- Import your repo at vercel.com
- Add all environment variables
- Update
NEXTAUTH_URLto your Vercel domain - Hit Deploy ✅
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/v1/chat |
Send a new message |
GET |
/api/v1/chat |
Fetch chat history |
GET |
/api/v1/chat/rate-limit |
Check rate limit status |
GET |
/api/v1/chat/favourite |
Get favourite chats |
POST |
/api/v1/chat/favourite |
Add chat to favourites |
export async function createChatSession(formData: FormData) {
const message = formData.get("message") as string;
const userId = formData.get("userId") as string;
const { text } = await generateText({
model: openai("gpt-4o-mini"),
system: TITLE_SYSTEM_PROMPT,
prompt: message,
});
const chat = await prisma.chat.create({
data: { userId, title: text },
});
await prisma.message.create({
data: {
chatId: chat.id,
userId,
sender: "user",
content: message,
status: "PENDING",
orderIndex: 1,
},
});
return { success: true, data: { chatId: chat.id } };
}Anurag Sharma — Full-Stack Developer & AI Engineer
PRs are welcome! Found this useful? Please ⭐ the repo — it really helps!
Built with ❤️ by Anurag Sharma