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:¶
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:¶
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:¶
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
- #116 Infrastructure as Effects with Sam Goodwin - YouTube. Sam Goodwin. Requirements-channel discussion; used for static infrastructure permissions. Accessed 2026-10-01.
- #81 TypeScript & Effects with Michael Arnaldi - YouTube. Michael Arnaldi. Effect type explanation; used for output, failure, and service requirements. Accessed 2026-10-01.
- Inspection machine actor. GitHub joelhooks/rat-stack. readStats asks for FileInspector, so its Effect carries that requirement. Accessed 2026-11-08.
- CLI composition root. GitHub joelhooks/rat-stack. The CLI provides FileInspector.layer and NodeServices.layer before it runs. Accessed 2026-11-08.
- 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
- 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.
- Change log. What changed in the files served here, newest first.
Context and requirements — new page: Initial commit from joelhooks/rat-stack template
- Dependency injection is the reason to choose Effect. Effect tracks service requirements in types and supplies replaceable implementations through Layers.
Read context and requirements.¶
- 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.¶
- Full agent guide. An Effect stack so pure (aspirational) Kit Langton will blush.
- Infrastructure as effects. Sam Goodwin relates application operations to infrastructure requirements in one typed program.
Effect tracks required services in its type.
- 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.
- 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.
- 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)
- A service captures its construction dependencies → A context holds supplied service implementations.¶
- add-a-capability → MCP (Model Context Protocol) adds a doThing tool with the same schemas and flags.¶
- Agent rules for rat-stack (AGENTS.md) → Effect Schema, Context.Service, CLI: .agent_sources/github.com/Effect-TS/effect/
- Code snippets quote a pinned source → This preserves the preceding source context for multiline comments and strings.¶
- Dependency injection is the reason to choose Effect → Shared Layer identity reuses construction within the same memoization context.¶
- Devtools → MCP means Model Context Protocol, which lets an agent discover and call tools.¶
- Effect + Alchemy peer patterns → The guidance makes app, product-package, and vendor-neutral-library ownership explicit; it also says services capture implementation dependencies and keep request context invocation-scoped.
- Effect 4 study: September 2026 → Two things learned on the way: the machine context must be declared via types<Ctx>() or schemas.context, otherwise createMachine’s function-form context falls back to MachineContext and the output type collapses to any; and ErrorFrom of a machine is unknown, so join needs orDie (or an explicit catch) to keep a typed…
- Effect basics → A context holds supplied service implementations.¶
- Effect Meetup SF 2023: Why Effect? → A Remix demo contrasts manually added logs, metrics, and traces and nested error handling with Effect context, Schema, spans, metrics, and retry policies.
- gardener → json, and turn useful unlinked mentions into explicit source links after checking their context; leave incidental matches alone.¶
- Handle expected failures without hiding defects → Its tag identifies the error type; its fields retain context.
- Happy Path 116: Infrastructure as effects → The program carries resource requirements in its context.
- Hosted agent interfaces → Those values can belong to the first request’s runtime context.
- Interest signup → MCP means Model Context Protocol, which lets an agent discover and call tools.¶
- Layer composition makes dependencies explicit → Sharing follows Layer identity within a build context that remembers which Layer values it has already constructed.
- learn → Omit context to follow the ordered learning path.
- Learn mode presents concepts at useful depths → Selection follows deck order when context is absent.
- Lint and type escape ledger (debt.md) → Reason: projection boundary erases the hook requirements; the group layer’s context holds them.
- MCP is another surface → The Model Context Protocol lets an agent client discover and call tools.
- Production-grade TypeScript → He demonstrates Effect context, Schema, spans, metrics, and retry policies in a Remix application.
- Run Effect at the integration boundary → Later calls reuse the built service context.
- Sam Goodwin → Its infrastructure context is the cloud environment and dependencies in which it runs.
- Schema projections: 2026-09-18 history → Tool annotations already exist as Context references: Tool.Readonly, Tool.Destructive, Tool.Idempotent, Tool.OpenWorld.
- security-audit → ts runs local programs in a child process with a VM context and a host-call bridge.
- Structure an Effect codebase by domain → Declare expected failures with useful context.
- Trace operations where they mean something → Add only context safe for that operation’s telemetry.¶
- write-a-wiki-page → The remaining context describes the requested source.¶