Deployment
Overview
The NextAI starter kit is designed to be easily deployed to various hosting platforms. This guide covers the recommended deployment options and best practices for taking your AI application to production.
Recommended Platforms
Vercel
Vercel is the recommended platform for deploying your NextAI application, offering seamless integration with Next.js and built-in support for serverless functions, edge functions, and more.
Deployment Steps
- Push your code to a Git repository (GitHub, GitLab, or Bitbucket)
- Connect your repository to Vercel
- Configure your environment variables
- Deploy your application
Other Options
- Netlify: Similar to Vercel, with good support for Next.js applications
- AWS Amplify: Provides a comprehensive set of tools for deploying and managing web applications
- Self-hosted: Deploy to your own infrastructure using Docker or traditional hosting
Environment Variables
Before deploying, ensure all necessary environment variables are configured in your deployment platform:
# Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=****
CLERK_SECRET_KEY=****
# Database
POSTGRES_URL="****"
POSTGRES_DIRECT_URL="****"
# AI Providers
GROQ_API_KEY=****
FAL_API_KEY=****
# Other Services
N8N_WEBHOOK_URL="****"
NEXT_PUBLIC_POSTHOG_KEY=****
NEXT_PUBLIC_POSTHOG_HOST=****
NEXT_PUBLIC_APP_URL=****
IMGUR_CLIENT_ID=****
IMGUR_CLIENT_SECRET=****
Database Migrations
Before deploying, ensure your database schema is up to date:
pnpm db:migrate
The starter kit includes a build script that automatically runs migrations during the build process:
"build": "tsx lib/db/migrate && next build"
Production Optimizations
Performance
- Enable caching: Configure caching strategies for static assets and API responses
- Use edge functions: Deploy compute-intensive operations to edge locations for lower latency
- Optimize images: Use Next.js image optimization features
Security
- Set up proper CORS policies: Restrict access to your API endpoints
- Configure Content Security Policy (CSP): Prevent XSS attacks
- Enable rate limiting: Protect your API endpoints from abuse
Monitoring
- Set up error tracking: Use services like Sentry or Vercel's built-in error tracking
- Configure analytics: Use PostHog or similar services to track user behavior
- Set up performance monitoring: Monitor server response times and resource usage
Scaling Considerations
Database
- Consider using connection pooling for better database performance
- Set up database replicas for read-heavy workloads
- Implement caching for frequently accessed data
AI Services
- Monitor API usage and costs for different AI providers
- Implement fallback mechanisms for when AI services are unavailable
- Consider using a queue system for processing large volumes of AI requests
Continuous Integration/Continuous Deployment (CI/CD)
Set up a CI/CD pipeline to automate testing and deployment:
- Run tests on every pull request
- Automatically deploy to staging environments for review
- Deploy to production after approval
Best Practices
- Use staging environments to test changes before deploying to production
- Implement feature flags for gradual rollouts
- Set up automated backups for your database
- Document your deployment process for team members
For more detailed information about specific deployment platforms or advanced configurations, refer to the Next.js deployment documentation (opens in a new tab).