Modern front-end engineering demands structural uniformity. By combining the modularity of Single Directory Components (SDC) with the responsive foundations of Bootstrap 5, engineering teams can eliminate component duplication and ship a design system that editors cannot accidentally break.
The Single Directory Components architecture
Historically, front-end assets in content management platforms were scattered: templates in one folder, styles in a global stylesheet, scripts somewhere else and a library definition tying them together. SDC isolates everything a component needs in a single directory:
themes/custom/corporate/components/card/
card.component.yml # schema: props & slots
card.twig # markup
card.css # auto-attached styles
card.js # auto-attached behaviour
README.md # usage notes for the team
Drupal discovers the component automatically and attaches its CSS and JS only on pages where it renders.
Encapsulating Bootstrap 5 inside components
Bootstrap supplies the grid, spacing scale and utility classes; SDC supplies the boundaries. The Twig template uses Bootstrap classes internally, while the outside world only sees typed props:
{# card.twig #}
<article class="card h-100 shadow-sm border-0 rounded-4">
{% if image %}
<img src="{{ image }}" class="card-img-top" alt="{{ image_alt }}" loading="lazy">
{% endif %}
<div class="card-body p-4">
<h3 class="h5 card-title">{{ title }}</h3>
{% block content %}{% endblock %}
</div>
</article>
Rendering it anywhere in the theme is a single include, with with_context = false so outer variables do not leak in:
{{ include('corporate:card', { title: node.label, image: image_url }, with_context = false) }}
Why the combination works
- Consistency: accordions, carousels and metrics blocks stay uniform across every breakpoint.
- Lower styling overhead: component CSS only handles what Bootstrap utilities do not.
- Reusability: components can be shared across sites or published as an internal library.
- Future-proofing: the same schemas power visual page builders such as Drupal Canvas.
Practical guidelines
- Customise Bootstrap through Sass variables once, at theme level, never per component.
- Keep components small and composable; prefer slots over boolean props for variations in content.
- Document every component in its README with an example include.
- Add visual regression tests for your most-used components.
Building or refactoring a component library? Our UI/UX and Drupal teams can help.