Skip to content

Functional Core / Imperative Shell

Functional Core / Imperative Shell is the internal structure of a Request Processing Unit.

The Functional Core makes the decision. The Imperative Shell does everything with an effect.

RPU internal Functional Core / Imperative Shell structure

Functional Core

The Functional Core is the decision.

It takes the command and the context and returns the outcome.

It is pure. It reads no clock and no store. Values it cannot compute, such as the current time or a new id, arrive as part of its input.

The same input always produces the same outcome, which makes the core testable on its own, without a database and without replacement objects.

Imperative Shell

The Imperative Shell is the code around the core.

It reads the facts from the Application State into the context.

It calls the core.

It records the consequences of an accepted outcome, and returns the response.

It uses Providers when the capability needs an external resource.

The RPU Is Not Pure

An RPU as a whole is not pure. The Functional Core is pure; the Imperative Shell holds the effects.

Concentrating the effects in the shell keeps the decision deterministic and keeps the reads and writes in one place.

Testing

The core is tested as a pure function: given a command and a context, it must return the expected outcome.

The shell is tested against the real store or a replaced one, to check that it loads the context, protects it, and records the consequences.

Summary

  • the internal structure of an RPU
  • a Functional Core that decides, pure, with no I/O
  • an Imperative Shell that reads, calls the core, and records the result
  • the core is testable without a database
  • the RPU as a whole is not pure; the shell contains the effects