Environment Variables Audit Report
🔍 Executive Summary
Section titled “🔍 Executive Summary”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.
🚨 Critical Issues Found
Section titled “🚨 Critical Issues Found”1. Inconsistent R2 Variable Names
Section titled “1. Inconsistent R2 Variable Names”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_ENVbut webapp .env.example hasVITE_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
loadEnvintegration with root .env - ❌ Missing: No shared variable access
Impact: Marketing app can’t access shared SMTP, analytics, or infrastructure variables.
📋 Complete Variable Inventory
Section titled “📋 Complete Variable Inventory”Variables Referenced in Code but Missing from .env.example
Section titled “Variables Referenced in Code but Missing from .env.example”# Trigger.dev Configuration (missing from all .env.example files)TRIGGER_SECRET_KEY=your_trigger_secret_keyTRIGGER_PROJECT_REF=proj_zwlhawgpqrmanfxhquwvTRIGGER_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_tokenGITHUB_REPO_OWNER=your_github_usernameGITHUB_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.domainVariables with Naming Mismatches
Section titled “Variables with Naming Mismatches”| 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 |
🛠️ Remediation Plan
Section titled “🛠️ Remediation Plan”Phase 1: Fix Critical R2 Variable Names (HIGH PRIORITY)
Section titled “Phase 1: Fix Critical R2 Variable Names (HIGH PRIORITY)”- Update R2 storage utility:
Terminal window # Fix apps/webapp/src/utils/r2-storage.tsR2_ACCOUNT_ID → PUBLIC_R2_ACCOUNT_IDR2_ACCESS_KEY → R2_ACCESS_KEY_IDR2_SECRET_KEY → R2_SECRET_ACCESS_KEYR2_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”-
Update root .env.example (shared infrastructure):
Terminal window # Add trigger.dev configurationTRIGGER_SECRET_KEY=your_trigger_secret_keyTRIGGER_PROJECT_REF=proj_zwlhawgpqrmanfxhquwvTRIGGER_API_TIMEOUT=10000# Add monitoringSLACK_WEBHOOK_URL=https://hooks.slack.com/services/your/webhook/url# Add deploymentCOOLIFY_URL=https://your-app.coolify.domain -
Update apps/webapp/.env.example (webapp-specific):
Terminal window # Add GitHub integrationGITHUB_TOKEN=your_github_tokenGITHUB_REPO_OWNER=your_github_usernameGITHUB_REPO_NAME=your_repo_name# Add application metadataAPP_VERSION=1.0.0
Phase 3: Fix Environment Variable Naming Consistency
Section titled “Phase 3: Fix Environment Variable Naming Consistency”- Standardize environment patterns:
- Use
APP_ENV(notVITE_APP_ENV) - Use
DEBUG_LOGGING(notVITE_DEBUG_LOGGING) - Update astro.config.mjs define statements
- Use
Phase 4: Fix Marketing App Environment Integration
Section titled “Phase 4: Fix Marketing App Environment Integration”-
Update
apps/marketing/astro.config.mjs:import { loadEnv } from 'vite';// Load environment variables from rootconst rootEnv = loadEnv(mode, path.resolve(process.cwd(), '../..'), '');const marketingEnv = loadEnv(mode, process.cwd(), '');const env = { ...rootEnv, ...marketingEnv };
🔍 Verification Tests
Section titled “🔍 Verification Tests”After implementing fixes, run these verification tests:
# 1. Check all env variables are definedgrep -r "process\.env\." apps/webapp/src | cut -d':' -f2 | grep -o 'process\.env\.[A-Z_]*' | sort -u
# 2. Verify no undefined variablespnpm --filter webapp build 2>&1 | grep -i "undefined"
# 3. Test R2 functionalitycurl -X POST http://localhost:4321/api/test/r2-upload
# 4. Verify environment loadingnode -e "console.log(Object.keys(process.env).filter(k => k.includes('R2')))"📊 Priority Matrix
Section titled “📊 Priority Matrix”| 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 |
✅ Success Criteria
Section titled “✅ Success Criteria”- 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
🚨 Breaking Changes
Section titled “🚨 Breaking Changes”WARNING: Implementing these fixes will require updating existing .env files:
- R2 variables must be renamed in existing
.envfiles - New variables must be added for Trigger.dev and GitHub integration
- VITE_* variables should be updated to use standard names
Migration Required: Document the .env file migration for existing deployments.