Skip to content

Commit a9ed24c

Browse files
spearwolfclaude
andcommitted
Redesign docs: ECS framing, flat 7-file structure
Replace Shadow Theater analogy with ECS game engine framing throughout all docs, READMEs, and AGENTS.md. Consolidate 15 files in 4 subdirs into 7 flat files in docs/: - concepts.md (merged 4 Concepts/ files) - guides.md (merged 3 Guides/ files + multi-env + framework integration) - api-reference.md (merged 5 API/ files, anchor-linked nav) - cheat-sheet.md (new: at-a-glance tables and snippets) - best-practices.md (expanded: local/remote guidance, ECS composition, cleanup checklist, unit testing patterns) - getting-started.md (moved from Guides/01, ECS terminology) Update AGENTS.md: ECS mental model, "How It Works (3 lines)" section, expanded monorepo package table, new 7-file doc structure table. Update root README.md: ECS analogy, positioning as complement to React/Vue/Svelte and evolution of Redux/Zustand/Jotai. Create shadow-objects-testing/README.md and shadow-objects-e2e/README.md. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6c11573 commit a9ed24c

27 files changed

Lines changed: 3259 additions & 2894 deletions

AGENTS.md

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,56 @@
22

33
This document provides context and guidelines for AI agents working on the **Shadow Objects Framework**.
44

5-
## 1. Project Overview
5+
## 1. How It Works (3 lines)
66

7-
The **Shadow Objects Framework** is a reactive library designed to decouple business logic and state management from the UI rendering layer. It runs application logic "in the dark" (e.g., in a web worker), mirroring the view hierarchy of the application.
8-
9-
**Goal:** Separate concerns by running logic in a separate thread/context from the UI, using a reactive architecture.
7+
Shadow Objects is an ECS framework where **Entities** (game objects) live in a **Shadow Environment** (main thread or web worker), and **Shadow Objects** (ECS components) attach behavior to them. The **View Layer** (DOM, Canvas) renders entity state and dispatches events back into the shadow environment. The **Kernel** orchestrates the entity lifecycle and schedules updates.
108

119
## 2. Architecture & Core Concepts
1210

13-
### Mental Model (The Shadow Theater)
14-
- **View (Screen):** The visible UI (DOM, Canvas). Minimal state, pure projection.
15-
- **Entities (Puppets):** Abstract representation of components in the Shadow World.
16-
- **Shadow Objects (Puppeteer):** Functional units of logic attached to Entities.
17-
- **Token:** String identifier linking View components to Logic.
11+
### Mental Model (ECS Game Engine)
12+
13+
Shadow Objects is an Entity-Component System (ECS) applied to web app state management:
14+
15+
- **View / Renderer:** The visible UI (DOM, Canvas). Minimal state, pure rendering.
16+
- **Entities (Game Objects):** Lightweight containers in the shadow environment — no logic of their own.
17+
- **Shadow Objects (ECS Components):** Functional units of logic attached to Entities. This is where behavior lives.
18+
- **Token (Component Tag):** String identifier linking View nodes to their shadow logic.
1819

1920
### Key Components
20-
- **Kernel:** The engine. Manages Entity lifecycle, orchestrates Shadow Objects, and schedules updates.
21-
- **Registry:** Maps **Tokens** to **Shadow Object Constructors**. Defines routing and composition rules.
22-
- **Message Dispatch:** Bridges the gap between Light World (UI) and Shadow World (Worker) via asynchronous messages.
21+
22+
- **Kernel (ECS System Runner):** Manages Entity lifecycle, orchestrates Shadow Objects, schedules updates.
23+
- **Registry (Component Manifest):** Maps **Tokens** to **Shadow Object Constructors**. Defines routing and composition rules.
24+
- **Message Dispatch:** Bridges View Layer and Shadow Environment via asynchronous messages.
2325

