Skip to main content

Overview

The generate_env_template tool scans the entire codebase and generates a complete .env.example file from scratch. It automatically:
  • Groups variables by detected cluster (Database, API, Authentication, etc.)
  • Adds inferred descriptions for each variable
  • Marks which variables are required vs optional
  • Generates sensible placeholder values

Parameters

projectPath
string
Path to the project directory. Defaults to current working directory.
outputPath
string
Path to write the generated .env.example file. If not provided, only returns the content without writing to disk.

Response

content
string
required
The generated .env.example file content
variableCount
number
required
Total number of variables included in the template
clusterCount
number
required
Number of variable clusters (groups) detected
requiredCount
number
required
Number of required variables (marked with [REQUIRED])
optionalCount
number
required
Number of optional variables (marked with [OPTIONAL])
writtenTo
string
Absolute path where the file was written (only present if outputPath was provided)
metadata
object
required
Scan metadata

Example Response

{
  "content": "# Environment Variables\n# Generated by Aegis\n#\n# Required variables are marked with [REQUIRED]\n# Optional variables (with defaults) are marked with [OPTIONAL]\n\n# ============================================\n# Database\n# ============================================\n\n# Database connection string [REQUIRED]\nDATABASE_URL=postgresql://localhost:5432/mydb\n\n# Database host address [OPTIONAL]\nDB_HOST=localhost\n\n# ============================================\n# Authentication\n# ============================================\n\n# Secret key for JWT token signing [REQUIRED]\nJWT_SECRET=your-secret-here\n\n# Session secret key [REQUIRED]\nSESSION_SECRET=your-secret-here\n\n# ============================================\n# API\n# ============================================\n\n# API key [REQUIRED]\nAPI_KEY=your-secret-here\n\n# Base URL for the application [OPTIONAL]\nBASE_URL=https://example.com\n",
  "variableCount": 6,
  "clusterCount": 3,
  "requiredCount": 4,
  "optionalCount": 2,
  "writtenTo": "/Users/dev/my-project/.env.example",
  "metadata": {
    "projectPath": "/Users/dev/my-project",
    "scannedFiles": 156,
    "cacheHit": false,
    "duration": 267
  }
}

Generated Content Example

# Environment Variables
# Generated by Aegis
#
# Required variables are marked with [REQUIRED]
# Optional variables (with defaults) are marked with [OPTIONAL]

# ============================================
# Server
# ============================================

# Server port number [OPTIONAL]
PORT=3000

# Server host address [OPTIONAL]
HOST=localhost

# Node.js environment (development/production/test) [OPTIONAL]
NODE_ENV=development

# ============================================
# Database
# ============================================

# Database connection string [REQUIRED]
DATABASE_URL=postgresql://localhost:5432/mydb

# Database host address [REQUIRED]
DB_HOST=localhost

# Database port number [REQUIRED]
DB_PORT=5432

# Database username [REQUIRED]
DB_USER=your-value-here

# Database password [REQUIRED]
DB_PASSWORD=your-secret-here

# ============================================
# Authentication
# ============================================

# Secret key for JWT token signing [REQUIRED]
JWT_SECRET=your-secret-here

# API key [REQUIRED]
API_KEY=your-secret-here

Usage Example

Generate and write to file:
{
  "name": "generate_env_template",
  "arguments": {
    "projectPath": "/path/to/project",
    "outputPath": ".env.example"
  }
}
Generate content only (don’t write):
{
  "name": "generate_env_template",
  "arguments": {
    "projectPath": "/path/to/project"
  }
}

Variable Clustering

Variables are automatically grouped into clusters:
  • Server: PORT, HOST, NODE_ENV, BASE_URL
  • Database: DATABASE_URL, DB_, POSTGRES_, MYSQL_*
  • Caching: REDIS_, MEMCACHED_
  • Authentication: JWT_, SESSION_, AUTH_*
  • API: API_KEY, API_SECRET, *_API_KEY
  • Email: SMTP_, SENDGRID_, MAILGUN_*
  • Monitoring: SENTRY_, DATADOG_, NEW_RELIC_*
  • AWS: AWS_*
  • Google Cloud: GOOGLE_, GCP_
  • Azure: AZURE_*
  • Payment: STRIPE_, PAYPAL_
  • Framework: Framework-specific variables
  • Secrets: Variables with SECRET, PASSWORD, TOKEN, KEY
  • Other: Uncategorized variables

Description Generation

Descriptions are automatically generated using:
  1. Known patterns: Common variables like DATABASE_URL, API_KEY get standard descriptions
  2. Service prefixes: AWS_, STRIPE_, etc. get service-specific descriptions
  3. Name analysis: Variable name parts are analyzed to generate meaningful descriptions
  4. Suffix patterns: _URL, _HOST, _PORT, _KEY get context-appropriate descriptions

Placeholder Values

Sensible placeholders are generated based on variable type:
  • Secrets (SECRET, PASSWORD, TOKEN, KEY): your-secret-here
  • URLs: https://example.com
  • Hosts: localhost
  • Ports: 3000
  • Emails: [email protected]
  • NODE_ENV: development
  • LOG_LEVEL: info
  • DEBUG: false
  • With defaults: Empty string
  • Other: your-value-here

Required vs Optional

Variables are marked as required if:
  • They have no default value in code AND
  • They match critical patterns (DATABASE*, DB_, REDIS, *SECRET, API_KEY)
Otherwise marked as optional.

Use Cases

  • New Projects: Generate initial .env.example from existing code
  • Documentation: Create comprehensive environment variable documentation
  • Onboarding: Help new developers understand all required configuration
  • Migration: Update .env.example when adding new variables to code
  • Auditing: Ensure .env.example is complete and up-to-date

Build docs developers (and LLMs) love