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

147 lines
3.3 KiB
Plaintext

# ==============================================
# Maternal App - Backend Configuration Template
# ==============================================
# Copy this file to .env and fill in your values
# Never commit .env files with real credentials!
# -----------------
# Environment
# -----------------
NODE_ENV=development
API_PORT=3020
API_URL=http://localhost:3020
# -----------------
# Database
# -----------------
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=maternal_app
DATABASE_USER=maternal_user
DATABASE_PASSWORD=your-secure-password-here
# Database SSL (required for production)
DATABASE_SSL=false
DATABASE_SSL_REJECT_UNAUTHORIZED=true
# -----------------
# Redis Cache
# -----------------
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_URL=redis://localhost:6379
REDIS_TTL=3600
# -----------------
# MongoDB (AI Chat History)
# -----------------
MONGODB_URI=mongodb://localhost:27017/maternal_ai_chat
# -----------------
# MinIO (S3-Compatible Storage)
# -----------------
MINIO_ENDPOINT=localhost
MINIO_PORT=9000
MINIO_USE_SSL=false
MINIO_ACCESS_KEY=your-minio-access-key
MINIO_SECRET_KEY=your-minio-secret-key
MINIO_BUCKET=maternal-files
MINIO_REGION=us-east-1
# -----------------
# JWT Authentication
# -----------------
JWT_SECRET=change-this-to-a-secure-random-string-in-production
JWT_EXPIRATION=1h
JWT_REFRESH_SECRET=change-this-to-another-secure-random-string
JWT_REFRESH_EXPIRATION=7d
# -----------------
# AI Services
# -----------------
# Primary provider: 'openai' or 'azure'
AI_PROVIDER=azure
# OpenAI Configuration
OPENAI_API_KEY=
OPENAI_MODEL=gpt-4o-mini
OPENAI_EMBEDDING_MODEL=text-embedding-3-small
OPENAI_MAX_TOKENS=1000
# Azure OpenAI - Chat/Completion
AZURE_OPENAI_ENABLED=true
AZURE_OPENAI_CHAT_ENDPOINT=
AZURE_OPENAI_CHAT_DEPLOYMENT=
AZURE_OPENAI_CHAT_API_VERSION=2025-04-01-preview
AZURE_OPENAI_CHAT_API_KEY=
AZURE_OPENAI_CHAT_MAX_TOKENS=1000
AZURE_OPENAI_REASONING_EFFORT=medium
# Azure OpenAI - Whisper/Voice
AZURE_OPENAI_WHISPER_ENDPOINT=
AZURE_OPENAI_WHISPER_DEPLOYMENT=whisper
AZURE_OPENAI_WHISPER_API_VERSION=2024-06-01
AZURE_OPENAI_WHISPER_API_KEY=
# Azure OpenAI - Embeddings
AZURE_OPENAI_EMBEDDINGS_ENDPOINT=
AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT=text-embedding-ada-002
AZURE_OPENAI_EMBEDDINGS_API_VERSION=2023-05-15
AZURE_OPENAI_EMBEDDINGS_API_KEY=
# -----------------
# Security
# -----------------
# CORS Origins (comma-separated)
CORS_ORIGIN=http://localhost:3030,http://localhost:19000
# Rate Limiting
RATE_LIMIT_TTL=60
RATE_LIMIT_MAX=100
# -----------------
# Logging
# -----------------
LOG_LEVEL=info
LOG_DIR=logs
# -----------------
# Error Tracking (Sentry)
# -----------------
SENTRY_ENABLED=false
SENTRY_DSN=
SENTRY_SAMPLE_RATE=1.0
SENTRY_TRACES_SAMPLE_RATE=0.1
SENTRY_PROFILES_SAMPLE_RATE=0.1
APP_VERSION=1.0.0
# -----------------
# Analytics
# -----------------
ANALYTICS_ENABLED=false
ANALYTICS_PROVIDER=posthog
POSTHOG_API_KEY=
POSTHOG_HOST=https://app.posthog.com
# -----------------
# Email Service (Mailgun)
# -----------------
MAILGUN_API_KEY=
MAILGUN_DOMAIN=
MAILGUN_REGION=eu
EMAIL_FROM=noreply@maternal-app.com
EMAIL_FROM_NAME=Maternal App
APP_URL=http://localhost:3030
# -----------------
# Backups
# -----------------
BACKUP_ENABLED=false
BACKUP_SCHEDULE=0 2 * * *
BACKUP_RETENTION_DAYS=30
BACKUP_S3_BUCKET=
BACKUP_S3_REGION=
BACKUP_S3_ACCESS_KEY=
BACKUP_S3_SECRET_KEY=