JavaScript can easily fit in a Domain Driven Design, at least at several levels:

  • Client layer,to validate input and create custom UI or reports (could be AJAX or even Delphi client);
  • Application layer, as the application logic should either not be part of the thin client, but stay on the server, either be injected into a rich and modular client from the server - JavaScript everywhere, but we may imagine to create a mORMot client, as native application, retrieving its business logic from the server;
  • Application layer, to adapt the common business model to one customer or a given application (e.g. custom behavior, reporting);
  • Business layer, to define the business logic using the domain objects (e.g. to adapt to a given change of policy).

Therefore, in addition to Pavel's proposal, I would like to make available two features of mORMot (in addition to other cross-cutting elements of the framework, like logging, security, session handling, reporting, pdf generation, cache):

Both of these features do make sense in a business model, to customize your project according to customer expectations, and even let the customer create or adapt its own application layer to its needs.
It is easy to adapt some existing JavaScript code, so that the report layout will change, or to apply a new tax or process.

Event-sourcing does also make sense from the JavaScript point of view.
It could be very handy to add an event listener to an existing business core, then use JavaScript to listen to those events, and define some custom process, without touching the main business logic.

My only concern, spending a lot of time in Delphi and C# source code, is that JavaScript, as a language, lacks of interface support and strong typing
This is why I'm looking (since months) at DWS script / SmartMobileStudio and TypeScript.

TypeScript is an Open Source scalable JavaScript development with types, classes and modules. It is published by Microsoft, but is open source.
It comes with full source code of its compiler in TypeScript, so can be embedded very easily to our SpiderMonkey modules.
TypeScript is great because it is a layer over JavaScript, adding strong typing and interfaces.
Other scripts compiling to JavaScript either lack of those two (like CoffeeScript or Opal), use a slow and non integrated virtual machine (yes, a virtual machine within a virtual machine... do you follow my mind?), or need a whole SDK to be available (like Dart).

And our little mORMot likes interfaces, efficient and small solutions.

DWS/SMS script compiler to JavaScript is not free any more. So it is no option for us (sorry Eric).
I suspect TypeScript could be a great optional syntax for our mORMot business layer.
Do not forget that Anders Hejlsberg, lead architect of Delphi and C#, has worked on development of TypeScript!

Feedback is welcome on our forum.