Skip to main content

Environment Management

πŸ“‹ Environment Overview​

The Toto ecosystem supports multiple environments for development, testing, and production deployment.

Environment Structure​

Development β†’ Staging β†’ Production
↓ ↓ ↓
Local Dev toto-*-stg toto-*

πŸ—οΈ Project Environments​

toto-app (Main Application)​

Staging Environment​

  • Project ID: toto-f9d2f-stg
  • URL: https://stg.app.betoto.pet
  • Purpose: Testing, QA, pre-production validation
  • Configuration: apphosting.staging.yaml

Production Environment​

  • Project ID: toto-f9d2f
  • URL: https://app.betoto.pet
  • Purpose: Live production system
  • Configuration: apphosting.production.yaml

toto-bo (Backoffice)​

Staging Environment​

  • Project ID: toto-bo-stg
  • URL: https://stg.bo.betoto.pet
  • Purpose: Testing, QA, pre-production validation
  • Configuration: apphosting.staging.yaml

Production Environment​

  • Project ID: toto-bo
  • URL: https://bo.betoto.pet
  • Purpose: Live production system
  • Configuration: apphosting.production.yaml

πŸ” Secrets Management​

toto-app Secrets​

Staging Secrets (toto-f9d2f-stg)​

  • toto-f9d2f-stg-jwt-secret
  • toto-f9d2f-stg-firebase-api-key
  • toto-f9d2f-stg-firebase-sender-id
  • toto-f9d2f-stg-firebase-app-id
  • toto-f9d2f-stg-stripe-secret-key
  • toto-f9d2f-stg-stripe-publishable-key
  • toto-f9d2f-stg-google-ai-key

Production Secrets (toto-f9d2f)​

  • toto-f9d2f-jwt-secret
  • toto-f9d2f-firebase-api-key
  • toto-f9d2f-firebase-sender-id
  • toto-f9d2f-firebase-app-id
  • toto-f9d2f-stripe-secret-key
  • toto-f9d2f-stripe-publishable-key
  • toto-f9d2f-google-ai-key

toto-bo Secrets​

Staging Secrets (toto-bo-stg)​

  • stg-firebase-main-private-key
  • stg-firebase-bo-private-key
  • stg-sendgrid-api-key
  • stg-firebase-web-api-key
  • stg-nextauth-secret
  • stg-google-client-id
  • stg-google-client-secret

Production Secrets (toto-bo)​

  • bo-firebase-main-private-key
  • bo-firebase-bo-private-key
  • bo-sendgrid-api-key
  • bo-firebase-web-api-key
  • bo-nextauth-secret
  • bo-google-client-id
  • bo-google-client-secret

πŸ“‹ Environment Variables​

toto-app Environment Variables​

Firebase Configuration​

NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project.firebasestorage.app
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=your_measurement_id

API Configuration​

GOOGLE_AI_API_KEY=your_google_ai_key
JWT_SECRET=your_jwt_secret
STRIPE_SECRET_KEY=your_stripe_secret_key
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=your_stripe_publishable_key

Environment Settings​

NODE_ENV=development|staging|production
NEXT_PUBLIC_ENVIRONMENT=dev|stg|prod

Monitoring Integration​

# Production
NEXT_PUBLIC_TOTO_BO_MONITORING_URL=https://bo.betoto.pet/api/monitoring
NEXT_PUBLIC_TOTO_BO_API_KEY=your_api_key

# Staging
NEXT_PUBLIC_TOTO_BO_MONITORING_URL=https://stg.bo.betoto.pet/api/monitoring
NEXT_PUBLIC_TOTO_BO_API_KEY=your_staging_api_key

# Development
NEXT_PUBLIC_TOTO_BO_MONITORING_URL=http://localhost:5000/api/monitoring
NEXT_PUBLIC_TOTO_BO_API_KEY=your_dev_api_key

toto-bo Environment Variables​

Firebase Configuration​

FIREBASE_PROJECT_ID=toto-f9d2f
FIREBASE_BO_PROJECT_ID=toto-bo
FIREBASE_WEB_API_KEY=your_firebase_web_key

Authentication​

NEXTAUTH_URL=https://bo.betoto.pet
NEXTAUTH_SECRET=your_nextauth_secret
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret

External Services​

SENDGRID_API_KEY=your_sendgrid_key

Monitoring & Performance​

MONITORING_ENABLED=true

Development & Testing​

NODE_ENV=development|staging|production

AI Integration​

TOTO_AI_HUB_URL=https://toto-ai-hub-backend--toto-ai-hub.us-central1.hosted.app

Description: AI Hub endpoint for all AI functionality (agents, insights, training) Required: Yes (production & staging) Setup: Set in apphosting.yaml env section

Firebase Admin SDK Configuration​

