4.2 KiB
4.2 KiB
🛠️ Development Setup Guide
🔒 Environment Files Security
✅ Safe for Development
Your .env files are automatically excluded from git commits via .gitignore. This means you can:
- ✅ Keep real credentials in
.envfiles locally - ✅ Develop with actual API connections
- ✅ Test with real data safely
- ✅ Never worry about committing secrets
📁 Environment File Structure
apps/bff/
├── .env # Your actual credentials (git ignored)
├── .env.example # Template with placeholder values (committed)
├── .env.production # Production template (committed)
└── .env.production.example # Production example (committed)
apps/portal/
├── .env.local # Your local overrides (git ignored)
├── .env.example # Template (committed)
└── .env.production # Production template (committed)
🚀 Quick Setup
1. Backend Environment Setup
cd apps/bff
cp .env.example .env
nano .env # Update with your actual values
2. Frontend Environment Setup
cd apps/portal
cp .env.example .env.local
nano .env.local # Update if needed (usually defaults are fine)
3. Salesforce Private Key
# Create secrets directory if not exists
mkdir -p secrets
# Add your Salesforce private key
nano secrets/sf-private.key
chmod 600 secrets/sf-private.key
🔧 Configuration Checklist
Backend (.env)
DATABASE_URL- Your PostgreSQL connectionREDIS_URL- Your Redis connectionWHMCS_BASE_URL- Your WHMCS installation URLWHMCS_API_IDENTIFIER- Your WHMCS API identifierWHMCS_API_SECRET- Your WHMCS API secretSF_LOGIN_URL- Salesforce login URLSF_CLIENT_ID- Salesforce Connected App consumer keySF_USERNAME- Salesforce integration user emailJWT_SECRET- Generate with:openssl rand -hex 64
Frontend (.env.local)
NEXT_PUBLIC_API_BASE- Usuallyhttp://localhost:4000for development
🎯 Development Commands
# Install dependencies
pnpm install
# Start development servers
pnpm dev
# Type checking
pnpm type-check
# Build for production test
pnpm build
🔒 Security Best Practices
✅ DO:
- Keep
.envfiles for local development - Use strong, unique passwords
- Generate secure JWT secrets
- Set proper file permissions (
chmod 600) for private keys - Test with real but non-production data when possible
❌ DON'T:
- Ever commit
.envfiles to git - Share credentials in chat/email
- Use production secrets in development
- Hardcode secrets in source code
- Use weak or default passwords
🚨 If You Accidentally Commit Secrets
- Immediately rotate all exposed credentials
- Remove from git history:
git filter-branch --force --index-filter \ "git rm --cached --ignore-unmatch path/to/secret/file" \ --prune-empty --tag-name-filter cat -- --all - Force push to overwrite history:
git push --force - Update all team members
🌍 Environment-Specific Configuration
Development
- Uses
.envfiles - Connects to local/development services
- Verbose logging enabled
- CORS permissive for localhost
Production
- Uses environment variables from deployment platform
- Connects to production services
- Structured logging
- Strict CORS and security headers
🛠️ Troubleshooting
"Environment variable not found"
- Check
.envfile exists and has the variable - Restart development server
- Check variable name spelling
"Database connection failed"
- Verify PostgreSQL is running
- Check
DATABASE_URLformat - Test connection manually
"Salesforce authentication failed"
- Verify private key file exists and permissions
- Check Connected App configuration
- Verify user permissions in Salesforce
"WHMCS API errors"
- Verify API credentials are correct
- Check IP whitelist in WHMCS
- Test API endpoints manually with curl