2426
### Reactivity
25-
- Uses Signals and Effects (via `@spearwolf/signalize`).
26-
- **Data Flow:**
27-
- **Downstream (Props):** View -> Kernel -> Entity -> Shadow Object Signal.
28-
- **Upstream (Events):** Shadow Object -> Entity -> Kernel -> View.
29-
- **Lateral (Context):** Hierarchical dependency injection (Provider/Consumer) between Entities.
27+
28+
Uses Signals and Effects (via `@spearwolf/signalize`).
29+
30+
**Data Flow:**
31+
- **Downstream (Props):** View -> Kernel -> Entity -> Shadow Object Signal.
32+
- **Upstream (Events):** Shadow Object -> Entity -> Kernel -> View.
33+
- **Lateral (Context):** Hierarchical dependency injection (Provider/Consumer) between Entities.
3034

3135
## 3. Monorepo Structure
3236

33-
- **`packages/shadow-objects/`**: The main framework library. Deployment package: `@spearwolf/shadow-objects`.
34-
- **`packages/shadow-objects/docs/`**: **The authoritative source of documentation.** Contains Fundamentals, Guides, and API references.
35-
- **`packages/shae-offscreen-canvas/`**: An offscreen canvas as custom HTML element based on shadow-objects.
36-
- **`packages/shadow-objects-testing/`**: Functional tests.
37-
- **`packages/shadow-objects-e2e/`**: Blackbox / E2E tests.
37+
| Package | npm name | Purpose |
38+
|---------|----------|---------|
39+
| `packages/shadow-objects/` | `@spearwolf/shadow-objects` | Core framework library |
40+
| `packages/shae-offscreen-canvas/` | `@spearwolf/shae-offscreen-canvas` | Offscreen canvas custom element (example impl) |
41+
| `packages/shadow-objects-testing/` | — (not published) | Functional/integration tests |
42+
| `packages/shadow-objects-e2e/` | — (not published) | Playwright E2E tests |
43+
44+
**Docs location:** `packages/shadow-objects/docs/` is the authoritative source of documentation. It uses a flat 7-file structure:
45+
46+
| File | Purpose |
47+
|------|---------|
48+
| `docs/README.md` | Overview and navigation |
49+
| `docs/getting-started.md` | Hello World, first shadow object |
50+
| `docs/concepts.md` | ECS mental model, architecture, lifecycle, entity tree |
51+
| `docs/guides.md` | Writing shadow objects, view integration, multi-env setup |
52+
| `docs/api-reference.md` | Full API reference (all methods, options, types) |
53+
| `docs/cheat-sheet.md` | At-a-glance tables and snippets |
54+
| `docs/best-practices.md` | Patterns, composition, cleanup, testing |
3855

3956
## 4. Coding Guidelines
4057

@@ -51,6 +68,7 @@ The **Shadow Objects Framework** is a reactive library designed to decouple busi
5168
3. `packages/shadow-objects/CHANGELOG.md`.
5269
- **Language:** Always use **English**.
5370
- **Format:** Use **Markdown**.
71+
- **Terminology:** Use ECS terms. Never use: "shadow theater", "puppet", "puppeteer", "light world", "screen" (as analogy).
5472

5573
### Development Workflow
5674
- **TODOs:** If you add, modify, or delete a TODO comment, run `pnpm make:todo` to update `TODO.md`.
@@ -77,10 +95,10 @@ The **Shadow Objects Framework** is a reactive library designed to decouple busi
7795

7896
You are a professional developer advocate from Google.
7997
When you write, you speak in a friendly tone.
80-
You dont add extra emojis or em dashes.
98+
You don't add extra emojis or em dashes.
8199
You write to developers as if they are your buddy.
82-
You are technical and arent afraid of including code samples.
83-
Dont assume too much knowledge, and include quotable short lines that people could post on social media when they share your content.
100+
You are technical and aren't afraid of including code samples.
101+
Don't assume too much knowledge, and include quotable short lines that people could post on social media when they share your content.
84102

85103
**Documentation Strategy:**
86104
- The new documentation is located at `packages/shadow-objects/docs/`.

README.md

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,65 @@
11
# shadow-objects
22

