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 🙏

© 2025 – Pkg Stats / Ryan Hefner

domain-eventrix

v1.0.15

Published

A Typescript library for managing domain events, providing integration with React,React Native , and supporting DDD use cases. Designed to work in Typescript projects.

Readme

domain-eventrix

A powerful TypeScript library for managing domain events with seamless integration for React, React Native, and Domain-Driven Design (DDD). Built to enhance event-driven architectures with features like retry strategies, dead letter queues, and state management.

npm version License: MIT

Features

  • 🚀 Robust event bus implementation with TypeScript support
  • 🔄 Built-in retry strategies and dead letter queue
  • 📊 Event processing state management
  • ⚛️ First-class React and React Native integration
  • 🏛️ DDD-friendly with aggregate root support
  • 🔍 Event monitoring system
  • 🎨 Flexible configuration options

Installation

npm install domain-eventrix
# or
yarn add domain-eventrix
# or
pnpm add domain-eventrix

Quick Start

1. Create an Event Bus

import DomainEventrix from "domain-eventrix"

// Create a shared (default) event bus
DomainEventrix.create()

// Or create a named event bus
DomainEventrix.create({
  eventBusKey: "CustomEventBus",
  enableStateManagement: true
})

2. Define Events and Handlers

import { DomainEvent, DomainEventMessage, EventHandler, DomainEventHandler } from "domain-eventrix"

// Define an event
@DomainEventMessage("UserRegistered")
class UserRegisteredEvent extends DomainEvent<User> {
  constructor(user: User) {
    super(user)
  }
}

// Define a handler
@DomainEventHandler(UserRegisteredEvent, {
  message: "Handle user registration",
  isVisibleOnUI: true
})
class UserRegistrationHandler extends EventHandler<User, UserRegisteredEvent> {
  async execute(event: UserRegisteredEvent): Promise<void> {
    const user = event.data
    // Handle the registration
    console.log(`User registered: ${user.name}`)
  }
}

3. Use the Event Bus

const eventBus = DomainEventrix.get() // Get shared bus
// or
const customBus = DomainEventrix.get("CustomEventBus") // Get named bus

// Publish events
eventBus.publish(new UserRegisteredEvent(user))
// or publish and execute immediately
eventBus.publishAndDispatchImmediate(new UserRegisteredEvent(user))

Core Concepts

Event Bus Types

Domain-eventrix provides two types of event buses:

  1. SharedEnhancedEventBus (Default)

    • Singleton instance shared across your application
    • Perfect for most use cases
  2. EnhancedEventBus

    • Named instances for specific contexts
    • Useful when you need isolated event handling

Event Processing Features

  • Retry Strategy: Configurable retry attempts for failed event processing
  • Dead Letter Queue: Handle persistently failed events
  • State Management: Track event processing status
  • Monitoring: observe event flow and processing metrics

Advanced Usage

Domain-Driven Design Integration

import { AggregateEventDispatcher, Aggregate } from 'domain-eventrix/ddd'

class UserAggregate implements Aggregate {
  private domainEvents: DomainEvent<any>[] = []
  
  constructor(public id: string, public name: string) {}
  
  register() {
    const event = new UserRegisteredEvent({ id: this.id, name: this.name })
    this.domainEvents.push(event)
    AggregateEventDispatcher.get().queueAggregateForDispatch(this)
  }
  
  getDomainEvents() { return this.domainEvents }
  getID() { return this.id }
  clearDomainEvent() { this.domainEvents = [] }
}

// Usage
const user = new UserAggregate("1", "John Doe")
user.register()
AggregateEventDispatcher.get().dispatchEventsForMarkedAggregate(user.id)

React Integration

Setup Event Provider

// eventrix.config.ts
import DomainEventrix from "domain-eventrix"

DomainEventrix.create({
  eventBusKey: "ReactApp",
  enableStateManagement: true
})

// App.tsx
import { EventProvider } from "domain-eventrix/react"
import "./eventrix.config"

function App() {
  return (
    <EventProvider eventBusKey="ReactApp">
      <YourApp />
    </EventProvider>
  )
}

Use Hooks

import { 
  useEventBus,
  useEventContext,
  useEventBusMethods,
  useEventProcessingState
} from "domain-eventrix/react"

function UserComponent() {
  const { publish } = useEventBusMethods()
  
  const handleRegister = () => {
    publish(new UserRegisteredEvent({ name: "John Doe" }))
  }
  
  // Monitor event processing
  useEventProcessingState(state => {
    console.log('Current processing state:', state)
  })
  
  return <button onClick={handleRegister}>Register User</button>
}

Configuration Options

DomainEventrix.create({
  eventBusKey?: string,           // Custom event bus identifier
  enableStateManagement?: boolean, // Enable processing state tracking
  enableMonitoringSystem?: boolean,// Enable event monitoring
  enableRetrySystem?: boolean,     // Enable retry strategy
  retryAttempts?: number,         // Number of retry attempts
  initialRetryDelay?: number,     // Initial delay between retries (ms)
  maxRetryDelay?: number,         // Maximum delay between retries (ms)
  deadLetterQueueSize?: number    // Size of dead letter queue
})

Usage

Best Practices

  1. Event Bus Creation

    • Use DomainEventrix.create() at your application's entry point
    • Configure options based on your environment needs
  2. Event Handling

    • Keep handlers focused and single-purpose
    • Handle errors appropriately in execute methods
    • Use TypeScript for better type safety
  3. React Integration

    • Initialize configuration before rendering
    • Use hooks for accessing event bus functionality
    • Monitor processing state for better UX
  4. DDD Implementation

    • Keep aggregates focused and consistent
    • Dispatch events after completing business logic
    • Clear domain events after successful dispatch

Contributing

We welcome contributions! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.