npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@babylonjsmarket/ecs

v0.5.0

Published

Entity-Component-System framework with Babylon and Three renderer adapters

Readme

@babylonjsmarket/ecs

The Entity-Component-System framework that powers BabylonJS Market games — extracted from the in-house CodeLibrary and published as a standalone runtime so any project can depend on it.

Where this fits

                      @babylonjsmarket/ecs              ← you are here
                                ▲
                                │
        ┌───────────────────────┼───────────────────────┐
        │                       │                       │
@babylonjsmarket/arcade   create-arcade games    your game
(curated components)     (scaffolded projects)

@babylonjsmarket/ecs is the foundation. It owns:

  • Core ECSComponent, Entity, System, World, EventBus, SceneLoader, SaveLoad, RaceDetector.
  • The renderer contractRendererAdapter is the interface that decouples your game logic from any specific 3D engine.
  • Babylon and Three.js adaptersBabylonAdapter (Havok physics, full scene support) and ThreeAdapter (with a pluggable JS physics integrator). Both live in this package so they evolve together, but each is behind a subpath so only the renderer you actually use gets pulled in.
  • Test infrastructureMockRendererAdapter for unit tests, and a runMechanicContract battery for proving a mechanic obeys the framework contract.

Everything is renderer-agnostic at the entity/system layer. Pick Babylon if you want first-class Havok physics and the full Babylon stack; pick Three if you want a leaner runtime and you're comfortable wiring physics yourself.

Install

npm install @babylonjsmarket/ecs

The core entry has zero runtime dependencies. Renderer adapters are optional peer dependencies — install only the one you use:

# For BabylonJS
npm install @babylonjs/core @babylonjs/loaders @babylonjs/havok

# For Three.js
npm install three

Entry points

| Import | Contents | Peer deps | | ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- | | @babylonjsmarket/ecs | Core: Component, Entity, System, World, EventBus, SceneLoader, SaveLoad, RaceDetector, RendererAdapter interface, MockRendererAdapter, withRaceTracking | none | | @babylonjsmarket/ecs/babylon | BabylonAdapter | @babylonjs/core, @babylonjs/loaders, @babylonjs/havok | | @babylonjsmarket/ecs/three | ThreeAdapter (accepts an injectable physicsFactory) | three | | @babylonjsmarket/ecs/renderer-types | The full RendererAdapter type surface — tuple Vec3, handle types, spec interfaces | none | | @babylonjsmarket/ecs/testing | runMechanicContract and related vitest helpers | vitest |

Quick start

import { World, Component, System, type ISystemQuery } from '@babylonjsmarket/ecs';
import { BabylonAdapter } from '@babylonjsmarket/ecs/babylon';

class Position extends Component {
  x = 0;
  y = 0;
  z = 0;
}

class MoveSystem extends System {
  query: ISystemQuery = { required: [Position] };
  onUpdate(dt: number) {
    for (const entity of this.entities) {
      const p = entity.get(Position)!;
      p.x += dt;
    }
  }
}

const renderer = new BabylonAdapter();
await renderer.init(canvas);

const world = new World({ renderer });
world.addSystem(new MoveSystem(world.eventBus));
const player = world.createEntity('Player');
player.add(new Position());

renderer.startLoop((dt) => world.update(dt));

Concepts

Components are data, Systems are logic

Components extend the Component base class and hold state. Systems extend System, declare a query (required components, excluded components, required tags), and implement onUpdate(dt). The World matches entities to systems and runs them each frame.

Events, not direct references

Systems publish via eventBus.emit(name, data) and subscribe via this.listen(name, cb). This keeps systems decoupled — PlayerInput can fire MOVE events without knowing or caring that Movement, Animation, or CameraShake will listen.

Since 0.4.0, the System base class provides listen(), listenOnce(), and listenForEntity() — auto-disposed subscriptions whose lifetime is tied to the system. Subscribe in onInitialize() and the base class unsubscribes everything when the system is removed from the World; no manual unsubscribe bookkeeping. Raw eventBus.on(name, cb) remains the primitive for non-System code.

Renderer adapters are a thin port

The RendererAdapter interface is what every system uses to talk to the 3D engine. Adapters return opaque handles (MeshHandle, LightHandle, CameraHandle, …) that only the adapter that created them can interpret. This is what lets the same MoveSystem run unchanged under Babylon, Three, or the MockRendererAdapter used in unit tests.

Race detection in development

If you pass { detectRaces: true } to the World constructor, the renderer adapter is wrapped in a Proxy that records every handle mutation. When two systems write to the same handle in the same frame, you get a stack trace pointing at the conflict. Off in production.

See also

  • @babylonjsmarket/arcade — A curated set of 14 reusable components (mesh, camera, lights, input, physics, scoring, animation) built on this framework. Start here if you want batteries included.
  • @babylonjsmarket/create-arcade — CLI scaffolder for new arcade-style games. Sets up a project that uses both packages above.
  • BabylonJS Market — Marketplace for additional components, full courses, and example games.

Notes

  • ESM only. "type": "module".
  • Built with TypeScript; ships .d.ts declarations.
  • Debug viz panels (Solid.js) are not shipped from this package — they live in the consuming application or @babylonjsmarket/arcade/viz.