Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Headache designing Symfony2 bundles organization

Tags:

symfony

I'm developing a SaaS where tenants are both real ones and admins (us). So "fornt-end" and "back-end" are the same. Anyway, according to many other questions bundles are a way to structure your project in reusable way.

I really don't think that our bundles are going to be reused, but i still need a way to split the project into bundles to quickly find files we want to work on. Application should:

  • CRUD for customers - tenants should be able to manage their customers/partnerships
  • CRUD for customers tags and keywords (a way to categorize their customers)
  • CRUD for broadcast notifications sent by us (a messaging system)
  • CRUD for tenants - we should be able to manage our tenants

So, how can organize my bundles? Could be:

  • CoreBundle: only Doctrine2 models
  • ResourcesBundle: templates, js, css, images
  • SystemUserBundle: manage tenants and customers CRUD
  • MessagingBundle: message system

How this design can be improved?

like image 852
gremo Avatar asked Dec 27 '22 05:12

gremo


1 Answers

According to the Symfony2 documentation:

In Symfony2, a bundle is like a plugin, except that all of the code in your application will live inside a bundle. A bundle is nothing more than a directory that houses everything related to a specific feature, including PHP classes, configuration, and even stylesheets and Javascript files (see The Bundle System).

Personally, following this description, I would set up the SystemUserBundle to contain the Doctrine2 model and templates/js/css/images that specifically relate to managing customers, rather than splitting them out into CoreBundle and ResourceBundle. However, splitting your app into SystemUserBundle and MessagingBundle sounds like a reasonable approach.

I like to think of it this way - does the bundle encapsulate some behaviour that I might need or want to plugin to a future Symfony project(s) I am involved in. Customer Management, for example, is something that might apply to any app and be re-used across projects (indeed, this is why the extensible FOSUserBundle exists).

I don't think the Symfony2 docs go into sufficient detail on bundles (yet!) but in case you haven't found all the relevant sections these are the ones I'm aware of:

  • Symfony 2 Page creation
  • Symfony 2 The Bundle System
  • Symfony 2 Bundles best practices
like image 101
redbirdo Avatar answered Jan 05 '23 09:01

redbirdo