Skip to content

Commit d29efd1

Browse files
Improve getting started docs (#218)
* better getting started docs * add getting started intro/overview * update homepage links --------- Co-authored-by: Theo Ephraim <[email protected]>
1 parent f300dc4 commit d29efd1

File tree

15 files changed

+217
-16
lines changed

15 files changed

+217
-16
lines changed

packages/varlock-website/astro.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ export default defineConfig({
7474
sidebar: [
7575
{
7676
label: 'Getting Started',
77-
items: [{ label: 'Installation', slug: 'getting-started/installation' }],
77+
items: [
78+
{ label: 'Introduction', slug: 'getting-started/introduction' },
79+
{ label: 'Installation', slug: 'getting-started/installation' },
80+
{ label: 'Usage', slug: 'getting-started/usage' },
81+
{ label: 'Migration', slug: 'getting-started/migration' },
82+
{ label: 'Wrapping up', slug: 'getting-started/wrapping-up' },
83+
],
7884
},
7985
{
8086
label: 'Guides',

packages/varlock-website/src/content/docs/getting-started/installation.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Installation
3-
description: How to install and set up varlock in your project
3+
description: How to install and set up Varlock in your project
44
---
55

66
import ExecCommandWidget from "@/components/ExecCommandWidget.astro";
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Introduction
3+
description: Introduction to Varlock - declarative schema for your environment variables
4+
---
5+
6+
Varlock is a universal configuration/secrets/environment variable management tool built on top of the [@env-spec](/env-spec/overview/) specification. It provides a comprehensive set of features out of the box that simplify managing, validating, and securing your environment configuration. Whether you need type-safe environment variables, multi-environment management, secure secret handling, or leak prevention, Varlock lets you focus on building your application instead of wrestling with configuration. While it is written in TypeScript, it is language and framework agnostic, and meant to be used in any project that needs configuration at build or boot time, usually passed in via environment variables.
7+
8+
## Features
9+
10+
Varlock aims to be the most comprehensive environment variable management tool. It provides a wide range of features out of the box:
11+
12+
- **[Validation & Type Safety](/reference/data-types/)** - Powerful validation capabilities with clear error messages, plus automatic type generation for IntelliSense support
13+
- **[Security](/guides/secrets/)** - Automatic log redaction for sensitive values and leak detection in bundled code and server responses
14+
- **[Multi-Environment Management](/guides/environments/)** - Flexible environment handling with support for environment-specific files, local overrides, and value composition
15+
- **[Secure Secrets](/guides/secrets/)** - Load secrets from external providers like [1Password](/plugins/1password/) via [plugins](/plugins/overview/) or any CLI tool using [exec()](/reference/functions/#exec)
16+
- **[Value Composition](/reference/functions/)** - Compose values together using functions, references, and external data sources
17+
- **[Framework Integrations](/integrations/overview/)** - Official integrations for Next.js, Vite, Astro, and more, plus support for any language via `varlock run`
18+
- **[Replacement for dotenv](/guides/migrate-from-dotenv/)** - Can be used as a direct replacement for `dotenv` in most projects with minimal code changes
19+
- **[AI-Friendly](/guides/ai-tools/)** - Built with AI-assisted development in mind, helping prevent accidental secret leaks to AI agents and allowing a schema-driven approach that is easier for AI to understand and remediate
20+
21+
## AI Tooling
22+
23+
### Docs MCP
24+
25+
Varlock provides a Docs MCP server that allows AI tools to search and understand the Varlock documentation. This makes it easier for AI assistants to help you integrate and use Varlock in your projects.
26+
27+
See the [MCP guide](/guides/mcp/#docs-mcp) for setup instructions for Cursor, Claude, Opencode, VS Code, and other MCP-compatible tools.
28+
29+
### LLMs.txt
30+
31+
Varlock also provides an `LLMs.txt` file that helps AI models understand how to integrate and interact with your environment variable configuration. See it at [https://varlock.dev/llms.txt](https://varlock.dev/llms.txt).
32+
33+
## Next Steps
34+
35+
Ready to get started? Check out the [Installation](/getting-started/installation/) guide to set up Varlock in your project.
36+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: Migration
3+
description: An overview if you have existing .env files and want to migrate to Varlock
4+
---
5+
6+
import ExecCommandWidget from "@/components/ExecCommandWidget.astro";
7+
8+
## Loading env vars using Varlock
9+
10+
### Migration from dotenv (Node.js)
11+
12+
In a [Node.js](/integrations/javascript/) app if you are already calling `dotenv/config`, you can replace it with `varlock/auto-load`.
13+
14+
```diff title="index.js" lang="js"
15+
- import 'dotenv/config';
16+
+ import 'varlock/auto-load';
17+
```
18+
19+
In some cases where `dotenv` is being called deep under the hood by another dependency, you may instead want to swap it in as a dependency override. See our [migrate from dotenv](/guides/migrate-from-dotenv/) guide for more information.
20+
21+
### Within a framework
22+
23+
We must replace framework's existing `.env` logic with Varlock. Our [framework integrations](/integrations/overview/) handle most of the work for you. After [installation](/getting-started/installation/), simply follow the instructions in the relevant integration guide to set up Varlock in your project. Usually this involves adding a new plugin to the existing build system or framework's config file.
24+
25+
### Minimal setup
26+
27+
In some cases, a code-level integration may be challenging or impossible. In this case you can use [`varlock run`](/reference/cli-commands/#run) to boot your application with env vars injected from Varlock. For example `varlock run -- your-app`. Sometimes you may need to use this alongside a deeper integration, for example to feed env vars into external tools or additional scripts.
28+
29+
30+
31+
## Using `varlock/env`
32+
33+
If you're currently using `import.meta.env` or `process.env`, your code will still work after switching to Varlock. However, we recommend using varlock's `ENV` object for better type-safety and an improved developer experience.
34+
35+
```diff title="index.js" lang="js"
36+
// Before (import.meta.env)
37+
- console.log(import.meta.env.SOMEVAR);
38+
39+
// After (ENV)
40+
import { ENV } from 'varlock/env';
41+
+ console.log(ENV.SOMEVAR);
42+
```
43+
44+
![intellisense](../../../assets/demo-images/intellisense.png)
45+
46+
See our [integrations](/integrations/overview/) section for more information.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Usage
3+
description: How to use Varlock in your project
4+
---
5+
6+
import ExecCommandWidget from "@/components/ExecCommandWidget.astro";
7+
8+
## Basics
9+
10+
The basic workflow for using Varlock is to:
11+
12+
1. Run [`varlock init`](/reference/cli-commands/#init) to set up your `.env.schema` file
13+
2. Run [`varlock load`](/reference/cli-commands/#load) to debug and refine your .env file(s)
14+
3. Use Varlock to load, validate, and inject env vars into your application, either:
15+
- Use an [existing framework / tool integration](/integrations/overview/) that automatically calls Varlock under the hood (_recommended_)
16+
- Use `import 'varlock/auto-load'` in a backend JavaScript/TypeScript project
17+
- Boot your command via [`varlock run`](/reference/cli-commands/#run)<br/>(_necessary for non-JS/TS projects, or feeding env vars to external tools_)
18+
19+
20+
## CLI Commands
21+
22+
### `varlock load`
23+
24+
<ExecCommandWidget command="varlock load" />
25+
26+
Validates your environment variables according to your `.env.schema` and associated `.env.*` files, and prints the results.
27+
28+
Useful for debugging locally, and in CI to print out a summary of env vars, also when you're authoring your `.env.schema` file and want immediate feedback.
29+
30+
:::tip
31+
Our [integrations](/integrations/overview) all use `varlock load` under the hood, so you'll get the same developer experience, but typically they will only let you know if there are errors, rather than the full summary.
32+
:::
33+
34+
35+
See the [`varlock load` CLI Reference](/reference/cli-commands/#load) for more information.
36+
37+
### `varlock run`
38+
39+
<ExecCommandWidget command="varlock run -- <your-command>" />
40+
41+
Executes a command in a child process, injecting your resolved and validated environment variables. This is useful when a code-level integration is not possible. For example, if you're using a database migration tool, you can use `varlock run` to run the migration tool with the correct environment variables. Or if you're using a non-js/ts language, you can use `varlock run` to run a command and inject validated environment variables.
42+
43+
44+
See the [`varlock run` CLI Reference](/reference/cli-commands/#run) for more information.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: Wrapping up
3+
description: How to get your project ready for production and collaboration
4+
---
5+
6+
import ExecCommandWidget from "@/components/ExecCommandWidget.astro";
7+
8+
## Next steps with your schema
9+
10+
With a more flexible env var toolkit, after an initial migration, you may be tempted to take advantage
11+
of Varlock's features to improve your developer experience and security posture.
12+
13+
- Move more configuration constants out of application code and into your `.env` files
14+
- Reduce the number of of env-style checks in your code, favouring individual flags, with a default value set based on the current env
15+
- Add deeper validation, more thorough comments, and additional docs links to each env var within your schema
16+
- Compose values together to keep your configuration DRY
17+
- Use [imports](/guides/import/) to share common configuration across a monorepo, or to break up a large `.env.schema`
18+
- Reduce secret sprawl, by loading secrets from a single source of truth, instead of injecting them from your CI/hosting platform
19+
20+
21+
## Repo setup
22+
23+
### `.gitignore`
24+
25+
Depending on your setup you will want to update your `.gitignore` to _not_ ignore your `.env.schema` file and any other `.env.xxx` files that can now be safely committed to your repo if they don't contain secrets (which they shouldn't).
26+
27+
If using [generated types](/reference/root-decorators/#generatetypes), we also recommend that you ignore the generated file (usually `env.d.ts` in TypeScript) as it is dynamically generated based the hierarchy of env files being loaded on each individual machine.
28+
29+
```diff title=".gitignore"
30+
31+
# Include .env.schema, .env.<dev|preview|prod|...> file
32+
# exclude local overrides
33+
-.env.*
34+
+.env.local
35+
+.env.*.local
36+
37+
# Exclude generated env types file
38+
+env.d.ts
39+
```
40+
41+
:::tip
42+
Depending on the [AI Tools](/guides/ai-tools/) you use, you may need to add a similar rule to allow `.env.schema` to be modified. For example, in `.cursorignore`.
43+
:::
44+
45+
### Monorepos
46+
47+
Consider how you can reuse and modularize your schema if you have a monorepo or multi-service setup. See the [Imports](/guides/import/) guide for more information.
48+
49+
## Deployment
50+
51+
### CI/CD platforms
52+
53+
It may be useful to validate your schema in CI/CD pipelines, especially if you want to validate configurations that you don't have access to locally (e.g. Staging or Production). You can do this manually by running `varlock load` in your pipeline. And if you're using GitHub Actions, you can use the [Varlock GitHub Action](/integrations/github-action/) to validate your schema automatically.
54+
55+
:::tip
56+
Having a well architected multi-environment setup is key to healthy CI/CD workflows. See the [Environments](/guides/environments/) guide for more information.
57+
:::
58+
59+
### Production deployments
60+
61+
Because varlock supports loading environment variables from the environment itself or via a [function](/reference/functions/) in your `.env.schema`, there are a few different approaches.
62+
63+
If you're already using your deployment platform's environment variable management, you may not need to do anything to benefit from varlock's validation and security features. If you have a multi-environment setup, you may need to set the `currentEnv` environment flag to the correct environment.
64+
65+
```bash
66+
APP_ENV=production varlock run -- your-production-command
67+
```
68+
69+
If you're not using your deployment platform's environment variable management, you may consider using one of our [plugins](/plugins/overview/) to securely load environment variables from a secret storage system such as [1Password](/plugins/1password/).

packages/varlock-website/src/content/docs/guides/telemetry.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ The anonymous usage data helps us:
6868
- Make informed decisions about future development
6969
- Prioritize bug fixes and new features
7070

71-
If you have any questions about our analytics or privacy practices, please [start a discussion](https://github.com/dmno-dev/varlock/discussions) on GitHub.
71+
If you have any questions about our analytics or privacy practices, please [start a discussion](https://github.com/dmno-dev/varlock/discussions) on GitHub.

packages/varlock-website/src/content/docs/integrations/astro.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ If you find you are not getting type completion on `ENV`, you may need to add yo
9696

9797
Even in a static front-end project, you may have other scripts in your project that rely on sensitive config.
9898

99-
You can use [`varlock run`](/reference/cli-commands/#varlock-run) to inject resolved config into other scripts as regular env vars.
99+
You can use [`varlock run`](/reference/cli-commands/#run) to inject resolved config into other scripts as regular env vars.
100100

101101
<ExecCommandWidget command="varlock run -- node ./script.js" showBinary={false} />
102102

packages/varlock-website/src/content/docs/integrations/javascript.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ If you are using [`dotenv`](https://www.npmjs.com/package/dotenv), or a package
3434

3535
## Boot via `varlock run`
3636

37-
A less invasive way to use varlock with your application is to run your application via [`varlock run`](/reference/cli-commands/#varlock-run).
37+
A less invasive way to use varlock with your application is to run your application via [`varlock run`](/reference/cli-commands/#run).
3838

3939
```bash
4040
varlock run -- <your-command>

packages/varlock-website/src/content/docs/integrations/nextjs.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ _you may need to adjust if you don't want to copy certain .local files_
299299

300300

301301
Standalone builds do not copy dependency binaries, and varlock depends on the CLI to load.
302-
So wherever you are booting your standalone server, you will also need to [install the varlock binary](/getting-started/installation/) and boot your server via [`varlock run`](/reference/cli-commands/#varlock-run)
302+
So wherever you are booting your standalone server, you will also need to [install the varlock binary](/getting-started/installation/) and boot your server via [`varlock run`](/reference/cli-commands/#run)
303303

304304
```bash
305305
varlock run -- node .next/standalone/server.js

0 commit comments

Comments
 (0)