Skip to content

XOOPS Module Generator

The XOOPS Module Generator is a CLI tool that scaffolds complete module structures following modern best practices, including PSR-4 autoloading, clean architecture patterns, and XOOPS 4.0 conventions.

Terminal window
composer global require xoops/module-generator
Terminal window
xoops module:generator install
Terminal window
xoops generate:module MyModule

This creates a complete module structure in modules/mymodule/.

Terminal window
xoops generate:module MyModule \
--author="Your Name" \
--description="Module description" \
--with-admin \
--with-blocks \
--with-templates \
--with-api

Creates a new module scaffold.

Terminal window
xoops generate:module <name> [options]

Options:

OptionDescriptionDefault
--authorModule author nameGit config
--descriptionModule descriptionEmpty
--namespacePHP namespaceXoopsModules\{Name}
--with-adminInclude admin paneltrue
--with-blocksInclude sample blockstrue
--with-templatesInclude templatestrue
--with-apiInclude REST APIfalse
--with-testsInclude test suitefalse
--architectureArchitecture styleclean

Creates a domain entity with repository.

Terminal window
xoops generate:entity MyModule Article \
--properties="title:string,content:text,status:enum" \
--with-handler \
--with-form

Generated files:

  • src/Entity/Article.php
  • src/Repository/ArticleRepository.php
  • src/Repository/ArticleRepositoryInterface.php
  • src/Handler/ArticleHandler.php (if --with-handler)
  • src/Form/ArticleForm.php (if --with-form)

Creates a service class.

Terminal window
xoops generate:service MyModule ArticleService \
--methods="create,update,delete,findById,findAll"

Creates a controller with actions.

Terminal window
xoops generate:controller MyModule ArticleController \
--actions="index,show,create,edit,delete" \
--resource

Creates a block with template.

Terminal window
xoops generate:block MyModule RecentArticles \
--options="limit:int:5,category:select"

Creates a database migration.

Terminal window
xoops generate:migration MyModule create_articles_table
modules/mymodule/
├── src/
│ ├── Controller/
│ ├── Entity/
│ ├── Repository/
│ ├── Service/
│ └── Helper.php
├── config/
│ ├── routes.php
│ └── services.php
├── templates/
│ ├── admin/
│ └── blocks/
├── language/
│ └── english/
├── sql/
│ └── mysql.sql
├── admin/
│ ├── index.php
│ └── menu.php
├── module.json
├── composer.json
└── README.md
modules/mymodule/
├── src/
│ ├── Application/
│ │ ├── Command/
│ │ ├── Query/
│ │ └── Service/
│ ├── Domain/
│ │ ├── Entity/
│ │ ├── ValueObject/
│ │ ├── Event/
│ │ └── Repository/
│ ├── Infrastructure/
│ │ ├── Persistence/
│ │ └── Service/
│ └── Presentation/
│ ├── Controller/
│ └── Form/
├── config/
├── templates/
└── ...

Create .xoops-generator.json in your project:

{
"defaults": {
"author": "Your Name",
"license": "GPL-2.0-or-later",
"namespace_prefix": "XoopsModules",
"architecture": "clean",
"php_version": "8.4"
},
"templates": {
"entity": "templates/entity.php.twig",
"service": "templates/service.php.twig"
},
"hooks": {
"post_generate": "composer dump-autoload"
}
}

Place custom Twig templates in .xoops-generator/templates/:

{# .xoops-generator/templates/entity.php.twig #}
<?php
declare(strict_types=1);
namespace {{ namespace }}\Entity;
final class {{ class_name }}
{
{% for property in properties %}
private {{ property.type }} ${{ property.name }};
{% endfor %}
// Custom template content...
}

Run without arguments for interactive prompts:

Terminal window
xoops generate:module
? Module name: MyModule
? Author: Your Name
? Description: My awesome module
? Include admin panel? Yes
? Include blocks? Yes
? Include REST API? No
? Architecture style? Clean Architecture
Generating module...
Created modules/mymodule/
Created 23 files
Module ready!

Generated modules include composer.json:

{
"name": "xoops-modules/mymodule",
"autoload": {
"psr-4": {
"XoopsModules\\MyModule\\": "src/"
}
}
}

If --with-tests is specified:

tests/
├── Unit/
│ ├── Entity/
│ └── Service/
├── Integration/
├── bootstrap.php
└── phpunit.xml
  • VS-Code-Snippets - IDE snippets
  • ../../03-Module-Development/Module-Structure - Directory structure guide
  • Test-Generator - Generate tests
  • ../../03-Module-Development/Best-Practices/Code-Organization - Architecture patterns