This guide provides step-by-step instructions for migrating the City Service Provider Application from Spring Boot + PostgreSQL to Supabase + Vercel.
- Serverless Architecture: No server management required
- Real-time Features: Built-in real-time subscriptions
- Automatic Scaling: Handles traffic spikes automatically
- Global CDN: Fast content delivery worldwide
- Integrated Auth: Built-in authentication with social providers
- File Storage: Integrated file storage with CDN
- Cost Effective: Pay only for what you use
- Developer Experience: Modern tooling and workflows
| Component | Before (Spring Boot) | After (Supabase + Vercel) |
|---|---|---|
| Backend | Java Spring Boot | Supabase Edge Functions (TypeScript) |
| Database | PostgreSQL | Supabase PostgreSQL |
| Authentication | Custom JWT | Supabase Auth |
| File Storage | Local/S3 | Supabase Storage |
| Frontend Hosting | Manual | Vercel (Automatic) |
| Real-time | Manual WebSocket | Supabase Real-time |
| API | REST | REST + GraphQL + Real-time |
# Node.js (v16 or later)
node --version
# npm or yarn
npm --version
# Supabase CLI
npm install -g supabase
# Vercel CLI
npm install -g vercel
# Git
git --version- Supabase Account (Free tier available)
- Vercel Account (Free tier available)
- GitHub Account (for deployment)
# Run the automated deployment script
./deploy-supabase-vercel.shFollow the detailed instructions below for manual setup and customization.
# Login to Supabase
supabase login
# Create new project (or use existing)
supabase projects create city-service-app
# Initialize local project
supabase init# Start local Supabase
supabase start
# Run initial migration
supabase db reset
# Apply custom schema
supabase db push-- Run in Supabase SQL Editor or locally
-- File: migration/data-migration.sqlsupabase functions deploy auth-helperssupabase functions deploy providerssupabase functions deploy servicescd frontend
npm install @supabase/supabase-js @supabase/auth-helpers-react# Copy environment template
cp env.supabase.example .env.local
# Update with your Supabase credentials
# REACT_APP_SUPABASE_URL=https://your-project.supabase.co
# REACT_APP_SUPABASE_ANON_KEY=your-anon-keyThe following files have been created/updated for Supabase integration:
src/lib/supabase.js- Supabase client configurationsrc/services/supabaseAuthService.js- Authentication servicesrc/services/supabaseProviderService.js- Provider servicesrc/services/supabaseServiceService.js- Service management
# Login to Vercel
vercel login
# Link project
vercel link
# Set environment variables
vercel env add REACT_APP_SUPABASE_URL
vercel env add REACT_APP_SUPABASE_ANON_KEY# Deploy to production
vercel --prod-- Example: Users can only view their own profile
CREATE POLICY "Users can view own profile" ON user_profiles
FOR SELECT USING (auth.uid() = id);
-- Example: Anyone can view active providers
CREATE POLICY "Anyone can view active providers" ON service_providers
FOR SELECT USING (is_available = true);-- Create storage buckets
INSERT INTO storage.buckets (id, name, public) VALUES
('profile-images', 'profile-images', true),
('service-images', 'service-images', true);Configure in Supabase Dashboard > Authentication > Email Templates:
- Confirmation email
- Password reset email
- Magic link email
Enable in Supabase Dashboard > Authentication > Providers:
- Google OAuth
- Facebook OAuth
- GitHub OAuth
// Subscribe to provider updates
const subscription = supabase
.channel('providers')
.on('postgres_changes',
{ event: '*', schema: 'public', table: 'service_providers' },
(payload) => {
console.log('Provider updated:', payload)
}
)
.subscribe()# Start local Supabase
supabase start
# Start frontend development server
cd frontend
npm start
# Run tests
npm test# Test Edge Functions
curl -X GET "https://your-project.supabase.co/functions/v1/providers"
# Test frontend
curl -X GET "https://your-app.vercel.app"- Database performance
- API usage
- Authentication metrics
- Storage usage
- Page views
- Performance metrics
- Error tracking
- Deployment logs
// Error tracking
window.addEventListener('error', (event) => {
// Send to monitoring service
console.error('Application error:', event.error)
})
// Performance monitoring
const observer = new PerformanceObserver((list) => {
// Track performance metrics
})
observer.observe({ entryTypes: ['navigation', 'paint'] })- β Enable Row Level Security on all tables
- β Use proper authentication checks
- β Validate input data
- β Use prepared statements (automatic with Supabase)
- β Implement rate limiting
- β Validate JWT tokens
- β Use HTTPS only
- β Sanitize user input
- β Store tokens securely
- β Implement CSP headers
- β Validate user permissions
- β Use environment variables for secrets
# Check Supabase connection
supabase status
# Verify environment variables
echo $REACT_APP_SUPABASE_URL
echo $REACT_APP_SUPABASE_ANON_KEY-- Check RLS policies
SELECT * FROM pg_policies WHERE tablename = 'user_profiles';
-- Verify user permissions
SELECT auth.uid(), auth.role();# Check function logs
supabase functions logs auth-helpers
# Deploy with verbose output
supabase functions deploy providers --debug# Check build logs
vercel logs
# Verify environment variables
vercel env ls# Enable debug mode in frontend
REACT_APP_DEBUG=true npm start
# Enable Supabase debug mode
supabase start --debug-- Add indexes for frequently queried columns
CREATE INDEX idx_providers_rating ON service_providers(average_rating DESC);
CREATE INDEX idx_services_category ON services(category_id);
CREATE INDEX idx_bookings_user ON bookings(user_id);// Lazy load components
const ProviderDetail = lazy(() => import('./ProviderDetail'))
// Optimize images
const optimizedImageUrl = supabase.storage
.from('profile-images')
.getPublicUrl('image.jpg', {
transform: {
width: 300,
height: 300,
quality: 80
}
})// Cache frequently accessed data
const cachedProviders = useMemo(() => {
return providers.filter(p => p.is_featured)
}, [providers])
// Use React Query for server state
const { data: providers } = useQuery(
'providers',
() => providerService.getProviders(),
{ staleTime: 5 * 60 * 1000 } // 5 minutes
)If issues arise, you can quickly rollback:
- DNS Revert: Point domain back to original server
- Database Restore: Restore from pre-migration backup
- Code Revert: Revert to previous Git commit
- Service Restart: Restart original Spring Boot application
- Use feature flags to disable new features
- Route specific endpoints to old backend
- Gradual migration of user segments
- β 99.9% uptime
- β < 200ms API response time
- β < 2s page load time
- β Zero security vulnerabilities
- β Reduced hosting costs by 60%
- β Improved developer productivity
- β Faster feature deployment
- β Better user experience
- Check Documentation: Review this guide and official docs
- Search Issues: Look for similar problems in GitHub issues
- Community Support: Ask in Discord or forums
- Professional Support: Contact Supabase/Vercel support
When reporting issues, include:
- Error messages and logs
- Steps to reproduce
- Environment details
- Expected vs actual behavior
π Congratulations! You've successfully migrated to a modern, scalable architecture with Supabase and Vercel. Your application is now ready for the future with real-time features, automatic scaling, and a great developer experience.