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-secrettoto-f9d2f-stg-firebase-api-keytoto-f9d2f-stg-firebase-sender-idtoto-f9d2f-stg-firebase-app-idtoto-f9d2f-stg-stripe-secret-keytoto-f9d2f-stg-stripe-publishable-keytoto-f9d2f-stg-google-ai-key
Production Secrets (toto-f9d2f)β
toto-f9d2f-jwt-secrettoto-f9d2f-firebase-api-keytoto-f9d2f-firebase-sender-idtoto-f9d2f-firebase-app-idtoto-f9d2f-stripe-secret-keytoto-f9d2f-stripe-publishable-keytoto-f9d2f-google-ai-key
toto-bo Secretsβ
Staging Secrets (toto-bo-stg)β
stg-firebase-main-private-keystg-firebase-bo-private-keystg-sendgrid-api-keystg-firebase-web-api-keystg-nextauth-secretstg-google-client-idstg-google-client-secret
Production Secrets (toto-bo)β
bo-firebase-main-private-keybo-firebase-bo-private-keybo-sendgrid-api-keybo-firebase-web-api-keybo-nextauth-secretbo-google-client-idbo-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:
- Go to Google Cloud Console β IAM & Admin β Service Accounts
- Download service account JSON
- Extract private_key, client_email, client_id
- Store private keys in Google Secret Manager
- 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β
- Push to
stagingbranch - GitHub Actions deploys to staging environment
- Test and validate changes
- Merge to
mainwhen ready
Staging β Productionβ
- Push to
mainbranch - GitHub Actions deploys to production environment
- 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β
| Feature | Development | Staging | Production |
|---|---|---|---|
| Instances | 1 | 1-5 | 1-10 |
| Cost | Free | Lower | Higher |
| Data | Local/Mock | Test data | Real data |
| URL | localhost:4000 | stg.betoto.pet | betoto.pet |
| Purpose | Development | Testing | Live system |
| Monitoring | Basic | Full | Full + 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β
- Never deploy staging secrets to production
- Always test in staging before production
- Use
firebase useto verify environment before deployment - Staging and production are completely isolated
- Each environment has its own Firebase project
- Environment variables are validated at startup
- All secrets are managed through Firebase CLI for production environments