How to create pug-in projects to work with main projects

I want to build a structure where a project can work as a standalone or it can be used as a plugin to be connected to another project [Everything is located in one gateway]

Currently I am using inheritance on and off for the plugin affect but I know that is not really how you are suppose to use that function.

Please let me know how I can make this concept work