Skip to content

refactor(config): move the config registry into Appwrite\Config - #14224

Closed
ChiragAgg5k wants to merge 2 commits into
mainfrom
refactor/config-registry
Closed

ChiragAgg5k wants to merge 2 commits into
mainfrom
refactor/config-registry

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Summary

utopia-php/config 2.x replaced the static key/value registry (Config::load, getParam, setParam) with a typed Source + Parser loader. Every consumer still uses the 1.x registry, so Appwrite was stuck on config 1.0.0, one of the last four utopia-php/* packages still vendored (#13828). The RFC's Version gaps table already calls for this: move the registry into src/Appwrite/Config/ and drop the dependency.

  • Appwrite\Config\Config is the 1.x registry. load, setParam and getParam behave the same, including dotted lookups through nested arrays.
  • Appwrite\Config\Adapter, Adapter\PHP and Adapter\Dotenv: the two adapters Appwrite uses. JSON and YAML had no callers, so they don't come over. Exception\Load and Exception\Parse replace Exceptions\*.
  • One behaviour change: when a PHP config file doesn't return an array, the PHP adapter now throws Load instead of a bare \Exception. Load extends \Exception, so existing catches still apply.
  • Every Utopia\Config\… import is rewritten (137 files, imports only; Pint reorders them), utopia-php/config is removed from require, and the lock loses only utopia-php/config 1.0.0.
  • rfc/monorepo.md: the config row in Version gaps is marked done, and open question 2 is resolved. 2.x gets a packages/config home in a follow-up absorb PR, so utopia-php/monorepo can be archived. Appwrite doesn't load it.

Impact on other repos

  • Cloud uses Utopia\Config\Config in 222 files and takes it through server-ce. Its next composer update appwrite/server-ce must apply the same import rewrite. Until the 2.x absorb lands, Utopia\Config\Config simply stops resolving in Cloud. After it lands, that name resolves to the 2.x class, which has no getParam.
  • Edge and open-runtimes/executor pin the 0.2 registry from Packagist and are unaffected.

Tests

  • New tests/unit/Config/ConfigTest.php covers flat and dotted lookups and defaults, a PHP config file reading a param loaded before it (as app/config/*.php does), the registry being left untouched when a load fails, and Dotenv comments, values that contain =, and a line with no name. I broke the dotted lookup on purpose and 4 tests failed, then restored it.
  • Full unit suite in appwrite/base:2.1.0 with .env: 1405 tests, all passing.
  • composer lint, composer refactor:check, composer analyze (no errors) and bin/monorepo validate all pass.

Related: #13828

utopia-php/config 2.x replaced the static key/value registry Appwrite is
built on with a typed Source/Parser loader, so the 1.x line was the last
thing keeping config vendored. The registry is about 100 lines and only
serves Appwrite's product config, so it moves here as planned in the RFC
(Version gaps) and the dependency is dropped. Only the PHP and Dotenv
adapters Appwrite uses come with it.

Refs #13828
@luxor-code-review

luxor-code-review Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review complete. 🟠 1 high · 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Dotenv parser truncates values at # inside quotes — Dotenv.php:15
📍 Findings outside the diff (1) — 🟠 1 high — defects on lines GitHub can't attach comments to

🟠 High — Error view still imports removed Utopia\Config\Config · app/views/general/error.phtml

The PR moved the config registry to Appwrite\Config\Config and dropped utopia-php/config from the dependencies, but app/views/general/error.phtml still imports Utopia\Config\Config and reads Config::getParam('platform', []) (line 2 and line 19). Since nothing populates the Utopia registry and the class no longer exists in the vendor tree, rendering any error page fatals with a class-not-found error — users get a broken/blank response instead of the error page.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 RFC claims 2.x absorbed into nonexistent packages/config (monorepo.md:163) — The updated RFC states config 2.x "is absorbed into packages/config" and marks open question 2 as resolved with that home (rfc/monorepo.md:163, rfc/monorepo.md:319), but no packages/config directory exists in the tree.

The change absorbs the Utopia config registry into the repo under src/Appwrite/Config/, adding adapter classes for PHP and Dotenv files plus Load/Parse exceptions, and swaps every Utopia\Config\Config import to Appwrite\Config\Config across app bootstrap, controllers, modules, workers, tasks, and tests. Unit and e2e tests are updated to match the new namespace and new adapter behavior.

Files Change
src/Appwrite/Config/**, composer.json New inlined config registry with PHP and Dotenv adapters replacing the utopia-php/config package.
app/init/configs.php, app/*.php entrypoints Load all config files through the new Appwrite\Config adapters at boot in HTTP, worker, CLI, realtime, and MQTT processes.
src/Appwrite/Platform/**, src/Appwrite/{Auth,Geo,Event,Migration,Vcs,Usage,Utopia}/** Mechanical import swap of Config call sites to the new namespace.
tests/unit/**, tests/e2e/** Tests updated for the new namespace and isolated static state in config tests.

Reviewed commit: 768fea8

@ghost

ghost commented Oct 7, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

No concrete defects found in the registry, adapter integrations, namespace migration, or added tests.

Moves the static configuration registry and its PHP/Dotenv adapters into Appwrite\Config, updates consumers to the new namespace, and removes the Composer dependency. Adds registry, adapter, and error-view regression tests, and updates the monorepo RFC to record the migration.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 11
File Change
src/Appwrite/Config/Config.php Adds the static registry with file loading, parameter assignment, and dotted lookups.
src/Appwrite/Config/Adapter.php, src/Appwrite/Config/Adapter/*.php Adds the base loader and PHP/Dotenv adapters.
src/Appwrite/Config/Exception/*.php Defines configuration load and parse exceptions.
app/cli.php, app/http.php, app/mqtt.php, app/realtime.php, app/worker.php Switches process entrypoints to the Appwrite registry.
app/config/**, app/init/**, app/controllers/**, app/views/general/error.phtml Rewrites configuration imports, including bootstrap adapters and the error template.
src/Appwrite/** (existing consumers) Rewrites registry imports and updates VCS Dotenv adapter and exception imports.
composer.json, composer.lock Removes utopia-php/config from required and locked dependencies.
tests/unit/Config/ConfigTest.php Tests registry lookups, loading failures, dependent PHP configuration, and Dotenv parsing.
tests/unit/Utopia/ErrorViewTest.php Tests error-page asset URLs using the configured console hostname.
tests/e2e/**, tests/unit/** (existing tests) Switches test consumers to the Appwrite registry.
rfc/monorepo.md Records the registry migration and resolves the future home of config 2.x.

Reviewed b592ab6 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Tier B · 1 blocking finding to address. Summary

Comment thread composer.json Resolved
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

32 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (17)
  • php.appwrite.permissive-write-permission (8)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

app/views/general/error.phtml was missed by the import rewrite, so every
HTML error page (OAuth failures, unknown project, site and proxy errors)
threw Class "Utopia\Config\Config" not found once the package was gone.
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR replaces the utopia-php/config dependency with an inlined Appwrite\Config implementation and migrates all Config call sites to the new namespace.

Key findings

  • 🟠 Error view still imports removed Utopia\Config\Config — error.phtml
  • 🟡 Dotenv parser truncates values at # inside quotes — Dotenv.php:15

Comment on lines +15 to +18
$pair = \strstr($line, '#', true);
if ($pair === false) {
$pair = $line;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

Dotenv parser truncates values at # inside quotes

Dotenv::parse() strips everything from the first # on every line with strstr($line, '#', true) before splitting the pair, so a quoted value like API_KEY="abc#def" is silently truncated and a stray quote is kept verbatim (src/Appwrite/Config/Adapter/Dotenv.php:15). The parser is reachable from the VCS import endpoints, which parse user repository .env files into function environment variables with no validation, so users importing a repo get silently corrupted secrets written to their deployments.

📋 Prompt for AI Agents

In src/Appwrite/Config/Adapter/Dotenv.php around lines 14-18, replace the unconditional strstr($line, '#', true) comment strip with quote-aware handling: find the first # that is not inside a single- or double-quoted section of the line and only truncate there; also strip a matching pair of surrounding quotes from the extracted value before storing it in $config. Values containing # (e.g. KEY="abc#def") are currently silently truncated and quotes stored literally, which corrupts secrets imported from repository .env files in src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/Detections/Create.php and XList.php. Extend tests/unit/Config/ConfigTest.php to cover quoted values containing #.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → refactor/config-registry (after).

Metric Before After Change
🚀 Requests/sec 208.54 205.58 ⚪ -1.4%
⏱️ Latency P50 81.95 ms 83.97 ms ⚪ +2.5%
⏱️ Latency P95 200.51 ms 196.71 ms ⚪ -1.9%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 83.97 196.71 12,768 205.58 -3.8
Account 156.8 294.58 672 11.16 -6.25
TablesDB 80.37 152.73 6,944 113.61 +9.21
Storage 79.36 179.01 3,360 56.92 +0.18
Functions 122.31 234.33 1,792 30.92 -8

Top API waits (after)

API request Max wait (ms)
account.prefs.update 417.99
account.name.update 399.56
functions.create 390.32
functions.variables.update 359.53
functions.variables.create 325.25

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

Superseded by #14227, which absorbs config 2.x into packages/config and puts the registry back on Utopia\Config\Config. Call sites keep their imports, so Cloud doesn't need its 222-file rewrite.

@ChiragAgg5k ChiragAgg5k closed this Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant