title: Domain Driven Design in Node.js Application
body: <p><em>TL; DR;
  I'm looking for trite example of DDD node.js application.</em></p>
  
  <hr>
  
  <p>Hi,</p>
  
  <p>I'm going to create node application. I wonder that I can not find any example of application with business logic separated in domain.</p>
  
  <p>OK, there are some examples like:
  <a href="https://github.com/adrai/node-cqrs-domain" rel="noreferrer">https://github.com/adrai/node-cqrs-domain</a> - but this is whole CQRS with event sourcing implementation.</p>
  
  <p>My idea is to do that like that:</p>
  
  <pre><code>//domain/book.js
  function Book(title, author)
  {
    this._title = title;
    this._author = author;
  }
  
  // domain methods ...
  
  //infrastructure/persistance/repository/book-repository.js
  function BookRepository()
  {}
  
  BookRepository.prototype.save(book)
  {
    var bookModel = mappers.mapToOrm(book);
    return bookModel.save();
  }
  
  // [...] get, getAll, getNextId
  
  //infrastructure/persistance/orm/book.js
  //using http://bookshelfjs.org/
  var Book = bookshelf.Model.extend({
    tableName: 'books'
  });
  
  //infrastructure/mappers/book-mapper.js
  function mapToOrm(book) {
    //mapping [...]
    return new persistance.Book();
  }
  
  function mapToDomain(domain) {
    //mapping [...]
    return new domain.Book();
  }
  </code></pre>
  
  <p>but on the other hand I've never seen any similar solution (with domain model, orm model, repository and mappers). Am I thinking in the right way? Maybe there is no reason to separate business logic in domain in node.js applications. If so, why? If not, can you send me an example of DDD implementation or improve my code?</p>
  
  <p><strong>[2017/01/13]</strong></p>
  
  <p>I've created sample application in TypeScript. For now without repositories and not much services. Issues and pull requests are welcome.
  <a href="https://github.com/dawiddominiak/ddd-typescript-bin-packing-problem-solution" rel="noreferrer">https://github.com/dawiddominiak/ddd-typescript-bin-packing-problem-solution</a></p>