A production-grade AI SaaS application that allows businesses to create, train, and deploy intelligent customer support chatbots powered by OpenAI and LangChain.
DEMO.VIDEO.2.mp4
- AI-Powered Chatbots: Create intelligent chatbots trained on your custom data
- RAG Pipeline: Retrieval Augmented Generation for accurate, context-aware responses
- Multiple Personalities: Professional, friendly, sales-focused, or support-oriented tones
- Document Upload: Support for PDFs, DOCX, TXT, Markdown, and CSV files
- Real-time Streaming: Stream AI responses for better user experience
- Session Management: Track customer conversations and collect leads
- Analytics Dashboard: View chatbot performance, sessions, and revenue metrics
- Stripe Integration: Subscriptions for owners and in-chat checkout for customers
- Secure & Scalable: Row-level security, PostgreSQL with pgvector, deployed on Vercel
- Frontend: Next.js 14 (App Router), React 18, TypeScript
- UI: ShadCN UI, Tailwind CSS, Radix UI, Framer Motion
- Backend: Next.js Server Actions, API Routes
- Database: Supabase (PostgreSQL + pgvector)
- Auth: Supabase Auth
- AI: OpenAI GPT-4, text-embedding-3-small, LangChain
- Payments: Stripe (subscriptions + checkout)
- Deployment: Vercel
Before you begin, ensure you have:
- Node.js 18+ and npm 9+
- A Supabase account (supabase.com)
- An OpenAI API key (platform.openai.com)
- A Stripe account (stripe.com)
- Git installed
git clone https://github.com/yourusername/answerly.git
cd answerlynpm install- Create a new project on Supabase
- Go to Project Settings > API and copy your credentials
- Go to SQL Editor and run the schema from
supabase/schema.sql - Enable the pgvector extension:
CREATE EXTENSION IF NOT EXISTS vector;
Create a .env.local file in the root directory:
# Supabase
NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
# OpenAI
OPENAI_API_KEY=your_openai_api_key
# Stripe
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=your_stripe_publishable_key
STRIPE_SECRET_KEY=your_stripe_secret_key
STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret
# App Configuration
NEXT_PUBLIC_APP_URL=http://localhost:3000
NODE_ENV=developmentnpm run devOpen http://localhost:3000 in your browser.
answerly/
├── src/
│ ├── app/ # Next.js App Router
│ │ ├── (auth)/ # Authentication pages
│ │ │ ├── login/
│ │ │ └── signup/
│ │ ├── dashboard/ # Dashboard pages
│ │ │ ├── chatbots/ # Chatbot management
│ │ │ ├── analytics/ # Analytics & sessions
│ │ │ └── billing/ # Stripe billing
│ │ ├── chatbot/ # Public chatbot pages
│ │ │ └── [id]/
│ │ ├── api/ # API routes
│ │ │ ├── chat/ # Streaming chat endpoint
│ │ │ ├── embeddings/ # Embedding generation
│ │ │ └── webhooks/ # Stripe webhooks
│ │ ├── actions/ # Server Actions
│ │ ├── layout.tsx
│ │ ├── page.tsx
│ │ └── globals.css
│ ├── components/ # React components
│ │ ├── ui/ # ShadCN UI components
│ │ ├── dashboard/ # Dashboard components
│ │ ├── chatbot/ # Chatbot components
│ │ ├── auth/ # Auth components
│ │ └── providers/ # Context providers
│ ├── lib/ # Utilities and libraries
│ │ ├── ai/ # AI/ML pipeline
│ │ │ ├── chat-service.ts
│ │ │ ├── embeddings.ts
│ │ │ ├── rag-pipeline.ts
│ │ │ ├── document-processor.ts
│ │ │ └── text-chunker.ts
│ │ ├── supabase/ # Supabase clients
│ │ └── utils.ts
│ └── types/ # TypeScript types
│ └── database.types.ts # Supabase generated types
├── supabase/
│ └── schema.sql # Database schema
├── public/ # Static assets
├── ARCHITECTURE.md # Architecture documentation
├── package.json
├── tsconfig.json
├── tailwind.config.ts
└── next.config.js
The application uses PostgreSQL with pgvector for vector similarity search. Key tables:
- users: User profiles with subscription info
- chatbots: Chatbot configurations
- chatbot_documents: Uploaded training documents
- chatbot_embeddings: Vector embeddings (1536 dimensions)
- sessions: Customer chat sessions
- messages: Individual chat messages
- payments: Stripe payment records
- subscriptions: Owner subscription management
- analytics: Pre-computed metrics
See supabase/schema.sql for the complete schema with Row Level Security policies.
The RAG (Retrieval Augmented Generation) pipeline consists of:
- Document Processing: Extract text from PDFs, DOCX, etc.
- Text Chunking: Split documents into semantic chunks (~1000 chars)
- Embedding Generation: Generate embeddings using OpenAI
- Vector Storage: Store embeddings in Supabase pgvector
- Similarity Search: Retrieve relevant context for user queries
- LLM Response: Generate responses using GPT-4 with context
Real-time AI responses are streamed using:
- OpenAI streaming API
- Next.js API routes with streaming support
- Server-Sent Events (SSE) for client updates
Secure multi-tenant architecture using:
- Supabase Row Level Security (RLS)
- Owner-based data isolation
- Public access for chatbot interfaces
-
Push your code to GitHub
-
Import project in Vercel:
- Go to vercel.com
- Click "New Project"
- Import your GitHub repository
-
Configure environment variables:
- Add all environment variables from
.env.local - Set
NEXT_PUBLIC_APP_URLto your Vercel domain
- Add all environment variables from
-
Deploy:
vercel --prod
- Go to Stripe Dashboard > Developers > Webhooks
- Add endpoint:
https://your-domain.vercel.app/api/webhooks/stripe - Select events:
checkout.session.completedcustomer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deletedpayment_intent.succeeded
- Copy the webhook signing secret to
STRIPE_WEBHOOK_SECRET
- Verify Supabase connection
- Test user registration and login
- Create a test chatbot
- Upload a test document
- Test public chatbot interface
- Verify Stripe webhooks
- Check analytics dashboard
- Test dark/light mode
# Development
npm run dev # Start dev server
npm run build # Build for production
npm run start # Start production server
# Code Quality
npm run lint # Run ESLint
npm run type-check # TypeScript type checking
# Supabase (requires Supabase CLI)
npm run supabase:start # Start local Supabase
npm run supabase:stop # Stop local Supabase
npm run supabase:reset # Reset local database
npm run supabase:migrate # Push schema to Supabase| Variable | Description | Required |
|---|---|---|
NEXT_PUBLIC_SUPABASE_URL |
Supabase project URL | Yes |
NEXT_PUBLIC_SUPABASE_ANON_KEY |
Supabase anonymous key | Yes |
SUPABASE_SERVICE_ROLE_KEY |
Supabase service role key (server-side only) | Yes |
OPENAI_API_KEY |
OpenAI API key | Yes |
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY |
Stripe publishable key | Yes |
STRIPE_SECRET_KEY |
Stripe secret key | Yes |
STRIPE_WEBHOOK_SECRET |
Stripe webhook signing secret | Yes |
NEXT_PUBLIC_APP_URL |
Application URL | Yes |
POST /api/chat
Body: { chatbotId, sessionId, message }
Returns: Streaming AI response
POST /api/embeddings/generate
Body: { chatbotId, documentId, content }
Returns: { success, embeddings }
POST /api/webhooks/stripe
Body: Stripe event payload
Returns: { received: true }
- Environment Variables: Never commit
.env.localto version control - Service Role Key: Only use on server-side, never expose to client
- RLS Policies: Always enabled for multi-tenant data isolation
- API Rate Limiting: Implement rate limiting for public endpoints
- Input Validation: Validate all user inputs on server-side
- File Upload: Validate file types, sizes, and scan for malware
- Stripe Webhooks: Always verify webhook signatures
- Server Components for initial page loads
- Edge caching via Vercel
- Database connection pooling
- Vector similarity indexing (HNSW)
- Incremental Static Regeneration
- Image optimization with Next.js Image
Database connection errors:
- Verify Supabase credentials in
.env.local - Check if pgvector extension is enabled
- Ensure RLS policies are correctly configured
OpenAI API errors:
- Verify API key is valid
- Check API quota and rate limits
- Ensure embeddings model is
text-embedding-3-small
Stripe webhook not working:
- Verify webhook secret matches Stripe dashboard
- Check webhook endpoint URL is accessible
- Review Stripe dashboard webhook logs
Build errors:
- Clear
.nextfolder:rm -rf .next - Delete node_modules:
rm -rf node_modules && npm install - Verify all environment variables are set
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
This project is licensed under the MIT License.
For support, email support@answerly.ai or join our Discord community.
- GraphQL API layer
- Webhook integrations (Zapier, Make)
- Multi-language support
- Voice chat capabilities
- White-label options
- Advanced analytics with charts
- A/B testing for chatbot personalities
- Integration marketplace
Built with ❤️ using Next.js, Supabase, and OpenAI