architecture-paradigm-functional-core
npx machina-cli add skill athola/claude-night-market/architecture-paradigm-functional-core --openclawThe Functional Core, Imperative Shell Paradigm
When To Use
- Separating pure business logic from side effects
- Improving testability through immutable domain models
When NOT To Use
- Performance-critical hot paths where immutability overhead matters
- Purely imperative codebases with no plans to adopt functional patterns
When to Employ This Paradigm
- When business logic is entangled with I/O operations (e.g., database calls, HTTP requests), making tests brittle and slow.
- When significant development time is spent rewriting adapters or dealing with framework churn.
- When you require a suite of fast, deterministic unit tests that operate on plain data, complemented by a thin integration testing layer.
Adoption Steps
- Inventory Side Effects: Create a map of all side effects in the system, such as database writes, external API calls, UI events, and filesystem access. Explicitly assign these responsibilities to the "shell."
- Model the Core Logic: Represent business rules and policies as pure functions. These functions should take domain data as input and return decisions or commands as output, avoiding shared mutable state.
- Design the Command Schema: Define a small, explicit set of command objects that the core can return and the shell can interpret (e.g.,
PersistOrder,PublishEvent,NotifyUser). - Refactor Incrementally: Begin with high-churn or critical modules. Wrap legacy imperative code behind adapters while progressively extracting pure calculations into the functional core.
- Enforce Boundaries: Use code reviews and automated architecture tests to validate a strict separation. The shell should only handle orchestration, sequencing, and retries, while the core should never call directly into frameworks or I/O libraries.
Key Deliverables
- An Architecture Decision Record (ADR) detailing why this pattern was chosen, which modules are affected, and the scope of the migration.
- A suite of unit tests for the core with high (>90%) and deterministic code coverage. Where applicable, use property-based or fixture-based testing to cover a wide range of inputs.
- A suite of contract and integration tests for the shell that verify correct command interpretation, retry logic, and telemetry.
- A set of rollout metrics (e.g., deployment lead time, incident rate in the shell layer) to demonstrate the value of the architectural change.
Risks & Mitigations
- Logic Drifting Between Core and Shell:
- Mitigation: It's common for business logic to accidentally be duplicated or placed in the shell. Enforce a "core owns all decisions" checklist during code reviews to prevent this.
- Mismatch with Frameworks:
- Mitigation: The imperative shell may still need to interact with framework-specific lifecycle hooks. Before committing to a large rewrite, build small proof-of-concept adapters to validate the integration strategy.
- Team Unfamiliarity with the Pattern:
- Mitigation: Introduce the pattern using pair programming and internal "brown-bag" learning sessions. Document common anti-patterns that are discovered during the pilot phase to guide future development.
Troubleshooting
Common Issues
Command not found Ensure all dependencies are installed and in PATH
Permission errors Check file permissions and run with appropriate privileges
Unexpected behavior
Enable verbose logging with --verbose flag
Source
git clone https://github.com/athola/claude-night-market/blob/master/plugins/archetypes/skills/architecture-paradigm-functional-core/SKILL.mdView on GitHub Overview
Separates pure business logic (functional core) from side effects (imperative shell) to improve testability and maintainability. By keeping domain rules immutable and deterministic, tests run faster and are easier to reason about, while the shell handles IO, retries, and integration adapters.
How This Skill Works
The core implements business rules as pure functions with no side effects, consuming domain data and returning decisions or commands. The shell orchestrates I/O, framework interactions, and adapters, interpreting core outputs via a small command schema (e.g., PersistOrder, PublishEvent, NotifyUser). Adoption steps guide wrapping legacy code behind adapters and enforcing strict boundaries so the core never calls into frameworks or I/O directly.
When to Use It
- Separating pure business logic from side effects to improve testability
- When tests are brittle due to entanglement with I/O or external calls
- When you want fast, deterministic unit tests on plain data with a thin integration layer
- When refactoring high-churn modules and migrating legacy imperative code behind adapters
- When enforcing a strict boundary where the core owns decisions and the shell handles orchestration
Quick Start
- Step 1: Inventory Side Effects: map all external calls (DB writes, API calls, UI events) and assign them to the shell
- Step 2: Model the Core Logic: implement business rules as pure functions with domain data inputs and outputs
- Step 3: Design the Command Schema: define a small set of commands (e.g., PersistOrder, PublishEvent) and wire adapters
Best Practices
- Inventory side effects and assign them to the shell to keep the core pure
- Model core logic as pure functions that take domain data and return decisions or commands
- Design an explicit command schema (e.g., PersistOrder, PublishEvent, NotifyUser)
- Refactor incrementally, wrapping legacy code behind adapters while extracting pure calculations
- Enforce boundaries with code reviews and architecture tests; limit the shell to orchestration, retries, and integration work
Example Use Cases
- Core returns command objects like PersistOrder, PublishEvent, NotifyUser which the shell interprets and executes
- Unit tests for the core achieving high (>90%) coverage with deterministic inputs; leverage property-based testing where applicable
- Shell contracts and integration tests verify correct command interpretation, retry logic, and telemetry
- An Architecture Decision Record (ADR) detailing migration scope, affected modules, and rationale
- Rollout metrics collected (deployment lead time, shell-layer incident rate) to demonstrate architectural value
Frequently Asked Questions
Related Skills
architecture-paradigm-space-based
athola/claude-night-market
'Data-grid architecture for high-traffic stateful workloads with linear
architecture-paradigm-layered
athola/claude-night-market
'Consult this skill when implementing layered patterns or enforcing layer
architecture-paradigm-microkernel
athola/claude-night-market
'Minimal core system with plugin-based feature extensibility for platform
architecture-paradigm-microservices
athola/claude-night-market
'Consult this skill when designing or evolving microservices architectures.
architecture-paradigm-pipeline
athola/claude-night-market
'Consult this skill when designing data pipelines or transformation workflows.
architecture-paradigm-serverless
athola/claude-night-market
'Serverless FaaS for event-driven workloads with minimal infrastructure