A comprehensive Next.js 15 framework for building AI-powered SaaS applications with multi-database architecture, authentication, payments, and RAG capabilities.
This framework implements a simplified two-database architecture for optimal performance and reduced complexity:
- Supabase: User authentication, profiles, subscriptions, sessions
- PostgreSQL + pgvector: Business data, domain content, vector embeddings, semantic search, RAG operations
- Redis: Enhanced caching layer for all databases
Before setting up fest-vibes-ai, ensure you have the following services ready:
- Supabase Account - Create account
- For user authentication, profiles, and session management
- Stripe Account - Create account
- For payment processing and subscription management
- NeonDB Database - PostgreSQL with pgvector extension
- For business data, content, and vector embeddings
- Serverless PostgreSQL optimized for modern applications
- Sign up at neon.tech
- Redis Instance - Upstash Redis or self-hosted
- For caching and session storage
You'll need to obtain API keys and connection strings from each service above.
- Clone and install dependencies:
cd ai-saas-framework
pnpm install
- Run the interactive setup:
pnpm create-new
This will guide you through configuring your application metadata, branding, and other settings. The setup creates an app.config.json
file that controls:
- Project metadata (title, description, version)
- SEO settings (keywords, Open Graph, Twitter cards)
- Brand configuration (logos, contact info, social media)
- Feature flags (analytics, dark mode, etc.)
- Environment-specific URLs
- Set up environment variables:
cp .env.example .env.local
# Fill in all required environment variables from the services above
-
Set up databases (see Database Setup section below)
-
Run the development server:
pnpm dev
-
Create a Supabase project: https://supabase.com/dashboard
-
Get your credentials:
- Go to Settings > API
- Copy the Project URL and anon/public key
- Copy the service_role key from the same page
-
Configure environment variables:
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key
- Create required tables in Supabase SQL Editor:
-- Create profiles table
CREATE TABLE profiles (
id UUID REFERENCES auth.users ON DELETE CASCADE,
email TEXT,
full_name TEXT,
avatar_url TEXT,
subscription_tier TEXT DEFAULT 'free',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
PRIMARY KEY (id)
);
-- Enable RLS
ALTER TABLE profiles ENABLE ROW LEVEL SECURITY;
-- Create policy for profiles
CREATE POLICY "Users can view own profile" ON profiles
FOR SELECT USING (auth.uid() = id);
CREATE POLICY "Users can update own profile" ON profiles
FOR UPDATE USING (auth.uid() = id);
-
Create a NeonDB Project:
- Go to neon.tech and sign up
- Create a new project with PostgreSQL 15+
- Choose a region close to your users
-
Enable Required Extensions:
- In the NeonDB SQL Editor, run:
CREATE EXTENSION IF NOT EXISTS vector; CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
-
Get Your Connection String:
- Go to your project dashboard
- Copy the connection string from the "Connection Details" section
- It should look like:
postgresql://username:password@hostname/database?sslmode=require
-
Alternative: Local PostgreSQL with pgvector (for development)
# Install PostgreSQL brew install postgresql # macOS sudo apt-get install postgresql postgresql-contrib # Ubuntu # Install pgvector git clone https://github.com/pgvector/pgvector.git cd pgvector make make install # or sudo make install # Start PostgreSQL brew services start postgresql # macOS sudo systemctl start postgresql # Ubuntu # Create database and enable extensions psql postgres CREATE DATABASE ai_saas_framework; \c ai_saas_framework CREATE EXTENSION vector; CREATE EXTENSION "uuid-ossp";
-
Configure environment variables:
# Use your NeonDB connection string
POSTGRES_URL=postgresql://username:password@hostname/database?sslmode=require
POSTGRES_DIRECT_URL=postgresql://username:password@hostname/database?sslmode=require
# For compatibility with existing database queries
DATABASE_URL=postgresql://username:password@hostname/database?sslmode=require
-
Option A: Redis Cloud (Recommended for production)
- Sign up at https://redis.com/try-free/
- Create a database
- Copy the Redis URL
-
Option B: Local Redis
# Install Redis brew install redis # macOS sudo apt-get install redis-server # Ubuntu # Start Redis brew services start redis # macOS sudo systemctl start redis-server # Ubuntu
-
Configure environment variables:
REDIS_URL=redis://localhost:6379
# or for Redis Cloud:
REDIS_URL=rediss://username:password@endpoint:port
The framework supports 12 AI models across 4 providers, plus embedding models for RAG functionality.
- GPT-4o: Advanced multimodal model with vision and reasoning capabilities
- GPT-4o Mini: Faster, cost-effective version of GPT-4o with vision support
- o1-preview: Advanced reasoning model (preview) - specialized for complex problem-solving
- o1-mini: Faster reasoning model with enhanced analytical capabilities
- Claude 3.5 Sonnet: Most capable Claude model with enhanced reasoning and vision
- Claude 3.5 Haiku: Fast and efficient Claude model with vision support
- Gemini 2.0 Flash: Fast multimodal model with enhanced capabilities and reasoning
- Gemini 1.5 Flash: Balanced speed and capability with vision support
- Gemini 1.5 Pro: Most capable Gemini model with extended context window
- Llama 3.1 Sonar Large (Online): Large model with real-time web search capabilities
- Llama 3.1 Sonar Small (Online): Efficient model with real-time web search
- OpenAI text-embedding-ada-002: Used for vector embeddings and semantic search
Model access varies by subscription tier:
- Guest: Claude 3.5 Haiku only (10 messages/day, no file uploads)
- Free: Claude 3.5 Haiku + Sonnet (50 messages/day, file uploads allowed)
- Pro: All Claude models (500 messages/day, RAG enabled, 50MB files)
- Enterprise: All Claude models (unlimited usage, RAG enabled, 100MB files)
Note: OpenAI, Google, and Perplexity models are configured but require additional entitlement updates to be available per tier.
To use specific model providers, obtain API keys from:
- Get API key: https://console.anthropic.com/
- Configure environment:
ANTHROPIC_API_KEY=sk-ant-your-api-key
- Get API key: https://platform.openai.com/api-keys
- Configure environment:
OPENAI_API_KEY=sk-your-openai-api-key
- Get API key: https://aistudio.google.com/app/apikey
- Configure environment:
GOOGLE_GENERATIVE_AI_API_KEY=your-google-api-key
- Get API key: https://www.perplexity.ai/settings/api
- Configure environment:
PERPLEXITY_API_KEY=your-perplexity-api-key
- Create Stripe account: https://dashboard.stripe.com/register
- Get your keys from Dashboard > Developers > API keys
- Configure environment:
STRIPE_SECRET_KEY=sk_test_your_secret_key
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_your_publishable_key
- Set up webhooks:
- Go to Dashboard > Developers > Webhooks
- Add endpoint:
https://yourdomain.com/api/stripe/webhook
- Select events:
customer.subscription.created
,customer.subscription.updated
,customer.subscription.deleted
,invoice.payment_succeeded
,invoice.payment_failed
- Copy webhook secret:
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-32-character-secret-key-here
Generate a secret:
openssl rand -base64 32
fest-vibes-ai uses a dynamic configuration system that allows you to customize your application without code changes.
The app.config.json
file (created by running pnpm create-new
) contains:
{
"project": {
"name": "your-app-name",
"version": "1.0.0",
"description": "Your app description",
"supabaseName": "your-supabase-app-name"
},
"metadata": {
"title": "Your App Title",
"description": "SEO description",
"keywords": ["keyword1", "keyword2"],
"themeColor": "#2acf80"
},
"brand": {
"name": "Your Brand",
"contact": {
"email": "[email protected]"
},
"social": {
"twitter": "https://twitter.com/yourapp"
}
},
"features": {
"analytics": true,
"darkMode": true,
"multiLanguage": false
}
}
The configuration automatically generates:
- Next.js metadata for SEO
- Open Graph tags for social sharing
- Twitter Card meta tags
- Web app manifest
- Favicon and icon configurations
To update your configuration:
pnpm create-new
Or manually edit app.config.json
and restart your development server.
# Initialize PostgreSQL database (extensions + tables)
pnpm db:init
# Test all database connections
curl http://localhost:3000/api/health
The framework includes built-in health checks for all databases:
# Check all database connections
curl http://localhost:3000/api/health
# Response format:
{
"supabase": { "healthy": true, "message": "Connected", "timestamp": "..." },
"postgres": {
"healthy": true,
"message": "Connected - Business + Vector operations ready",
"extensions": ["vector", "uuid-ossp"],
"timestamp": "..."
},
"redis": { "healthy": true, "message": "Connected", "timestamp": "..." },
"timestamp": "2024-01-15T10:30:00.000Z"
}
-
Set up production databases:
- Supabase: Upgrade to Pro plan for production usage
- PostgreSQL: Use managed PostgreSQL with pgvector support (Supabase, AWS RDS, etc.)
- Redis: Use Redis Cloud or managed Redis service
-
Configure production environment variables in your deployment platform
-
Set up monitoring:
- Database connection monitoring via
/api/health
- Application performance monitoring
- Error tracking and logging
- Database connection monitoring via
-
Database Security:
- Enable SSL/TLS for all database connections
- Use strong passwords and rotate them regularly
- Configure proper firewall rules and IP whitelisting
- Enable audit logging for sensitive operations
-
API Security:
- Validate all environment variables are set
- Implement rate limiting on API routes
- Use HTTPS in production
- Validate webhook signatures (Stripe)
-
User Data Protection:
- Implement proper data retention policies
- Use encryption for sensitive data
- Comply with GDPR/CCPA requirements
- Regular security audits
- Connection Pooling: Pre-configured for each database type
- Caching Strategy: Redis caching for frequently accessed data
- Query Optimization: Proper indexing and query patterns
- Load Balancing: Ready for read/write splitting
- User Data: 5-minute TTL
- Vector Search Results: 30-minute TTL
- Content Data: 10-minute TTL (configurable)
- Session Data: 1-hour TTL
-
Database Connection Issues:
# Check health endpoint curl http://localhost:3000/api/health # Check environment variables echo $SUPABASE_URL echo $MONGODB_URI echo $VECTOR_DATABASE_URL echo $REDIS_URL
-
Authentication Issues:
- Verify Supabase credentials
- Check NEXTAUTH_SECRET is set
- Ensure callback URLs are configured
-
Payment Issues:
- Verify Stripe keys are correct
- Check webhook endpoint is accessible
- Verify webhook secret matches
-
AI/Vector Issues:
- Verify Anthropic API key
- Check pgvector extension is installed
- Verify vector database connectivity
This framework uses a streamlined two-database architecture for optimal performance and reduced complexity:
- User Database (Supabase): High-frequency, low-latency authentication operations
- Business + Vector Database (PostgreSQL + pgvector): All business data, content, and AI operations
- Cache Layer (Redis): Enhanced caching for frequently accessed data
- User Authentication: Supabase handles all auth operations with dedicated connection pool
- Business Operations: PostgreSQL handles chat, content, and business logic with optimized queries
- AI Operations: Same PostgreSQL instance provides semantic search and RAG with vector operations
- Performance: Enhanced Redis caching compensates for unified database approach
- Connection Management: Optimized connection pooling balances business and vector workloads
This simplified architecture reduces operational complexity while maintaining performance through intelligent caching and connection pooling strategies.
- Fork the repository
- Create a feature branch
- Make your changes
- Test all database integrations
- Submit a pull request
MIT License - see LICENSE file for details.