Skip to content

refactor(config): centralize environment access behind typed configuration #236

Description

@karagozemin

Problem

Environment variables are read directly throughout runtime modules, CLIs, build configuration, and operational scripts. Each call site applies different defaults and parsing rules, so missing, empty, malformed, and secret values are handled inconsistently.

Goal

Create a typed configuration boundary and migrate all first-party environment access through it. Configuration should be parsed once at startup and passed to the code that uses it.

Requirements

  • Provide reusable readers for required and optional strings, booleans, integers, URLs, enums, Stellar identifiers, and secret values.
  • Distinguish missing, empty, and malformed input with stable typed errors.
  • Let each application, service, CLI, and operational script declare an explicit schema and return an immutable typed configuration object.
  • Keep browser-exposed configuration separate and enforce the existing public-variable prefix policy.
  • Ensure diagnostics identify the invalid key without printing secret values.
  • Replace direct environment access across first-party runtime code, scripts, and build configuration with the typed boundary.
  • Keep dependency injection available so tests can pass plain environment maps without mutating global process state.
  • Add a repository guard that rejects new direct environment reads outside narrowly documented bootstrap adapters.
  • Wire the guard into normal validation and CI.
  • Add tests for defaults, empty values, invalid numbers and URLs, enum validation, secret redaction, and environment-map injection.

Acceptance criteria

  • Runtime and operational code receives parsed configuration instead of reading global environment state.
  • A repository-wide search finds no direct environment access outside approved bootstrap adapters.
  • Existing commands preserve their defaults and exit behavior.
  • Invalid configuration fails before side effects begin and never exposes secret contents.
  • New tests, affected workspace tests and typechecks, and the configuration guard pass.
  • The PR contains no unrelated formatting or generated output.

Suggested implementation prompt

Implement this issue end to end from the current main branch. Inventory every first-party environment read and document its type, default, required state, secrecy, and consumer. Build reusable typed environment readers, define explicit configuration schemas at each executable boundary, parse once at startup, and pass immutable configuration inward. Migrate every inventoried call site, preserve current defaults and command behavior, add focused tests and a regression guard, run affected tests and typechecks, and keep unrelated changes out of the diff.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third Campaign

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions