nwave-ai/nwave/nw-fp-hexagonal-architecture
Claude Code and agent skill by nwave-ai/nwave
- community
Checking that the SKILL.md file is still in the repository.
Hexagonal architecture patterns with pure core and side-effect shell for functional codebases
Install
npx vskill@latest install nwave-ai/nwave/nw-fp-hexagonal-architectureSKILL.md
The same SKILL.md was published earlier as nwave-ai/nwave/nw-fp-hexagonal-architecture.
FP Hexagonal Architecture
File and folder layout of the core, ports and adapters follows the File layout section of nw-code-craftsmanship.
Ports and adapters in functional programming. Structure applications with a pure core and side-effect shell.
Cross-references: fp-principles | fp-domain-modeling | fp-usable-design
1. The Natural Fit
[STARTER]
Functional architecture naturally implements ports and adapters. The paradigm's separation of pure functions from side effects IS the hexagonal boundary.
| OOP Concept | FP Equivalent | Why | |
|---|---|---|---|
| Port (interface) | Function type signature / type alias | Port defines contract; function signature IS that contract | |
| Adapter (class) | Concrete function implementation | Adapter fulfills contract; matching function does same | |
| DI container | Function parameters / partial application | Dependencies passed as arguments, no container needed | |
| Domain service class | Module of pure functions | Related pure functions replace stateful service object | |
| Entity with behavior | Immutable data + functions operating on it | Data and behavior separated; functions transform immutable values |
2. Pure Core / Side-Effect Shell
[STARTER]
All business logic is pure; all side effects live at the system's edges.
The Sandwich Pattern: Read (impure) -> Decide (pure) -> Write (impure)
Dependency Rule: Shell may call core. Core never calls shell. Core is unaware of shell's existence.
Why: Pure core is trivially testable (no mocks, no setup, no teardown). Shell is thin and needs few integration tests.
3. Ports as Function Types
[STARTER]
A port is a function type signature describing a capability the domain needs:
When to define: Domain needs a capability involving I/O or external systems. Domain declares WHAT; adapter provides HOW.
Naming: Verb-noun. Name describes capability, not technology.
4. Adapters as Implementations
[STARTER]
An adapter is a concrete function matching a port's type signature:
Both match the FindOrder port. Domain doesn't know which is used.
5. Dependency Injection via Functions
[STARTER] -> [INTERMEDIATE] -> [ADVANCED]
Decision Tree: How to Inject This Dependency?
[STARTER] Functions as Parameters
Pass dependencies as function parameters. Partially apply at composition root.
[INTERMEDIATE] Environment Pattern (Reader)
Dependencies in a record, provided once at top level. Use when parameter threading becomes painful (4+ deps).
[ADVANCED] Capability Interfaces / Effect Systems
Abstract over effect types (tagless final) or use fine-grained effect tracking (ZIO, Koka). Use for large codebases with many effects.
Recommendation by Context
| Context | Approach | |
|---|---|---|
| Small/medium codebase | Functions as parameters | |
| Large codebase, many effects | Capability interfaces or effect system | |
| Pragmatic TypeScript/F# | Functions as parameters + modules |
6. Pipeline Composition Through Architecture
[INTERMEDIATE]
Workflows flow through architecture as pipelines:
Each pure step is a function in the pipeline. Shell handles I/O at start and end.
Error-track pipelines: Each step returns Result type; pipeline short-circuits on first failure. See fp-domain-modeling.
Collect-all-errors: When you need ALL validation errors, use Applicative style. See fp-principles section 5.
7. Testing Strategy
[INTERMEDIATE]
| Layer | Test Type | Volume | Speed | Mocks | |
|---|---|---|---|---|---|
| Pure core (domain) | Unit + Property-based | Many | Fast (ms) | None | |
| Composition root | Integration (wiring) | Few | Medium | None | |
| Adapters | Integration | Few per adapter | Slow | None (real deps) | |
| End-to-end | System tests | Very few | Slowest | None |
Key insight: Pure functions need no mocking. Input in, output out. Strongest practical argument for maximizing the pure core.
Property-based testing is the natural companion. Define rules that hold for all valid inputs. See fp-algebra-driven-design.
8. Side Effect Management Approaches
[ADVANCED]
| Approach | Enforcement | Granularity | Best For | |
|---|---|---|---|---|
| Convention (discipline) | None | N/A | Any language, small teams | |
| IO Type (Haskell) | Compile-time | Binary (pure/impure) | Haskell | |
| Effect Systems (ZIO, Koka) | Compile-time | Per-effect | Large systems | |
| Pure Core / Shell | Architectural | Module-level | Any language, pragmatic |
IO actions as values: Side effects are descriptions of actions, not actions themselves. Can be stored, composed, and only execute when runtime reaches them.
Type-level effect tracking: Mark impure functions clearly -- through return types, naming conventions, or annotations. Even without compiler enforcement, the discipline applies.
9. Combining Patterns
Worked Example: Place Order Workflow
Recommended learning sequence:
[STARTER]: Pure Core/Shell -> Domain Wrappers -> Smart Constructors -> Pipeline Composition
[INTERMEDIATE]: Choice Types -> Error-Track Pipelines -> Functions as Parameters -> Property Testing
[ADVANCED]: Capability Interfaces -> Effect Systems -> Collect-All-Errors Validation
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingnWave/skills/nw-fp-hexagonal-architecture/SKILL.md
Popularity
- Repository stars
- 568
- Repository forks
- 57
- 7-day trend score
- 32
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/nwave-ai/nwave/nw-fp-hexagonal-architecture)