envguard

module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2026 License: MIT

README ΒΆ

πŸ›‘οΈ EnvGuard

Smart .env file manager β€” scan, validate, diff, and sync environment variables

CI Release License Go Report Card


Ever deployed to production only to crash because DATABASE_URL was missing?

EnvGuard scans your code, validates your .env files, detects leaked secrets, and keeps environments in sync β€” all from one CLI.

✨ Features

  • πŸ” Code Scanner β€” Finds every env var your code actually uses (JS/TS, Python, Go, Rust, Docker)
  • βœ… Validator β€” Validates .env against a schema with type checking (int, bool, url, port, email, enum)
  • πŸ”„ Cross-Validation β€” Detects vars used in code but missing from .env, and vars in .env but unused
  • πŸ“Š Diff β€” Compare .env files across environments with color-coded output
  • πŸ” Secret Detection β€” Finds AWS keys, private keys, JWTs, and tokens in your codebase
  • πŸ”’ Encrypted Sync β€” Share .env files via git safely with AES-256-GCM encryption
  • πŸͺ Pre-commit Hook β€” Validate before every commit automatically
  • πŸ“‹ Schema Generator β€” Auto-generate .env.schema from existing .env with type inference
  • πŸš€ CI-Ready β€” Clean exit codes (0=ok, 1=warnings, 2=errors) for pipeline integration

πŸ“¦ Installation

Go Install

go install github.com/AbdullahTarakji/envguard/cmd/envguard@latest

From Source

git clone https://github.com/AbdullahTarakji/envguard.git
cd envguard
make build
sudo mv envguard /usr/local/bin/

Binary Releases

Download pre-built binaries from Releases.

🎬 Demo

EnvGuard Demo

πŸš€ Quick Start

# Scan your code for env var usage
envguard scan

# Validate your .env file
envguard validate

# Run all checks (validate + security scan)
envguard check

# Compare dev vs prod env files
envguard diff .env .env.production

πŸ“– Usage

envguard scan β€” Find Environment Variables in Code

Scans your source code to discover which environment variables are actually used:

$ envguard scan
Found 8 unique environment variables in 12 references:

  DATABASE_URL     src/db.ts:5 (js)
  PORT             src/index.ts:3 (js)
  API_KEY          src/api.ts:10 (js)
  DEBUG            src/config.py:8 (python)
  REDIS_URL        src/cache.go:15 (go)
  ...

Supported languages:

Language Patterns Detected
JavaScript/TypeScript process.env.VAR, process.env['VAR'], import.meta.env.VITE_*
Python os.environ['VAR'], os.getenv('VAR'), os.environ.get('VAR')
Go os.Getenv("VAR"), os.LookupEnv("VAR")
Rust std::env::var("VAR"), env::var("VAR"), env!("VAR")
Docker ENV VAR=val, ARG VAR, ${VAR} in compose
# Filter by language
envguard scan --lang js

# JSON output
envguard scan --json

# Scan specific directory
envguard scan ./src

envguard validate β€” Validate Your .env File

Against Code (default)

Checks that every env var your code uses is defined in .env, and warns about unused vars:

$ envguard validate
  βœ— MISSING_VAR: variable used in code but missing from .env
  ⚠ OLD_CONFIG: variable defined in .env but not used in code
  βœ“ 12 variables validated successfully
Against a Schema

Create a .env.schema to enforce types and requirements:

# type: string, required
DATABASE_URL=
# type: port, required
PORT=
# type: bool, optional, default: false
DEBUG=
# type: enum(development,staging,production), required
NODE_ENV=
# type: url, required
API_ENDPOINT=
# type: email, optional
ADMIN_EMAIL=
$ envguard validate --schema .env.schema
  βœ— PORT: expected type "port", got "abc" (not a valid port number)
  βœ— NODE_ENV: expected one of [development, staging, production], got "test"
  βœ“ 8/10 variables passed validation

Supported types: string, int, bool, url, email, port, enum(val1,val2,...)

# Strict mode (warnings become errors)
envguard validate --strict

# JSON output for CI
envguard validate --json

# Explicit paths
envguard validate --env .env.staging --schema .env.schema

envguard diff β€” Compare Environment Files

$ envguard diff .env .env.production
  ~ DATABASE_URL: localhost:5432/dev β†’ prod-db:5432/app (line 1 β†’ 1)
  ~ PORT: 3000 β†’ 8080 (line 2 β†’ 2)
  - DEBUG=true (line 3)
  + SENTRY_DSN=https://... (line 8)
  ~ NODE_ENV: development β†’ production (line 5 β†’ 4)
# Mask sensitive values (for sharing/logging)
envguard diff .env .env.prod --mask
  ~ DATABASE_URL: ***** β†’ ***** (line 1 β†’ 1)
  ~ API_KEY: ***** β†’ ***** (line 4 β†’ 3)

# JSON output
envguard diff .env .env.prod --json

envguard init β€” Generate Schema from .env

Auto-generates a .env.schema with inferred types:

$ envguard init
Generated .env.schema with 10 entries

$ cat .env.schema
# type: string, required
DATABASE_URL=
# type: port, required
PORT=
# type: bool, required
DEBUG=
# type: url, required
API_ENDPOINT=

Type inference:

  • Numbers β†’ int (or port if 1-65535)
  • true/false/yes/no β†’ bool
  • http:///https:// β†’ url
  • Contains @ and . β†’ email
  • Everything else β†’ string

envguard check β€” Run All Checks

