hexagonal-inversify-di

Wire Hexagonal architecture ports and adapters with InversifyJS across a monorepo.

54|10|Updated Apr 1, 2025
One-click install
npx skills add https://github.com/ndthanhdev/mcp-browser-kit --skill hexagonal-inversify-di
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hexagonal-inversify-di
Source: https://github.com/ndthanhdev/mcp-browser-kit/tree/main/.agents/skills/hexagonal-inversify-di
Command: npx skills add https://github.com/ndthanhdev/mcp-browser-kit --skill hexagonal-inversify-di

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill codifies a repeatable, repo-wide convention for wiring Hexagonal (Ports & Adapters) architecture using InversifyJS so teams avoid inconsistent bindings, accidental adapter-to-adapter coupling, and runtime container mistakes when adding packages, ports, or adapters.

Core Features & Use Cases

  • Clear package roles: explains core-, -driving-, -driven-, helper-, and types responsibilities to prevent incorrect dependencies.
  • Port pattern: prescribes the dual identifier pattern (TypeScript interface + Symbol) for input and output ports so tokens are injectable and type-safe.
  • Container factories & binding order: specifies createCore<Name>Container conventions, default singleton scope, adapter setupContainer static registration, and the required wiring order for app composition roots.
  • Recipes & examples: step-by-step recipes for defining ports, implementing driven and driving adapters, composing app containers, and handling per-runtime bootstrap for MV2/MV3 browser extension runtimes.
  • Gotchas & decision guidance: highlights common pitfalls like multi-token aliasing, Symbol vs Symbol.for, and no shared containers across extension runtimes.

Quick Start

Create a new core package with Foo input and output ports, implement a FooDrivenAdapter that exposes setupContainer, and wire them in apps/<app>/src/services/container.ts by calling createCoreFooContainer then registering FooDrivenAdapter.setupContainer(container, FooOutputPort).

Frequently Asked Questions about hexagonal-inversify-di

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I wire Hexagonal architecture ports and adapters with InversifyJS in a monorepo?

Wire Hexagonal architecture ports and adapters with InversifyJS by creating core-*, driven-*, and driving-* packages, defining dual identifier ports, implementing adapters, and composing app containers with explicit binding order per runtime. This enforces consistent container wiring and prevents adapter-to-adapter coupling.

What is the dual identifier port pattern in TypeScript dependency injection?

The dual identifier port pattern in TypeScript dependency injection pairs an interface with a Symbol to make ports injectable and type-safe. This ensures tokens are uniquely identified within the InversifyJS container and prevents multi-token aliasing issues during binding.

How do I set up InversifyJS composition roots for different browser extension runtimes?

Set up InversifyJS composition roots for browser extension runtimes by creating separate bootstrap containers per runtime, such as for MV2 and MV3. Never share containers across extension runtimes to avoid state conflicts and unexpected container initialization behavior.

Can I use InversifyJS to enforce default singleton scope for use cases in Hexagonal architecture?

InversifyJS enforces default singleton scope for use cases in Hexagonal architecture by utilizing createCore<Name>Container factory conventions. This ensures consistent application state management and prevents accidental transient bindings when composing app containers.

Why does my InversifyJS container binding fail when using Symbol instead of Symbol.for in Hexagonal architecture?

InversifyJS container binding fails when using Symbol instead of Symbol.for because Symbol generates unique instances across modules, breaking identifier matching. Use Symbol.for to ensure global symbol registry sharing for your ports and adapters.

What is the required binding order for InversifyJS adapter setupContainer static registration?

The required binding order for InversifyJS adapter setupContainer static registration dictates calling createCore<Name>Container first, followed by registering driven and driving adapters. This explicit composition root order ensures dependencies are available before adapter resolution.