A modern chatbot application built with Nuxt 3, featuring real-time AI conversations powered by Google Gemini, complete with message editing, deletion, and conversation branching capabilities. https://gemini-chatbot-alfien.netlify.app/
This application provides an intelligent chat interface where users can:
- Have real-time conversations with AI using Google Gemini models
- Upload and analyze images
- Edit previous messages and regenerate AI responses
- Delete messages with confirmation
- Manage multiple chat sessions
- Track conversation history
Frontend
- Nuxt 3 - Vue 3 framework with server-side rendering
- Vue 3 Composition API - Reactive component logic
- TypeScript - Type-safe development
- Tailwind CSS - Utility-first styling
- Shadcn-vue - UI component library
- Markdown rendering with syntax highlighting
Backend
- Nuxt Server Routes (Nitro) - API endpoints
- Prisma ORM - Database management
- PostgreSQL - Primary database (Neon)
- Google Generative AI SDK - AI model integration
- Vercel AI SDK - Streaming responses
Authentication
- Logto - Modern authentication solution
Before you begin, ensure you have installed:
- Node.js 18.x or higher
- pnpm 8.x or higher
- Neon cloud database (Pgsql)
- Clone the repository:
git clone <repository-url>
cd gemini-ai-chatbot- Install dependencies:
pnpm install- Create environment file:
cp .env.example .env- Configure environment variables in
.env:
# Database (Required)
DATABASE_URL="postgresql://user:password@host:5432/database"
# Logto Authentication (Required)
NUXT_LOGTO_ENDPOINT="https://your-logto-endpoint.logto.app"
NUXT_LOGTO_APP_ID="your-app-id"
NUXT_LOGTO_APP_SECRET="your-app-secret"
NUXT_LOGTO_COOKIE_ENCRYPTION_KEY="your-32-character-encryption-key"
# Google AI (Required)
GOOGLE_API_KEY="your-google-ai-api-key"
# Application (Required)
NUXT_PUBLIC_APP_URL="http://localhost:3000"- Generate Prisma client:
pnpm prisma generate- Run database migrations:
pnpm prisma migrate dev- Optional - Seed database (if seed script exists):
pnpm prisma db seedStart the development server:
pnpm devApplication will be available at http://localhost:3000
Build for production:
pnpm buildPreview production build:
pnpm preview- Visit Google AI Studio
- Create new API key
- Copy to
GOOGLE_API_KEYin.env
- Sign up at Logto Cloud
- Create new application
- Configure redirect URIs:
http://localhost:3000/callback - Copy credentials to
.env
- Sign up at Neon
- Create new project
- Copy connection string to
DATABASE_URLin.env
├── components/ # Vue components
│ ├── Layout/ # Layout components
│ └── ui/ # Shadcn UI components
├── composables/ # Vue composables
├── middleware/ # Route middleware
├── pages/ # Application pages
├── prisma/ # Database schema and migrations
├── server/ # Server-side code
│ └── api/ # API endpoints
└── public/ # Static assets
Chat Management
- Create and manage multiple chat sessions
- Auto-generated session titles
- Session deletion with confirmation
- Real-time message updates
Message Operations
- Edit messages with inline editing
- Delete messages with confirmation dialog
- Automatic AI response regeneration after edits
- Edit history tracking (isEdited, editedAt, originalContent)
Message Branching
- Create conversation branches from any message
- Maintain parent-child relationships (parentMessageId)
- Preserve original conversation history
- Future: Branch navigation and visualization
AI Integration
- Multiple model support (Gemini 2.0 Flash, 2.5 Pro, 2.5 Flash)
- Real-time streaming responses
- Image upload and analysis
- Context-aware conversations
The application uses three main models:
User
- Stores user authentication data
- Links to chat sessions
ChatSession
- Represents individual chat conversations
- Contains messages and metadata
- Tracks creation and update timestamps
Message
- Individual chat messages (user or assistant)
- Supports message branching (parentMessageId)
- Tracks edit history (isEdited, editedAt, originalContent)
- Cascade deletion with sessions
Chat
POST /api/chat- Create new sessionGET /api/chat/:sessionId- Get session with messagesDELETE /api/chat/:sessionId- Delete sessionGET /api/chat/sessions- List all user sessionsPOST /api/chat/stream- Stream AI responsesPOST /api/chat/generate-title- Generate session title
Messages
PATCH /api/message/:id- Edit message (supports branching)DELETE /api/message/:id- Delete message
User
GET /api/user/me- Get current user info
pnpm dev # Start development server
pnpm build # Build for production
pnpm preview # Preview production build
pnpm generate # Generate static site
pnpm prisma:generate # Generate Prisma client
pnpm prisma:migrate # Run database migrations
pnpm prisma:studio # Open Prisma StudioDatabase Connection Issues
- Verify
DATABASE_URLis correct - Ensure database is running
- Check firewall/network settings
Authentication Errors
- Verify Logto credentials in
.env - Check redirect URIs in Logto dashboard
- Clear browser cookies and try again
AI Response Errors
- Verify
GOOGLE_API_KEYis valid - Check API quota limits
- Review error messages in browser console
Build Errors
- Delete
node_modulesand.nuxtfolders - Run
pnpm installagain - Clear pnpm cache:
pnpm store prune
Auto-refresh Behavior
- Sidebar refreshes every 2 seconds when on chat page
- Immediate refresh after sending messages
- Session reloads after message edits/deletes
Message IDs
- Messages need database IDs for edit/delete buttons
- Session reloads after streaming to fetch IDs
- 1-second delay ensures database writes complete
Streaming Implementation
- Uses Vercel AI SDK for streaming
- Real-time message updates during AI response
- Proper error handling and recovery
MIT License - See LICENSE file for details
Contributions are welcome. Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
For issues or questions:
- Open an issue on GitHub
- Check existing issues for solutions