# env

Validated environment contracts: responsibilities, supported exports and extension points.

## Purpose [#purpose]

Separate server, web, native, email, storage and MCP resource entries validate their own configuration. Server secrets are parsed with Zod through the env helpers. Public web and native variables are intentionally limited. `runtime-flags` reads the deployment switches (`DB_TENANT_PIPELINE`, `TENANCY_PROBE`, `NATIVE_DEV_SCHEME`, `TRUSTED_PROXY_HEADER`, `TRUSTED_PROXIES`) on every call, without loading the whole server contract. `email` and `storage` work the same way: `server` validates their variables at startup, and `packages/email` / `packages/storage` parse them when they send or open a handle, so importing either package validates nothing. `error-reporting` reads the error tracker's settings (`ERROR_REPORTING_DSN`, `ERROR_REPORTING_ENVIRONMENT`, `ERROR_REPORTING_RELEASE`) and turns reporting off with one warning instead of failing on a malformed DSN; its `parseErrorReportingDsn` checks the public `VITE_`/`EXPO_PUBLIC_` DSNs the same way. The Feedback inbox reads `FEEDBACK_GITHUB_REPO` and `FEEDBACK_GITHUB_TOKEN` (both optional; "Create GitHub issue" appears only with both, well formed) and `ERROR_REPORTING_DASHBOARD_URL` (the tracker's dashboard, for the link to a report's error event; it falls back to `ERROR_REPORTING_URL`), see [Feedback reports](/docs/features/feedback).

## Public exports [#public-exports]

| Subpath             | Target                     |
| ------------------- | -------------------------- |
| `./server`          | `./src/server.ts`          |
| `./mcp-resource`    | `./src/mcp-resource.ts`    |
| `./web`             | `./src/web.ts`             |
| `./native`          | `./src/native.ts`          |
| `./email`           | `./src/email.ts`           |
| `./storage`         | `./src/storage.ts`         |
| `./runtime-flags`   | `./src/runtime-flags.ts`   |
| `./error-reporting` | `./src/error-reporting.ts` |

These paths come from `packages/env/package.json`. A `.` entry is the package root. Conditional targets distinguish platform or type resolution; consumers should import the subpath, not its source file.

## How to extend [#how-to-extend]

Add a variable to its correct contract and setup/deploy path. Never add a secret to a VITE* or EXPO_PUBLIC* contract. Test missing, blank and malformed values; preserve existing credentials when rerunning setup.

Read the [validated environment contracts guide](/docs/development/environments) for the full flow.

## Key files [#key-files]

- [`packages/env/src/runtime-flags.ts`](https://github.com/CarlosZiegler/template-cloudflare/blob/main/packages/env/src/runtime-flags.ts)
- [`packages/env/package.json`](https://github.com/CarlosZiegler/template-cloudflare/blob/main/packages/env/package.json)
