Area
Backend — Database / Models
Category
Test coverage
Description
The env package is the second most imported package in the backend (82 files depend on it) with only 1 test covering 1 of 12 helper functions.
This package loads all 100 environment variables into a single Configuration struct at startup. It has no validation, no defaults, and no type safety — all fields are strings. Bugs here silently propagate across the entire backend.
Documentation needs:
- Inline godoc for all exported functions
- Document which env vars are required vs optional for self-hosted deployment
- Document the
IsProduction() Doppler coupling (doesn't work for HoldFast)
Test coverage priorities:
load() — verify mapstructure decoding with mock env vars- Environment detection —
IsDevEnv, IsOnPrem, IsProduction, IsEnterpriseDeploy ConsumerSpanSamplingRate() — valid input, invalid input, empty string (inverse rate logic is confusing)CopyTo() — reflection-based merge, empty vs non-empty fieldsGetEnterpriseEnvPublicKey() — base64 decoding, build-time vs runtime keyGetFrontendCookieDomain() — edge cases (IP address, port, .co.uk TLDs, invalid URL)
Improvement candidates:
- Add validation for required infra vars (PSQL_HOST, CLICKHOUSE_ADDRESS, KAFKA_SERVERS, REDIS)
- Add typed accessors instead of string-everywhere pattern
- Fix
GetFrontendCookieDomain() for multi-level TLDs (.co.uk) - Decouple
IsProduction() from Doppler
See src/backend/env/MODULE.md for full analysis.
Affected Files / Packages
src/backend/env/environment.go (232 lines, 100 config fields, 12 helper functions)
src/backend/env/environment_test.go (23 lines — 1 test, 3 cases)
Area
Backend — Database / Models
Category
Test coverage
Description
The
envpackage is the second most imported package in the backend (82 files depend on it) with only 1 test covering 1 of 12 helper functions.This package loads all 100 environment variables into a single
Configurationstruct at startup. It has no validation, no defaults, and no type safety — all fields are strings. Bugs here silently propagate across the entire backend.Documentation needs:
IsProduction()Doppler coupling (doesn't work for HoldFast)Test coverage priorities:
load()— verify mapstructure decoding with mock env varsIsDevEnv,IsOnPrem,IsProduction,IsEnterpriseDeployConsumerSpanSamplingRate()— valid input, invalid input, empty string (inverse rate logic is confusing)CopyTo()— reflection-based merge, empty vs non-empty fieldsGetEnterpriseEnvPublicKey()— base64 decoding, build-time vs runtime keyGetFrontendCookieDomain()— edge cases (IP address, port,.co.ukTLDs, invalid URL)Improvement candidates:
GetFrontendCookieDomain()for multi-level TLDs (.co.uk)IsProduction()from DopplerSee
src/backend/env/MODULE.mdfor full analysis.Affected Files / Packages