agentleFS
bmcszkbmcszk/agent-skills/skills/ebiten/ecs/SKILL.md

ecs

Skill1 starsChanged 2 months agoMITView on GitHub

Entity Component System patterns for Ebitengine: Donburi, Ark, Mizu. Architecture, queries, systems.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill only when the task clearly matches the scope described above.

    line 407
  2. Distinctive:

    Do not treat the output as a substitute for environment-specific validation, testing, or expert review.

    line 408
  3. Distinctive:

    Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

    line 409

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Entity Component System (ECS)

ECS architecture patterns and libraries for Ebitengine games.


When to Use ECS

ScenarioUse ECS?Recommended
Hundreds+ entities (bullets, particles)YesDonburi or Ark
Deep inheritance hierarchiesYesAny ECS
Systems operate on entity subsetsYesDonburi
Prototype/quick game jamNoPlain structs
Simple game with < 50 entitiesNoComposition via structs
Turn-based with complex stateMaybeEvaluate per case
Real-time strategy with many unit typesYesDonburi or Ark

Library Comparison

FeatureDonburiArkMizuGohan
ApproachSparse set ECSArchetype ECSECS frameworkECS framework
PerformanceGoodExcellentGoodGood
API StyleBuilder patternArchetype queriesDeclarativeDeclarative
World ModelSingle worldMultiple worldsSingle worldSingle world
SerializationVia pluginsBuilt-inManualPartial
Ebiten IntegrationFirst-classManualFirst-classManual
Tag SupportYesYesYesYes
Networkingnecs pluginManualManualManual
GitHubyohamta/donburimlange-42/arksedyh/mizumttchpmn/gohan

Donburi Deep Dive

Donburi is the most popular ECS for Ebitengine, created by the same author as ganim8.

Components

package component

import (
    "github.com/yohamta/donburi"
    "github.com/yohamta/donburi/ecs"
)

type PositionData struct {
    X, Y float64
}

var Position = donburi.NewComponentType[PositionData]()

type VelocityData struct {
    X, Y float64
}

var Velocity = donburi.NewComponentType[VelocityData]()

type SpriteData struct {
    Image   *ebiten.Image
    Width   int
    Height  int
}

var Sprite = donburi.NewComponentType[SpriteData]()

type PlayerTag struct{}

var Player = donburi.NewTag().SetName("Player")

type HealthData struct {
    Current int
    Max     int
}

var Health = donburi.NewComponentType[HealthData]()

type EnemyTag struct{}

var Enemy = donburi.NewTag().SetName("Enemy")

Creating Entities

func CreatePlayer(ecs *ecs.ECS, x, y float64, img *ebiten.Image) donburi.Entity {
    entity := ecs.World.Create(
        component.Position,
        component.Velocity,
        component.Sprite,
        component.Health,
        component.Player,
    )
    entry := ecs.World.Entry(entity)
    donburi.SetValue(entry, component.Position, &component.PositionData{X: x, Y: y})
    donburi.SetValue(entry, component.Velocity, &component.VelocityData{})
    donburi.SetValue(entry, component.Sprite, &component.SpriteData{Image: img})
    donburi.SetValue(entry, component.Health, &component.HealthData{Current: 100, Max: 100})
    return entity
}

func CreateBullet(ecs *ecs.ECS, x, y, vx, vy float64, img *ebiten.Image) donburi.Entity {
    entity := ecs.World.Create(
        component.Position,
        component.Velocity,
        component.Sprite,
    )
    entry := ecs.World.Entry(entity)
    donburi.SetValue(entry, component.Position, &component.PositionData{X: x, Y: y})
    donburi.SetValue(entry, component.Velocity, &component.VelocityData{X: vx, Y: vy})
    donburi.SetValue(entry, component.Sprite, &component.SpriteData{Image: img})
    return entity
}

Queries

// Query all entities with Position and Velocity
query := donburi.NewQuery(
    filter.Contains(component.Position),
    filter.Contains(component.Velocity),
)

// Query with optional component
query := donburi.NewQuery(
    filter.Contains(component.Position),
    filter.Optional(component.Sprite),
)

// Query by tag
playerQuery := donburi.NewQuery(
    filter.Contains(component.Player),
)

// Iterate
query.Each(ecs.World, func(entry *donburi.Entry) {
    pos := component.Position.Get(entry)
    vel := component.Velocity.Get(entry)
    pos.X += vel.X
    pos.Y += vel.Y
})

Systems

type MovementSystem struct{}

func (s *MovementSystem) Update(ecs *ecs.ECS) {
    query := donburi.NewQuery(
        filter.Contains(component.Position),
        filter.Contains(component.Velocity),
    )
    query.Each(ecs.World, func(entry *donburi.Entry) {
        pos := component.Position.Get(entry)
        vel := component.Velocity.Get(entry)
        pos.X += vel.X
        pos.Y += vel.Y
    })
}

type RenderSystem struct{}

func (s *RenderSystem) Draw(ecs *ecs.ECS, screen *ebiten.Image) {
    opts := &ebiten.DrawImageOptions{}
    query := donburi.NewQuery(
        filter.Contains(component.Position),
        filter.Contains(component.Sprite),
    )
    query.Each(ecs.World, func(entry *donburi.Entry) {
        pos := component.Position.Get(entry)
        spr := component.Sprite.Get(entry)
        opts.GeoM.Reset()
        opts.GeoM.Translate(pos.X, pos.Y)
        screen.DrawImage(spr.Image, opts)
    })
}

