Granular Imports by Category
In addition to the barrel (import from root), each pattern can be imported by its category path. This doesn’t add new symbols — they’re the same ones reexported from /decorators, /operators, /pipe, /run, and /policy.
By pattern category
Section titled “By pattern category”Each GoF pattern can be imported from its category:
// Creationalimport { Singleton } from 'annotations-design-patterns/creational/singleton';import { Factory, RegisterIn } from 'annotations-design-patterns/creational/factory';import { builderFor } from 'annotations-design-patterns/creational/builder';
// Structuralimport { Adapt } from 'annotations-design-patterns/structural/adapt';import { Decorate, Intercept } from 'annotations-design-patterns/structural/decorate';import { Frozen, Sealed } from 'annotations-design-patterns/structural/frozen';
// Behavioralimport { Subject, Emits } from 'annotations-design-patterns/behavioral/observer';import { StateMachine, When, TransitionTo } from 'annotations-design-patterns/behavioral/state-machine';import { CommandHistory, Revertible } from 'annotations-design-patterns/behavioral/command';Stable decorators facade
Section titled “Stable decorators facade”For resilience, there’s a stable facade at /decorators:
import { Retry, Timeout, CircuitBreaker, Fallback, Memoize, CachedFor, Semaphore, Mutex,} from 'annotations-design-patterns/decorators';This facade does not include GoF decorators (Singleton, Factory, etc.) or internal TC39 adapters.
Functional API: explicit subpaths
Section titled “Functional API: explicit subpaths”The functional API uses explicit subpaths, not granular categories:
import { pipe } from 'annotations-design-patterns/pipe';import { run } from 'annotations-design-patterns/run';import { retry, fallback, timeout } from 'annotations-design-patterns/operators';import { definePolicy } from 'annotations-design-patterns/policy';Bundle optimization
Section titled “Bundle optimization”With a modern bundler (Vite, esbuild, webpack 5+), you don’t need granular imports to optimize. The barrels are already tree-shakeable:
// Equivalent in bundle (both fit equally small):
// Granular importimport { Singleton } from 'annotations-design-patterns/creational/singleton';
// Barrel importimport { Singleton } from 'annotations-design-patterns';Use granular imports if you prefer explicit clarity in your imports, not for optimization.
Internal location (not public)
Section titled “Internal location (not public)”Don’t import from paths like:
// ❌ Not these, they're internalimport { Operator } from 'annotations-design-patterns/core/operator';import { ObserverEvents } from 'annotations-design-patterns/core/events';The /core directory contains implementation types not reexported publicly. Any symbol you need from those paths is available from the public subpaths.
For reference of all public symbols
Section titled “For reference of all public symbols”See the Root Reference for the complete barrel, or the specific references:
- Decorators — Resilience facade
- Operators — Functional API
- Pipe — Composition with pipe
- Run — Execution with context
- Policy — Reusable policies
- Store — Async store
- Node — Node.js context
- Observability — Errors and events
- Experimental — Experimental APIs

