---
name: "env-schema-fluent-json-validation"
description: "Validate and parse process.env environment variables on application startup with JSON Schema."
metadata:
  author: "Fastify"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "validate process.env schema"
  - "env-schema type coercion"
  - "fail startup missing env"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# env-schema & Fluent JSON Schema Environment Validation

Configures Fastify env-schema: defining expected environment variables, data types (string, integer, boolean), default values, required fields, and preventing server boot when critical keys are missing.

## When to Invoke
Invoke this skill whenever you need to:
- validate process.env schema
- env-schema type coercion
- fail startup missing env

## Execution SOP & Rules
1. Define schema: const schema = S.object().prop('PORT', S.number().default(3000)).prop('DATABASE_URL', S.string().required()).valueOf().
2. Parse and validate: const config = envSchema({ schema, dotenv: true }).
3. Export validated config object with full TypeScript typing across application services.
4. Verify server immediately halts on missing required secrets without throwing obscure runtime errors later.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
