Skip to content

Environment Variables Audit Report

A comprehensive audit of environment variable usage across the monorepo revealed multiple critical inconsistencies between the consolidated .env.example files and actual source code references. This report details all issues found and provides a complete remediation plan.

Issue: R2 Storage variables have inconsistent naming

Section titled “Issue: R2 Storage variables have inconsistent naming”

File: apps/webapp/src/utils/r2-storage.ts

Code References Consolidated .env Names Status
R2_ACCOUNT_ID PUBLIC_R2_ACCOUNT_ID ❌ MISMATCH
R2_ACCESS_KEY R2_ACCESS_KEY_ID ❌ MISMATCH
R2_SECRET_KEY R2_SECRET_ACCESS_KEY ❌ MISMATCH
R2_BUCKET_NAME PUBLIC_R2_BUCKET_NAME ❌ MISMATCH

Impact: R2 file uploads/downloads will fail in production.

2. Missing Variables in .env.example Files

Section titled “2. Missing Variables in .env.example Files”

Issue: Code references variables not defined in consolidated .env.example

Section titled “Issue: Code references variables not defined in consolidated .env.example”
Variable Referenced In Missing From
TRIGGER_SECRET_KEY apps/webapp/src/trigger/health-check.ts All .env.example files
TRIGGER_PROJECT_REF apps/webapp/src/trigger/health-check.ts All .env.example files
TRIGGER_API_TIMEOUT apps/webapp/src/trigger/health-check.ts All .env.example files
SLACK_WEBHOOK_URL apps/webapp/src/trigger/health-check.ts All .env.example files
GITHUB_TOKEN apps/webapp/src/config/env.ts All .env.example files
GITHUB_REPO_OWNER apps/webapp/src/config/env.ts All .env.example files
GITHUB_REPO_NAME apps/webapp/src/config/env.ts All .env.example files
APP_VERSION apps/webapp/src/trigger/logger.ts All .env.example files
COOLIFY_URL apps/webapp/astro.config.mjs All .env.example files

Impact: These features will fail silently or throw errors.

3. Environment Variable Naming Inconsistencies

Section titled “3. Environment Variable Naming Inconsistencies”

Issue: Multiple patterns for the same concept

Section titled “Issue: Multiple patterns for the same concept”
Concept Pattern 1 Pattern 2 Files
App Environment APP_ENV VITE_APP_ENV config/env.ts vs astro.config.mjs
Debug Logging DEBUG_LOGGING VITE_DEBUG_LOGGING Multiple files

Impact: Inconsistent behavior between client and server sides.

4. Astro Environment Loading Priority Issues

Section titled “4. Astro Environment Loading Priority Issues”

Issue: Environment loading precedence is correct but variable references are inconsistent

Section titled “Issue: Environment loading precedence is correct but variable references are inconsistent”

File: apps/webapp/astro.config.mjs

  • ✅ Correct: Local env overrides root env ({ ...rootEnv, ...webappEnv })
  • ❌ Issue: References env.APP_ENV but webapp .env.example has VITE_APP_ENV

5. Marketing App Missing Environment Integration

Section titled “5. Marketing App Missing Environment Integration”

Issue: Marketing app doesn’t load shared environment variables

Section titled “Issue: Marketing app doesn’t load shared environment variables”

File: apps/marketing/astro.config.mjs

  • ❌ Missing: No loadEnv integration with root .env
  • ❌ Missing: No shared variable access

Impact: Marketing app can’t access shared SMTP, analytics, or infrastructure variables.

Variables Referenced in Code but Missing from .env.example

Section titled “Variables Referenced in Code but Missing from .env.example”
Terminal window
# Trigger.dev Configuration (missing from all .env.example files)
TRIGGER_SECRET_KEY=your_trigger_secret_key
TRIGGER_PROJECT_REF=proj_zwlhawgpqrmanfxhquwv
TRIGGER_API_TIMEOUT=10000
# Monitoring & Alerts (missing from all .env.example files)
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/your/webhook/url
# GitHub Integration (missing from all .env.example files)
GITHUB_TOKEN=your_github_token
GITHUB_REPO_OWNER=your_github_username
GITHUB_REPO_NAME=your_repo_name
# Application Metadata (missing from all .env.example files)
APP_VERSION=1.0.0
# Deployment (missing from all .env.example files)
COOLIFY_URL=https://your-app.coolify.domain
Current Code Should Be Files
R2_ACCOUNT_ID PUBLIC_R2_ACCOUNT_ID r2-storage.ts
R2_ACCESS_KEY R2_ACCESS_KEY_ID r2-storage.ts
R2_SECRET_KEY R2_SECRET_ACCESS_KEY r2-storage.ts

Phase 1: Fix Critical R2 Variable Names (HIGH PRIORITY)

Section titled “Phase 1: Fix Critical R2 Variable Names (HIGH PRIORITY)”
  1. Update R2 storage utility:
    Terminal window
    # Fix apps/webapp/src/utils/r2-storage.ts
    R2_ACCOUNT_ID → PUBLIC_R2_ACCOUNT_ID
    R2_ACCESS_KEY → R2_ACCESS_KEY_ID
    R2_SECRET_KEY → R2_SECRET_ACCESS_KEY
    R2_BUCKET_NAME → PUBLIC_R2_BUCKET_NAME

Phase 2: Add Missing Variables to .env.example Files

Section titled “Phase 2: Add Missing Variables to .env.example Files”
  1. Update root .env.example (shared infrastructure):

    Terminal window
    # Add trigger.dev configuration
    TRIGGER_SECRET_KEY=your_trigger_secret_key
    TRIGGER_PROJECT_REF=proj_zwlhawgpqrmanfxhquwv
    TRIGGER_API_TIMEOUT=10000
    # Add monitoring
    SLACK_WEBHOOK_URL=https://hooks.slack.com/services/your/webhook/url
    # Add deployment
    COOLIFY_URL=https://your-app.coolify.domain
  2. Update apps/webapp/.env.example (webapp-specific):

    Terminal window
    # Add GitHub integration
    GITHUB_TOKEN=your_github_token
    GITHUB_REPO_OWNER=your_github_username
    GITHUB_REPO_NAME=your_repo_name
    # Add application metadata
    APP_VERSION=1.0.0

Phase 3: Fix Environment Variable Naming Consistency

Section titled “Phase 3: Fix Environment Variable Naming Consistency”
  1. Standardize environment patterns:
    • Use APP_ENV (not VITE_APP_ENV)
    • Use DEBUG_LOGGING (not VITE_DEBUG_LOGGING)
    • Update astro.config.mjs define statements

Phase 4: Fix Marketing App Environment Integration

Section titled “Phase 4: Fix Marketing App Environment Integration”
  1. Update apps/marketing/astro.config.mjs:

    import { loadEnv } from 'vite';
    // Load environment variables from root
    const rootEnv = loadEnv(mode, path.resolve(process.cwd(), '../..'), '');
    const marketingEnv = loadEnv(mode, process.cwd(), '');
    const env = { ...rootEnv, ...marketingEnv };

After implementing fixes, run these verification tests:

Terminal window
# 1. Check all env variables are defined
grep -r "process\.env\." apps/webapp/src | cut -d':' -f2 | grep -o 'process\.env\.[A-Z_]*' | sort -u
# 2. Verify no undefined variables
pnpm --filter webapp build 2>&1 | grep -i "undefined"
# 3. Test R2 functionality
curl -X POST http://localhost:4321/api/test/r2-upload
# 4. Verify environment loading
node -e "console.log(Object.keys(process.env).filter(k => k.includes('R2')))"
Issue Impact Effort Priority
R2 Variable Names HIGH LOW 🔴 P0
Missing Trigger Variables HIGH LOW 🔴 P0
Environment Naming MEDIUM MEDIUM 🟡 P1
Marketing App Integration LOW MEDIUM 🟢 P2
  • All R2 operations work correctly
  • No undefined environment variable errors
  • Trigger.dev health checks pass
  • Marketing app can access shared variables
  • Build passes without environment warnings
  • Local development works with new .env structure

WARNING: Implementing these fixes will require updating existing .env files:

  1. R2 variables must be renamed in existing .env files
  2. New variables must be added for Trigger.dev and GitHub integration
  3. VITE_* variables should be updated to use standard names

Migration Required: Document the .env file migration for existing deployments.