4천자 넘습니다! →
2 shot prompt
/goal
MAIN_GOAL:
Implement an environment variable management recipe for DB / EMAIL service integration across local, preview, and production environments. Use the existing project stack, framework, deployment platform, CI system, ORM, and env-loading conventions unless they conflict with the requirements below. Do not omit any requirement.
OBJECTIVE:
Create a reproducible environment configuration system with:
1. tracked .env.example only
2. ignored real .env files
3. local-only .env.local
4. preview-scoped deployment environment variables
5. production-scoped deployment environment variables
6. CI-only direct DB secrets for migrations
7. runtime/build-time environment validation
8. clear local / preview / production review and operation flow
ENV FILE REQUIREMENTS:
Create or update .env.example at the project root.
.env.example must be committed to git and must contain keys only with empty string values:
DATABASE_URL=""
MAIL_API_KEY=""
MAIL_FROM=""
ADMIN_EMAIL=""
PUBLIC_APP_URL=""
Do not put real secrets or real service URLs into .env.example.
GITIGNORE REQUIREMENTS:
Ensure .gitignore contains:
.env*
!.env.example
This means all real env files are ignored, but .env.example is tracked.
LOCAL ENV REQUIREMENTS:
Create or document .env.local for local development.
Required local example:
DATABASE_URL="postgres://local-user:local-pass@localhost:5432/localdb"
MAIL_API_KEY=""
MAIL_FROM=""
ADMIN_EMAIL="[email protected]"
PUBLIC_APP_URL="<http://localhost:3000>"
Rules:
1. local uses a local DB only.
2. local must not send real emails.
3. local MAIL_API_KEY must be empty by default.
4. local MAIL_FROM may be empty.
5. local validation must require DATABASE_URL only.
6. local must not require MAIL_API_KEY.
7. local must not require MAIL_FROM.
8. local must not require PUBLIC_APP_URL unless the existing framework needs it for local URL generation.
9. local must treat email sending as disabled even if a MAIL_API_KEY is accidentally present, if the existing email policy uses a deployment-environment gate.
PREVIEW ENV REQUIREMENTS:
Configure or document Preview-scope deployment environment variables.
Required Preview-scope variables:
DATABASE_URL="preview DB general connection URL"
MAIL_API_KEY="preview Resend API key"
MAIL_FROM="Service Preview <[email protected]>"
ADMIN_EMAIL="[email protected]"
Rules:
1. preview must use a preview-only DB.
2. preview DB must be separate from production DB.
3. preview must send real emails.
4. preview emails must automatically prepend "[preview] " to the subject.
5. preview must not require PUBLIC_APP_URL unless the existing app requires it.
6. if preview URLs are deployment-specific, derive them from platform-provided system variables instead of requiring a fixed PUBLIC_APP_URL.
7. preview validation must require DATABASE_URL, MAIL_API_KEY, MAIL_FROM, ADMIN_EMAIL.
PRODUCTION ENV REQUIREMENTS:
Configure or document Production-scope deployment environment variables.
Required Production-scope variables:
DATABASE_URL="production DB general connection URL"
MAIL_API_KEY="production Resend API key"
MAIL_FROM="Service <[email protected]>"
ADMIN_EMAIL="[email protected]"
PUBLIC_APP_URL="<https://example.com>"
Rules:
1. production must use production DB only.
2. production DB must be separate from preview DB.
3. production must send real emails.
4. production emails must not prepend "[preview] ".
5. production validation must require DATABASE_URL, MAIL_API_KEY, MAIL_FROM, ADMIN_EMAIL, PUBLIC_APP_URL.
6. production env values must be managed in the deployment platform Production scope, not in a committed env file.
CI SECRET REQUIREMENTS:
Configure or document CI-only secrets separately from app runtime environment variables.
Required CI secrets:
DIRECT_URL_PREVIEW="preview DB direct connection URL"
DIRECT_URL_PROD="production DB direct connection URL"
Rules:
1. DIRECT_URL_PREVIEW is used only by preview migration automation.
2. DIRECT_URL_PROD is used only by production migration automation.
3. App runtime must not use DIRECT_URL_PREVIEW or DIRECT_URL_PROD.
4. CI migration jobs must use direct DB connections, not pooled app DB URLs, if the project has migrations.
5. Do not run database migrations inside the app build step.
6. Migration automation must be separate from app build/deployment execution.
ENV VALIDATION REQUIREMENTS:
Implement an environment validation module or script using the existing language and project conventions.
It must support runtime values:
- local
- preview
- production
Required validation behavior:
For local:
- require DATABASE_URL
- do not require MAIL_API_KEY
- do not require MAIL_FROM
- do not require ADMIN_EMAIL
- do not require PUBLIC_APP_URL unless required by current app logic
For preview:
- require DATABASE_URL
- require MAIL_API_KEY
- require MAIL_FROM
- require ADMIN_EMAIL
- do not require PUBLIC_APP_URL unless current app logic requires it
For production:
- require DATABASE_URL
- require MAIL_API_KEY
- require MAIL_FROM
- require ADMIN_EMAIL
- require PUBLIC_APP_URL
Validation must fail fast with clear missing-variable errors.
Implement behavior equivalent to:
type RuntimeEnv = "local" | "preview" | "production";
function requireEnv(name: string): string {
const value = process.env[name];
if (!value) {
throw new Error(`필수 환경변수 누락: ${name}`);
}
return value;
}
export function validateRuntimeEnv(runtime: RuntimeEnv) {
if (runtime === "local") {
requireEnv("DATABASE_URL");
return;
}
if (runtime === "preview") {
requireEnv("DATABASE_URL");
requireEnv("MAIL_API_KEY");
requireEnv("MAIL_FROM");
requireEnv("ADMIN_EMAIL");
return;
}
if (runtime === "production") {
requireEnv("DATABASE_URL");
requireEnv("MAIL_API_KEY");
requireEnv("MAIL_FROM");
requireEnv("ADMIN_EMAIL");
requireEnv("PUBLIC_APP_URL");
return;
}
}
Adapt syntax to the existing codebase if it is not TypeScript.
VALIDATION EXECUTION REQUIREMENTS:
1. Run environment validation before app startup or during build-time preflight.
2. Do not run DB migrations as part of this validation.
3. Do not run DB migrations inside the app build process.
4. Validation should only check required configuration availability and shape.
5. Validation must not print secret values.
6. Error messages may include missing key names but not secret values.
EMAIL POLICY INTEGRATION:
Ensure env handling supports the following behavior:
1. local: real email sending disabled.
2. preview: real email sending enabled and subject prefix "[preview] " applied automatically.
3. production: real email sending enabled and no subject prefix applied.
4. MAIL_API_KEY alone must not be treated as sufficient proof that email sending should happen in local.
5. Email adapter or equivalent email service layer must consume MAIL_API_KEY and MAIL_FROM only after environment validation passes.
REVIEW / OPERATION FLOW REQUIREMENTS:
Document or encode the intended workflow.
Development:
- environment: local
- checks: typecheck, tests, lint, build
- manual review: customer/user-facing screens only
- email: no real sending
Review:
- environment: preview
- checks: full scenario review including admin scenarios
- email: real email receiving test
- DB: preview-only DB records
- preview email subjects must include "[preview] "
Production release:
- environment: production
- checks: health check and core screen smoke test only
- no long scenario testing in production
Production operation:
- treat all production admin actions as real
- treat all production DB writes as real
- treat all production emails as real
- do not perform test-like email sends or experimental data manipulation in production
TESTS REQUIRED:
Add or update tests if the project has a test setup.
Required test cases:
1. .env.example exists and contains the required keys with empty values.
2. .gitignore ignores .env* and allows .env.example.
3. local validation passes with DATABASE_URL only.
4. local validation does not require MAIL_API_KEY.
5. preview validation fails without DATABASE_URL.
6. preview validation fails without MAIL_API_KEY.
7. preview validation fails without MAIL_FROM.
8. preview validation fails without ADMIN_EMAIL.
9. production validation fails without PUBLIC_APP_URL.
10. production validation requires DATABASE_URL, MAIL_API_KEY, MAIL_FROM, ADMIN_EMAIL, PUBLIC_APP_URL.
11. validation errors do not print secret values.
12. local email sending remains disabled.
13. preview email subject gets "[preview] " prefix.
14. production email subject does not get "[preview] " prefix.
IMPLEMENTATION OUTPUT:
After implementation, summarize:
1. files created or changed
2. env keys added or validated
3. local / preview / production validation behavior
4. CI secrets required
5. whether tests were added or updated
6. any assumptions made because of existing project structure