Skip to content

WillH0lt/woven-ecs

Repository files navigation

Woven ECS Logo

CI npm License: MIT

Read the Docs →

Woven-ECS

A high-performance, multithreaded Entity Component System (ECS) framework for TypeScript.

  • Multithreaded: Execute systems in parallel across worker threads with automatic entity partitioning
  • Change Tracking: Query for entities that were added, removed, or changed since last frame
  • Powerful Queries: Filter entities by component presence with with, without, and any operators
  • Entity References: Reference other entities with automatic validation
  • Zero dependencies - Lightweight core with no external runtime dependencies

Packages

Package Description
@woven-ecs/core Core ECS framework with components, systems, queries, and multi-threading
@woven-ecs/canvas-store Persistence, undo/redo, and real-time collaboration for design and whiteboard applications
@woven-ecs/canvas-store-server Server for real-time collaboration with @woven-ecs/canvas-store clients

Installation

npm install @woven-ecs/core

Quick Start

import {
  addComponent,
  createEntity,
  defineComponent,
  defineQuery,
  defineSystem,
  field,
  World,
} from '@woven-ecs/core';

// Define components with typed fields
const Position = defineComponent({
  x: field.float32(),
  y: field.float32(),
});

const Velocity = defineComponent({
  x: field.float32(),
  y: field.float32(),
});

// Define a query to find entities with both components
const movingEntities = defineQuery((q) =>
  q.with(Position, Velocity)
);

// Define a system to process matching entities
const movementSystem = defineSystem((ctx) => {
  for (const eid of movingEntities.current(ctx)) {
    const pos = Position.write(ctx, eid);
    const vel = Velocity.read(ctx, eid);
    pos.x += vel.x;
    pos.y += vel.y;
  }
});

// Create the world
const world = new World([Position, Velocity]);

// Create an entity with Position and Velocity components
world.execute((ctx) => { 
  const entity = createEntity(ctx);
  addComponent(ctx, entity, Position, { x: 0, y: 0 });
  addComponent(ctx, entity, Velocity, { x: 1, y: 1 });
})

// Game loop
function loop() {
  world.execute(movementSystem);
  requestAnimationFrame(loop);
}

loop();

Documentation

Examples

Example Description
React Binding Integrating woven-ecs with React using useSyncExternalStore.
Three.js + Workers Multithreaded particle physics with Three.js rendering.

Canvas Store

The @woven-ecs/canvas-store and @woven-ecs/canvas-store-server packages extend Woven-ECS with everything you need to build multiplayer editor applications like infinite canvases or other creative design tools.

  • Real-time Sync — WebSocket-based multiplayer with conflict resolution. Multiple users can edit the same document simultaneously.
  • Local-First — Your app works offline by default. Data lives on the client and syncs to the server when connected.
  • Undo/Redo — Full history tracking with configurable depth. Support for undo/redo across multiple users with proper conflict resolution.
  • Persistence — Automatic IndexedDB storage for offline support. Changes are saved locally and synced when back online.
  • Migrations — Version your component schemas with automatic migrations. Evolve your data model without breaking existing documents.
  • Configurable — Configure sync behavior per component: persist to server, sync ephemerally, store locally, or skip entirely.

Learn more →

Local Development

git clone https://github.com/WillH0lt/woven-ecs.git
cd woven-ecs
pnpm install
pnpm build
pnpm test

License

MIT License.

Community

About

A multi-threaded ECS Framework for TypeScript

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors