Files
maternal-app/maternal-app/maternal-app-backend/.env.example
Andrei fa61405954
Some checks failed
CI/CD Pipeline / Build Application (push) Has been cancelled
CI/CD Pipeline / Lint and Test (push) Has been cancelled
CI/CD Pipeline / E2E Tests (push) Has been cancelled
feat: Add production infrastructure - Environment config, secrets, and backups
**Environment Configuration**
Created comprehensive environment configuration for all deployment stages:
- .env.example: Template with all configuration options documented
- .env.staging: Staging environment with managed services and moderate security
- .env.production: Production template with strict security and AWS integrations

Features:
- Environment-specific database, Redis, MongoDB, MinIO/S3 settings
- SSL/TLS configuration for production databases
- Connection pooling configuration
- Azure OpenAI endpoints for chat, whisper, and embeddings
- Rate limiting and CORS per environment
- Error tracking with Sentry (different sample rates)
- Analytics with PostHog
- Email service with Mailgun
- Backup configuration with S3 support

**Secret Management**
Created SecretsService for unified secret access:
- Development: .env files
- Staging/Production: AWS Secrets Manager, HashiCorp Vault, or env variables
- Features:
  * 5-minute caching with automatic refresh
  * Multiple provider support (AWS, Vault, env)
  * Batch secret retrieval
  * Required secrets validation
  * Cache management (clear, refresh)
- Files: src/common/config/secrets.service.ts (189 lines)

**Environment Config Service**
Created typed configuration service (environment.config.ts):
- Centralized configuration with type safety
- Environment detection (isProduction, isStaging, isDevelopment)
- Nested configuration objects for all services
- Default values for development
- Ready for @nestjs/config integration

**Database Backup System**
Comprehensive automated backup solution:
- BackupService (306 lines):
  * Automated daily backups at 2 AM (configurable cron)
  * PostgreSQL backup with pg_dump + gzip compression
  * MongoDB backup with mongodump + tar.gz
  * 30-day retention policy with automatic cleanup
  * S3 upload for off-site storage (ready for @aws-sdk/client-s3)
  * Backup verification (file size, integrity)
  * Restore functionality
  * Human-readable file size formatting

- BackupController:
  * Manual backup triggering (POST /api/v1/backups)
  * List available backups (GET /api/v1/backups)
  * Restore from backup (POST /api/v1/backups/restore)
  * Admin-only access with JWT + roles guards

- BackupModule:
  * Scheduled backup execution
  * Integration with @nestjs/schedule

**Documentation**
Created comprehensive BACKUP_STRATEGY.md (343 lines):
- Configuration guide
- Usage examples with curl commands
- Disaster recovery procedures (RTO: 1h, RPO: 24h)
- Best practices for production
- Monitoring and alerting recommendations
- Security considerations
- Troubleshooting guide
- Cost optimization tips
- GDPR/COPPA/HIPAA compliance notes
- Future enhancements roadmap

**Impact**
- Environment-specific configuration enables proper staging and production deployments
- Secret management prepares for AWS Secrets Manager or HashiCorp Vault integration
- Automated backups protect against data loss with 30-day retention
- Admin backup controls enable manual intervention when needed
- S3 integration ready for off-site backup storage

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 22:19:59 +00:00

3.3 KiB