3-
A reactive Entity&larr;Component Framework that feels at home in the shadows 🧛
3+
A reactive Entity-Component Framework for running app logic in a shadow environment.
44

55
> [!WARNING]
6-
> 🚀 This is a highly experimental framework that is slowly maturing. Use at your own risk. 🔥
6+
> This is a highly experimental framework that is slowly maturing. Use at your own risk.
77
88
---
99

10-
## 🎭 The Mental Model: The Shadow Theater
10+
## The Mental Model: ECS for Web Apps
11+
12+
Think of shadow-objects like a **game engine for your application state**:
1113

12-
Imagine a **web application** like a classic **Shadow Theater**:
14+
- **Your UI (React, Vue, Svelte, Canvas)** is the renderer — it just draws what it's told.
15+
- **Entities** are lightweight game objects in the shadow environment. No logic, just identity.
16+
- **Shadow Objects** are ECS components that attach behavior to entities — signals, effects, event handlers.
17+
- **The Kernel** runs the show: it manages entity lifecycle and schedules updates.
1318

14-
* **The Screen (View):** What the user sees – the DOM elements and UI components.
15-
* **The Puppets (Entities):** The abstract objects in the background representing the actual scene.
16-
* **The Puppeteer (Shadow Object):** The logic pulling the strings. The puppeteer decides how the puppets move but remains invisible to the audience.
19+
Your UI is the renderer. Shadow Objects is the game world.
1720

18-
**The Problem with Traditional Frameworks:**
19-
Logic (puppeteer) and presentation (screen) are often mixed in the same thread (Main Thread). This works well for document-centric applications, but friction arises in complex, rich interactions like 3D configurators, game engines, or data-intensive tools and leads to complexity bottlenecks because UI rendering blocks business logic – and vice versa.
21+
The shadow environment can run on the **main thread** (local mode, zero overhead) or in a **web worker** (remote mode, parallel execution). Both are first-class citizens.
2022

21-
**The Solution by `shadow-objects`:**
22-
We separate the worlds strictly.
23+
**Shadow Objects doesn't replace React, Vue, or Svelte.** It's the logic layer those frameworks render. When your app state gets complex enough that you're fighting your UI framework's reactivity, shadow-objects gives you a clean separation: business logic over here, rendering over there.
2324

24-
![The Shadow Theater Model](packages/shadow-objects/docs/shadow-theater.svg)
25+
If Redux and Zustand are global state on one thread, shadow-objects is reactive ECS state across any number of threads.
2526

26-
1. **In the Light (Main Thread):** The dumb View. It only displays and forwards events.
27-
2. **In the Shadow (Web Worker _or_ Main Thread):** The smart Logic. This is where **Entities** and **Shadow Objects** live. They process data, calculate states, and "project" the result back onto the screen.
27+
---
2828

29-
Through this architecture, your application logic runs parallel to the UI, decoupled and reactive.
29+
> [!WARNING]
30+
> 🚀 This is a highly experimental framework that is slowly maturing. Use at your own risk. 🔥
3031
3132
---
3233

33-
## 📚 Documentation
34+
## Documentation
3435

35-
**The complete and authoritative documentation is located in the [`packages/shadow-objects/docs/`](packages/shadow-objects/docs/) directory.**
36+
**The complete and authoritative documentation is in [`packages/shadow-objects/docs/`](packages/shadow-objects/docs/).**
3637

37-
* [**Fundamentals**](packages/shadow-objects/docs/01-concepts/): Understand the mental model, architecture, and lifecycle in detail.
38-
* [**Guides**](packages/shadow-objects/docs/02-guides/): Step-by-step instructions for getting started.
39-
* [**API Reference**](packages/shadow-objects/docs/03-api/): Detailed description of the interfaces.
38+
| File | What's inside |
39+
| :--- | :--- |
40+
| [**getting-started.md**](packages/shadow-objects/docs/getting-started.md) | Hello World, your first shadow object |
41+
| [**concepts.md**](packages/shadow-objects/docs/concepts.md) | ECS mental model, architecture, lifecycle, entity tree |
42+
| [**guides.md**](packages/shadow-objects/docs/guides.md) | Writing shadow objects, view integration, multi-env setup |
43+
| [**api-reference.md**](packages/shadow-objects/docs/api-reference.md) | Full API reference |
44+
| [**cheat-sheet.md**](packages/shadow-objects/docs/cheat-sheet.md) | At-a-glance tables and snippets |
45+
| [**best-practices.md**](packages/shadow-objects/docs/best-practices.md) | Patterns, composition, cleanup, testing |
4046

4147
---
4248

43-
## 🏗️ Project Structure (Monorepo)
49+
## Project Structure (Monorepo)
4450

