tito10047 / ux-sdc
A performance-optimized SDC implementation for Symfony UX components with automatic discovery and static metadata registry.
Requires
- php: >=8.1
- symfony/asset: ^6.4|^7.0|^8.0
- symfony/asset-mapper: ^6.4|^7.0|^8.0
- symfony/framework-bundle: ^6.4|^7.0|^8.0
- symfony/ux-twig-component: ^2.13|^3.0
- symfony/web-link: ^6.4|^7.0|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.92
- phpbench/phpbench: ^1.4
- phpstan/phpstan: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^10.5
- symfony/browser-kit: ^6.4|^7.0|^8.0
- symfony/maker-bundle: ^1.65
- symfony/stimulus-bundle: ^2.32|^3.0
- symfony/twig-bundle: ^6.4|^7.0|^8.0
- symfony/ux-live-component: ^2.32|^3.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- v1.0.x-dev
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.0
- 0.1.2
- 0.1.1
- 0.1.0
- 0.0.1
- dev-feature/scss-discovery
- dev-claude/beta-fixes
- dev-claude/admiring-newton-yhvtxd
- dev-claude/wonderful-planck-5u20tl
- dev-ccr-df9ec3ff-xwm1fe
- dev-release-1.0
- dev-docs-agent-skill
- dev-support-ux-3
- dev-make-action
- dev-bundle-name
- dev-colon-baset-separator
- dev-optimizing
This package is auto-updated.
Last update: 2026-11-29 13:26:47 UTC
README
Single Directory Components for Symfony UX: a component's PHP class, Twig template, CSS and JavaScript live in one directory, and the CSS and JS reach the page only when the component is rendered on it.
src_component/
└── Alert/
├── Alert.php # the component class
├── Alert.html.twig # its template, found without configuration
├── Alert.css # added to <head> when an Alert is rendered
└── Alert_controller.js # its Stimulus controller (optional)
The bundle connects Twig Components
with AssetMapper: it
registers the component directory with Twig, AssetMapper and StimulusBundle, finds
the files next to each component class (or template, for an anonymous component),
and injects the <link> and <script> tags of the components a response actually
rendered — into the page, or for Live Components and Turbo fragments, through a
response header the bundle's Stimulus controller reads.
The idea comes from Hugo Alliaume's article A Better Architecture for Your Symfony UX Twig Components. It is used in production on mostka.sk, formalitka.mostka.sk and ycon.cc.
Requirements
PHP 8.1+, Symfony 6.4, 7.x or 8.x, symfony/ux-twig-component 2.20+ or 3.x, and
AssetMapper (Webpack Encore is not supported). StimulusBundle, LiveComponent,
MakerBundle and UX Icons are optional. See Installation.
Installation
composer require tito10047/ux-sdc
A Flex recipe is proposed to
symfony/recipes-contrib. It configures the bundle, imports its routes and adds
{{ render_component_assets() }} to templates/base.html.twig; what is left to
you — the Composer PSR-4 entry, and for Live Components or Turbo the loader
controller on <body> — it prints. Until it is available, or without Flex,
follow Without the recipe: five short
steps.
Quick start
With App\Component\ mapped to src_component/ and the bundle configured as
above, src_component/Alert/Alert.php:
<?php namespace App\Component\Alert; use Tito10047\UX\Sdc\Attribute\AsSdcComponent; #[AsSdcComponent] final class Alert { public string $type = 'info'; public string $message; }
src_component/Alert/Alert.html.twig:
<div {{ attributes.defaults({class: 'alert alert-' ~ type}) }}> {{ message }} </div>
src_component/Alert/Alert.css:
.alert { padding: 1rem; border-radius: .25rem; } .alert-success { background: #e6f4ea; }
Render it from any template:
<twig:Alert:Alert type="success" message="Saved." />
A page that renders an Alert gets
<link rel="stylesheet" href="/assets/Alert/Alert-….css" data-turbo-track="dynamic">
in its <head> and a Link: </assets/Alert/Alert-….css>; rel="preload"; as="style"
header. A page without an Alert gets neither.
php bin/console make:sdc-component Alert generates such a skeleton, and
php bin/console debug:sdc shows what each component gets.
Documentation
- Installation — requirements, the Flex recipe, manual setup
- Components — names, co-located files, templates, Stimulus controllers, where components can live, anonymous components
- Assets —
#[AsSdcComponent],#[Asset], ES modules, Sass, font and image preloads, CSP nonces - Component icons — SVG icons in the component's folder with
symfony/ux-icons,
ux:sdc:icons:import(experimental) - Live Components and Turbo — the loader controller and
the
X-SDC-Assetsheader - Generating components —
make:sdc-component, page components with--action - Configuration — every option
- Diagnostics —
debug:sdc, logs, the web profiler panel - How it works — the build-time and runtime pipelines, performance
- Known limitations and non-goals
- Upgrading from 0.4 to 1.0 and the changelog
tito10047/ux-sdc-skills teaches
coding agents how components are discovered, how their assets reach the browser
and how to diagnose the failure modes. In Claude Code:
/plugin marketplace add tito10047/ux-sdc-skills, then
/plugin install ux-sdc-skills. For other agents it is a plain directory of
Markdown in the agentskills.io layout, with AGENTS.md,
CLAUDE.md and llms.txt.
Backward compatibility
The bundle follows Semantic Versioning. From 1.0, a minor or patch release does not break:
- Configuration: the
ux_sdcoptions, their defaults and accepted values (Configuration), and theux_sdc.ux_components_dirparameter. - PHP:
Attribute\AsSdcComponentandAttribute\Asset(with itsCSS,JS,FONTandIMAGEconstants), theTwig\Stimulustrait,Twig\ComponentNamespaceInterface,Csp\NonceProviderInterface,Csp\NelmioNonceProvideras a value ofcsp_nonce_provider,Service\AssetRegistry::isolate()(the service of that class), andSdcBundlewithSdcBundle::STIMULUS_CONTROLLER— all inTito10047\UX\Sdc. - Twig: the
render_component_assets()function, thesdc_loader_controllerglobal, thecontrollervariable and how its value is derived, how components and their co-located files are named. - HTTP: the
X-SDC-Assetsheader, format version 1, and the loader Stimulus controller that reads it. - Routing: the
type: ux_sdcroute import. - Logging: the
ux_sdclog channel. - Console: the names, arguments and options of
debug:sdcandmake:sdc-component, the exit codes and the JSON structure ofdebug:sdc.
Not covered, and free to change in any release: the experimental
component icons (the icons options, the sdc: icon names and
ux:sdc:icons:import), every class, method and constant
marked @internal (all of src/ not listed above), service IDs, other container
parameters, the format of the metadata cache, the text output of debug:sdc, the
wording of log messages and the code make:sdc-component generates. A minor
release may add debug:sdc checks, so --strict may find problems it did not
find before. Something covered is deprecated in a minor release, with a deprecation
notice where possible, and removed in the next major one.
Contributing
Bug reports and pull requests are welcome on
GitHub. Run ./vendor/bin/phpunit,
./vendor/bin/phpstan analyse and ./vendor/bin/php-cs-fixer fix --dry-run
before opening a pull request.
License
MIT — see LICENSE.md.