XOOPS Module Generator
Overview
Section titled “Overview”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.
Installation
Section titled “Installation”Via Composer
Section titled “Via Composer”composer global require xoops/module-generatorVia XOOPS CLI
Section titled “Via XOOPS CLI”xoops module:generator installQuick Start
Section titled “Quick Start”Generate a Basic Module
Section titled “Generate a Basic Module”xoops generate:module MyModuleThis creates a complete module structure in modules/mymodule/.
Generate with Options
Section titled “Generate with Options”xoops generate:module MyModule \ --author="Your Name" \ --description="Module description" \ --with-admin \ --with-blocks \ --with-templates \ --with-apiCommand Reference
Section titled “Command Reference”generate:module
Section titled “generate:module”Creates a new module scaffold.
xoops generate:module <name> [options]Options:
| Option | Description | Default |
|---|---|---|
--author | Module author name | Git config |
--description | Module description | Empty |
--namespace | PHP namespace | XoopsModules\{Name} |
--with-admin | Include admin panel | true |
--with-blocks | Include sample blocks | true |
--with-templates | Include templates | true |
--with-api | Include REST API | false |
--with-tests | Include test suite | false |
--architecture | Architecture style | clean |
generate:entity
Section titled “generate:entity”Creates a domain entity with repository.
xoops generate:entity MyModule Article \ --properties="title:string,content:text,status:enum" \ --with-handler \ --with-formGenerated files:
src/Entity/Article.phpsrc/Repository/ArticleRepository.phpsrc/Repository/ArticleRepositoryInterface.phpsrc/Handler/ArticleHandler.php(if--with-handler)src/Form/ArticleForm.php(if--with-form)
generate:service
Section titled “generate:service”Creates a service class.
xoops generate:service MyModule ArticleService \ --methods="create,update,delete,findById,findAll"generate:controller
Section titled “generate:controller”Creates a controller with actions.
xoops generate:controller MyModule ArticleController \ --actions="index,show,create,edit,delete" \ --resourcegenerate:block
Section titled “generate:block”Creates a block with template.
xoops generate:block MyModule RecentArticles \ --options="limit:int:5,category:select"generate:migration
Section titled “generate:migration”Creates a database migration.
xoops generate:migration MyModule create_articles_tableGenerated Structure
Section titled “Generated Structure”Basic Module
Section titled “Basic Module”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.mdWith Clean Architecture
Section titled “With Clean Architecture”modules/mymodule/├── src/│ ├── Application/│ │ ├── Command/│ │ ├── Query/│ │ └── Service/│ ├── Domain/│ │ ├── Entity/│ │ ├── ValueObject/│ │ ├── Event/│ │ └── Repository/│ ├── Infrastructure/│ │ ├── Persistence/│ │ └── Service/│ └── Presentation/│ ├── Controller/│ └── Form/├── config/├── templates/└── ...Configuration
Section titled “Configuration”Generator Config File
Section titled “Generator Config File”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" }}Custom Templates
Section titled “Custom Templates”Override Default Templates
Section titled “Override Default Templates”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...}Interactive Mode
Section titled “Interactive Mode”Run without arguments for interactive prompts:
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!Integration
Section titled “Integration”With Composer
Section titled “With Composer”Generated modules include composer.json:
{ "name": "xoops-modules/mymodule", "autoload": { "psr-4": { "XoopsModules\\MyModule\\": "src/" } }}With PHPUnit
Section titled “With PHPUnit”If --with-tests is specified:
tests/├── Unit/│ ├── Entity/│ └── Service/├── Integration/├── bootstrap.php└── phpunit.xmlRelated Documentation
Section titled “Related Documentation”- 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