Environment Configuration
Guide for setting up different environments (Development, Staging, Production).
Environment Types
Development
Local development environment for developers.
Staging
Pre-production environment for testing.
Production
Live environment serving real users.
Development Environment
Local Setup
# Clone repository
git clone https://github.com/your-org/sbm-crm-platform.git
cd sbm-crm-platform
# Install dependencies
npm install
# Copy development config
cp .env.example .env.development
# Start services with Docker Compose
docker-compose -f docker-compose.dev.yml up
Development Configuration
{
"server": {
"port": 3000,
"env": "development"
},
"database": {
"host": "localhost",
"name": "sbmcrm_development"
},
"logging": {
"level": "debug"
},
"features": {
"enableDebugMode": true,
"skipAuth": false
}
}
Development Features
- Hot reload
- Detailed error messages
- Debug logging
- Test data seeding
- Mock external services
Staging Environment
Staging Setup
# Deploy to staging
npm run deploy:staging
# Run migrations
npm run migrate:staging
# Seed test data
npm run seed:staging
Staging Configuration
{
"server": {
"port": 3000,
"env": "staging"
},
"database": {
"host": "staging-db.example.com",
"name": "sbmcrm_staging"
},
"wechat": {
"appId": "staging_app_id",
"useSandbox": true
},
"logging": {
"level": "info"
}
}
Staging Features
- Production-like configuration
- Test WeChat sandbox
- Staging database
- Limited external integrations
- Performance testing enabled
Production Environment
Production Setup
# Deploy to production
npm run deploy:production
# Run migrations with backup
npm run migrate:production -- --backup
# Verify deployment
npm run health:check
Production Configuration
{
"server": {
"port": 3000,
"env": "production"
},
"database": {
"host": "production-db.example.com",
"name": "sbmcrm_production",
"ssl": true,
"pool": {
"min": 5,
"max": 20
}
},
"security": {
"rateLimit": true,
"cors": {
"origin": ["https://yourdomain.com"]
}
},
"logging": {
"level": "warn",
"file": "/var/log/sbmcrm/app.log"
},
"monitoring": {
"enabled": true,
"sentry": {
"dsn": "production_sentry_dsn"
}
}
}
Production Features
- Full security enabled
- SSL/TLS required
- Rate limiting
- Monitoring and alerting
- Backup automation
- High availability
Environment Variables
Development
NODE_ENV=development
DB_NAME=sbmcrm_development
LOG_LEVEL=debug
ENABLE_DEBUG=true
Staging
NODE_ENV=staging
DB_NAME=sbmcrm_staging
LOG_LEVEL=info
WECHAT_SANDBOX=true
Production
NODE_ENV=production
DB_NAME=sbmcrm_production
LOG_LEVEL=warn
ENABLE_MONITORING=true
Deployment Process
Development
# Local development
npm run dev
# No formal deployment process
# Changes are local
Staging
# Deploy to staging
git push origin staging
# CI/CD pipeline:
# 1. Run tests
# 2. Build application
# 3. Deploy to staging
# 4. Run smoke tests
Production
# Deploy to production
git push origin main
# CI/CD pipeline:
# 1. Run full test suite
# 2. Build application
# 3. Create database backup
# 4. Deploy to production
# 5. Run health checks
# 6. Monitor for issues
Database Management
Development
- Local PostgreSQL
- Frequent resets
- Test data
- No backups required
Staging
- Shared staging database
- Periodic resets
- Test data
- Daily backups
Production
- Production database cluster
- No resets
- Real data
- Continuous backups
- Point-in-time recovery
Access Control
Development
- Open access for developers
- No restrictions
- Debug tools enabled
Staging
- Limited access
- Test accounts only
- Monitoring enabled
Production
- Restricted access
- Role-based permissions
- Audit logging
- Security monitoring
Monitoring
Development
- Basic logging
- No alerting
- Local debugging
Staging
- Full logging
- Test alerts
- Performance monitoring
Production
- Comprehensive monitoring
- Real-time alerting
- APM tools
- Error tracking
Best Practices
- Separate Environments - Never mix dev/staging/prod
- Configuration Management - Use environment variables
- Secrets Management - Never commit secrets
- Deployment Process - Consistent deployment steps
- Testing - Test in staging before production
- Documentation - Document environment differences
- Access Control - Limit production access