npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ddd-tool/domain-designer-core

v0.3.4

Published

> Core domain modeling library for Domain-Driven Design (DDD) in TypeScript

Readme

@ddd-tool/domain-designer-core

Core domain modeling library for Domain-Driven Design (DDD) in TypeScript

@ddd-tool/domain-designer-core enables developers to design domains using TypeScript code with similar expressiveness as visual diagrams. Leverage TypeScript's type checking to ensure model completeness and catch design errors at compile time.

Features

  • Type-Safe Domain Modeling: Design domains with full TypeScript type safety
  • Fluent Workflow Builder: Chain actor → command → aggregate → event sequences naturally
  • User Story Organization: Group workflows by user intent
  • Event Storming Support: Model DDD concepts like actors, commands, events, aggregates, policies, and more
  • Code Generation Ready: Seamlessly integrates with code generators for multiple languages

Installation

npm install @ddd-tool/domain-designer-core
pnpm add @ddd-tool/domain-designer-core
bun add @ddd-tool/domain-designer-core

Quick Start

import { createDomainDesigner } from '@ddd-tool/domain-designer-core'

const d = createDomainDesigner()
const i = d.info

// Define value objects and IDs
const orderId = i.id('OrderId')
const userId = i.valueObj('UserId')
const orderTime = i.valueObj('OrderTime')

// Define domain elements
const placeOrder = d.command('PlaceOrder', [orderId, userId])
const orderAggregate = d.agg('OrderAggregate', [
  orderId,
  userId,
  orderTime,
  'ProductPrice',
  'ProductQuantity',
])
const orderPlaced = d.event('OrderPlaced', [orderId, orderTime])

// Define actors and systems
const customer = d.actor('Customer', 'The user placing orders')
const paymentSystem = d.system('PaymentSystem')

// Build workflows
const placeOrderWorkflow = d.startWorkflow('Place Order')
customer.command(placeOrder).agg(orderAggregate).event(orderPlaced)
orderPlaced.system(paymentSystem)

// Define user stories
d.defineUserStory('As a customer, I want to place an order', [placeOrderWorkflow])

export default d

Core Concepts

Domain Elements

The library provides methods to create all essential DDD building blocks:

  • Actors (d.actor()): Users or systems that initiate commands
  • Commands (d.command()): Intent to change state
  • Events (d.event()): Facts that have happened
  • Aggregates (d.agg()): Consistency boundaries with entities and value objects
  • Policies (d.policy()): Business rules that trigger on events
  • Services (d.service()): Domain services for complex operations
  • Systems (d.system()): External systems your domain interacts with
  • Read Models (d.readModel()): Query models optimized for reads
  • Facade Commands (d.facadeCmd()): Composite commands that delegate to services

Info Types

Define structured data within your domain:

const i = d.info

// Value objects
const orderId = i.id('OrderId')
const price = i.valueObj('Price')

// Documents
const spec = i.document('Specification')

// Functions with dependencies
const totalAmount = i.func('TotalAmount', [price, 'quantity'])

// Versions
const version = i.version('Version')

Workflow Builder Pattern

Build fluent chains that represent your domain flows:

const workflow = d.startWorkflow('Order Processing Workflow')
customer
  .command(placeOrder)
  .agg(orderAggregate)
  .event(orderPlaced)
  .policy(paymentPolicy)
  .service(paymentService)
  .command(processPayment)
  .agg(paymentAggregate)
  .event(paymentCompleted)

Each element in the chain can continue to the next appropriate element:

  • Command → Aggregate
  • Aggregate → Event
  • Event → Policy, System, ReadModel
  • Policy → Command, FacadeCommand, Service
  • Service → Command, FacadeCommand, Aggregate
  • System → Command, FacadeCommand, Event

User Stories

Group related workflows by user intent:

d.defineUserStory('Place and pay for order', [
  'Place Order',
  'Process Payment',
  'Handle Payment Failure',
])

Notes and Documentation

Add descriptive notes using template literals:

const paymentPolicy = d.policy(
  'PaymentPolicy',
  d.note`
    Process payment when ${orderPlaced} occurs
    Rules:
    1. Validate ${paymentAmount}
    2. Check ${customerStatus}
    3. Charge ${paymentMethod}
  `,
)

API Reference

createDomainDesigner(options?)

Creates a new DomainDesigner instance.

interface DomainDesignOptions {
  moduleName?: string
  ignoreValueObjects?: string[]
  __toFormatType?: 'BngleBrackets' | 'JSON' | 'JSONPretty'
}

const d = createDomainDesigner({
  moduleName: 'OrderManagement',
  ignoreValueObjects: ['time', 'id', 'name'],
})

DomainDesigner Methods

| Method | Description | | :--------------------------------- | :------------------------------ | | actor(name, note?) | Create an actor | | command(name, infos, note?) | Create a command | | facadeCmd(name, infos, note?) | Create a facade command | | agg(name, infos, note?) | Create an aggregate | | event(name, infos, note?) | Create an event | | policy(name, note?) | Create a policy | | service(name, note?) | Create a domain service | | system(name, note?) | Create an external system | | readModel(name, infos, note?) | Create a read model | | info.document(name, note?) | Create a document info | | info.func(name, deps?, note?) | Create a function info | | info.id(name, note?) | Create an ID info | | info.valueObj(name, note?) | Create a value object | | info.version(name, note?) | Create a version info | | startWorkflow(name) | Start a new workflow chain | | defineUserStory(name, workflows) | Define a user story | | note | Create a note for documentation |

Type Safety

The library provides full TypeScript type safety:

// Type-safe access to aggregate internals
const order = d.agg('Order', [orderId, userId])
console.log(order.inner.orderId) // Fully typed!

// Type-safe workflow chains
customer.command(placeOrder).agg(order) // Compile-time validation

License

Apache-2.0

Repository

https://github.com/ddd-tool/domain-designer-core-ts

Author

AlphaFoxz (https://github.com/AlphaFoxz)