Deployment Guide
Overview
This guide covers deploying the LyfeAI Provider Platform in various environments. The application is currently configured for Vercel deployment but can be adapted for other platforms.
Prerequisites
Required Accounts
- GitHub account with repository access
- Vercel account (for current deployment)
- Supabase account (for database)
- OpenAI API account (for AI features)
- AWS account (optional, for Textract/Comprehend)
Required Tools
- Node.js 18+ and npm
- Git
- PostgreSQL client (for database operations)
Environment Variables
Complete List
# Supabase (Required)
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
# OpenAI (Required for AI features)
OPENAI_API_KEY=sk-your-openai-api-key
# AWS (Optional - for document processing)
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=us-east-1
AWS_S3_BUCKET=your-document-bucket
# Application (Optional)
NEXT_PUBLIC_APP_URL=https://your-domain.com
Environment Variable Security
- Never commit
.env.localor any env files - Use Vercel/platform secrets for sensitive values
- Rotate keys regularly
- Use different keys for dev/staging/prod
Local Development Setup
1. Clone Repository
git clone https://github.com/SkaFld-Ignite/lyfe-provider-ui
cd lyfe-provider-ui
2. Install Dependencies
npm install
3. Configure Environment
# Create local environment file
cp .env.example .env.local
# Edit .env.local with your values
nano .env.local
4. Database Setup
Option A: Use Existing Supabase Project
- Get connection details from Supabase dashboard
- Add to
.env.local - Run migrations (see below)
Option B: Create New Supabase Project
- Create project at https://app.supabase.com
- Get API keys from Settings > API
- Run migration scripts:
# Connect to Supabase database
psql -h db.your-project.supabase.co -p 5432 -U postgres -d postgres
# Run scripts in order
\i scripts/01_create_tables.sql
\i scripts/02_create_views.sql
\i scripts/03_create_policies.sql
\i scripts/04_insert_sample_data.sql
5. Start Development Server
npm run dev
# Opens at http://localhost:3000
6. Test Key Features
- Login with demo credentials:
- Admin:
[email protected]/demo - Doctor:
[email protected]/demo
- Admin:
- Upload a sample medical document
- View patient list
- Check AI features work
Vercel Deployment
1. Connect Repository
Via Vercel Dashboard
- Go to https://vercel.com/new
- Import Git repository
- Select the
lyfe-provider-uirepo - Configure project settings
Via CLI
# Install Vercel CLI
npm i -g vercel
# Deploy
vercel
# Follow prompts to link project
2. Configure Build Settings
- Framework Preset: Next.js (auto-detected)
- Build Command:
npm run build - Output Directory:
.next - Install Command:
npm install - Node.js Version: 18.x
3. Add Environment Variables
- Go to Project Settings > Environment Variables
- Add all required variables
- Select appropriate environments (Production/Preview/Development)
- Mark sensitive variables as "Sensitive"
4. Configure Domains
# Default domain
https://your-project.vercel.app
# Custom domain
1. Go to Settings > Domains
2. Add your domain
3. Configure DNS as instructed
5. Deploy
# Automatic deployment on push to main
git push origin main
# Manual deployment
vercel --prod
# Preview deployment
vercel
Alternative Deployment Options
AWS Amplify
# amplify.yml
version: 1
frontend:
phases:
preBuild:
commands:
- npm install
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
Docker Deployment
# Dockerfile
FROM node:18-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package*.json ./
RUN npm ci
FROM node:18-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
FROM node:18-alpine AS runner
WORKDIR /app
ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD ["node", "server.js"]
Traditional VPS
# On your server
# Install Node.js 18+
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
# Clone and setup
git clone https://github.com/SkaFld-Ignite/lyfe-provider-ui
cd lyfe-provider-ui
npm install
npm run build
# Use PM2 for process management
npm install -g pm2
pm2 start npm --name "lyfeai" -- start
pm2 save
pm2 startup
Database Migration Guide
Running Migrations
# Order is important!
psql $DATABASE_URL -f scripts/01_create_tables.sql
psql $DATABASE_URL -f scripts/02_create_views.sql
psql $DATABASE_URL -f scripts/03_create_policies.sql
psql $DATABASE_URL -f scripts/04_insert_sample_data.sql
Rollback Procedure
# Complete reset (DESTRUCTIVE)
psql $DATABASE_URL -f scripts/06_reset_database.sql
# Then re-run migrations
Backup Before Migration
# Backup current database
pg_dump $DATABASE_URL > backup_$(date +%Y%m%d_%H%M%S).sql
# Restore if needed
psql $DATABASE_URL < backup_20240615_120000.sql
Post-Deployment Checklist
1. Functionality Tests
- Authentication works
- Document upload processes
- Patient data loads
- AI features respond
- Real-time features connect
2. Security Checks
- Environment variables not exposed
- HTTPS enforced
- CORS configured correctly
- Rate limiting active
- Error messages don't leak info
3. Performance Validation
- Page load under 3 seconds
- API responses under 500ms
- No memory leaks
- Proper caching headers
4. Monitoring Setup
// Add to app/layout.tsx for basic monitoring
useEffect(() => {
// Log page views
if (typeof window !== 'undefined') {
console.log('Page view:', window.location.pathname);
}
// Capture errors
window.addEventListener('error', (e) => {
console.error('Global error:', e.error);
// Send to monitoring service
});
}, []);
Troubleshooting
Common Issues
1. Build Failures
# Clear cache and rebuild
rm -rf .next node_modules
npm install
npm run build
2. Database Connection
# Test connection
psql $DATABASE_URL -c "SELECT 1"
# Check if tables exist
psql $DATABASE_URL -c "\dt"
3. Environment Variables
# Verify all required vars
node -e "
const required = [
'NEXT_PUBLIC_SUPABASE_URL',
'NEXT_PUBLIC_SUPABASE_ANON_KEY',
'SUPABASE_SERVICE_ROLE_KEY',
'OPENAI_API_KEY'
];
required.forEach(key => {
if (!process.env[key]) {
console.error('Missing:', key);
}
});
"
4. Memory Issues
// Add to next.config.js
module.exports = {
experimental: {
workerThreads: false,
cpus: 1
}
}
Production Considerations
1. Security Hardening
- Enable Supabase RLS on all tables
- Implement rate limiting
- Add request validation
- Enable audit logging
- Regular security scans
2. Performance Optimization
- Enable Next.js ISR
- Implement Redis caching
- Use CDN for static assets
- Optimize images
- Database query optimization
3. Monitoring & Alerts
- Set up error tracking (Sentry)
- Configure uptime monitoring
- Database performance alerts
- API response time tracking
- User activity analytics
4. Backup Strategy
- Automated daily database backups
- Point-in-time recovery setup
- Document storage backups
- Configuration backups
- Disaster recovery plan
Cost Optimization
Vercel
- Monitor bandwidth usage
- Optimize image delivery
- Use ISR over SSR where possible
- Monitor function invocations
Supabase
- Right-size database instance
- Monitor storage usage
- Optimize real-time connections
- Regular data cleanup
OpenAI
- Implement caching for repeated queries
- Use appropriate models (GPT-3.5 vs GPT-4)
- Batch requests when possible
- Monitor token usage
Support & Resources
Documentation
- Next.js: https://nextjs.org/docs
- Vercel: https://vercel.com/docs
- Supabase: https://supabase.com/docs
- OpenAI: https://platform.openai.com/docs
Getting Help
- GitHub Issues: For bugs and features
- Vercel Support: For deployment issues
- Supabase Support: For database issues
Monitoring URLs
- Vercel Dashboard: https://vercel.com/dashboard
- Supabase Dashboard: https://app.supabase.com
- GitHub Actions: Check repo Actions tab
Final Notes
This deployment guide covers the essential steps to get the LyfeAI Provider Platform running. However, moving to production requires additional work in security, compliance, and reliability. Always test thoroughly in a staging environment before deploying to production, especially given the sensitive nature of healthcare data.