type CollisionSystem struct{}

func (s *CollisionSystem) Update(ecs *ecs.ECS) {
    playerQuery := donburi.NewQuery(filter.Contains(component.Player))
    enemyQuery := donburi.NewQuery(filter.Contains(component.Enemy))

    playerQuery.Each(ecs.World, func(pEntry *donburi.Entry) {
        pPos := component.Position.Get(pEntry)
        enemyQuery.Each(ecs.World, func(eEntry *donburi.Entry) {
            ePos := component.Position.Get(eEntry)
            if math.Abs(pPos.X-ePos.X) < 16 && math.Abs(pPos.Y-ePos.Y) < 16 {
                health := component.Health.Get(pEntry)
                health.Current -= 10
            }
        })
    })
}

Tags

Tags are zero-size components used to categorize entities:

var Player = donburi.NewTag().SetName("Player")
var Enemy = donburi.NewTag().SetName("Enemy")
var Bullet = donburi.NewTag().SetName("Bullet")
var Collectible = donburi.NewTag().SetName("Collectible")

// Adding a tag
ecs.World.Create(component.Position, component.Player)

// Querying by tag
query := donburi.NewQuery(filter.Contains(component.Enemy))

Entity Removal

// Remove a single entity
entry := ecs.World.Entry(entity)
entry.Remove()

// Remove entities matching query (e.g., off-screen bullets)
query := donburi.NewQuery(
    filter.Contains(component.Bullet),
    filter.Contains(component.Position),
)
var toRemove []donburi.EntityID
query.Each(ecs.World, func(entry *donburi.Entry) {
    pos := component.Position.Get(entry)
    if pos.X < -50 || pos.X > 1000 || pos.Y < -50 || pos.Y > 1000 {
        toRemove = append(toRemove, entry.EntityID())
    }
})
for _, id := range toRemove {
    ecs.World.Remove(id)
}

Game Integration Pattern

package main

import (
    "github.com/hajimehoshi/ebiten/v2"
    "github.com/yohamta/donburi"
    "github.com/yohamta/donburi/ecs"
    "github.com/yohamta/donburi/filter"
)

type System interface {
    Update(e *ecs.ECS)
    Draw(e *ecs.ECS, screen *ebiten.Image)
}

type Game struct {
    ecs      *ecs.ECS
    systems  []System
}

func NewGame() *Game {
    g := &Game{
        ecs: ecs.NewECS(ecs.NewWorld()),
    }
    g.systems = []System{
        &InputSystem{},
        &MovementSystem{},
        &CollisionSystem{},
        &CleanupSystem{},
        &RenderSystem{},
    }

    // Create initial entities
    CreatePlayer(g.ecs, 100, 100, playerSprite)

    return g
}

func (g *Game) Update() error {
    for _, sys := range g.systems {
        sys.Update(g.ecs)
    }
    return nil
}

func (g *Game) Draw(screen *ebiten.Image) {
    for _, sys := range g.systems {
        sys.Draw(g.ecs, screen)
    }
}

func (g *Game) Layout(w, h int) (int, int) {
    return 320, 240
}

Networking with necs

import "github.com/leap-fish/necs"

// Setup networking layer on top of Donburi ECS
// necs provides:
// - Entity synchronization across network
// - Component replication
// - RPC system
// - Client/Server architecture

Ark (Alternative)

import "github.com/mlange-42/ark/ecs"

// Archetype-based ECS with excellent cache performance
w := ecs.NewWorld()

posMapper := ecs.NewMap1[Position](&w)
velMapper := ecs.NewMap2[Position, Velocity](&w)

// Create entity
entity := posMapper.NewEntity(&Position{X: 10, Y: 20})

// Query
query := ecs.NewFilter1[Position](&w)
for q.Next() {
    pos := q.Get()
    pos.X += 1
}

Ark is faster for large entity counts due to archetype storage, but has a steeper API.


When NOT to Use ECS

ScenarioBetter Approach
Simple game with few entity typesPlain Go structs with composition
Game jam / prototypeDirect struct-based design
Turn-based RPG with complex stateObject-oriented with interfaces
UI-heavy gameebitenui or furex
Puzzle game with grid state2D array with game logic

Simple Alternative (No ECS)

type Game struct {
    player   *Player
    enemies  []*Enemy
    bullets  []*Bullet
    particles []*Particle
}

func (g *Game) Update() error {
    g.player.Update()
    for _, e := range g.enemies {
        e.Update()
    }
    for _, b := range g.bullets {
        b.Update()
    }
    return nil
}

Anti-Patterns

Don'tDo
Store *ebiten.Image in every entityStore sprite ID, use a lookup table
Create/destroy entities every frame for particlesUse an object pool
Put game logic in component getters/settersKeep components as pure data
Query all entities when you need oneUse tag + targeted query
Mix rendering logic into ECS systemsKeep render systems separate
Use ECS for UI elementsUse a UI library instead
Create world per level (Donburi)Use a single world, manage entity lifecycles
Store references to entries across framesRe-query or use Entity IDs
Skip removing dead entitiesClean up each frame to prevent memory leaks

When to Use

This skill is applicable when designing or implementing an Entity Component System architecture in an Ebitengine game.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.