Environment File Structure
The project uses multiple environment files:.env.local- Main application environment variablesprisma/.env- Prisma-specific database configuration.env.example- Template with all required variables
Required Environment Variables
Database Configuration
PostgreSQL Database
Set up your PostgreSQL connection string:Recommended Provider: Supabase
- Create a new Supabase project
- Navigate to Settings → Database
- Copy the connection string (URI format)
- Ensure the
pgvectorextension is enabled
Supabase automatically includes the
pgvector extension, which is required for the RAG (Retrieval-Augmented Generation) functionality.Redis Configuration
Configure Redis for BullMQ job queues:Recommended Provider: Upstash
- Create a new Upstash Redis database
- Copy the host, port, and password
- Or use Railway’s managed Redis service
WhatsApp Cloud API
Get WhatsApp Credentials
Obtain credentials from Meta for Developers:
- Create a Facebook App
- Add WhatsApp product
- Set up a phone number
- Generate access token
AI Configuration
Anthropic API Key
Get your API key from Anthropic Console:The application uses Claude 3 Haiku for:
- Customer conversation handling
- RAG-based knowledge retrieval
- Natural language understanding
Application Configuration
Optional: Email Configuration
If using email notifications:Complete Environment Template
Here’s a complete.env.local template:
Platform-Specific Setup
Vercel
Add Variables in Dashboard
- Go to Project Settings → Environment Variables
- Add each variable individually
- Select environments (Production, Preview, Development)
- Save changes
Railway
Add Variables in Service
- Select your service
- Go to “Variables” tab
- Add variables (Railway auto-provides
DATABASE_URLandREDIS_URL) - Click “Deploy” to apply changes
VPS (Self-Hosted)
Create Environment File
SSH into your server and create Paste your environment variables and save.
.env.local:Database Initialization
After configuring environment variables:Enable pgvector Extension
Connect to your database and run:For Supabase:
- Go to Database → Extensions
- Search for “vector”
- Enable the extension
Validation
Validate your environment setup:Test Redis Connection
Start your application and check logs:Look for Redis connection success messages.
Troubleshooting
Database Connection Fails
- Verify
DATABASE_URLformat is correct - Check database allows connections from your deployment IP
- Ensure database is running and accessible
- Test connection using Prisma Studio
Redis Connection Fails
- Verify
REDIS_HOST,REDIS_PORT, andREDIS_PASSWORD - Check Redis instance is running
- Test connection using Redis CLI or GUI
- Ensure firewall allows connections
WhatsApp Webhook Errors
- Verify
WHATSAPP_VERIFY_TOKENmatches Meta configuration - Check webhook URL is publicly accessible
- Review webhook logs in Meta for Developers
- Ensure SSL certificate is valid
AI Responses Not Working
- Verify
ANTHROPIC_API_KEYis correct - Check API key has available credits
- Review Anthropic API status
- Check application logs for AI errors
Security Best Practices
- Rotate Secrets Regularly: Change API keys, tokens, and secrets periodically
- Use Strong Secrets: Generate random strings for JWT and session secrets
- Limit Access: Use least-privilege principles for database users
- Enable 2FA: For all service accounts (Supabase, Anthropic, etc.)
- Monitor Usage: Set up alerts for unusual API usage
- Backup Credentials: Store credentials securely (e.g., password manager)
- Environment Isolation: Keep development and production credentials separate
Next Steps
Vercel Deployment
Deploy to Vercel with these variables
Railway Deployment
Deploy to Railway with these variables