AI FAQ Assistant
An AI-powered FAQ chatbot built with Next.js 15, NestJS, MongoDB, and Google Gemini AI.
Architecture
The project is structured into two main parts:
- Frontend: Developed using Next.js 15 (with React 19 and TypeScript), featuring an App Router for pages and layouts, reusable components like ChatMessage, ChatInput, Sidebar, and Header, and an API client in lib/api.ts.
- Backend: Built with NestJS (TypeScript), containing modules for chat functionality (controller, service, schema, DTOs), Gemini AI integration, and core application setup.
A docker-compose.yml file is provided for containerization.
Prerequisites
- Node.js 20+
- npm or yarn
- MongoDB Atlas account (or local MongoDB)
- Google Gemini API key
Setup Instructions
Option A: Run Without Docker (Manual)
- Backend: Navigate to the backend directory, run npm install, and then npm run start:dev. The backend will run on http://localhost:3001.
- Frontend: Navigate to the frontend directory, run npm install --legacy-peer-deps, and then npm run dev. The frontend will run on http://localhost:3000.
Option B: Run With Docker
- From the root directory, run docker-compose up --build.
The application will be accessible at http://localhost:3000 (Frontend) and http://localhost:3001 (Backend).
API Endpoints
POST/api/chat/askAsk a question (standard)POST/api/chat/ask/streamAsk with streaming (SSE)GET/api/chat/historyGet paginated historyGET/api/chat/search?q=querySearch conversationsGET/api/chat/statsGet total/today countsDELETE/api/chat/:idDelete a conversation
Features
Core
- ✅ Chat interface with user/AI message bubbles
- ✅ AI-powered answers via Google Gemini 1.5 Flash
- ✅ Conversations stored in MongoDB Atlas
- ✅ Conversation history API with pagination
Bonus
- ✅ Streaming responses — real-time token-by-token display via SSE
- ✅ Dark mode — toggle with persistence in localStorage
- ✅ Conversation search — full-text search with regex fallback
- ✅ Docker setup — docker-compose up --build
Technical Decisions
Backend
- NestJS for structured, scalable TypeScript APIs with dependency injection
- Mongoose schemas with text indexes for efficient search
- Timestamp index for fast history queries sorted by recency
- Global validation pipe with class-validator for input sanitization
- CORS configured to allow frontend origins
Frontend
- Next.js 15 App Router with React 19 for the latest patterns
- Streaming via SSE — fetch ReadableStream for real-time display
- react-markdown + remark-gfm to render AI responses as rich markdown
- No external state library — React useState handles all local state
- CSS variables for instant dark/light theme switching
MongoDB Schema Design
{
question: String, // Indexed (text)
answer: String, // Indexed (text)
timestamp: Date, // Indexed (desc) for sorted history
}
// Compound text index on question + answer for full-text search