Skip to main content

Overview

Argument Cartographer requires multiple environment variables for AI services, external APIs, and Firebase configuration. This guide provides a complete reference extracted from the actual codebase.
Never commit .env files to version control. Use Vercel’s environment variable settings for production deployments.

Environment File Structure

Create a .env file in your project root:
.env

Variable Reference

AI Configuration

string
required
Google Gemini API Key for AI-powered argument analysis.
  • Used in: All AI flows (blueprint generation, fallacy detection, summarization)
  • Model: Gemini 1.5 Pro
  • Get key: Google AI Studio
The application requires a valid API key. Missing or invalid keys will cause all AI flows to fail.

External API Tools

string
required
Firecrawl API Key for web scraping and search functionality.
  • Used in: web-search.ts, web-scraper.ts
  • Purpose: Scrapes article content and performs web searches
  • Limit: 20 results per search, 20,000 characters per scrape
  • Get key: Firecrawl
Error handling:
If Firecrawl fails or credits are depleted, the application falls back to using user query only with limited analysis mode.
string
required
Twitter API v2 Bearer Token for social media sentiment analysis.
  • Used in: twitter-search.ts for Social Pulse feature
  • Query format: {query} lang:en -is:retweet
  • Max results: 20 tweets, sorted by relevancy
  • Get token: Twitter Developer Portal
Required expansions:
  • author_id - Get full user objects
  • tweet.fields: created_at, author_id, public_metrics
  • user.fields: profile_image_url, username, name
Twitter search failures are non-fatal. The application continues without social pulse data if the API fails.

Firebase Client Configuration

These variables are public (prefixed with NEXT_PUBLIC_) and exposed to the browser:
string
required
Firebase Web API key for client-side authentication.Location: Firebase Console → Project Settings → General → Web API Key
string
required
Firebase authentication domain.Format: {project-id}.firebaseapp.com
string
required
Unique Firebase project identifier.Used in: Client SDK initialization, Firestore paths
string
required
Firebase Storage bucket name.Format: {project-id}.appspot.com
string
required
Firebase Cloud Messaging sender ID for push notifications.
string
required
Unique Firebase app identifier.Format: 1:xxxxx:web:xxxxxx

Firebase Admin Configuration

These variables are private (server-side only) and used for admin operations:
string
required
Firebase project ID for admin SDK.Must match: NEXT_PUBLIC_FIREBASE_PROJECT_ID
string
required
Service account email for Firebase Admin SDK.Format: firebase-adminsdk-{id}@{project-id}.iam.gserviceaccount.comLocation: Firebase Console → Project Settings → Service Accounts → Generate new private key
string
required
Service account private key for server-side Firebase operations.Format: Must be enclosed in double quotes with escaped newlines:
Critical Security Note:
  • Keep this key secret and never expose it in client-side code
  • In Vercel, paste the entire key including quotes and newlines
  • Rotation recommended every 90 days

Validation and Error Handling

The application validates environment variables at runtime:

API Key Validation

Fallback Behavior

When Firecrawl API fails or credits are depleted:
  1. Application attempts fallback to general search without site filtering
  2. If all scraping fails, uses search snippets as context
  3. If search also fails, enters limited analysis mode using only the user query
Twitter search failures are non-fatal:
The application continues without social pulse data and returns an empty tweets array.

Security Best Practices

1

Never Commit Secrets

Add .env to .gitignore:
.gitignore
2

Use Vercel Environment Variables

For production, add variables in:Vercel Dashboard → Project Settings → Environment VariablesSet scope:
  • Production: Live environment
  • Preview: Pull request previews
  • Development: Local development (optional)
3

Rotate Keys Regularly

  • Firebase service account keys: Every 90 days
  • API keys: When team members leave
  • Immediately if keys are exposed
4

Use Separate Environments

Maintain separate Firebase projects and API keys for:
  • Development
  • Staging
  • Production

Testing Configuration

Verify your environment variables are loaded correctly:
Never log actual API keys or secrets to the console in production.

Troubleshooting

Solution:
  1. Verify variables are added in Vercel dashboard
  2. Check variable scope (Production/Preview/Development)
  3. Redeploy after adding new variables
  4. Ensure NEXT_PUBLIC_ prefix for client-side variables
Check:
  • All 6 NEXT_PUBLIC_FIREBASE_* variables are set
  • Auth domain matches Firebase console
  • Service account private key format (escaped newlines)
Check:
  • API keys are valid and not expired
  • Keys don’t have placeholder values like YOUR_API_KEY_HERE
  • Billing is enabled for paid APIs
  • Rate limits not exceeded

Next Steps

Firebase Setup

Configure Firebase project and security rules

Vercel Deployment

Deploy your application to production

API Errors

Debug API integration issues

Common Issues

Resolve common deployment problems