agentleFS
sbrudzsbrudz/agent-skills/skills/functional-core-imperative-shell/SKILL.md

functional-core-imperative-shell

Skill2 starsChanged 9 months agoMITView on GitHub

Use when reviewing code that mixes business logic with I/O, database calls, or side effects, or when tests require extensive mocking to verify logic

  • Reads credentials

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If the answer is no, the function mixes core and shell.

    line 14

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Functional Core, Imperative Shell — Code Review Checklist

Detect code that tangles business logic with side effects. The fix is always the same: push decisions into pure functions (the core), confine I/O to a thin orchestration layer (the shell).

The Litmus Test

Can you test this function's business logic without mocking anything?

If the answer is no, the function mixes core and shell. Every mock in a test is evidence of a missing boundary.

When to Use

During code review on any codebase. Language-agnostic.

Apply as an additional pass after the standard review. Flag violations as Important.

1. Impure Business Logic

Business logic functions that perform I/O. The most common violation.

Flag when a function both:

  • Makes a decision (branching, validation, calculation, transformation)
  • AND performs I/O (database query, API call, file read/write, network request)

Signals:

  • Function validates input, then queries a database, then calculates based on the result — all in one body
  • Calculation depends on a value fetched mid-function (e.g., fetching a discount rule then applying it)
  • Function determines what action to take AND executes that action

The pattern: The shell gathers inputs (I/O), passes them to the core (pure), then acts on the result (I/O).

// BAD: decision + I/O tangled
function processOrder(orderId) {
  order = db.getOrder(orderId)              // I/O
  if (order.total > 100)                    // decision
    db.applyDiscount(orderId, order.total * 0.1)  // I/O
}

// GOOD: separated
function calculateDiscount(order) {         // pure core
  if (order.total > 100) return order.total * 0.1
  return 0
}
// shell: order = db.get() → discount = calculateDiscount(order) → db.apply(discount)

2. Fat Shells

The shell should be a flat sequence: gather → decide → act. No branching, no transformation.

Flag when the shell contains:

  • if/else or switch that determines behavior (not just dispatching on a core return value)
  • Data transformation, mapping, or filtering
  • Validation logic
  • Multiple sequential decisions interleaved with I/O (read → decide → write → read → decide → write)

Dispatching is OK: if (result.notify) sendEmail() is fine — the shell executes the core's decision. Flag when the shell makes the decision.

3. Hidden Side Effects in the Core

Functions that look pure but aren't. Subtle — easy to miss in review.

Flag these in any function that should be pure:

Hidden side effectWhy it breaks purityFix
Logging (logger.info, console.log)I/O operationReturn diagnostic data; let the shell log
Current time (new Date(), Date.now())Non-deterministic inputAccept timestamp as parameter
Randomness (Math.random(), uuid())Non-deterministic inputAccept seed/value as parameter
Environment variables (process.env)Implicit external inputAccept as parameter
Global/module-level mutable stateShared state mutationReturn new values; let the shell persist
Throwing exceptions for control flowForces caller into try/catchReturn result/error values

The test: Given the same arguments, does this function always return the same result with no observable effect on the outside world?

Severity Guide

  • Impure business logic (Section 1): Important — core architectural issue, causes mock-heavy tests and tangled concerns
  • Fat shell (Section 2): Important when the shell contains non-trivial logic; Minor for simple dispatch branching
  • Hidden side effects (Section 3): Important for non-determinism (Date, random) and mutable state; Minor for logging in small functions

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.