A full-featured AI chatbot built with Next.js 15, React 19, Prisma, NextAuth.js, and OpenRouter AI.
- Real AI Chat - Powered by OpenRouter with streaming responses
- Authentication - Secure login with Google and GitHub OAuth via NextAuth.js
- Persistent Storage - All conversations and messages saved to PostgreSQL database
- Organization - Folders and templates for organizing your conversations
- Modern UI - Beautiful, responsive interface with dark mode support
- Real-time Streaming - See AI responses appear in real-time
- Search - Find conversations quickly with built-in search
- Frontend: Next.js 15, React 19, TailwindCSS, Radix UI
- Backend: Next.js API Routes, Prisma ORM
- Database: PostgreSQL (via Prisma Accelerate)
- Authentication: NextAuth.js with OAuth providers
- AI: OpenRouter API
- Deployment: Vercel
- Node.js 18+ and pnpm
- A PostgreSQL database (or use Prisma Accelerate)
- OpenRouter API key
- OAuth credentials (Google and/or GitHub)
- Clone the repository:
git clone <your-repo-url>
cd Modern-AI-Chatbot- Install dependencies:
pnpm install- Set up environment variables:
cp .env.example .envThen edit .env with your credentials:
OPEN_ROUTER_API_KEY- Get from OpenRouterDATABASE_URL- Your PostgreSQL connection stringNEXTAUTH_SECRET- Generate withopenssl rand -base64 32GOOGLE_CLIENT_ID&GOOGLE_CLIENT_SECRET- From Google Cloud ConsoleGITHUB_ID&GITHUB_SECRET- From GitHub Developer Settings
- Set up the database:
npx prisma generate --no-engine
npx prisma migrate dev --name init- Run the development server:
pnpm dev- Open http://localhost:3000 in your browser
The app uses the following database models:
- User - Authentication and user data
- Account - OAuth account linking
- Session - User sessions
- Conversation - Chat conversations
- Message - Individual chat messages
- Folder - Conversation organization
- Template - Reusable message templates
Required environment variables (see .env.example):
OPEN_ROUTER_API_KEY- Your OpenRouter API keyDATABASE_URL- PostgreSQL database connection stringNEXTAUTH_URL- Your app URL (http://localhost:3000 for dev)NEXTAUTH_SECRET- Secret for NextAuth.js session encryptionGOOGLE_CLIENT_ID- Google OAuth client ID (optional)GOOGLE_CLIENT_SECRET- Google OAuth client secret (optional)GITHUB_ID- GitHub OAuth client ID (optional)GITHUB_SECRET- GitHub OAuth client secret (optional)
- Push your code to GitHub
- Import the project in Vercel
- Add all environment variables in Vercel project settings
- Deploy!
Make sure to:
- Set up a production PostgreSQL database
- Update
NEXTAUTH_URLto your production URL - Add OAuth redirect URIs in Google/GitHub settings pointing to your production URL
The project structure:
├── app/ # Next.js app directory
│ ├── api/ # API routes
│ │ ├── auth/ # NextAuth.js
│ │ ├── chat/ # AI chat endpoint
│ │ ├── conversations/ # Conversation CRUD
│ │ ├── messages/ # Message CRUD
│ │ ├── folders/ # Folder CRUD
│ │ └── templates/ # Template CRUD
│ ├── login/ # Login page
│ └── page.tsx # Main app page
├── components/ # React components
├── lib/ # Utilities
│ ├── auth.ts # NextAuth config
│ └── prisma.ts # Prisma client
└── prisma/ # Database schema and migrations
-
Authentication Flow:
- Users land on the app and are redirected to
/login - They can sign in with Google or GitHub
- NextAuth.js creates a session and stores user data in the database
- Users land on the app and are redirected to
-
Chat Flow:
- User creates a new conversation or selects an existing one
- When sending a message:
- Message is saved to the database
- Sent to OpenRouter AI with conversation history
- AI response streams back in real-time
- Response is saved to the database
-
Data Persistence:
- All conversations, messages, folders, and templates are stored in PostgreSQL
- Data is fetched on page load and updated in real-time
- Changes sync to the database immediately
Contributions are welcome! Please feel free to submit a Pull Request.
MIT