What is a module and what is a bundle?

27 June 2021

A short explanation of how a module differs from a bundle.
Because "bundle" is a symfony term this article is mostly aims symfony developers.

Module

Module is a part of a system that provides particular functionality.
From language to language there are alternative terms that usually describe a module.
It varies between library, package, component, unit, crate and etc..
Sometimes it goes even further and complex composites, that contains multiple modules, may be called module too.
Yet this is rather exceptional because such complexities usually have particular naming.
Like applications, microservices and so on.

Modules can be fully independent or lowly coupled with other modules.
Also, it is highly recommended to pay more attention for LCHC principle from GRASP while working on module architecture.
In short, the principle says two things:

  1. module responsibility shall be isolated in one module (do not spread one action between different modules).
  2. module shall have as less communication with another modules as possible (also avoid bidirectional communication at all cost).

Bundle

Bundle is just a common module that contains instructions for symfony application.
Those instructions make possible automatically installing and configuring the module. Nothing more. For example: twig is a template engine module that has to be installed through composer, manually configured and injected through DI. twig bundle is a twig module itself plus some bundle configs that automatically injects pre-baked service into DI for further usage.

Sometimes bundle can contain application input. Like controllers and commands.
Popular fos-oauth-server-bundle provides authorization controller.

Don't take everything plain: we have to challenge and prove the information we face.

Here is what really helps me to do it.