The most modules use the following convention for its files:
- mymodule.inc
- mymodule.pages
- mymodule.admin.inc
- mymodule/includes/
etc.
I suggest to improve this convention and introduce a new convention, because if module is a big, there is a chance that chaos will occur without such convention. More over the new convention will help us to find necessary functions/classes/methods.
Main conventions
I suggest to use at least the following conventions.
- module_name/forms/ - all forms. For example for the form callback module_name_my_form_id(), the file name can be 'my_form_id.inc'.
- module_name/libs/ - some useful libraries/classes that module can use.
- module_name/ui/ - user interface including (theme_*() functions, and the *.tpl.php files).
- module_name/tests/ - tests (already used by the most modules).
Additional conventions (optional)
More over I suggest to introduce controllers to help collect all path handlers in one place. This convention can lead to adding an other directories like repos/, models/ etc.
- module_name/controllers/ - page controllers (if controllers will be used). Each controller can handle set of paths. Each controller is class that should end with the "Controller" suffix, for example MyController. The controller classes can use the namespace. Please see the sandbox project also.
- module_name/models/ - models
- module_name/services/ - services. Each service can be called from the Page Controller or other service class. Each service is class that can end with the "Service" suffix, for example MyService. The service classes can use namespaces. Other utility classes can be placed inside this directory too. Such classes can don't have the "Service" suffix.
- module_name/repos/ - repositories (Repository pattern, optional).
Comments
Comment #0.0
hinikato commentedAdded more descriptions.
Comment #0.1
hinikato commentedFixed description of utility classes.
Comment #1
Crell commentedDrupal has changed sufficiently in the last 4 years that this discussion is no longer relevant.