Skip to content

Modules, Features and Slices

Organize a Screenplay application around its business boundaries and the work people do within them. A module names a boundary, features group related work, and each slice describes one behavior, such as registering an invoice or listing invoices.

A module is the top-level namespace and maps to a bounded context: an area with its own business vocabulary and rules. Use one module per file by convention; the compiler does not enforce that choice.

module <Name>
[description "<text>"]
[depends on <Name>]*
[<screen templates>]
[<dialog templates>]
[<features>]

Screen templates and dialog templates declared at module level are described in Layouts and templates.

Group related slices in a feature. Features can contain sub-features at any depth, so you can organize a larger workflow without putting all its behavior in one slice.

feature <Name>
[description "<text>"]
[depends on <Name>]*
[feature <Name>]* ← sub-features
[slice <type> <Name>]+

Use depends on <Name> on a module or feature to state which other modules or features it intends to use. Write one target per line:

module Payroll
description "Pays people for approved time"
depends on Timesheets
feature Handover
depends on Timesheets.Approval
depends on Timesheets.Reporting
depends on Runs
feature Runs
module Timesheets
feature Approval
feature Reporting

A bare name searches the declaring container’s siblings, then each ancestor’s siblings, then root modules. It does not search cousins or features in another module: qualify those targets. A dotted name matches an unambiguous trailing part of a container’s full address. Equally near matches raise PLAY0198 and name the candidates.

A sibling feature shadows a same-named root module. That root module has no longer qualifying address, so rename one of the containers to make it addressable. Self, ancestor, descendant and unresolved targets raise warning PLAY0554. Repeated declarations of the same resolved target (including different spellings such as Runs and Payroll.Runs) raise warning PLAY0555 and keep the first. Unresolved repeats compare by target text.

The dependency check starts only when a module or feature declares a dependency. Its own list must then cover every counted explicit reference leaving that container, including references from descendant features. A module target covers all its features; a feature target covers its descendants.

Keep parent and child lists complete independently: a parent’s declaration does not satisfy a child’s list, or vice versa. References within the checked container, or into an ancestor’s own slices, are ignored.

The check counts usesFactsFrom, reactsTo, decidesFrom, asks and shows, not specification (verifiedWith) or outside-context (outsideTheModel) edges. It reports one warning PLAY0552 per checked container and uncovered producer module, at the container header, naming the shared feature path when possible and listing source evidence. An unused valid declaration gets information PLAY0553 on its line. Two containers declaring each other get information PLAY0556 on each declaring line; this does not permit cycles or prohibit reverse coupling.

Ambiguous graph ownership never produces an undeclared warning. Any declaration covering a candidate is provisionally satisfied and is not reported as unused. The MCP declarations view shows this uncertainty. The graph covers explicit slice references only, not code, expressions or module-owned forms.

Declared dependencies document intended coupling. They are optional authoring metadata and do not control execution or ordering, add executable model bytes, or change revisions or identities. The printer places them after description, in authored order.

Folder models accumulate dependencies per owner. Renaming a module or feature repairs proven targets. It refuses unresolved or ambiguous targets that could name the renamed container, or a rename that would capture another target.

A slice describes one behavior in Event Modeling. Give it a type and a name, then place the constructs that implement that behavior inside it. The slice types distinguish a change to state from a view of state, an automated reaction or a translation across a boundary.

slice <SliceType> <Name>
[direction inbound|outbound] // Translate only
[description "<text>"]
[file <path>]
<constructs>

The optional file line names the repository relative file this declaration is realized by, so a document can be navigated back to the code it describes. It is additive - it never stands in for any part of the declaration. See File references.

Use description for a human-readable summary. On a specification, it names the rule or case that scenario witnesses. Use documentation for longer reasoning: assumptions, boundaries and rejected alternatives that should stay with the model.

Modules, features, slices, commands, events, read models, graphs and reactions accept one nonempty documentation block with a markdown fence. It belongs directly in the declaration body, not under a reaction trigger. A bare documentation line never declares a property; documentation String still declares a typed property where properties are allowed.

module Invoicing
description "Bills customers"
documentation
```markdown
## Boundary
Invoicing records billing decisions. Delivery is a separate workflow.
```

Both fields are report-only authoring metadata (PLAY0270), not executable conditions. They do not add bytes to the executable semantic model (ESM) or require a new ESM version. The printer keeps them on their owning declaration, and MCP declaration-details includes both fields in its summary wherever supported. In a folder model, the first module or feature documentation is kept; identical copies are accepted, while conflicting copies warn with PLAY0559.

Malformed, empty or repeated documentation on these new owners reports PLAY0558; events retain PLAY0477. Other kinds, including projections and screens, do not accept documentation. These diagnostics have no automatic repair: choose the text to retain, the correct fence language or the owning file explicitly.

