> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nanoforge.eu/llms.txt
> Use this file to discover all available pages before exploring further.

# System

> Generate a NanoForge ECS system

## Overview

The `system` schematic scaffolds a new ECS system function for a NanoForge client or server part. The generated file includes the system function, a default export required for code generation, and an `EDITOR_SYSTEM_MANIFEST` required for the NanoForge editor to display and configure the system.

## Usage

```bash theme={null}
schematics @nanoforge-dev/schematics:system --part=client --name=movement
```

## Options

| Option | Type | Default | Description |
| - | - | - | - |
| `name` | `string` | `example` | System name (Converted to camelCase for the function name (e.g. 'movement' → 'movementSystem') and kebab-case for the file name (e.g. 'movement.system.ts').) |
| `part` | `"client" \| "server"` | *(required)* | The part of the application this system belongs to (Determines which ECS package to import from: @nanoforge-dev/ecs-client or @nanoforge-dev/ecs-server.) |
| `directory` | `string` | `.` | Destination directory for the generated file (Typically the systems/ folder inside your part directory, e.g. client/systems/.) |
| `language` | `"ts" \| "js"` | `ts` | Language to use for the generated file |

## Generated file

`{directory}/{name}.system.ts`

```ts theme={null}
import { type Context } from "@nanoforge-dev/common";
import { type EditorSystemManifest, type Registry } from "@nanoforge-dev/ecs-client";

import { ExampleComponent } from "../components/example.component";

export const movementSystem = (registry: Registry, ctx: Context) => {
  const entities = registry.getZipper([ExampleComponent]);

  entities.forEach((entity) => {
    if (entity.ExampleComponent.paramA === "end") {
      ctx.app.setIsRunning(false);
      return;
    }

    if (entity.ExampleComponent.paramB === 0) entity.ExampleComponent.paramA = "end";

    if (entity.ExampleComponent.paramB >= 0)
      entity.ExampleComponent.paramB = entity.ExampleComponent.paramB - 1;
  });
};

// Required to generate code
export default movementSystem.name;

// Required for the editor to display the system and generate code
export const EDITOR_SYSTEM_MANIFEST: EditorSystemManifest = {
  name: "movement",
  description:
    "This system end the game when paramB reaches 0 for any entity with ExampleComponent",
  dependencies: ["ExampleComponent"],
};
```

## Editor manifest

The `EDITOR_SYSTEM_MANIFEST` export is required for the NanoForge editor to discover the system and wire it into the game loop.

| Field | Required | Description |
| - | - | - |
| `name` | Yes | System name as displayed in the editor |
| `description` | Yes | Human-readable description of what the system does |
| `dependencies` | Yes | Component names this system depends on (Lists the component class names this system queries via registry.getZipper(). The editor uses this to validate wiring.) |

## System signature

Every NanoForge system follows the same function signature:

```ts theme={null}
(registry: Registry, ctx: Context) => void
```

* **`registry`** — the ECS registry; use `registry.getZipper([...])` to query entities with specific components.
* **`ctx`** — the application context; provides access to `ctx.app`, `ctx.assets`, and other engine services.

## Examples

**Generate a `PhysicsSystem` for the client:**

```bash theme={null}
schematics @nanoforge-dev/schematics:system \
  --part=client \
  --name=physics \
  --directory=client/systems
```

**Generate a JavaScript server system:**

```bash theme={null}
schematics @nanoforge-dev/schematics:system \
  --part=server \
  --name=sync-state \
  --language=js \
  --directory=server/systems
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.