Scaffold new Drupal modules with correct .info.yml, PSR-4 namespace structure, and .module file conventions. Use WHENEVER creating a new Drupal module, starting a custom module, setting up module boilerplate, or generating the initial file structure for any Drupal development task. Covers D10/D11 .info.yml format, dependency declarations, and hook vs OOP file placement. Do NOT use for adding specific features (routes, forms, entities) -- use the relevant feature skill instead.
When creating a new Drupal module, decide which files to create based on what the module will do.
Every Drupal module requires at minimum:
module_name.info.yml -- Makes Drupal recognize the module. Without this, nothing works.src/ directory -- PSR-4 autoloading root. Even if empty initially, create it for any class-based code.Ask yourself these questions to decide what else to create:
Does the module implement hooks?
YES -> Create module_name.module (procedural hook implementations go here)
NO -> Do not create a .module file. Many modern modules have no .module file at all.
Does the module define pages or API endpoints?
YES -> Create module_name.routing.yml + a Controller class in src/Controller/
NO -> Skip routing. See also: drupal-routing-controllers (if installed) for full routing patterns.
Does the module provide services (shared logic, API clients, managers)?
YES -> Create module_name.services.yml + service class in src/
NO -> Skip services file.
Does the module define permissions?
YES -> Create module_name.permissions.yml
NO -> Skip permissions file.
Does the module add CSS or JS?
YES -> Create module_name.libraries.yml + asset files
NO -> Skip libraries file.
Does the module define entity types?
YES -> See drupal-entities-fields (if installed) for content and config entity type creation. If not available, you need entity classes in src/Entity/, schema files, and handler definitions.
NO -> Skip entity infrastructure.
The .info.yml file is the only file strictly required for a module to be recognized by Drupal. Place it at the root of your module directory.