# Add Dark Mode to a Symfony App

Yes. An agent adds a light, dark and system theme switch to your Symfony app with Bootstrap color modes and a Stimulus controller, and opens a pull request.

[Run this on Rush](https://cloud.getrush.ai/run/add-dark-mode/symfony/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the front-end setup before choosing a mechanism. In a Symfony app like symfony/demo there is no Node toolchain: `importmap.php` maps `bootstrap` 5.3.8, `@hotwired/stimulus` 3.2.2 and `highlight.js` through AssetMapper, `assets/app.js` imports `./styles/app.scss`, and `symfonycasts/sass-bundle` compiles that file from `assets/styles/app.scss`, which imports the Bootswatch variables, `vendor/twbs/bootstrap/scss/bootstrap.scss`, the Bootswatch theme and `_rtl.scss`. Bootstrap 5.3 ships color modes driven by a `data-bs-theme` attribute, so the version already installed is the mechanism, and the `highlight.js` stylesheet in use, `github-dark-dimmed`, is already a dark one. `templates/base.html.twig` opens with `<html lang="{{ app.locale }}" dir="{{ is_rtl() ? 'rtl' : 'ltr' }}">`, puts a `navbar-dark bg-primary` navbar in its `header` block, and renders the language selector from `default/_language_selector.html.twig` as the last `nav-item`; that is where a theme switch belongs.

The agent adds `assets/controllers/theme_controller.js` beside the two existing Stimulus controllers, `csrf_protection_controller.js` and `login-controller.js`. It reads a stored choice from `localStorage`, falls back to `prefers-color-scheme`, sets `data-bs-theme` on `<html>`, listens for the system preference changing while `auto` is selected, and marks the active item in the switch. Because `importmap()` loads modules after the first paint, a one-line inline script goes in `<head>` of `base.html.twig` before the stylesheets to apply the stored theme immediately, so a dark-mode user never sees a white flash. The switch itself is a `nav-item dropdown` with three entries, light, dark and auto, each with a Tabler icon through `<twig:ux:icon>` as the existing menu items use, and its labels are new `menu.theme.*` keys in `translations/messages+intl-icu.en.xlf` and the other 30 locale files, because `.github/workflows/lint.yaml` runs `bin/console lint:translations` and `lint:xliff`.

The stylesheet is where the real work is. Bootstrap's own components switch with the attribute, but `app.scss` declares hard-coded colours as custom properties under `:root`, among them `--text-color: #2c3e50`, `--secondary-color: #ecf0f1` and a full grey scale, and the Bootswatch theme sets a light `$body-bg`. The agent adds a `[data-bs-theme="dark"]` block that redefines those properties and the Bootswatch surface colours, checks every component the demo renders, the post list, the comment form, the admin tables from `assets/styles/admin.css`, the `flatpickr` date picker and the `bootstrap-tagsinput` widget, each of which has its own CSS file in `assets/styles/`, and overrides the ones that stay light. `admin.js` is a second entrypoint in `importmap.php`, so the same controller is registered for the admin pages too.

It verifies the result the way a person would and the way CI does. It runs `bin/console sass:build` to compile the SCSS, starts the app with the SQLite database from `.env` and the fixtures, and opens the blog, a post with comments, the login page and the admin post editor in its browser with each of the three settings, taking screenshots. It adds a WebTestCase under `tests/Controller/` asserting the switch renders in the navbar and the `<html>` element carries the controller attribute, since the browser-side behaviour is not reachable from PHPUnit, and runs `vendor/bin/phpunit`, `php-cs-fixer check`, `lint:twig templates --env=prod`, `lint:xliff translations`, `lint:translations` and `phpstan` before opening the pull request.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add dark mode to this Symfony app and open a pull request. Read importmap.php, assets/app.js, assets/admin.js, assets/stimulus_bootstrap.js, assets/controllers.json, the controllers under assets/controllers, assets/styles/app.scss, assets/styles/_variables.scss, assets/styles/admin.css, the bootswatch directory under assets/styles, config/packages/symfonycasts_sass.yaml, config/packages/asset_mapper.yaml, templates/base.html.twig, templates/default/_language_selector.html.twig, translations/messages+intl-icu.en.xlf, tests/Controller/DefaultControllerTest.php and .github/workflows/lint.yaml first. Use Bootstrap 5.3's data-bs-theme color modes, which the installed version supports. Add assets/controllers/theme_controller.js that reads a choice from localStorage, falls back to prefers-color-scheme, sets data-bs-theme on the html element, follows system changes while auto is selected, and marks the active option. Add a short inline script in the head of base.html.twig before the stylesheets so the stored theme applies before first paint. Add a light, dark and auto dropdown as a nav-item next to the language selector using twig:ux:icon Tabler icons, with its labels as new menu.theme keys added to every translations file so lint:translations passes. In app.scss add a [data-bs-theme=\"dark\"] block redefining the :root custom properties and the Bootswatch surface colours, and override admin.css, the flatpickr and bootstrap-tagsinput styles where they stay light. Make sure the admin entrypoint gets the controller too. Run bin/console sass:build, start the app, open the blog index, a post with comments, the login page and the admin post editor under each setting in the browser and keep screenshots. Add a WebTestCase asserting the switch renders and the html element carries the controller attribute. Run vendor/bin/phpunit, php-cs-fixer check, bin/console lint:twig templates --env=prod, lint:xliff translations, lint:translations and phpstan, fix what they report, and open the pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The result is a pull request with one new Stimulus controller, a changed `base.html.twig`, a dark block in `app.scss` with overrides for the admin, date picker and tags-input styles, new translation keys in every `messages+intl-icu.*.xlf` file, and one new functional test. The description shows screenshots of the same four pages in light and dark, lists the custom properties that were redefined, and states that the default is `auto`, so a visitor with no stored choice sees the theme their system asks for.

The transcript holds the `sass:build` output, the PHPUnit run, each lint from `lint.yaml`, and the browser session with its screenshots attached to the run as artifacts, each with a download link that works for an hour and is refreshed on every read of the session. `GET /o/{org}/p/{project}/sessions/{id}/changes` gives the diff per file for review in your own tooling.

A reviewer looks at the screenshots first, especially the admin editor and the comment form where third-party widgets most often stay white, then checks that the inline head script is tiny and has no dependency, that the `lang` and `dir` attributes on `<html>` are untouched so right-to-left locales still render, and that no translation file lost a key.

## Run it on every design request from your terminal

A theme is the kind of front-end job that is easy to describe and slow to finish, so hand it off from where you are. With Rush added to Claude Code or Cursor as an MCP server at `https://api.phoenix.so/mcp`, ask it to `create_session` with this prompt and your repository; it returns at once, and `wait_for_sessions` or `get_session` reads the result later. The sandbox parks when the turn ends, and a `send_session_message` such as asking for a different dark accent colour wakes it with the compiled assets still there.

From a script, it is one `POST /o/{org}/sessions` with the repository in `resources`. Set a `webhook_url` on the key and Rush POSTs `run.completed` with `data.session_url` when the pull request is open, so the link can land in your design channel without anyone polling.

## Why run it on Rush?

Dark mode is finished only when every page has been looked at in both themes, and that is the step a developer skips at the end of a long day: the admin tables, the date picker, the tags widget, the code blocks. The agent runs the app in its own sandbox with a real browser, opens each page under each setting and keeps the screenshots, so the review starts from pictures rather than from a promise.

The run also touches 31 translation files and a compiled stylesheet, work that is tedious and exact. Every lint the repository runs in CI is run first, in the transcript, and the pull request arrives with those checks already green. Several sites can get the same treatment at once, each run reading its own stylesheet rather than applying a fixed palette.

## Frequently asked questions

### Why not a separate dark stylesheet?

Because Bootstrap 5.3.8, already in `importmap.php` and `composer.lock`, implements color modes through the `data-bs-theme` attribute and CSS variables, so every Bootstrap component switches with one attribute. The agent only has to cover the app's own custom properties in `app.scss` and the third-party widget styles; a second stylesheet would duplicate all of Bootstrap.

### Will the page flash white before going dark?

No. Modules loaded through `importmap()` run after the first paint, so the agent puts a few lines of inline script in the `<head>` of `base.html.twig`, before the stylesheets, that read the stored choice and set the attribute. The Stimulus controller takes over once it loads.

### Does the choice follow the user across devices?

Not in this change; it is stored in the browser's `localStorage`, which needs no schema change and works for anonymous readers. Persisting it on the `User` entity for signed-in users is a reasonable follow-up on the same session, since `UserController` already has an edit form.

### What about the admin pages?

They use the `admin` entrypoint from `importmap.php` and `assets/styles/admin.css`, so the agent registers the controller there too and overrides the admin table and form colours in the dark block. The admin post editor is one of the four pages it screenshots under each setting.

### Why does it edit every translation file?

The switch's labels are translatable like every other menu item, and `.github/workflows/lint.yaml` runs `lint:translations`, so a key present in English and missing elsewhere fails CI. The agent adds the keys to all 31 files; a reviewer who prefers English fallbacks can say so in a follow-up.

## More Symfony jobs

- [Add Health Checks to a Symfony App](https://getrush.ai/run/add-health-checks/symfony/)
- [Add a Password Reset Flow to a Symfony App](https://getrush.ai/run/add-password-reset/symfony/)
- [Schedule Posts for Later in a Symfony App from a Linear Issue](https://getrush.ai/run/add-post-scheduling/symfony/)

## The same job on other stacks

- [Add Dark Mode to a Tauri App](https://getrush.ai/run/add-dark-mode/tauri/)
- [Add a Dark Mode Toggle to a Vite React App from a Linear Issue](https://getrush.ai/run/add-dark-mode/vite-react/)
- [Add a Dark Mode Toggle to a VitePress Blog With a Custom Theme](https://getrush.ai/run/add-dark-mode/vitepress/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
