RuleStack

Configs

Stacks

Compare

Diff

RuleStack

Configs

Stacks

Compare

Diff

Read API

RuleStack

Configs

Stacks

Compare

Diff

Read API

Configs/Cursor rules/poglesbyg/htsf-consultant

Cursor rule

.cursor/rules/env-vars.mdc

How to add env vas or environmental variables to the app.

Cursor rules

Quality

63/100

Scores the file, not the repository.

Length

640 words

0 headings · 7 code blocks

Repository

0

— · pushed 396 days ago

Last changed

3 days ago

First indexed 3 days ago.
poglesbyg/htsf-consultant/.cursor/rules/env-vars.mdcRawGitHub
1---
2description: How to add env vas or environmental variables to the app.
3globs:
4alwaysApply: false
5---
6**Environment Variables (Astro Way)**: Astro provides type-safe environment variables. Follow these steps:
7 
8 **1. Define in astro.config.ts:**
9```typescript
10 // astro.config.ts
11 env: {
12 schema: {
13 MY_ENV_VAR: envField.string({
14 context: 'server', // 'server' or 'client'
15 access: 'secret', // 'secret' or 'public'
16 optional: false, // true if the variable is optional
17 }),
18 PUBLIC_API_URL: envField.string({
19 context: 'client',
20 access: 'public',
21 optional: false,
22 }),
23 },
24 },
25```
26 
27 **2. Import and use in your code:**
28```typescript
29 // Server-side variables (access: 'secret', context: 'server')
30 import { DATABASE_URL, MAILGUN_WEBHOOK_SIGNING_KEY } from 'astro:env/server'
31
32 // Client-side variables (access: 'public', context: 'client')
33 import { LIVEKIT_API_KEY } from 'astro:env/client'
34```
35 
36 **Key guidelines:**
37 - **Server variables** (`context: 'server'`): Only accessible in server-side code, import from `astro:env/server`
38 - **Client variables** (`context: 'client'`): Accessible in both client and server code, import from `astro:env/client`
39 - **Secret variables** (`access: 'secret'`): Should never be exposed to the client
40 - **Public variables** (`access: 'public'`): Can be safely exposed to the client
41 - All environment variables are type-safe and validated at build time
42 - Ignore linter errors on recently created env vars. Astro needs to rerun its dev server to update its internal types references first.
43 
44 **Example usage:**
45```typescript
46 // apps/web/src/server/db.ts
47 import { setupDb } from '@app/db'
48 import { DATABASE_URL } from 'astro:env/server'
49
50 export const db = setupDb({
51 connectionString: DATABASE_URL,
52 })
53```
54
55 
56**Passing Environment Variables to tRPC**: To make environment variables available in tRPC procedures, follow this pattern:
57 
58 **1. Define the Env interface in context.ts:**
59```typescript
60 // packages/api/src/context.ts
61 export interface Env {
62 appEndpoint: string
63 gcsProjectId: string
64 ...
65 }
66 
67 export interface Context {
68 db: Kysely<DB>
69 env: Env
70 session: Session | null
71 user: SelectableUser | null
72 }
73```
74 
75 **2. Pass environment variables in the tRPC handler:**
76```typescript
77 // apps/web/src/pages/api/trpc/[trpc].ts
78 import { LIVEKIT_API_KEY } from 'astro:env/client'
79 import {
80 GCS_BUCKET,
81 GCS_CLIENT_EMAIL,
82 GCS_PRIVATE_KEY,
83 GCS_PROJECT_ID,
84 GEMINI_API_KEY,
85 LIVEKIT_API_SECRET,
86 LIVEKIT_URL,
87 PERPLEXITY_API_KEY,
88 } from 'astro:env/server'
89 
90 async function createContext({ req }: CreateContextOptions): Promise<Context> {
91 const env: Env = {
92 appEndpoint: getAppEndpoint(req),
93 gcsProjectId: GCS_PROJECT_ID,
94 ...
95 }
96 
97 return { db, session: session ?? null, env, user }
98 }
99```
100 
101 **3. Access environment variables in tRPC procedures:**
102```typescript
103 // In any tRPC procedure
104 export const myProcedure = protectedProcedure
105 .input(z.object({ /* ... */ }))
106 .mutation(async ({ ctx, input }) => {
107 // Access env vars through ctx.env
108 const gcsProjectId = ctx.env.gcsProjectId
109 // ... use the environment variables
110 })
111```
112 
113 **Key guidelines for tRPC env vars:**
114 - Always define new env vars in the `Env` interface in `context.ts`
115 - Import env vars from Astro's env system in the tRPC handler
116 - Map them to the `env` object in `createContext`
117 - Access them via `ctx.env` in any tRPC procedure
118 - This ensures type safety and centralized env var management
119 
120**Build and CI Configuration**: When adding new environment variables, you must also update build and CI configuration files:
121 
122 **1. Update turbo.json:**
123 Add new environment variables to the `env` array under the `build` task so Turborepo can properly cache builds:
124```json
125 // turbo.json
126 {
127 "tasks": {
128 "build": {
129 "outputs": ["dist/**"],
130 "dependsOn": ["^build"],
131 "env": [
132 "DATABASE_URL",
133 "AUTH_SECRET",
134 "MY_NEW_ENV_VAR", // Add your new env var here
135 // ... other env vars
136 ]
137 }
138 }
139 }
140```
141 
142 **2. Update GitHub Actions (if needed):**
143 If your environment variable needs to be available during CI/CD builds or tests, ensure it's properly configured in your GitHub Actions workflows. This may involve:
144 - Adding the env var to repository secrets (for sensitive values)
145 - Setting the env var in workflow files (for public values)
146 - Updating setup actions if they need access to the env var
147 
148 **Key guidelines for build/CI config:**
149 - **Always** add new env vars to `turbo.json` if they affect build output
150 - Only add sensitive env vars to GitHub repository secrets, never commit them to workflow files
151 - Test your builds locally with the new env vars before pushing
152 - Consider whether the env var is needed at build time vs runtime
153 - Document any new env vars in your project's README or deployment docs
154 

Commands it names

  • turbo.json

What it covers

securitydo-not

Stack — with the evidence

typescript

(1.00)

tailwind

(1.00)

turborepo

(1.00)

eslint

(1.00)

node

(0.70)

react

(0.70)

astro

(0.70)

postgres

(0.70)

vitest

(0.70)

javascript

(0.60)

monorepo

(0.60)

pnpm

(0.60)

docker

(0.60)

github-actions

(0.60)

Glob targeting

  • [object Object]

Format

Cursor rules

The most expressive format here. Many small .mdc files, each with frontmatter declaring when it should load, so a rule about migrations only enters context when a migration is open. Costs the most to maintain and only one editor reads it.

What the corpus says about it

Repository

Owner
poglesbyg
Language
—
License
—
Archived
no

All configs in this repo

Also in poglesbyg/htsf-consultant

Diff this repo’s formats

One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?

The other instruction files in this repository
RepositoryFormatStackCoversScoreChanged
poglesbyg/htsf-consultant.cursor/rules/always.mdc · 0Cursor rulestypescripttailwind+12test35/1003 days ago
poglesbyg/htsf-consultant.cursor/rules/code-conventions.mdc · 0Cursor rulestypescripttailwind+12setuplint-formatstyledo-not+180/1003 days ago
poglesbyg/htsf-consultant.cursor/rules/crispr-algorithms.mdc · 0Cursor rulestypescripttailwind+12deployment44/1003 days ago
poglesbyg/htsf-consultant.cursor/rules/data-models.mdc · 0Cursor rulestypescripttailwind+12typessecuritydatabase44/1003 days ago
poglesbyg/htsf-consultant.cursor/rules/database.mdc · 0Cursor rulestypescripttailwind+12typesdatabasedo-not61/1003 days ago
poglesbyg/htsf-consultant.cursor/rules/react.mdc · 0Cursor rulestypescripttailwind+12style34/1003 days ago
poglesbyg/htsf-consultant.cursor/rules/shadcn-components.mdc · 0Cursor rulestypescripttailwind+12ui63/1003 days ago
poglesbyg/htsf-consultant.cursor/rules/smart-polling.mdc · 0Cursor rulestypescripttailwind+12no sections44/1003 days ago
poglesbyg/htsf-consultant.cursor/rules/trpc-architecture.mdc · 0Cursor rulestypescripttailwind+12archtypes56/1003 days ago
poglesbyg/htsf-consultant.cursor/rules/trpc.mdc · 0Cursor rulestypescripttailwind+12no sections40/1003 days ago
poglesbyg/htsf-consultant.cursor/rules/typescript.mdc · 0Cursor rulestypescripttailwind+12styletypesdo-not55/1003 days ago
poglesbyg/htsf-consultant.cursorrules · 0.cursorrulestypescripttailwind+12archdeploymentagent-behaviour48/1003 days ago
Diff against .cursor/rules/always.mdc Diff against .cursor/rules/code-conventions.mdc Diff against .cursor/rules/crispr-algorithms.mdc Diff against .cursor/rules/data-models.mdc Diff against .cursor/rules/database.mdc Diff against .cursor/rules/react.mdc Diff against .cursor/rules/shadcn-components.mdc Diff against .cursor/rules/smart-polling.mdc Diff against .cursor/rules/trpc-architecture.mdc Diff against .cursor/rules/trpc.mdc Diff against .cursor/rules/typescript.mdc Diff against .cursorrules

Similar configs

Same format, overlapping stack, ranked by quality.

Same format, overlapping stack, ranked by quality
RepositoryFormatStackCoversScoreChanged
hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126Cursor rulesgobun+5setupbuildtestlint-format+6100/1003 days ago
TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45Cursor rulestypescriptpytest+15testlint-formatstylearch+5100/1003 days ago
markstev/mark-starter.cursor/rules/frontend.mdc · 0Cursor rulestypescriptturborepo+14setuptestlint-formatstyle+699/1003 days ago
Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0Cursor rulestypescriptturborepo+13setuptestlint-formatstyle+799/1003 days ago
dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0Cursor rulestypescriptturborepo+15setuptestlint-formatstyle+799/1003 days ago
deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1Cursor rulestypescriptnextjs+5setuptestlint-formatstyle+799/1003 days ago
langflow-ai/langflow.cursor/rules/docs_development.mdc · 153kCursor rulespythonnode+16setupbuildtestlint-format+797/1003 days ago
TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45Cursor rulestypescriptpytest+15teststyletesting-strategysecurity+397/1003 days ago
RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack

RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack

RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack