Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer suggested approach for internal packages

Some background first

Our company, a small startup with only four developers, is starting the refactoring of our products into reusable modules to simplify the development process, increase productivity and, along the way, we would like to introduce unit tests where fits.

As usual on a small startup, we can't afford wasting too much development time but, as we see, this is extremely important for the success of our business on a medium and long term.

Currently, we have two end-user products. Both are Laravel (PHP) applications built on top of our own internal business layer, mainly composed of webservices, restful apis and a huge database.

This business layer provides most of the data for these products, but each of them makes completely different use of it. We plan to build other products on the near future besides maintaining and improving those two that are almost finished.

For that to happen, we intend to abstract the common logic of those (and the future) products into reusable and decoupled modules. The obvious choice seems to be Composer, even with our little knowledge about it.

Now to the real question

I would like to ask other opinions on how to develop internal packages on a test driven fashion. Should each module be a composer package with it's own unit tests and requiring it's dependencies, or should we build a single package with each module namespaced?

To clarify a bit, we would like to have, for instance, a CurlWrapper module and that would be required on our InternalWebserviceAPI module (and a few others).

I personally like the idea of having completely separate packages for each module and declaring dependencies on composer.json, which would mentally enforce decoupling and would allow us to publish some of those packages as opensource someday. It also may simplify breaking changes on those modules because we could freeze it's version on the dependents that will need to be updated.

Although, I also think this separation may add a lot of complexity and may be harder to maintain and test, since each module would need to be a project on it's own and we don't have all that man power to keep track of so many small projects.

Is really Composer the ideal solution for our problem? If so, which would recommend: single package or multiple packages?

Edit 1:

I would like to point out that most of these modules are going to be:

  • Libraries (ie obtaining an ID from an youtube URL or converting dates to "x seconds ago")
  • Wrappers (like a chainable CURL wrapper)
  • Facades (of our multiple webservices, those require the other two kinds)
like image 1000
vFragosop Avatar asked Mar 05 '13 21:03

vFragosop


People also ask

What is a Composer package?

Composer is a dependency manager. It installs packages locally. A package is essentially a directory containing something. In this case it is PHP code, but in theory it could be anything. And it contains a package description which has a name and a version.

What is a Composer Git?

Composer helps you declare, manage, and install dependencies of PHP projects. See https://getcomposer.org/ for more information and documentation.


1 Answers

Yes, composer is the way to go and I recommend you to use single packages.

You don't know when you need these modules. It is better to create many single packages and be able to include them all (or a single one), than creating big packages and need to put more time in breaking a package in multiple ones when you need some classes from it.

For instance, see the Symfony2 project. That is a lot of components which are all required for the full-stack Symfony2 framework, but you can also use some components in your own project (like Drupal8 is doing). Moreover, Symfony2 gets more and more packages, it seems so usefull to have small packages that people put time in breaking some big packages in pieces.

like image 69
Wouter J Avatar answered Oct 05 '22 23:10

Wouter J