Our domain layer would mainly consist of 3 items: services, models, and repositories. We went in depth in the last chapter, Layered/N-Tier Architecture: The Unpopular Proven Way, so make sure to read up on those concepts if you are not sure about what those 3 items are.


We talked about services and what they are, services will usually use other services and repositories to perform some sort of business logic operation.

For example, a UserService will have a method called registerUser.

UserService would potentially use a UserRepository to insert the user into the database and an EmailService to send an email to the user if they successfully registered.

Models (Entities)

Models usually represent something in the business and are generally going to be some sort of Object Relational Mapper (ORM). They could be SQL based or NoSQL based. Models can also be just plain old objects. For us, we will be using a MongoDB, and Mongoose as our NoSQL database adapter.

Examples of models would be a User, a Car, a Book, a House, an Animal, and more.


If you can recall, repositories are essentially an abstraction layer of models. In general, repositories will have CRUD operations as their methods wrapped around the native models.

An example would be:


  • getAllBooks()

  • createABook(book)

  • deleteABook(bookId)

Last updated