4551
This repository is a monorepo managed with [nx](https://nx.dev/) and [pnpm](https://pnpm.io/).
4652

47-
### Core Packages
48-
49-
| Package | Description |
50-
| :--- | :--- |
51-
| **[`shadow-objects`](packages/shadow-objects/)** | The heart. The core library of the framework. |
52-
| **[`shae-offscreen-canvas`](packages/shae-offscreen-canvas/)** | A Custom Element implementing an **Offscreen Canvas** – demonstrates the power of `shadow-objects` for graphics applications. |
53-
54-
### Testing & Quality Assurance
55-
56-
| Package | Description |
57-
| :--- | :--- |
58-
| **[`shadow-objects-testing`](packages/shadow-objects-testing/)** | Functional and integration tests. |
59-
| **[`shadow-objects-e2e`](packages/shadow-objects-e2e/)** | End-to-End tests using [Playwright](https://playwright.dev/). |
53+
| Package | npm name | Description |
54+
| :--- | :--- | :--- |
55+
| [**`shadow-objects`**](packages/shadow-objects/) | `@spearwolf/shadow-objects` | The core framework library |
56+
| [**`shae-offscreen-canvas`**](packages/shae-offscreen-canvas/) | `@spearwolf/shae-offscreen-canvas` | Custom element for offscreen canvas rendering — demonstrates shadow-objects for graphics |
57+
| [**`shadow-objects-testing`**](packages/shadow-objects-testing/) | — (not published) | Functional and integration tests |
58+
| [**`shadow-objects-e2e`**](packages/shadow-objects-e2e/) | — (not published) | End-to-end tests using [Playwright](https://playwright.dev/) |
6059

6160
---
6261

63-
## Available Scripts
62+
## Available Scripts
6463

6564
Run these commands from the root directory:
6665

@@ -76,14 +75,14 @@ Run these commands from the root directory:
7675

7776
---
7877

79-
## ⚙️ Development Setup
78+
## Development Setup
8079

81-
1. **Prerequisites:** Node.js >=20.12.2, pnpm >=9.1.2
82-
2. **Install Dependencies:**
80+
1. **Prerequisites:** Node.js >=20.12.2, pnpm >=9.1.2
81+
2. **Install Dependencies:**
8382
```sh
8483
pnpm install
8584
```
86-
3. **Install Playwright Browsers (for E2E Tests):**
85+
3. **Install Playwright Browsers (for E2E Tests):**
8786
```sh
8887
cd packages/shadow-objects-e2e
8988
pnpm exec playwright install chromium firefox
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# shadow-objects-e2e
2+
3+
Playwright end-to-end test suite for the shadow-objects ecosystem.
4+
5+
This package is not published to npm. It runs full browser tests against a Vite-served app, covering scenarios that require a real page load -- remote worker environments, bundle integrity, and multi-entity interactions.
6+
7+
## What lives here
8+
9+
- **Remote worker environment tests** -- spinning up a shadow environment in a web worker and verifying it communicates correctly with the view layer
10+
- **Bundle smoke tests** -- loading the published build artifacts in a real browser to catch packaging mistakes early
11+
- **Worker and canvas integration tests** -- exercising the full path from view-layer entities through the worker to rendered output
12+
13+
## Prerequisites
14+
15+
Playwright browsers must be installed before running the tests:
16+
17+
```bash
18+
pnpm exec playwright install chromium firefox
19+
```
20+
21+
## How to run
22+
23+
From the monorepo root:
24+
25+
```bash
26+
pnpm nx run shadow-objects-e2e:e2e
27+
```
28+
29+
Or from inside this package:
30+
31+
```bash
32+
pnpm test
33+
```
34+
35+
To run with the Playwright UI:
36+
37+
```bash
38+
pnpm test:ui
39+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# shadow-objects-testing
2+
3+
Functional and integration test suite for the `@spearwolf/shadow-objects` core library.
4+
5+
This package is not published to npm. It exists solely to exercise the shadow-objects internals in a real browser environment using `@web/test-runner`.
6+
7+
## What lives here
8+
9+
- **Entity and component lifecycle tests** -- verifying that entities are created, destroyed, and re-parented correctly
10+
- **Token and registry tests** -- confirming that tokens connect view nodes to the right shadow objects
11+
- **Change propagation tests** -- covering how property and token changes flow through the shadow environment
12+
- **Event routing tests** -- ensuring that events sent from the view layer reach the correct shadow objects
13+
14+
## How to run
15+
16+
From the monorepo root:
17+
18+
```bash
19+
pnpm nx run shadow-objects-testing:test
20+
```
21+
22+
Or from inside this package:
23+
24+
```bash
25+
pnpm test
26+
```
27+
28+
To run in watch mode:
29+
30+
```bash
31+
pnpm watch
32+
```

packages/shadow-objects/README.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,42 @@
1-
# Shadow Objects Framework
1+
# Shadow Objects
22

3-
This package contains the core library for the **Shadow Objects Framework** — a reactive library that decouples business logic from UI rendering using a full Entity Component System (ECS) architecture.
3+
[![npm](https://img.shields.io/npm/v/@spearwolf/shadow-objects)](https://www.npmjs.com/package/@spearwolf/shadow-objects)
44

5-
**👉 [Read the Documentation](./docs/README.md)**
6-
7-
## Contents
8-
9-
* [**Concepts**](./docs/01-concepts/): Understand the mental model, architecture, and lifecycle.
10-
* [**Guides**](./docs/02-guides/): Step-by-step instructions.
11-
* [**API Reference**](./docs/03-api/): Detailed API docs.
12-
* [**Best Practices & Patterns**](./docs/04-patterns/): Idiomatic usage and design patterns.
5+
Shadow Objects is a reactive ECS (Entity Component System) library that decouples business logic from UI rendering. Entities are lightweight game objects; Shadow Objects are ECS components that attach behavior to them. Shadow environments can run on the main thread (local) or in a web worker (remote) -- both are first-class.
136

147
## Installation
158

169
```bash
1710
npm install @spearwolf/shadow-objects
1811
```
12+
13+
## Quick Example
14+
15+
```typescript
16+
import { Registry } from '@spearwolf/shadow-objects';
17+
18+
// Define a shadow object -- an ECS component with behavior
19+
function MyComponent({ entity, useSignals }) {
20+
const [count, setCount] = useSignals('count', 0);
21+
22+
entity.on('increment', () => setCount(count.get() + 1));
23+
24+
return () => {
25+
// cleanup on destroy
26+
};
27+
}
28+
29+
// Register it: when a view node has the token 'my-component',
30+
// this shadow object runs in the shadow environment
31+
Registry.define('my-component', MyComponent);
32+
```
33+
34+
## Documentation
35+
36+
- [Overview](./docs/README.md)
37+
- [Getting Started](./docs/getting-started.md)
38+
- [Concepts](./docs/concepts.md)
39+
- [Guides](./docs/guides.md)
40+
- [API Reference](./docs/api-reference.md)
41+
- [Cheat Sheet](./docs/cheat-sheet.md)
42+
- [Best Practices](./docs/best-practices.md)

0 commit comments

Comments
 (0)