Overview
This guide covers deploying Your Finance App to production, including environment configuration, database migrations, monitoring, and performance optimization.Environment Configuration
Required Environment Variables
Create a production.env file with these required variables:
.env
Environment Variable Security
Use a Secret Manager
Store sensitive variables in:
- AWS Secrets Manager
- Google Cloud Secret Manager
- Azure Key Vault
- Railway/Vercel encrypted environment variables
Database Setup
Using Supabase (Recommended)
Your Finance App is configured for Supabase PostgreSQL:Create Supabase Project
- Go to supabase.com
- Create a new project
- Wait for database provisioning
Get Connection Strings
Navigate to Settings → Database and copy:
- Transaction Mode (port 6543) →
DATABASE_URL - Session Mode (port 5432) →
DIRECT_URL
Supabase uses connection pooling (PgBouncer) on port 6543 for better performance. Migrations require direct connection on port 5432.
Database Migrations in Production
Safe Migration Process
Migration Strategy
Non-Breaking Changes
Non-Breaking Changes
Safe to deploy directly:
- Adding new tables
- Adding nullable columns
- Adding indexes
- Creating new enums
Breaking Changes
Breaking Changes
Require careful planning:
- Renaming columns
- Deleting columns
- Changing column types
- Adding non-nullable columns
- Add new column (nullable)
- Backfill data
- Make non-nullable
- Remove old column
Rollback Strategy
Rollback Strategy
If a migration fails:
Initial Data Seeding
The app includes a seed script for default categories:apps/backend/prisma/seed.ts
Deployment Platforms
Railway (Recommended)
Railway provides easy deployment with automatic builds:Connect Repository
- Go to railway.app
- Create new project
- Connect your GitHub repository
Add Environment Variables
In Railway dashboard, add all required environment variables from your
.env.exampleVercel (Frontend)
Deploy the frontend to Vercel:vercel.json:
apps/frontend/vercel.json
Docker Deployment
While Your Finance App doesn’t include a Dockerfile by default, here’s a production-ready setup:Dockerfile
Docker Compose
For local production testing:docker-compose.yml
Monitoring and Logging
Application Logging
The app uses a custom logger utility:apps/backend/src/common/utils/logger.util.ts
Error Tracking
Integrate error tracking services:- Sentry
- LogRocket
main.ts
Health Checks
Implement health check endpoints:apps/backend/src/app.controller.ts
Performance Optimization
Enable Production Mode
- Optimized builds
- Disabled debug logs
- Better error handling
- Performance optimizations
Database Connection Pooling
Optimize Prisma connection settings:Connection pooling limits are based on your plan:
- Free tier: 10 connections
- Pro tier: 50 connections
- Enterprise: Custom
Response Compression
Enable compression middleware:main.ts
Rate Limiting
Protect against abuse:app.module.ts
Caching Headers
Set appropriate cache headers:Security Hardening
Helmet for Security Headers
main.ts
X-Frame-OptionsX-Content-Type-OptionsStrict-Transport-Security- And more security headers
CORS Configuration
apps/backend/src/main.ts
SSL/TLS
Always use HTTPS in production:- Most platforms (Railway, Vercel, etc.) provide free SSL certificates
- For custom domains, use Let’s Encrypt
- Enforce HTTPS redirects
Deployment Checklist
Troubleshooting
Common Issues
Database Connection Errors
Database Connection Errors
Symptoms:
Can't reach database server or Connection timeoutSolutions:- Verify
DATABASE_URLis correct - Check database is accessible from your deployment platform
- Ensure connection string includes
?pgbouncer=truefor Supabase - Check IP whitelist in database settings
Migration Failures
Migration Failures
Symptoms:
Migration failed to applySolutions:- Use
DIRECT_URLfor migrations (port 5432, not 6543) - Check migration files for syntax errors
- Verify database user has sufficient permissions
- Review migration logs for specific error messages
JWT Errors
JWT Errors
Symptoms:
Invalid token or Token expiredSolutions:- Ensure
JWT_SECRETis set and consistent - Verify
JWT_EXPIRES_INis valid format (e.g., ‘7d’) - Check system time is synchronized
- Clear old tokens and re-authenticate
CORS Errors
CORS Errors
Symptoms: Browser shows CORS policy errorsSolutions:
- Set
FRONTEND_URLto your actual frontend domain - Ensure
credentials: trueis set if using cookies - Check
allowedHeadersincludes required headers - Verify OPTIONS requests are handled
Monitoring Production
Key Metrics to Track
Response Time
Monitor API endpoint response times. Target: < 200ms for most endpoints.
Error Rate
Track 4xx and 5xx errors. Target: < 1% error rate.
Database Performance
Monitor query times and connection pool usage.
Resource Usage
Track CPU, memory, and disk usage. Scale when consistently > 70%.
Logging Best Practices
Related Resources
Advanced Concepts
Technical patterns and architecture
Best Practices
Code quality and testing strategies
Supabase Docs
Database setup and configuration
Railway Docs
Deployment platform documentation
