---
url: /api/kiln/functions/system.md
---
[Kiln API](../../index.md) / [kiln](../index.md) / system

# Function: system()

## Call Signature

```ts
function system(fn, options?): System;
```

A system with no query: runs once per phase run with only the context.

### Parameters

| Parameter | Type |
| ------ | ------ |
| `fn` | (`ctx`) => `void` |
| `options?` | [`SystemOptions`](../interfaces/SystemOptions.md) |

### Returns

[`System`](../interfaces/System.md)

## Call Signature

```ts
function system<P>(
   query, 
   fn, 
   options?
): System;
```

A per-entity system: runs fn once per entity matching the query.

### Type Parameters

| Type Parameter |
| ------ |
| `P` *extends* [`QueryList`](../type-aliases/QueryList.md) |

### Parameters

| Parameter | Type |
| ------ | ------ |
| `query` | `P` |
| `fn` | (`row`, `ctx`) => `void` |
| `options?` | [`SystemOptions`](../interfaces/SystemOptions.md) |

### Returns

[`System`](../interfaces/System.md)

## Call Signature

```ts
function system<Q>(
   queries, 
   fn, 
   options?
): System;
```

A system over named queries: runs once per phase run with each query's results.

### Type Parameters

| Type Parameter |
| ------ |
| `Q` *extends* `NamedQueries` |

### Parameters

| Parameter | Type |
| ------ | ------ |
| `queries` | `Q` |
| `fn` | (`queries`, `ctx`) => `void` |
| `options?` | [`SystemOptions`](../interfaces/SystemOptions.md) |

### Returns

[`System`](../interfaces/System.md)
