Renaming Symfony's App Namespace: Every Place It Hides, and the One File That Kept the Old Name

By Lars Nielsen ·

A new Symfony project puts everything under the App namespace. In July 2025, CaRMen, my CRM, changed that to CaRMen, in one commit titled "big: Changed root namespace from App to CaRMen". It touched 57 files, and the interesting part was not in the PHP classes. The namespace is written down in more places than src/, and one file added two weeks later still got it wrong.

Where App is written down

Changing namespace App\... to namespace CaRMen\... in every class, and every use statement that refers to them, is the obvious part. The commit shows the rest:

  • composer.json: the PSR-4 autoload maps "App\\": "src/" and "App\\Tests\\": "tests/" became CaRMen\\ and CaRMen\\Tests\\. Without this, Composer's autoloader can't find any class at all.
  • config/services.yaml: the resource block that registers everything under src/ as services is keyed by the namespace, App\:, and so is every service configured individually, like the permission checker and its strategies.
  • config/packages/doctrine.yaml: the entity mapping has a prefix of App\Entity and an alias of App. Both changed.
  • config/routes.yaml: attribute routes are loaded with namespace: App\Controller.
  • public/index.php and bin/console: both use App\Kernel, the one class that boots everything else.
  • .env.test: KERNEL_CLASS='App\Kernel' tells the test framework which kernel to boot.

Two of those fail loudly when missed: the autoload map and the kernel class, since nothing starts. The others can fail more quietly, as a service that isn't registered or an entity Doctrine doesn't map, which show up only when something uses them.

The same commit also carried unrelated changes, a maintenance-mode listener and a new SQLite migration. A rename that big is easier to review, and to revert, on its own.

The file that missed it

Just before the project was rewritten in March 2026, 65 PHP files under src/ and tests/ declared a CaRMen namespace and exactly one declared App: tests/ResetPasswordControllerTest.php. It was added on 17 July, two weeks after the rename, with the password-reset feature. It starts like this:

  • namespace App\Tests;
  • use CaRMen\Entity\User;
  • use CaRMen\Repository\UserRepository;

The rest of that feature, controller, entity, forms and repository, used CaRMen correctly. And the project had done the thing I'd have suggested first: two days after the rename, it added config/packages/maker.yaml with root_namespace: 'CaRMen'. Symfony's MakerBundle, which generates controllers, entities and the like, documents that setting's default as App, so without it every generated class would start out in the old namespace. With it configured, the generator wasn't the obvious culprit, and the history doesn't show how the one test file got its old prefix. That's the useful part: even with every setting right, the old namespace came back in once, and only a search finds that.

If you rename the namespace

  • Change all the places above in one commit, and nothing else in that commit.
  • Add config/packages/maker.yaml with root_namespace set to the new name, as CaRMen did, so generated code starts out right.
  • Afterwards, search for the old prefix in src/, tests/, config/, bin/, public/ and the .env files, and keep searching after the rename, since new code is where it creeps back in.

The epilogue: when CaRMen was rewritten from scratch in March 2026, as a Symfony API with a React frontend, the new backend went back to the default App namespace. A rename is a cost you pay once to make, and again every time a tool, an example or a generator assumes the default.

Filed under

Leave a comment

Comments are reviewed before they appear.

Basic HTML allowed: links, emphasis, code and lists. Web addresses become links automatically.