internachi/modularize
Adds internachi/modular support to Laravel package commands via traits. Provides a --module option for console and generator commands, returning module config and generating files into the module directory with correct paths and namespaces.
ModuleConfig. This introduces a moderate risk (~25%) for projects with unconventional module structures, but the package’s hook-based design (e.g., getDefaultNamespace()) mitigates this by allowing overrides.ModularizeGeneratorCommand trait is highly specialized for file generators, automating module-aware path/namespacing logic. This reduces boilerplate for commands like make:controller but excludes non-generator commands (e.g., queue:work), which is a deliberate architectural choice to maintain simplicity and focus. For non-generators, the Modularize trait provides basic module access without path/namespace automation.internachi/modular Dependency: The package’s reliance on internachi/modular’s ModuleConfig introduces vendor lock-in risk. If the underlying modular system evolves (e.g., breaking changes in ModuleConfig or internachi/modular’s core API), the package may require updates. Mitigation:
internachi/modular’s release cadence and backward compatibility guarantees.spatie/laravel-modules) if internachi/modular’s roadmap introduces instability.--module flag across all commands, reducing cognitive load for developers. This is particularly valuable for large teams or SaaS platforms where module isolation is critical. However, runtime module discovery (e.g., dynamic module loading at request time) is not supported, limiting use cases to CLI-only workflows.ModuleConfig. Risk: Moderate (~20–30%), but the package’s extensible design allows workarounds.internachi/modular: The package’s utility is directly tied to internachi/modular. If the project does not use this library, the package is useless. Risk: High for projects not already committed to internachi/modular, but this is a deliberate trade-off for consistency.Modularize trait provides basic module access but lacks the automated path/namespacing of ModularizeGeneratorCommand. Risk: Low for generators, but non-generator commands (e.g., php artisan my:custom-command) will require additional logic to leverage module-specific paths.internachi/modular already in use or planned for adoption?
ModularizeGeneratorCommand trait may not provide sufficient value.ModuleConfig or override default behaviors.spatie/laravel-modules) we should evaluate?
internachi/modular is not a hard requirement, alternatives may offer broader compatibility.internachi/modular, which must be already integrated or planned into the project. If the project uses a different modular system (e.g., spatie/laravel-modules), the package is incompatible without significant modifications.ModularizeGeneratorCommand trait is ideal for file-generating commands (e.g., make:controller, make:migration), automating module-aware path/namespacing. For non-generator commands, the Modularize trait provides basic module access but requires additional logic for path handling.internachi/modular is already installed and configured.ModularizeGeneratorCommand) and non-generators (target for Modularize).composer require internachi/modularize
MakeController, MakeMigration):
use InterNACHI\Modularize\Support\ModularizeGeneratorCommand;
class MakeWidget extends GeneratorCommand {
use ModularizeGeneratorCommand;
}
use InterNACHI\Modularize\Support\Modularize;
class MyCommand extends Command {
use Modularize;
public function handle() {
if ($module = $this->module()) {
// Module-specific logic
}
}
}
--module flag works as expected:
php artisan make:controller --module=Blog PostController
getDefaultNamespace() or extend ModuleConfig if needed.ModuleConfig to match the project’s path conventions.--module flag for developers.internachi/modular: Required. The package will not work without it.ModuleConfig to handle custom paths.getDefaultNamespace() in generator commands.Modularize trait provides module access but does not automate path/namespacing for non-file operationsHow can I help you explore Laravel packages today?