DomainDrivenJSDomainDrivenJS
Home
  • Getting Started
  • Quick Start
  • DDD Fundamentals
  • Core Concepts
  • Advanced Topics
API
Examples
GitHub
Home
  • Getting Started
  • Quick Start
  • DDD Fundamentals
  • Core Concepts
  • Advanced Topics
API
Examples
GitHub
DomainDrivenJS

DomainDrivenJS

A modern, composition-based approach to Domain-Driven Design in JavaScript

Get StartedView on GitHub

Composition Over Inheritance

Build domain models through functional composition patterns that are natural in JavaScript, rather than deep class hierarchies.

Type-Safe with Runtime Validation

Leverage Zod schemas for both compile-time type inference and runtime validation to ensure your domain objects are always valid.

Immutable by Design

All domain objects are immutable, preventing unexpected state changes and making your code more predictable and easier to reason about.

Domain Events Built-In

First-class support for domain events, enabling loosely coupled, event-driven architectures that accurately model business processes.

Framework Agnostic

Works with any JavaScript or TypeScript project regardless of framework, allowing you to focus on modeling your domain.

Developer Experience First

Clear error messages, minimal boilerplate, and intuitive APIs designed to make DDD approachable and practical.

Intro Diagram

What is Domain-Driven Design?

Domain-Driven Design (DDD) is an approach to software development that focuses on creating a model that reflects your business domain. It gives you tools to tackle complex business logic and build maintainable software that closely aligns with business needs.

With DDD, you'll:

  • Build a shared language between developers and domain experts
  • Create a flexible model that evolves with your understanding
  • Focus development efforts on the core domain that provides the most value
  • Establish clear boundaries within a complex system

Why DomainDrivenJS?

Traditional DDD implementations often rely heavily on class inheritance, which can lead to rigid and complex hierarchies. DomainDrivenJS takes a different approach:

// Create a Money value object using composition
const Money = valueObject({
  name: 'Money',
  schema: z.object({
    amount: z.number().nonnegative(),
    currency: z.string().length(3)
  }),
  methods: {
    add(other) {
      if (this.currency !== other.currency) {
        throw new Error('Cannot add different currencies');
      }
      return Money.create({ 
        amount: this.amount + other.amount, 
        currency: this.currency 
      });
    }
  }
});

// Use the value object in your domain
const price = Money.create({ amount: 10.99, currency: 'USD' });
const tax = Money.create({ amount: 0.55, currency: 'USD' });
const total = price.add(tax); // Returns a new Money instance

Getting Started

DomainDrivenJS makes it easy to implement DDD in your JavaScript projects:

npm
npm install domaindrivenjs
yarn
yarn add domaindrivenjs
pnpm
pnpm add domaindrivenjs

Learning Path

Learning Path

New to DDD? Start with DDD Fundamentals to learn the core concepts.

Ready to code? The Quick Start will get you building immediately.

Looking for examples? Check out complete applications in our Examples section.

Need specific guidance? Dive into our comprehensive API Reference.

MIT Licensed | Copyright © 2023-present Marco Müllner