A Next.js chat application that uses MongoDB to store chat history, built with the Vercel AI SDK. This application provides persistent memory for AI conversations, allowing users to maintain chat history across sessions.
- Persistent chat history using MongoDB
- Real-time AI responses with streaming
- Modern UI with dark/light mode using shadcn/ui
- Chat history navigation sidebar
- Chat deletion functionality
- Responsive design
- Next.js - React framework
- MongoDB - Database for chat persistence
- Vercel AI SDK - AI integration
- shadcn/ui - UI components
- Tailwind CSS - Styling
- TypeScript - Type safety
- Node.js 18.18 or later
- MongoDB Atlas account (free tier works)
- OpenAI API key
Create a .env.local
file in the root directory with the following variables:
MONGODB_URI=your_mongodb_uri
MONGODB_DB=your_database_name
OPENAI_API_KEY=your_openai_api_key
- Clone the repository
- Install dependencies:
npm install
- Set up your environment variables
- Run the development server:
npm run dev
- Open http://localhost:3000 in your browser
The application uses the Next.js App Router and is structured as follows:
app/
- Next.js application routes and API endpointscomponents/
- React components including chat interfacelib/
- Utility functions and database connectionpublic/
- Static assets