My TypeScript Software Design & Architecture book just prelaunched! Check out

How To Decide Where To Put Domain Logic | Domain Driven Design w/ TypeScript

Jul 1st, 2019 / 1 min read / Share / Edit on GitHub
In this post, I walk you through a process for determining where different types of domain logic belongs in a Domain-Driven Design project.

The reason we use Domain-Driven Design is because when our applications get sufficiently complex, we need to figure out better ways to organize domain logic than how we normally do with MVC in RESTful CRUD applications.

Domain Events

During the process of figuring out our requirements and understanding the domain, sometimes we'll hear language being used that sounds similar to:

"when this, then do this" or "when this, do this only if this has this"

When we hear that, we should automatically think "Domain Events".

Domain events should be named in the form of [Entity][Past Tense Verb]Event.

Some examples are: VinylCreatedEvent, VinylUpdatedEvent, OfferAcceptedEvent, OfferDeclinedEvent.

Just the, it naturally signifies that the model will be responsible for the verb/method.

Therefore: VinylCreatedEvent = Vinyl.create(props: VinylProps, id?: UniqueEntityId).

Therefore: VinylUpdatedEvent = vinyl.update(props: VinylProps).

Therefore: OfferAcceptedEvent = offer.accept().

And it just so happens that we would also create those domain events within those entity method invokations.

Validation and Invariant Logic => Value Objects & Entities


Liked this? Sing it loud and proud 👨‍🎤.


Be the first to leave a comment


Stay in touch!

About the author

Khalil Stemmler

Khalil Stemmler is a Developer / Designer and co-founder of Univjobs. He frequently publishes articles about Domain-Driven Design and Advanced TypeScript & Node.js best practices for large-scale applications.

View more in Domain-Driven Design

You may also enjoy...

A few more related articles

An Introduction to Domain-Driven Design - DDD w/ TypeScript
Jul 30th, 2019 / 12 min read
Domain-Driven Design is the approach to software development which enables us to translate complex problem domains into rich, expr...
Handling Collections in Aggregates (0-to-Many, Many-to-Many) - Domain-Driven Design w/ TypeScript
Jul 25th, 2019 / 10 min read
In this article, we discuss how we can use a few CQS principles to handle unbounded 0-to-many or many-to-many collections in aggre...
Challenges in Aggregate Design #1 - Domain-Driven Design w/ TypeScript
Jul 25th, 2019 / 5 min read
In this series, we answer common questions in aggregate design. Here's an article orignating from the question, "How can a domain ...
How to Design & Persist Aggregates - Domain-Driven Design w/ TypeScript
Jul 24th, 2019 / 28 min read
In this article, you'll learn how identify the aggregate root and encapsulate a boundary around related entities. You'll also lear...

Want to be notified when new content comes out?

Join 2000+ other developers learning about Domain-Driven Design and Enterprise Node.js.

I won't spam ya. 🖖 Unsubscribe anytime.

Get updates