An AI-powered marketing chatbot with intelligent product search, persistent chat history, and aggressive sales conversion optimization.
- π€ AI-Powered Sales Agent - GPT-3.5 Turbo with aggressive sales prompting
- π Intelligent Product Search - Multi-strategy search with full-text capabilities
- π¬ Persistent Chat History - Cross-session conversation management
- β‘ Real-time Streaming - Token-by-token response streaming
- π± Responsive Design - Mobile-first UI with modern components
- π Secure & Validated - Input sanitization and type-safe APIs
- Frontend: Next.js 14+, TypeScript, Tailwind CSS, shadcn/ui
- Backend: Node.js, PostgreSQL, Drizzle ORM
- AI: OpenAI GPT-3.5 Turbo via Vercel AI SDK
- Database: PostgreSQL with GIN indexes for full-text search
- Node.js 18+
- PostgreSQL 13+
- OpenAI API key
-
Clone the repository
git clone <repository-url> cd marketbot-agent
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env.local
Configure the following variables:
DATABASE_URL="postgresql://username:password@localhost:5432/marketbot" OPENAI_API_KEY="your-openai-api-key" NODE_ENV="development"
-
Set up the database
# Create database createdb marketbot # Run migrations npm run db:migrate # Seed sample data (optional) npm run db:seed
-
Start the development server
npm run dev
Open http://localhost:3000 in your browser.
The application uses PostgreSQL with advanced indexing for optimal search performance. Key features:
- GIN indexes for full-text search on product names and descriptions
- JSONB support for flexible product features and tags
- Connection pooling for scalable concurrent access
- Automatic session cleanup for expired conversations
products- Product catalog with full-text search capabilitieschat_sessions- User conversation sessions with auto-expirationchat_messages- Individual messages with product context linking
GET /api/products- Search products with filtering and paginationGET /api/products/[id]- Get single product detailsPOST /api/products- Create new productPUT /api/products/[id]- Update productDELETE /api/products/[id]- Delete product
POST /api/chat/stream- Stream AI responsesGET /api/chat/history- Get conversation historyDELETE /api/chat/history- Clear conversation historyPOST /api/chat/history/save- Save message
GET /api/chat/sessions- List user sessionsDELETE /api/chat/sessions- Delete sessionPUT /api/chat/sessions/rename- Rename session
- Start a conversation - The AI agent will greet you and ask about your product interests
- Search for products - Ask about specific products or categories
- Get recommendations - The AI will suggest relevant products based on your queries
- View chat history - Access previous conversations from the sidebar
- Manage sessions - Rename or delete conversation sessions
| Variable | Description | Required |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | Yes |
OPENAI_API_KEY |
OpenAI API key for GPT-3.5 Turbo | Yes |
NODE_ENV |
Environment (development/production) | Yes |
Connection pooling settings (adjust in db/index.ts):
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
max: 10, // Maximum connections
idleTimeoutMillis: 30000, // Close idle connections
connectionTimeoutMillis: 2000
});npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
npm run lint # Run ESLint
npm run type-check # Run TypeScript checks
npm run db:migrate # Run database migrations
npm run db:seed # Seed sample dataβββ app/ # Next.js app directory
β βββ api/ # API routes
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
β βββ page.tsx # Home page
βββ components/ # React components
β βββ chat/ # Chat-related components
β βββ ui/ # UI components (shadcn/ui)
βββ db/ # Database configuration
β βββ index.ts # Database connection
β βββ schema.ts # Drizzle schema
βββ lib/ # Utility libraries
β βββ chat-history.ts # Chat history service
β βββ db-service.ts # Database service
β βββ prompt.ts # AI prompt configuration
β βββ validation.ts # Input validation schemas
βββ public/ # Static assets
- Set up production PostgreSQL database
- Configure environment variables
- Run database migrations
- Build and deploy the application
- Set up health monitoring on
/api/health
- Database connection pooling is configured for production use
- GIN indexes optimize search performance
- Session cleanup prevents memory leaks
- Response streaming improves perceived performance