Applications these days rely on distributed, redundant and scalable microservices. Gone are the days when you could write an app in PHP with the Frontend and the Backend strictly coupled (PHP, seriously?)
I'll give you a simple model everyone uses these days: a frontend, usually written in AngularJS, Ember or React; a backend, say Node.js (because why not); a messaging stack, Redis or RabbitMQ. Personally, I prefer RabbitMQ and ZeroMQ for MQs. And a data tier: combination of volatile storage options, persistent storage options and what not.
If you're in a big team, sharing the code becomes redundant. I mean, seriously. If you see it in this way: frontend code is generally written for cross-browser compatibility; for server-side, stripping all of that code, re writing it for cluster management is a big pain.
However, there are times when you HAVE to use the code. Say, a database adapter or whatever. For that, I use the Universal Module Definition. Something like this:
( ( root, factory ) => {
if ( typeof define === 'function' && define.amd ) {
// 'define' is used in Async. Module Definitions
define( [ '--Dependencies--' ], factory );
} else if (typeof exports === 'object') {
// Node/CommonJS export object
module.exports = factory( require( '--Dependencies--' ) );
} else {
// Otherwise, attach it to the root object we provide
root.attachedExports = factory( root.dependency );
}
}( this, FACTORY_FUNCTION ) );
And then upload it to either a private NPM repo, or wherever I like. Works flawlessly across everything.
That was code sharing. If I have to share some services, I create a deployment pipeline, attached to the core process (the primary app requiring it) and then add some children (any other processes which want it). This eliminates a lot of security risk there is when sharing services and works very well.
Since these services are easy to deploy, it helps in scaling it as well.
Shreyansh Pandey
node, coffee and everything in between