agentleFS
param087param087/saas-starter-skills/skills/environment-and-config/SKILL.md

environment-and-config

Skill2 starsChanged 6 months agoMITView on GitHub

Use when wiring up env vars, secrets, or runtime config — validate them with zod at boot, split server-only from public (NEXT_PUBLIC_) values, and fail fast with a clear error instead of a cryptic undefined at runtime.

  • Reads credentials

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 0 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Import env everywhere instead of process.env.

    line 46
  2. Very specific:

    Only NEXT_PUBLIC_* vars reach the browser.

    line 50
  3. Very specific:

    Keep a client schema separate so it's obvious which values are public.

    line 51
  4. Very specific:

    Commit a .env.example with every key (empty or dummy values) — it's the contract for new devs and CI.

    line 56
  5. Very specific:

    Add .env*.local to .gitignore.

    line 57

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Environment & Config

Overview

Untyped process.env is a runtime landmine: a missing STRIPE_SECRET_KEY shows up as undefined three layers deep at 2am. Validate the whole environment once at boot with zod, expose a typed env object, and make a misconfiguration a startup crash with an actionable message.

When to use

  • Adding any new secret or config value.
  • A bug traces back to an undefined/empty env var.
  • You need to keep server secrets out of the client bundle.

The pattern

// src/env.ts
import { z } from "zod";

const server = z.object({
  DATABASE_URL: z.string().url(),
  AUTH_SECRET: z.string().min(32),
  STRIPE_SECRET_KEY: z.string().startsWith("sk_"),
  STRIPE_WEBHOOK_SECRET: z.string().startsWith("whsec_"),
  RESEND_API_KEY: z.string().startsWith("re_"),
  NODE_ENV: z.enum(["development", "test", "production"]).default("development"),
});

const client = z.object({
  NEXT_PUBLIC_APP_URL: z.string().url(),
});

const parsed = server.merge(client).safeParse(process.env);
if (!parsed.success) {
  console.error("❌ Invalid environment:", parsed.error.flatten().fieldErrors);
  throw new Error("Invalid environment variables");
}

export const env = parsed.data;

Import env everywhere instead of process.env. TypeScript now knows every key exists and its type.

Server vs client

  • Only NEXT_PUBLIC_* vars reach the browser. Never prefix a secret with NEXT_PUBLIC_.
  • Keep a client schema separate so it's obvious which values are public.
  • For strict isolation, put import "server-only" in a env.server.ts and only merge public keys into a client-safe export.

Operational hygiene

  • Commit a .env.example with every key (empty or dummy values) — it's the contract for new devs and CI.
  • Add .env*.local to .gitignore; never commit real secrets.
  • In CI/prod, set vars in the platform (Vercel/Doppler/1Password), not in files.

Pitfalls

  • Reading process.env directly — bypasses validation and types; you lose the safety net.
  • NEXT_PUBLIC_ on a secret — it gets inlined into client JS and shipped to every visitor.
  • Validating lazily per-request — validate once at module load so boot fails loudly.
  • No .env.example — onboarding becomes guesswork and CI breaks mysteriously.
  • Trusting defaults in prod — require critical vars; only default the harmless ones.

Hand-off

A typed env that the whole app trusts. database-schema, authentication, payments-stripe, and transactional-email all read their secrets from here.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.