{"id":13534247,"url":"https://github.com/ecsyjs/ecsy","last_synced_at":"2025-09-27T08:30:40.837Z","repository":{"id":40463737,"uuid":"185996067","full_name":"ecsyjs/ecsy","owner":"ecsyjs","description":"Entity Component System for javascript","archived":true,"fork":false,"pushed_at":"2022-05-06T18:03:44.000Z","size":3987,"stargazers_count":1121,"open_issues_count":47,"forks_count":115,"subscribers_count":41,"default_branch":"dev","last_synced_at":"2025-01-12T07:12:24.894Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://ecsyjs.github.io/ecsy/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ecsyjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-10T13:48:06.000Z","updated_at":"2025-01-05T19:43:41.000Z","dependencies_parsed_at":"2022-08-09T21:12:35.838Z","dependency_job_id":null,"html_url":"https://github.com/ecsyjs/ecsy","commit_stats":null,"previous_names":["mozillareality/ecsy"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecsyjs%2Fecsy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecsyjs%2Fecsy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecsyjs%2Fecsy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecsyjs%2Fecsy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ecsyjs","download_url":"https://codeload.github.com/ecsyjs/ecsy/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234410531,"owners_count":18828227,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T07:01:28.808Z","updated_at":"2025-09-27T08:30:35.209Z","avatar_url":"https://github.com/ecsyjs.png","language":"JavaScript","readme":"# ecsy\n\n[![NPM package][npm]][npm-url]\n[![Build Size][build-size]][build-size-url]\n[![Dev Dependencies][dev-dependencies]][dev-dependencies-url]\n[![Build Status][build-status]][build-status-url]\n\u003c!--[![Language Grade][lgtm]][lgtm-url]\n[![Dependencies][dependencies]][dependencies-url]--\u003e\n\nECSY (pronounced as \"eck-see\") is an highly experimental Entity Component System framework implemented in javascript, aiming to be lightweight, easy to use and with good performance.\n\nFor detailed information on the architecture and API please visit the [documentation page](https://ecsyjs.github.io/ecsy/docs/#/)\n\n* discourse forum: https://discourse.mozilla.org/c/mixed-reality/ecsy\n* discord: https://discord.gg/cFnrQ2v\n\n## Features\n- Framework agnostic\n- Focused on providing a simple but yet efficient API\n- Designed to avoid garbage collection as possible\n- Systems, entities and components are scoped in a `world` instance\n- Multiple queries per system\n- Reactive support:\n  - Support for reactive behaviour on systems (React to changes on entities and components)\n  - System can query mutable or immutable components\n- Predictable:\n  - Systems will run on the order they were registered or based on the priority defined when registering them\n  - Reactive events will not generate a random callback when emited but queued and be processed in order\n- Modern Javascript: ES6, classes, modules,...\n- Pool for components and entities\n\n## Goals\nOur goal is for ECSY to be a lightweight, simple, and performant ECS library that can be easily extended and encoruages open source collaboration.\n\nECSY will not ship with features that bind it to a rendering engine or framework. Instead, we encourage the community to build framework specific projects like [ecsy-three](https://github.com/MozillaReality/ecsy-three), [ecsy-babylon](https://github.com/kaliber5/ecsy-babylon), and [ecsy-two](https://github.com/joshmarinacci/ecsy-two).\n\nECSY does not adhere strictly to \"pure ECS design\". We focus on APIs that push users towards good ECS design like putting their logic in systems and data in components. However, we will sometimes break the rules for API ergonomics, performance in a JS context, or integration with non-ECS frameworks.\n\nECSY is designed for a community driven ecosystem. We encourage users to come up with modular components and systems that can be composed into larger games, apps, and engines.\n\n# Examples\n- Ball example:\n  - three.js: https://ecsyjs.github.io/ecsy/examples/ball-example/three\n  - babylon: https://ecsyjs.github.io/ecsy/examples/ball-example/babylon\n- 2D Canvas https://ecsyjs.github.io/ecsy/examples/canvas\n- Factory pattern with `Not` operator: https://ecsyjs.github.io/ecsy/examples/factory\n- System state component example: https://ecsyjs.github.io/ecsy/examples/systemstatecomponents\n\n# Usage\n\nInstalling the package via `npm`:\n\n```\nnpm install --save ecsy\n```\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003ctitle\u003eHello!\u003c/title\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003cmeta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\"\u003e\n    \u003cstyle\u003e\n      html, body: {\n        margin: 0;\n        padding: 0;\n      }\n    \u003c/style\u003e\n\n    \u003cscript type=\"module\"\u003e\n      import { World, System, Component, TagComponent, Types } from \"https://ecsyjs.github.io/ecsy/build/ecsy.module.js\";\n\n      const NUM_ELEMENTS = 50;\n      const SPEED_MULTIPLIER = 0.3;\n      const SHAPE_SIZE = 50;\n      const SHAPE_HALF_SIZE = SHAPE_SIZE / 2;\n\n      // Initialize canvas\n      let canvas = document.querySelector(\"canvas\");\n      let canvasWidth = canvas.width = window.innerWidth;\n      let canvasHeight = canvas.height = window.innerHeight;\n      let ctx = canvas.getContext(\"2d\");\n\n      //----------------------\n      // Components\n      //----------------------\n\n      // Velocity component\n      class Velocity extends Component {}\n\n      Velocity.schema = {\n        x: { type: Types.Number },\n        y: { type: Types.Number }\n      };\n\n      // Position component\n      class Position extends Component {}\n\n      Position.schema = {\n        x: { type: Types.Number },\n        y: { type: Types.Number }\n      };\n\n      // Shape component\n      class Shape extends Component {}\n\n      Shape.schema = {\n        primitive: { type: Types.String, default: 'box' }\n      };\n\n      // Renderable component\n      class Renderable extends TagComponent {}\n\n      //----------------------\n      // Systems\n      //----------------------\n\n      // MovableSystem\n      class MovableSystem extends System {\n        // This method will get called on every frame by default\n        execute(delta, time) {\n          // Iterate through all the entities on the query\n          this.queries.moving.results.forEach(entity =\u003e {\n            var velocity = entity.getComponent(Velocity);\n            var position = entity.getMutableComponent(Position);\n            position.x += velocity.x * delta;\n            position.y += velocity.y * delta;\n\n            if (position.x \u003e canvasWidth + SHAPE_HALF_SIZE) position.x = - SHAPE_HALF_SIZE;\n            if (position.x \u003c - SHAPE_HALF_SIZE) position.x = canvasWidth + SHAPE_HALF_SIZE;\n            if (position.y \u003e canvasHeight + SHAPE_HALF_SIZE) position.y = - SHAPE_HALF_SIZE;\n            if (position.y \u003c - SHAPE_HALF_SIZE) position.y = canvasHeight + SHAPE_HALF_SIZE;\n          });\n        }\n      }\n\n      // Define a query of entities that have \"Velocity\" and \"Position\" components\n      MovableSystem.queries = {\n        moving: {\n          components: [Velocity, Position]\n        }\n      }\n\n      // RendererSystem\n      class RendererSystem extends System {\n        // This method will get called on every frame by default\n        execute(delta, time) {\n\n          ctx.fillStyle = \"#d4d4d4\";\n          ctx.fillRect(0, 0, canvasWidth, canvasHeight);\n\n          // Iterate through all the entities on the query\n          this.queries.renderables.results.forEach(entity =\u003e {\n            var shape = entity.getComponent(Shape);\n            var position = entity.getComponent(Position);\n            if (shape.primitive === 'box') {\n              this.drawBox(position);\n            } else {\n              this.drawCircle(position);\n            }\n          });\n        }\n\n        drawCircle(position) {\n          ctx.beginPath();\n          ctx.arc(position.x, position.y, SHAPE_HALF_SIZE, 0, 2 * Math.PI, false);\n          ctx.fillStyle= \"#39c495\";\n          ctx.fill();\n          ctx.lineWidth = 2;\n          ctx.strokeStyle = \"#0b845b\";\n          ctx.stroke();\n        }\n\n        drawBox(position) {\n          ctx.beginPath();\n          ctx.rect(position.x - SHAPE_HALF_SIZE, position.y - SHAPE_HALF_SIZE, SHAPE_SIZE, SHAPE_SIZE);\n          ctx.fillStyle= \"#e2736e\";\n          ctx.fill();\n          ctx.lineWidth = 2;\n          ctx.strokeStyle = \"#b74843\";\n          ctx.stroke();\n        }\n      }\n\n      // Define a query of entities that have \"Renderable\" and \"Shape\" components\n      RendererSystem.queries = {\n        renderables: { components: [Renderable, Shape] }\n      }\n\n      // Create world and register the components and systems on it\n      var world = new World();\n      world\n        .registerComponent(Velocity)\n        .registerComponent(Position)\n        .registerComponent(Shape)\n        .registerComponent(Renderable)\n        .registerSystem(MovableSystem)\n        .registerSystem(RendererSystem);\n\n      // Some helper functions when creating the components\n      function getRandomVelocity() {\n        return {\n          x: SPEED_MULTIPLIER * (2 * Math.random() - 1),\n          y: SPEED_MULTIPLIER * (2 * Math.random() - 1)\n        };\n      }\n\n      function getRandomPosition() {\n        return {\n          x: Math.random() * canvasWidth,\n          y: Math.random() * canvasHeight\n        };\n      }\n\n      function getRandomShape() {\n         return {\n           primitive: Math.random() \u003e= 0.5 ? 'circle' : 'box'\n         };\n      }\n\n      for (let i = 0; i \u003c NUM_ELEMENTS; i++) {\n        world\n          .createEntity()\n          .addComponent(Velocity, getRandomVelocity())\n          .addComponent(Shape, getRandomShape())\n          .addComponent(Position, getRandomPosition())\n          .addComponent(Renderable)\n      }\n\n      // Run!\n      function run() {\n        // Compute delta and elapsed time\n        var time = performance.now();\n        var delta = time - lastTime;\n\n        // Run all the systems\n        world.execute(delta, time);\n\n        lastTime = time;\n        requestAnimationFrame(run);\n      }\n\n      var lastTime = performance.now();\n      run();\n    \u003c/script\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ccanvas width=\"500\" height=\"500\"\u003e\u003c/canvas\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n[Try it on glitch](https://glitch.com/~ecsy-0-3-0-boxes-and-circles)\n\n\nYou can also include the hosted javascript directly on your HTML:\n\n```html\n\u003c!-- Using UMD (It will expose a global ECSY namespace) --\u003e\n\u003cscript src=\"https://ecsyjs.github.io/ecsy/build/ecsy.js\"\u003e\u003c/script\u003e\n\n\u003c!-- Using ES6 modules --\u003e\n\u003cscript src=\"https://ecsyjs.github.io/ecsy/build/ecsy.module.js\"\u003e\u003c/script\u003e\n```\n\n[npm]: https://img.shields.io/npm/v/ecsy.svg\n[npm-url]: https://www.npmjs.com/package/ecsy\n[build-size]: https://badgen.net/bundlephobia/minzip/ecsy\n[build-size-url]: https://bundlephobia.com/result?p=ecsy\n[dependencies]: https://img.shields.io/david/fernandojsg/ecsy.svg\n[dependencies-url]: https://david-dm.org/fernandojsg/ecsy\n[dev-dependencies]: https://img.shields.io/david/dev/fernandojsg/ecsy.svg\n[dev-dependencies-url]: https://david-dm.org/fernandojsg/ecsy#info=devDependencies\n[lgtm]: https://img.shields.io/lgtm/grade/javascript/g/fernandojsg/ecsy.svg?label=code%20quality\n[lgtm-url]: https://lgtm.com/projects/g/fernandojsg/ecsy/\n[build-status]: https://travis-ci.com/fernandojsg/ecsy.svg?branch=master\n[build-status-url]: https://travis-ci.com/fernandojsg/ecsy\n","funding_links":[],"categories":["JavaScript","[ECS Libraries](#contents)","Libraries"],"sub_categories":["JavaScript"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecsyjs%2Fecsy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecsyjs%2Fecsy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecsyjs%2Fecsy/lists"}