Skip to content

Creating Modules

This documentation provides guidelines for creating modules compatible with the Module Manager (MM) using the Skeleton module template.

Skeleton Module

The Skeleton module serves as a template for creating new modules in the system. It provides a streamlined structure and a convenient command-line tool to quickly generate new modules based on this template.

Module Structure

The Skeleton module contains a basic structure that follows best practices for module development:

  • Configuration files
  • Service provider setup
  • Basic directory structure
  • Composer configuration
  • Module manifest

Creating a New Module

Using the Module Builder Command

The easiest way to create a new module is to use the built-in module-build command:

bash
php artisan module-build

This interactive command will:

  1. Ask for your module name
  2. Create a properly structured module based on the Skeleton template
  3. Register the module with the system

Command Options

You can also specify the module name directly with the --name option:

bash
php artisan module-build --name=MyNewModule

What the Command Does

The module-build command performs the following operations:

  1. Creates a new module directory based on the provided name
  2. Copies all files from the Skeleton module to the new module
  3. Renames files and directories by replacing "Skeleton" with your module name
    • PascalCase substitution: "Skeleton" → "YourModuleName"
    • Lowercase substitution: "skeleton" → "yourmodulename"
  4. Updates file contents to replace all occurrences of "Skeleton" with your module name
  5. Updates specific files:
    • composer.json: Updates package name and namespaces
    • module.json: Updates name, alias, and provider paths
    • Service Provider: Updates namespace, class name, and properties
  6. Cleans up:
    • Removes .git directory if it exists
    • Removes vendor directory if it exists
    • Removes the ModuleBuildCommand from the new module
  7. Registers the module:
    • Updates modules_statuses.json to enable the new module
  8. Updates autoloader:
    • Runs composer dump-autoload to register the new namespaces

After Module Creation

Once your new module is created, it will be:

  1. Properly registered in the system
  2. Ready for development
  3. Accessible through its namespace (Modules\YourModuleName)

You can then add your specific functionality to the new module.

Setting Up a Remote Repository

After creating your module, you should set up a Git repository:

bash
# Navigate to the module directory
cd Modules/YourModuleName

# Initialize Git if not already done
git init

# Add all files
git add .

# Make initial commit
git commit -m "Initial module setup from skeleton"

# Add remote repository (create this on GitHub first)
git remote add origin https://github.com/e2tmk/newmodule-module.git

# Push to remote
git branch -M main
git push -u origin main

Module Registration in Module Manager

To make your module available for installation in other applications:

  1. Register it in the Module Manager Panel
  2. Ensure you follow the naming convention with the -module suffix for your repository

Best Practices

  • Maintain the standard directory structure for new modules
  • Follow the naming conventions established by the Skeleton module
  • Include all package dependencies in your module's composer.json
  • Use Module Manager's traits to properly integrate with multi-tenancy
  • Add detailed documentation in your module's README.md

Example

To create a new "Reports" module:

bash
php artisan module-build --name=Reports

This will create a fully functional Reports module with all necessary files and configurations.