Context and requirements

Goal: read an Effect35 type and say which services the work still needs.

An Effect type has three parts: what the work returns, how it can fail, and which services it needs. The third part is the requirements. A context is the set of services that running work receives.

Worked example: inspecting a file

rat-stack’s file inspection reads a file through a FileInspector service30. The actor27 that does the read asks for that service by name:

packages/core/src/inspect-machine.ts · a3f5a148 · The read asks for FileInspector
const readStats = createEffectLogic({
  effect: ({ input }) =>
    FileInspector.use((inspector) => inspector.inspect(input.path)),
  schemas: { input: Schema.Struct({ path: Schema.String }) },
});

FileInspector.use returns an Effect whose requirements include FileInspector. Nothing runs yet. The type now records a debt: some caller must supply a FileInspector.

The CLI pays that debt once, at startup:

apps/cli/src/cli.ts · a3f5a148 · The composition root supplies it
  Effect.provide(
    Layer.mergeAll(
      Layer.provideMerge(FileInspector.layer, NodeServices.layer),

Effect.provide removes FileInspector from the requirements. FileInspector.layer itself needs a file system, and NodeServices.layer supplies it.

The tests pay the same debt with their own Layer:

packages/core/test/inspect-machine.test.ts · a3f5a148 · A test supplies the same requirement
const TestLayer = Layer.provideMerge(FileInspector.layer, NodeServices.layer);

The diagram above shows the same move on a small Greeter service: provide turns Greeter into never.

Why the type carries it

The compiler rejects execution while a required service remains unsupplied. Dependency injection14 shows that rule. A forgotten service fails the typecheck before the program runs.

Sam Goodwin8 describes this requirements channel as a way to model permissions before execution, which he calls a static effect. He connects that idea to Alchemy inferring which identity and access management (IAM) policy a program needs. Happy Path 116, 11:54

Michael Arnaldi7 describes an Effect by its output, predictable failures, and requirements. Happy Path 81, 49:15

Next

Read how a service captures its dependencies30 to see what FileInspector keeps inside itself. Then read why dependency injection matters14.

See Effect basics35 for the whole type, and infrastructure as effects10 for Sam’s infrastructure reading.

Sources

  1. #116 Infrastructure as Effects with Sam Goodwin - YouTube. Sam Goodwin. Requirements-channel discussion; used for static infrastructure permissions. Accessed 2026-10-01.
  2. #81 TypeScript & Effects with Michael Arnaldi - YouTube. Michael Arnaldi. Effect type explanation; used for output, failure, and service requirements. Accessed 2026-10-01.
  3. Inspection machine actor. GitHub joelhooks/rat-stack. readStats asks for FileInspector, so its Effect carries that requirement. Accessed 2026-11-08.
  4. CLI composition root. GitHub joelhooks/rat-stack. The CLI provides FileInspector.layer and NodeServices.layer before it runs. Accessed 2026-11-08.
  5. Inspection machine tests. GitHub joelhooks/rat-stack. The tests supply the same requirement through their own TestLayer. Accessed 2026-11-08.

Last changed 2026-11-08 in 4f96c98. Source on GitHub. Change log.

Linked from

  1. Agent guide. An Effect stack so pure (aspirational) Kit Langton will blush.

    Context and requirements — Effect requirements make a computation’s needed services visible in its type.

  2. Change log. What changed in the files served here, newest first.

    Context and requirements — new page: Initial commit from joelhooks/rat-stack template

  3. Dependency injection is the reason to choose Effect. Effect tracks service requirements in types and supplies replaceable implementations through Layers.

    Read context and requirements.¶

  4. Effect basics. An Effect describes work, expected failures, and required services before a runtime executes it.

    Read service construction, Layer composition, and context and requirements.¶

  5. Full agent guide. An Effect stack so pure (aspirational) Kit Langton will blush.
  6. Infrastructure as effects. Sam Goodwin relates application operations to infrastructure requirements in one typed program.

    Effect tracks required services in its type.

  7. Learn rat-stack from your own agent. Turn on learn mode: your own agent explains rat-stack ideas during real work and keeps progress local.

    The first path starts with context and requirements, then how a service captures its dependencies.

  8. Rat Stack lore | rat-stack. Short, source-grounded notes on the ideas and decisions behind rat-stack.

    Context and requirements — Effect requirements make a computation’s needed services visible in its type.

  9. Source change history (log.md). The generated change log as Markdown.

    Context and requirements — new page: Initial commit from joelhooks/rat-stack template

Unlinked mentions (28)