|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +objECS is a TypeScript Entity Component System (ECS) library for game development. It uses a pnpm monorepo structure. |
| 8 | + |
| 9 | +## Monorepo Structure |
| 10 | + |
| 11 | +- `packages/objecs/` - Core ECS library (published to npm as `objecs`) |
| 12 | +- `packages/examples/` - Vite-based demo applications using the library |
| 13 | +- `packages/ecs-benchmark/` - Benchmarks comparing objecs against other ECS libraries |
| 14 | +- `packages/benchmark/` - Additional benchmarking utilities |
| 15 | + |
| 16 | +## Common Commands |
| 17 | + |
| 18 | +### Root-level |
| 19 | +```bash |
| 20 | +pnpm install # Install all dependencies |
| 21 | +pnpm lint # Lint all packages |
| 22 | +pnpm lint:fix # Fix lint issues |
| 23 | +``` |
| 24 | + |
| 25 | +### Core Library (packages/objecs) |
| 26 | +```bash |
| 27 | +pnpm --filter objecs build # Build the library (runs lint first) |
| 28 | +pnpm --filter objecs test # Run tests in watch mode |
| 29 | +pnpm --filter objecs test run # Run tests once |
| 30 | +pnpm --filter objecs lint # Lint the library |
| 31 | +``` |
| 32 | + |
| 33 | +### Examples (packages/examples) |
| 34 | +```bash |
| 35 | +pnpm --filter examples dev # Start Vite dev server |
| 36 | +pnpm --filter examples build # Build examples |
| 37 | +``` |
| 38 | + |
| 39 | +### Benchmarks |
| 40 | +```bash |
| 41 | +pnpm --filter ecs-benchmark start # Run ECS comparison benchmarks |
| 42 | +``` |
| 43 | + |
| 44 | +## Architecture |
| 45 | + |
| 46 | +### Core Concepts |
| 47 | + |
| 48 | +**World** (`packages/objecs/src/world.ts`): Container for all entities. Creates entities, manages archetypes, and handles component operations. |
| 49 | + |
| 50 | +**Archetype** (`packages/objecs/src/archetype.ts`): A query that groups entities sharing the same component combination. Created via `world.archetype('component1', 'component2', ...)`. Supports `without()` for exclusion filters. |
| 51 | + |
| 52 | +**Entity**: Plain JavaScript objects (must be `JsonObject` from type-fest). Components are simply properties on the entity object. |
| 53 | + |
| 54 | +### Usage Pattern |
| 55 | + |
| 56 | +```typescript |
| 57 | +// Define entity type with all possible components |
| 58 | +type Entity = { |
| 59 | + position?: { x: number; y: number }; |
| 60 | + velocity?: { x: number; y: number }; |
| 61 | + health?: number; |
| 62 | +}; |
| 63 | + |
| 64 | +// Create world and entities |
| 65 | +const world = new World<Entity>(); |
| 66 | +world.createEntity({ position: { x: 0, y: 0 }, velocity: { x: 1, y: 0 } }); |
| 67 | + |
| 68 | +// Create archetype query (entities matching these components) |
| 69 | +const movingEntities = world.archetype('position', 'velocity'); |
| 70 | + |
| 71 | +// Iterate in systems |
| 72 | +for (const entity of movingEntities.entities) { |
| 73 | + entity.position.x += entity.velocity.x * dt; |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +### Type Safety |
| 78 | + |
| 79 | +- `SafeEntity<Entity, Components>` ensures queried components exist |
| 80 | +- Archetypes return entities with required components as non-optional |
| 81 | +- `createEntity()` with arguments requires at least one component |
| 82 | + |
| 83 | +## Development Workflow |
| 84 | + |
| 85 | +Uses [Conventional Commits](https://www.conventionalcommits.org/). For releases: |
| 86 | +1. Run `bumpp` to interactively create a version tag |
| 87 | +2. Create GitHub release to trigger publish workflow |
| 88 | + |
| 89 | +## Testing |
| 90 | + |
| 91 | +Tests use Vitest. Test files are colocated with source (`.test.ts` suffix). |
0 commit comments