> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/kstij/Envark/llms.txt
> Use this file to discover all available pages before exploring further.

# generate_env_template

> Generate a complete .env.example file from codebase analysis

## 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

<ParamField path="projectPath" type="string" optional>
  Path to the project directory. Defaults to current working directory.
</ParamField>

<ParamField path="outputPath" type="string" optional>
  Path to write the generated .env.example file. If not provided, only returns the content without writing to disk.
</ParamField>

## Response

<ResponseField name="content" type="string" required>
  The generated .env.example file content
</ResponseField>

<ResponseField name="variableCount" type="number" required>
  Total number of variables included in the template
</ResponseField>

<ResponseField name="clusterCount" type="number" required>
  Number of variable clusters (groups) detected
</ResponseField>

<ResponseField name="requiredCount" type="number" required>
  Number of required variables (marked with \[REQUIRED])
</ResponseField>

<ResponseField name="optionalCount" type="number" required>
  Number of optional variables (marked with \[OPTIONAL])
</ResponseField>

<ResponseField name="writtenTo" type="string" optional>
  Absolute path where the file was written (only present if outputPath was provided)
</ResponseField>

<ResponseField name="metadata" type="object" required>
  Scan metadata

  <Expandable title="properties">
    <ResponseField name="projectPath" type="string">
      Absolute path to the scanned project
    </ResponseField>

    <ResponseField name="scannedFiles" type="number">
      Number of files scanned
    </ResponseField>

    <ResponseField name="cacheHit" type="boolean">
      Whether the scan used cached results
    </ResponseField>

    <ResponseField name="duration" type="number">
      Scan duration in milliseconds
    </ResponseField>
  </Expandable>
</ResponseField>

## Example Response

```json theme={null}
{
  "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

```bash theme={null}
# 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:

```json theme={null}
{
  "name": "generate_env_template",
  "arguments": {
    "projectPath": "/path/to/project",
    "outputPath": ".env.example"
  }
}
```

Generate content only (don't write):

```json theme={null}
{
  "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**: `user@example.com`
* **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
