Best Practice: Laminas MVC vs Mezzio vs DotKernel API

I’m interested in everyone’s opinion on the matter. Here’s a brief of my use case.

I develop a variety of applications. All of which require a frontend, which Laminas MVC ( and ZF2 & ZF3) has handled solely thus far. Some of the more involved applications can greatly benefit from an API interface, and on more than one occasion a command line option would be extremely helpful. From day one I’ve had a terrible time trying to integrate all of these features into one cohesive skeleton to be the platform for all of my applications. My goal is be able to support all these features, on a maintained platform, and conform to all the best practices of that framework.

I’ve attempted to develop an API very late in the game, and once coming across api-tools, very quickly was redirected to dotkernel-api. Upon first glance it was a very easy implementation and got the job done … for an API/CLI … but once trying to dive into creating a frontend I found myself balking at simple tasks that I could’ve written in MVC blindfolded.

I’ve been unable to find really informative tutorials on how to implement API and CLI calls within MVC, so much so that I intended to write my own tutorials. And now Mezzio comes into the mix which I hear great things about, but again don’t have the time to really weigh pro and cons for all these frameworks before deciding on “one” which will be my go-to for years to come.

So, in conclusion, I ask the community for your thoughts:

  • MVC vs Mezzio. Who’s going to stand the test of time? Is it worth switching?
  • API into MVC. Doable or no Doable? Are there decent tutorials out there?
  • CLI. Is it worth bundling all these features into one application?

Also I want to be able to write submodules that are shareable between multiple applications. To do this, all applications need to be on the same framework, and I’m just scared to pull the trigger one way or another without more information.

I Appreciate any feedback you can provide.

I would summarize your 3 questions into a single one:
MVC versus Middleware
and there isn’t yet a consensus in the community about that.
And the anser is: depends

There are pros and cons for each architecture.
For a greenfield project , in which you do not know yet how many separate applications will evolve in time , i would advice to go for Middleware.

At Dotkernel we will publish in the near future 2 new projects and some documentation about how to split an Dotkernel API into parts:

  • The API itself, based on Mezzio
  • A Core repository , where the common business logic will be kept and shared between various applications, as a git submodule

That way , starting from Dotkernel API, you can extend a project into :

  1. API
  2. CLI as a secondary API
  3. Frontend ( html, css, js, and mezzio )
  4. Admin ( backend)
  5. and so on

and each of those parts will use the same Core repository

I agree with @arhimede here. It’s really a question between middleware/handler and MVC. I advocated for MVC for a long time. Mezzio is the way to go. MVC is dead, it just does not know it yet because there is so many current applications in the wild that use it. That’s just my opinion. Middleware/handlers is a much more streamlined/performant/simpler paradigm for building Http applications.

Some current MVC frameworks have introduced support for middleware which run prior to their controllers. Seems a bad choice to me. At that point their “controllers” are just handlers. With Mezzio you get a streamlined, built for the task, implementation that is only what is required. You make all of the other choices with zero extra overhead.

API into MVC…
Sure, it can be done which is why MVC has a AbstractRestfulController but it is 100 times simpler in Mezzio. In mezzio it does not require any special setup or configuration. It just works.

With laminas MVC, as well as with symfony iirc if you want to support psr-7 then both require translation to and from psr-7. With laminas-diactoros (which mezzio uses) you get this support out of the box with no translation required. Why incur the overhead of translation?

CLI.
Since cli commands are namespaced you can provide a suite of CLI tooling to your applications that is namespaced consistently and aggregated from the modules that expose them.

I made the switch to mezzio about 18 months ago and have not regretted it for a single moment. All of your code from MVC (outside of the controllers/controller plugins themselves) can with a little work be adapted for Mezzio. Most times it’s simply a matter of Adding a ConfigProvider to the module and modifying the config file to call the providers methods as the config array values.

1 Like

Hey @COMCDUARTE ,

welcome to the laminas forums. Writing submodules is wether with Mezzio nor with MVC a problem. Don 't fall into the rabbit hole and think, that everything must run on the same framework. To avoid that case, just write abstractions.

The basic bussiness logic should be programmed once. Everything else, that accesses the logic of your submodule, should be written as abstraction, that is based on the specific framework you use. Think of vendor packages, that follow the same principle. Some Symfony packages are used with Laminas MVC. On the other hand Symfony or even Laravel use Laminas packages.