# Main App Service Account
FIREBASE_PRIVATE_KEY=secret # From Google Secret Manager
FIREBASE_CLIENT_EMAIL=firebase-adminsdk-fbsvc@toto-f9d2f.iam.gserviceaccount.com
FIREBASE_CLIENT_ID=112915412214358030503

# Backoffice Service Account
FIREBASE_BO_PRIVATE_KEY=secret # From Google Secret Manager
FIREBASE_BO_CLIENT_EMAIL=firebase-adminsdk-fbsvc@toto-bo.iam.gserviceaccount.com

Description: Service account credentials for Firebase Admin SDK initialization Required: Yes (production & staging) Setup:

  1. Go to Google Cloud Console β†’ IAM & Admin β†’ Service Accounts
  2. Download service account JSON
  3. Extract private_key, client_email, client_id
  4. Store private keys in Google Secret Manager
  5. Reference secrets in apphosting.yaml

Public Client URLs​

NEXT_PUBLIC_TOTO_WALLET_URL=https://us-central1-toto-wallet-76e93.cloudfunctions.net
NEXT_PUBLIC_API_BASE_URL=https://us-central1-toto-f9d2f.cloudfunctions.net/api

Description: Client-side API endpoints for wallet and main API Required: Yes (production & staging, different URLs per environment) Note: Safe to expose (public client-side configuration)

Public Firebase Client Configuration (Staging)​

NEXT_PUBLIC_FIREBASE_API_KEY=AIzaSyBrj7ILbk5szp9j7xU_9usnh2PhGIPJUds
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=toto-f9d2f.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=toto-f9d2f
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=toto-f9d2f.firebasestorage.app
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=1025669933653
NEXT_PUBLIC_FIREBASE_APP_ID=1:1025669933653:web:88d547e8c3e3b241fc42dc
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=G-T4JNM73B05

Description: Firebase client SDK configuration (public, safe to expose) Required: Staging environment (check if needed in production) Setup: Obtain from Firebase Console β†’ Project Settings β†’ General β†’ Your apps

Debug & Development Flags (Optional)​

DEBUG_ENV=1           # Enable verbose environment logging
DEBUG_AUTH=1 # Enable verbose authentication logging
DEBUG_EMAIL=1 # Enable verbose email service logging

Description: Enable verbose logging for troubleshooting Required: No (optional for debugging) Note: Set to "1" to enable, omit or set to "0" to disable


πŸš€ Deployment Commands​

toto-app Deployment​

Staging Deployment​

# Switch to staging environment
firebase use staging

# Deploy to staging
firebase deploy --only hosting --project toto-f9d2f-stg

# Or use npm script
npm run deploy:staging

Production Deployment​

# Switch to production environment
firebase use production

# Deploy to production
firebase deploy --only hosting --project toto-f9d2f

# Or use npm script
npm run deploy:production

toto-bo Deployment​

Staging Deployment​

# Deploy to staging
firebase deploy --project toto-bo-stg

# Or use npm script
npm run deploy:staging

Production Deployment​

# Deploy to production
firebase deploy --project toto-bo

# Or use npm script
npm run deploy:production

πŸ”„ Deployment Flow​

Development β†’ Staging​

  1. Push to staging branch
  2. GitHub Actions deploys to staging environment
  3. Test and validate changes
  4. Merge to main when ready

Staging β†’ Production​

  1. Push to main branch
  2. GitHub Actions deploys to production environment
  3. Production is live

πŸ› οΈ Setup Commands​

Create New Secret​

# Create secret
gcloud secrets create secret-name --project=project-id

# Grant access to App Hosting
firebase apphosting:secrets:grantaccess secret-name --backend backend-name --project project-id

Update Secret Value​

echo "secret-value" | gcloud secrets versions add secret-name --data-file=- --project=project-id

Switch Environment​

# Switch to staging
firebase use staging

# Switch to production
firebase use production

# Check current environment
firebase use

πŸ“Š Environment Comparison​

FeatureDevelopmentStagingProduction
Instances11-51-10
CostFreeLowerHigher
DataLocal/MockTest dataReal data
URLlocalhost:4000stg.betoto.petbetoto.pet
PurposeDevelopmentTestingLive system
MonitoringBasicFullFull + Alerts

πŸ” Troubleshooting​

Deployment Issues​

For detailed debugging of App Hosting deployment failures, see the comprehensive App Hosting Debugging Guide.

Common Issues​

  • Secret Access: Verify all secrets exist and have proper permissions
  • Build Failures: Check Cloud Build logs for specific error messages
  • Runtime Errors: Monitor Cloud Run logs for application issues
  • Environment Variables: Ensure all required variables are set correctly

🚨 Important Notes​

  1. Never deploy staging secrets to production
  2. Always test in staging before production
  3. Use firebase use to verify environment before deployment
  4. Staging and production are completely isolated
  5. Each environment has its own Firebase project
  6. Environment variables are validated at startup
  7. All secrets are managed through Firebase CLI for production environments