How dmno-dev/varlock works
Purpose and Entry Points
Varlock is a TypeScript monorepo for schema-driven, AI-safe environment configuration. .env.schema describes variables, validation, sensitivity, resolution, and plugins; the system resolves values without making secrets part of the shareable schema. The primary product is the varlock CLI, launched through packages/varlock/bin/cli.js and implemented by packages/varlock/src/cli/cli-executable.ts. Its public library/runtime entry is packages/varlock/src/index.ts.
Schema Parsing and Environment Graph
@env-spec/parser supplies the DSL parser and transformations for JSDoc-style decorators, values, expansion, and updates: packages/env-spec-parser/grammar.peggy, packages/env-spec-parser/src/index.ts, and packages/env-spec-parser/src/expand.ts.
The core CLI converts parsed schema plus .env sources into an environment dependency graph. Loader, graph model, and resolver boundaries are concentrated in packages/varlock/src/env-graph/lib/loader.ts, packages/varlock/src/env-graph/lib/env-graph.ts, and packages/varlock/src/env-graph/lib/resolver.ts. This is the primary control flow: locate schema/source files → parse decorators/types → construct dependencies/imports → resolve values/plugins → validate/filter/serialize the result.
CLI Operations and Process Injection
Commands expose graph behavior for initialization, loading, printing, running child processes, scanning, encryption, cache, proxy, and type generation. The main execution-facing paths are packages/varlock/src/cli/commands/load.command.ts, packages/varlock/src/cli/commands/run.command.ts, and packages/varlock/src/cli/commands/scan.command.ts.
run is the important process boundary: resolved values are injected into a spawned program rather than requiring application code to parse configuration. Shared graph-loading and injected-environment reuse mechanisms live in packages/varlock/src/lib/load-graph.ts and packages/varlock/src/lib/injected-env-reuse.ts.
Secret Resolution, Plugins, and Caching
Plugins extend the graph with decorators, functions, types, and remote secret resolvers; plugin discovery/registration is managed by packages/varlock/src/env-graph/lib/plugins.ts and runtime context APIs by packages/varlock/src/plugin-context.ts. Individual packages adapt external secret systems, for example packages/plugins/aws-secrets/src/plugin.ts, packages/plugins/1password/src/plugin.ts, and packages/plugins/kubernetes/src/plugin.ts.
Resolution caching is a distinct persistence boundary, including per-key storage and plugin cache access: packages/varlock/src/lib/cache/cache-store.ts, packages/varlock/src/lib/cache/env-key-cache-store.ts, and packages/varlock/src/lib/cache/plugin-cache-accessor.ts.
Runtime Leak Protection and Framework Builds
Application-side runtime support initializes environment state and protects output by redacting sensitive values from console, response, and stream paths: packages/varlock/src/runtime/init-server.ts, packages/varlock/src/runtime/lib/redaction.ts, and packages/varlock/src/runtime/patch-response.ts.
Framework integrations modify build/runtime behavior rather than being standalone applications. Key adapters are Vite (packages/integrations/vite/src/index.ts), Next.js webpack/Turbopack (packages/integrations/nextjs/src/plugin.ts, packages/integrations/nextjs/src/turbopack-runtime-inject.ts), and Cloudflare/Wrangler (packages/integrations/cloudflare/src/varlock-wrangler.ts).
Local Encryption and Native Trust Boundary
Local encryption delegates key operations to platform-specific native binaries/daemons. JavaScript orchestration and binary selection are in packages/varlock/src/lib/local-encrypt/index.ts, packages/varlock/src/lib/local-encrypt/daemon-client.ts, and packages/varlock/src/lib/local-encrypt/binary-resolver.ts. The Rust implementation provides crypto, IPC, daemon, and OS key-store backends in packages/encryption-binary-rust/src/main.rs, packages/encryption-binary-rust/src/daemon.rs, and packages/encryption-binary-rust/src/key_store/mod.rs; macOS has a Swift Secure Enclave/Keychain implementation at packages/encryption-binary-swift/swift/Sources/VarlockEnclave/main.swift.
Distribution and Supporting Surfaces
The repository ships npm packages, native platform helpers, a Docker image, a VS Code language extension, and a documentation MCP service. Delivery artifacts are rooted at Dockerfile, packages/native-helpers/platforms.ts, packages/vscode-plugin/src/extension.ts, and packages/varlock-docs-mcp/src/index.ts. The Astro documentation site is separately deployed with Cloudflare configuration in packages/varlock-website/astro.config.ts and packages/varlock-website/wrangler.jsonc.
Main entry points: resolver.ts Value resolver · run.command.ts Load, run, scan commands · loader.ts Graph loader · load-graph.ts Shared graph loading
Components 21
CLI and resolution
- .env.schema and .env sources · Shareable schema stays separate from secret values.
- Env Spec parser
packages/env-spec-parser/src/index.ts - Schema expansion
packages/env-spec-parser/src/expand.ts - varlock CLI
packages/varlock/src/cli/cli-executable.ts - Load, run, scan commands
packages/varlock/src/cli/commands/run.command.ts - Graph loader
packages/varlock/src/env-graph/lib/loader.ts - Environment graph · Models variables, imports, and dependencies.
packages/varlock/src/env-graph/lib/env-graph.ts - Value resolver · Resolves, validates, filters, and serializes values.
packages/varlock/src/env-graph/lib/resolver.ts - Shared graph loading
packages/varlock/src/lib/load-graph.ts - Spawned process environment · Run injects resolved values into child programs.
packages/varlock/src/lib/injected-env-reuse.ts
Plugins and integrations
- Plugin registry
packages/varlock/src/env-graph/lib/plugins.ts - Plugin context APIs
packages/varlock/src/plugin-context.ts - Remote secret plugins · Adapters include AWS Secrets, 1Password, and Kubernetes.
packages/plugins/aws-secrets/src/plugin.ts - Framework adapters · Vite, Next.js, and Cloudflare/Wrangler adapt configuration at build and runtime.
packages/integrations/nextjs/src/plugin.ts
Runtime and trust
- Resolution cache · Provides per-key and plugin cache access.
packages/varlock/src/lib/cache/cache-store.ts - Runtime initialization
packages/varlock/src/runtime/init-server.ts - Sensitive output redaction · Redacts console, response, and stream output.
packages/varlock/src/runtime/lib/redaction.ts - Local encryption client
packages/varlock/src/lib/local-encrypt/index.ts - Native crypto and key stores · Rust daemon and OS key-store backends protect local key operations.
packages/encryption-binary-rust/src/main.rs
Distribution surfaces
- Varlock library API
packages/varlock/src/index.ts - Shipping surfaces · Docker, native helpers, VS Code extension, docs MCP, and Astro docs site.
Dockerfile
Connections 21
- varlock CLI → Load, run, scan commands: dispatches
- Load, run, scan commands → Shared graph loading: loads configuration
- Load, run, scan commands → Spawned process environment: run injects
- Shared graph loading → Graph loader: uses
- .env.schema and .env sources → Env Spec parser: parsed as DSL
- Env Spec parser → Schema expansion: transforms
- Schema expansion → Graph loader: supplies schema
- Graph loader → Environment graph: constructs
- Environment graph → Value resolver: resolved by
- Plugin registry → Remote secret plugins: registers
- Plugin context APIs → Remote secret plugins: runtime APIs
- Plugin registry → Value resolver: extends resolution
- Remote secret plugins → Value resolver: retrieve secrets
- Resolution cache → Value resolver: cached values
- Value resolver → Spawned process environment: resolved environment
- Value resolver → Runtime initialization: initializes state
- Runtime initialization → Sensitive output redaction: protects output
- Local encryption client → Native crypto and key stores: delegates keys and IPC
- Varlock library API → Shared graph loading: exposes loading
- Framework adapters → Runtime initialization: wire runtime behavior
- Shipping surfaces → Varlock library API: distributes