Environment Files
| File | Location | Purpose |
|---|---|---|
.env.local | backend/ | Local development with PostgreSQL |
.env.local | frontend/ | Local development frontend config |
.env.production | backend/ | Production with CockroachDB |
| Platform Variables | Vercel/Render/Plesk | Production frontend config |
Backend Environment Variables
Database Configuration
Primary database connection string. In production, this should include connection pooling parameters:
connection_limit=20- Max connections (20-30 for 50-100 users)pool_timeout=20- Connection timeout in seconds
Direct database connection for migrations. Do not include pooling parameters.
Server Configuration
Port the backend server listens on.
Allowed frontend origin for CORS. In production, set to your frontend URL (e.g.,
https://app.millenniumpotters.com).Environment mode. Set to
production for production deployments.Authentication
Secret key for signing JWT tokens. Must be at least 32 characters. Generate with:
Access token expiration time (e.g.,
1h, 7d, 30d).Refresh token expiration time.
Cloud Storage (Cloudinary)
Your Cloudinary cloud name from the dashboard.
Cloudinary API key for authenticated uploads.
Cloudinary API secret.
Email Configuration (Optional)
SMTP server hostname (e.g.,
smtp.gmail.com, smtp.sendgrid.net).SMTP port (587 for TLS, 465 for SSL).
SMTP username (usually your email address).
SMTP password or app-specific password.
Sender name and email in format:
Name <[email protected]>.Frontend Environment Variables
Backend API base URL. Must include
/api suffix.Supabase project URL from your project settings.
Supabase anonymous key (safe to expose in frontend).
Complete Environment File Examples
Backend .env.local (Development)
Frontend .env.local (Development)
Environment Variable Validation
The backend validates required environment variables on startup. Missing variables will cause the server to fail with clear error messages.Testing Your Configuration
Frontend connection test
Open http://localhost:3000 and check browser console for errors.Look for:
- No CORS errors
- Successful API connection messages
- Supabase client initialization
Production Deployment
Platform-Specific Setup
- Vercel
- Render
- Plesk
Add environment variables in Project Settings → Environment Variables:
- Go to your project dashboard
- Click “Settings” → “Environment Variables”
- Add each variable from the frontend configuration
- Select “Production” environment
- Click “Save”
Vercel automatically prefixes exposed variables with
NEXT_PUBLIC_.Security Best Practices
Rotate secrets regularly
Rotate secrets regularly
- Change
JWT_SECRETevery 90 days - Rotate database passwords quarterly
- Update API keys if compromised
Use strong secrets
Use strong secrets
- JWT secrets: minimum 32 characters
- Database passwords: 16+ characters with mixed case, numbers, symbols
- Never use default or example values in production
Limit access scope
Limit access scope
- Use read-only database users where possible
- Restrict Cloudinary upload presets
- Enable IP whitelisting on CockroachDB
Monitor for leaks
Monitor for leaks
- Scan repositories for exposed secrets
- Review server logs for credential exposure
- Enable GitHub secret scanning
Troubleshooting
Database connection fails
Database connection fails
Symptoms:
Error: connect ECONNREFUSED or timeout errorsSolutions:- Verify
DATABASE_URLformat is correct - Check PostgreSQL is running:
sudo systemctl status postgresql - Confirm database exists:
psql -l - Test connection:
psql "$DATABASE_URL"
CORS errors in browser
CORS errors in browser
Symptoms:
Access-Control-Allow-Origin errorsSolutions:- Ensure
CORS_ORIGINmatches your frontend URL exactly - Include protocol (
http://orhttps://) - Remove trailing slashes
- Restart backend after changing env vars
JWT token errors
JWT token errors
Symptoms: 401 Unauthorized or token validation failsSolutions:
- Verify
JWT_SECRETis at least 32 characters - Check secret matches between environments
- Clear browser localStorage/cookies
- Generate new secret:
openssl rand -base64 32
Cloudinary upload fails
Cloudinary upload fails
Symptoms: Document uploads return 401 or 403Solutions:
- Verify all three Cloudinary variables are set
- Check API key and secret for typos
- Test credentials in Cloudinary dashboard
- Ensure cloud name is correct (no URL, just the name)
Next Steps
Database Setup
Initialize schema and run migrations
Production Deployment
Deploy to production environment