Modules, features, slices, personas, commands, read models, reactions, and specifications take an optional description as their first body line — a human-readable summary consumers such as Prologue surface when presenting the model. At most one per declaration.

module Invoicing
description "Everything related to invoicing customers"
feature InvoiceManagement
description "Registering and managing the lifecycle of invoices"
slice StateChange RegisterInvoice
description "Registers a new invoice"

When one line is not enough, use a fenced block — the same ``` convention as inline code blocks. The fenced text is kept verbatim:

module Invoicing
description
```text
Everything related to invoicing customers.
Registration, lifecycle and payment tracking of invoices.
```
Type Description
StateChange A command → events flow; something that changes the system
StateView A query + projection + screen; something that reads the system
Automation A reaction or reducer; something that runs when something happens
Translate Translates outside occurrences to private local facts (inbound), or private facts to a public contract (outbound)

Declare direction inbound or direction outbound once directly inside a Translate slice. Inbound includes existing captures of outside data and translation of another application’s public events. Outbound describes publishing a local public contract. Direction on any other slice type, an unknown value, or a repeated directive is an error (PLAY0027, invalid slice declaration). Legacy directionless Translate slices remain accepted and are interpreted as inbound; the printer does not insert a directive into them.

SliceSyntax.Direction (direction in TypeScript) is a nullable property preserving whether the author wrote the directive; EffectiveDirection supplies inbound for legacy translations and null for other slice types. Both compilers’ printers, typed JSON and the authoring workspace preserve the explicit value, and Monaco and VS Code complete and validate it. An explicit direction selects ESM v9 and is part of the executable model; a legacy translation without one keeps its version and bytes. The reference evaluator implements publication as a recorded fact only: no subscription, delivery or Stage behavior. Public/private usage constraints and translation cardinality are checked by PLAY0607-PLAY0620 (diagnostics); PLAY0614 has an editor and MCP repair that declares the one consistent direction.

An outbound slice publishes its one public event with a projection/reducer whose => target is that event (projecting to an event), or with a reaction. An inbound slice may consume another application’s public events with source events. Both select ESM v9.

Capturing an outside occurrence and reacting to the resulting local fact are two behaviors. Keep the capture in a Translate slice and put the follow-up in an Automation slice, each with its own specifications:

module Orders
feature Importing
slice Translate ReceiveOrder
event OrderReceived
capture Feed
append OrderReceived
specification ReceivesOrder
when capture Feed
then OrderReceived
slice Automation FollowUpOrder
reaction FollowUp
when OrderReceived
specification ReactsToOrder
when append OrderReceived

A directionless Translate slice that instead contains an unrouted reaction to an event its own capture appends gets warning PLAY0694 at the reaction. This includes child and nested appends, but not fixtures or captures in other slices. The check compares resolved event declarations; unresolved or ambiguous references never match. A reaction with a from filter is excluded because captures are unrouted. Other producers of the event elsewhere do not make co-location appropriate. Ordinary compilation remains valid, but --warnaserror requires the split. Adding direction inbound is not the repair: explicit inbound consumption of local facts is refused by PLAY0616. There is no automatic split because the new slice’s name, placement and specifications require author choices.

Construct Typical slice type Page
event any Events
command StateChange Commands
constraint StateChange Constraints
query StateView Queries
readmodel StateView Read models
projection StateView Projections
reducer StateView Read models
screen StateView Screens
reaction Automation Reactions
capture Translate Captures
shows any Show an element in more than one slice

Use as many of these constructs as the behavior needs. A slice may contain several commands or events, or several projections. Only description is limited to one; the boundary is the behavior, not a count of artifacts.

On an event model timeline the same event or read model often belongs in more than one place: where it is produced, and again where a later slice reads it. Declare it once and let the other slices show it:

slice StateChange PlaceOrder
event OrderPlaced
orderId OrderId
slice StateView ShipOrder
shows event OrderPlaced
shows readmodel OpenOrders

shows event <Name> and shows readmodel <Name> place a linked copy of a declaration from elsewhere in the application on this slice. The copy refers to the declaration, so a board draws both occurrences as the same element, editing either edits the one declaration, and renaming the declaration renames every placement. A placement is presentation only: it adds nothing to the executable semantic model and changes no behavior.

The compiler refuses a malformed line (PLAY0953), warns when no event or read model has the name (PLAY0954), and warns when the slice declares the element itself or shows it twice (PLAY0955).

module Invoicing
feature InvoiceManagement
slice StateChange RegisterInvoice
command RegisterInvoice
...
event InvoiceRegistered
...
slice StateView InvoiceList
query ListInvoices => InvoiceListReadModel[]
projection InvoiceList => InvoiceListReadModel
...
screen InvoiceList
...