Combined validation + security scan, perfect for CI:

$ envguard check
  ⚠ .env is not in .gitignore
  βœ— MISSING_VAR: used in code but not in .env
  ⚠ Found potential AWS key pattern in src/config.js:15
  βœ“ Encryption check passed

$ echo $?
2  # exit code 2 = errors found

Exit codes: 0 = clean, 1 = warnings only, 2 = errors

envguard encrypt / decrypt β€” Secure .env Sharing

Share .env files through git safely with AES-256-GCM encryption:

# Encrypt .env β†’ .env.enc (from project directory)
envguard encrypt --password "team-secret"

# Or specify the file path directly
envguard encrypt .env.staging --password "team-secret"

# Decrypt .env.enc β†’ .env
envguard decrypt --password "team-secret"

# Decrypt a specific file
envguard decrypt .env.staging.enc --password "team-secret"

# Password from environment variable
export ENVGUARD_PASSWORD="team-secret"
envguard encrypt
envguard decrypt

Add .env.enc to git, add .env to .gitignore. Team members decrypt with the shared password.

envguard hook install β€” Pre-commit Hook

$ envguard hook install
Installed pre-commit hook at .git/hooks/pre-commit

This runs envguard check before every commit. Failed checks block the commit.

βš™οΈ Configuration

Create .envguard.yaml in your project root:

# Paths
env_file: .env
schema_file: .env.schema

# Scanning
scan_paths:
  - src/
  - lib/
  - cmd/
ignore_patterns:
  - node_modules/
  - vendor/
  - dist/
  - build/
  - .git/

# Custom secret patterns
secret_patterns:
  - name: internal_token
    pattern: "MYAPP_[A-Z]+_TOKEN"

# Variables to ignore in validation
ignore_vars:
  - PATH
  - HOME
  - USER
  - SHELL

πŸ—οΈ Tech Stack

  • Language: Go β€” Fast, single binary, cross-platform
  • CLI Framework: Cobra β€” Industry-standard Go CLI
  • Encryption: AES-256-GCM with scrypt key derivation
  • Color Output: fatih/color β€” Cross-platform terminal colors

πŸ“ Project Structure

envguard/
β”œβ”€β”€ cmd/envguard/
β”‚   └── main.go              # Entry point, Cobra commands
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ envfile/
β”‚   β”‚   β”œβ”€β”€ parser.go         # .env file parser
β”‚   β”‚   └── parser_test.go
β”‚   β”œβ”€β”€ scanner/
β”‚   β”‚   β”œβ”€β”€ scanner.go        # Directory walker + interface
β”‚   β”‚   β”œβ”€β”€ javascript.go     # JS/TS patterns
β”‚   β”‚   β”œβ”€β”€ python.go         # Python patterns
β”‚   β”‚   β”œβ”€β”€ golang.go         # Go patterns
β”‚   β”‚   β”œβ”€β”€ rust.go           # Rust patterns
β”‚   β”‚   β”œβ”€β”€ docker.go         # Dockerfile/compose patterns
β”‚   β”‚   └── scanner_test.go
β”‚   β”œβ”€β”€ validator/
β”‚   β”‚   β”œβ”€β”€ validator.go      # Validation engine
β”‚   β”‚   β”œβ”€β”€ schema.go         # Schema parsing
β”‚   β”‚   β”œβ”€β”€ types.go          # Type validators
β”‚   β”‚   └── validator_test.go
β”‚   β”œβ”€β”€ differ/
β”‚   β”‚   β”œβ”€β”€ differ.go         # Env file diffing
β”‚   β”‚   └── differ_test.go
β”‚   β”œβ”€β”€ gitguard/
β”‚   β”‚   β”œβ”€β”€ gitguard.go       # Security checks
β”‚   β”‚   β”œβ”€β”€ patterns.go       # Secret detection patterns
β”‚   β”‚   └── gitguard_test.go
β”‚   β”œβ”€β”€ sync/
β”‚   β”‚   β”œβ”€β”€ crypto.go         # AES-256-GCM encrypt/decrypt
β”‚   β”‚   └── crypto_test.go
β”‚   └── config/
β”‚       β”œβ”€β”€ config.go         # .envguard.yaml parsing
β”‚       └── config_test.go
β”œβ”€β”€ .github/workflows/        # CI + Release
β”œβ”€β”€ .goreleaser.yaml
β”œβ”€β”€ Makefile
β”œβ”€β”€ BACKLOG.md
β”œβ”€β”€ CHANGELOG.md
β”œβ”€β”€ CONTRIBUTING.md
└── README.md

🀝 Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

πŸ“„ License

MIT β€” use it however you want.

Directories ΒΆ

Path Synopsis
cmd
envguard command
Package main is the entry point for the envguard CLI.
Package main is the entry point for the envguard CLI.
internal
config
Package config handles project configuration from .envguard.yaml.
Package config handles project configuration from .envguard.yaml.
differ
Package differ compares two sets of environment variables.
Package differ compares two sets of environment variables.
envfile
Package envfile provides parsing for .env files.
Package envfile provides parsing for .env files.
gitguard
Package gitguard provides security checks for environment files and git repositories.
Package gitguard provides security checks for environment files and git repositories.
scanner
Package scanner scans source code for environment variable references.
Package scanner scans source code for environment variable references.
sync
Package sync provides encryption and decryption for .env files.
Package sync provides encryption and decryption for .env files.
validator
Package validator provides .env file validation against schemas and code usage.
Package validator provides .env file validation against schemas and code usage.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL