sinemacula/laravel-modules
Composer 安装命令:
composer require sinemacula/laravel-modules
包简介
A lightweight, convention-driven modular architecture package for Laravel - auto-discovers modules as directories with zero manifests, zero boilerplate, and nothing new to learn.
README 文档
README
A lightweight, convention-driven modular architecture package for Laravel. Replaces the standard app/ directory with a
modules/ directory where each subdirectory is a self-contained module following standard Laravel conventions.
Modules are auto-discovered at boot time and cached for performance. All standard Laravel conventions work inside each module - there is no new API to learn.
How It Works
Each subdirectory under modules/ is a self-contained module with its own models, controllers, routes, commands,
listeners, events, observers, policies, and more:
modules/
├── Foundation/ # Core framework module
│ ├── Console/ # Commands and schedule
│ └── Providers/ # Service providers
└── Billing/ # Example domain module
├── Events/
├── Http/
│ ├── Controllers/
│ ├── Requests/
│ ├── Resources/
│ └── routes.php
├── Listeners/
├── Models/
├── Observers/
└── Policies/
What Gets Discovered
| Convention | Module Path | How It's Loaded |
|---|---|---|
| Console commands | Console/Commands/ |
Auto-registered via withCommands() |
| Scheduled tasks | Console/schedule.php |
Auto-registered via withCommands() |
| Event listeners | Listeners/ |
Auto-registered via withEvents() |
| Views | Resources/views/ |
Auto-registered in ModuleServiceProvider |
| Translations | Resources/lang/ |
Auto-registered in ModuleServiceProvider |
| Routes | Http/routes.php |
Discovered; you wire them in bootstrap/app.php |
Everything else - controllers, requests, resources, events, observers, policies, models, jobs, mail, notifications - works via PSR-4 autoloading. No registration required.
Service providers work exactly as they do in a standard Laravel app: register them in bootstrap/providers.php. The
package does not auto-discover module providers, so you keep full control over their registration order.
Artisan Commands
| Command | Description |
|---|---|
module:make {name} |
Scaffold a new module with the standard directory structure |
module:list |
List all discovered modules and their paths |
module:cache |
Cache discovered module paths for faster resolution |
module:clear |
Clear the cached module paths |
module:make Billing creates:
modules/Billing/
├── Console/Commands/
├── Http/
│ ├── Controllers/
│ ├── Requests/
│ └── routes.php
├── Listeners/
└── Models/
Module Caching
Module paths are cached to bootstrap/cache/modules.php and integrated into Laravel's optimize / optimize:clear
lifecycle:
php artisan optimize # Includes module:cache php artisan optimize:clear # Includes module:clear
Installation
composer require sinemacula/laravel-modules
1. Edit bootstrap/app.php
Replace the default Laravel application with the modular variant:
<?php use Illuminate\Foundation\Configuration\Exceptions; use Illuminate\Foundation\Configuration\Middleware; use SineMacula\Laravel\Modules\Application; use SineMacula\Laravel\Modules\Configuration\Modules; Modules::setBasePath(dirname(__DIR__)); return Application::configure(basePath: dirname(__DIR__)) ->withRouting( api : Modules::routePaths(), health : '/health', apiPrefix: '', ) ->withMiddleware(function (Middleware $middleware): void {}) ->withExceptions(function (Exceptions $exceptions): void {}) ->create();
2. Update your autoload mapping
In your application's composer.json, point the PSR-4 autoload at the modules/ directory:
{
"autoload": {
"psr-4": {
"App\\": "modules/"
}
}
}
Then run composer dump-autoload.
3. Create the modules/ directory
Create a modules/ directory at your project root and add your first module:
mkdir -p modules/Foundation/Providers
4. Wire up routing
Each module defines its own routes in Http/routes.php. Modules::routePaths() discovers them for you; you wire the
result into withRouting() in bootstrap/app.php (as shown above). Routing stays explicit, exactly like standard
Laravel - the package just saves you from listing each module's route file by hand.
Requirements
- PHP ^8.3
- Laravel ^12.0 || ^13.0
Testing
composer test # PHPUnit suite in parallel via Paratest composer test:coverage # suite with Clover coverage output composer test:mutation # Infection mutation gate (min MSI 90) composer test:mutation:full # full mutation suite without thresholds composer check # static analysis and lint via qlty composer format # format via qlty composer smells # duplication / complexity smells via qlty composer bench # PHPBench suite for the hot paths composer bench:ci # PHPBench with CI artifact dump composer bench:smoke # single-rev pass to verify every subject runs
Changelog
See CHANGELOG.md for a list of notable changes.
Contributing
Contributions are welcome. Please read CONTRIBUTING.md for guidelines on branching, commits, code quality, and pull requests.
Security
If you discover a security vulnerability, please report it responsibly. See SECURITY.md for the disclosure policy and contact details.
License
Licensed under the Apache License, Version 2.0.
sinemacula/laravel-modules 适用场景与选型建议
sinemacula/laravel-modules 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「modules」 「laravel」 「modular」 「architecture」 「sine macula」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sinemacula/laravel-modules 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sinemacula/laravel-modules 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sinemacula/laravel-modules 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This is Paymorrow module for OXID eShop.
Silverstripe content blocks module
Analysis module for finding problematical shop data.
yii2 swiper slider
An interactive tour through the TYPO3 backend.
Enterprise-Grade Modular Architecture for Laravel Applications - A powerful Laravel package that revolutionizes application development with robust Service Repository Pattern, Dynamic Module Management, and 50+ Artisan commands for scalable, maintainable applications.
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 42
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-04-04