Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ECS

Beverly brand mark

ECS composition allows systems and data to stay efficient and composable. In a Bevy-based UI stack like Beverly, this is not just a performance optimization; it is the organizing principle for how the application model is structured.

What ECS means

ECS stands for Entity, Component, and System. Each term describes a different role in the architecture:

  • Entity: the identity of a thing in the world or interface
  • Component: the data attached to that thing
  • System: the logic that processes entities with matching data

This separates identity, state, and behavior. A button, a card, a table row, a modal, or a form field can all be represented as entities without forcing them into a rigid inheritance hierarchy.

Entities are identity, not classes

An entity is usually just a unique id. It does not carry much behavior by itself. It is a placeholder for “this thing exists in the app.” In practice, a UI element may be a button entity, a panel entity, or an input entity, but those are not defined by one large object with every possible method attached.

This is useful because many UI primitives share common concepts: layout, focus, semantics, visibility, theme tokens, or interaction state. Instead of building a monolithic widget type tree, Beverly can represent a widget as an entity with the relevant components for its current purpose.

Components hold state

A component is plain data. It describes the facts about an entity.

Examples include:

  • transform or layout info
  • interaction state such as pressed, hovered, or disabled
  • semantic metadata and accessibility attributes
  • theme values like color, spacing, radius, or motion
  • visibility and stacking order
  • data bindings or selection state

A component should be small, focused, and easy to reason about. It answers the question: “What does this entity currently know?” It does not answer the question: “What should happen next?” That belongs to systems.

Systems implement behavior

A system is a function that runs over entities matching a specific set of components. A system might say:

  • update layout for every entity with both Transform and Layout
  • apply hover states for every entity with ButtonState and PointerInteraction
  • compute accessibility relationships for focusable elements
  • render visible nodes after the layout pass has completed

This creates a clear separation of responsibilities. Components define state, and systems define behavior. Instead of scattering logic across many object methods, the architecture collects related logic in one place and applies it to all matching entities.

Why this is a good fit for UI work

ECS gives Beverly a structure that is both efficient and composable.

Efficient

Data is processed in a way that keeps work local and predictable. Systems can iterate over only the entities they need, instead of walking a deeply nested object graph or performing broad state checks across unrelated widgets.

This matters in real interfaces where layout, interaction, and rendering all happen repeatedly and often under time constraints.

Composable

An entity can easily take on new capabilities by adding components. A widget can become focusable, semantically labeled, and theme-aware without requiring a new class hierarchy. This keeps reusable UI primitives flexible while preserving a strong architectural model.

Clear boundaries

A layout system does not need to know about how a button renders; a rendering system does not need to know about how data is stored; a theme system only concerns itself with token resolution and visual styling. This reduces accidental coupling and helps UI code stay understandable as the application grows.

Example: a button

A simple button could be represented as an entity with components like:

  • Layout
  • Transform
  • ButtonState
  • ThemeTokens
  • AccessibilityLabel
  • Visibility

Then several systems operate on it:

  1. LayoutSystem positions and sizes the button.
  2. InteractionSystem updates pressed, hovered, and disabled states.
  3. ThemeSystem applies colors, borders, and motion style.
  4. RenderSystem draws the button to the screen.
  5. AccessibilitySystem ensures the button exposes the proper semantics to assistive technology.

The same entity can participate in all of these systems without becoming a huge, brittle object.

ECS and Beverly’s architecture

This is why Beverly is described as ECS-first. The framework is built around the idea that the UI is not just an object tree; it is a composition of entities, stateful components, and systems that operate over that state.

The application layer remains focused on domain logic and workflows, while the UI layer provides reusable components and rules for layout, semantics, theming, and rendering. That keeps the architecture aligned with the way Bevy and ECS naturally think about scenes and systems.

The core takeaway

ECS is valuable because it makes the app easier to scale without turning every screen into a handcrafted set of special-case widgets. It keeps data local, behavior explicit, and composition flexible, which is exactly what a modern UI framework needs when the app grows beyond a few simple screens.

In short: entities are things, components are their data, and systems are the rules that act on that data. That model is the foundation of a performant, composable UI architecture.