关于 fusecore
fusecore 是面向 Laravel 13 与 React 19 项目的模块化单体架构技能,介绍模块自动发现、隔离与实现规范。适用于在 FuseCore 项目中创建模块或开发功能的团队。
主要功能
- 01通过 module.json 自动发现模块
- 02按模块隔离模型、迁移和路由
- 03提供模块契约与 HasModule 指南
- 04涵盖 React 集成与多语言支持
- 05提供模块实现代码模板
- 06说明跨模块依赖声明
适用场景
- 01在 FuseCore 项目中创建新模块
- 02配置模块服务提供者与路由
- 03组织模块专属迁移和 React 资源
- 04通过契约声明模块间依赖
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ fusengine/ agents --skill fusecore安装后在 Claude Code 中输入/fusecore确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/architecture.mdcontracts.mdcreating-module.mdi18n.mdmigrations.mdmodule-discovery.mdmodule-json.mdmodule-structure.mdreact-integration.mdroutes.mdservice-provider.mdtraits.mdreferences/templates/ApiRoutes.php.mdController.php.mdMigration.php.mdModel.php.mdmodule.json.mdReactStructure.mdRequest.php.mdResource.php.mdService.php.mdServiceProvider.php.md详细介绍
FuseCore 是一种面向 Laravel 13、集成 React 19 的模块化单体架构,基于自动发现(module.json)、SOLID 原则和按模块隔离(模型、迁移、路由、React 资源、i18n)。
涵盖如何创建新模块、了解 FuseCore 目录结构和模块发现机制,以及如何在 FuseCore 项目中实现功能——包括模块契约、特征(HasModule)、服务提供者和跨模块依赖声明。
FuseCore 模块化架构
Agent 工作流(必需)
在 FuseCore 项目中进行任何实现之前,必须先并行启动 3 个 Agent,每个 Agent 调用一次,并指定一个 name:
- fuse-ai-pilot:explore-codebase - 分析
/FuseCore/中的现有模块 - fuse-ai-pilot:research-expert - 通过 Context7 验证 Laravel 13 模式
- fuse-laravel:laravel-expert - 应用 Laravel 最佳实践
实现完成后,运行 fuse-ai-pilot:sniper 进行验证。
概览
FuseCore 是一种面向 Laravel 13、集成 React 19 的模块化单体架构。
| 组件 | 用途 |
|---|---|
| 模块 | 独立的功能(User、Dashboard、Blog) |
| 自动发现 | 通过 module.json 自动注册 |
| 特征 | 用于加载资源的 HasModule |
| 契约 | ModuleInterface、ReactModuleInterface |
| React 集成 | 每个模块隔离的 React |
| i18n | 多语言支持(FR/EN/DE/IT/ES) |
关键规则
- 所有代码都放在
/FuseCore/{Module}/中——绝不放在/app/中 - 每个模块一个 module.json——发现模块所必需
- 每个模块一个 ServiceProvider——使用
HasModule特征 - 文件少于 100 行——在 90 行处分拆(SOLID)
- 接口放在
/App/Contracts/中——绝不放在组件中 - 迁移放在模块中——
/Database/Migrations/ - 路由放在模块中——
/Routes/api.php
架构概览
FuseCore/
├── Core/ # Infrastructure (priority 0)
│ ├── App/
│ │ ├── Contracts/ # ModuleInterface, ReactModuleInterface
│ │ ├── Services/ # ModuleDiscovery, RouteAggregator
│ │ ├── Traits/ # HasModule, HasModuleDatabase
│ │ └── Providers/ # FuseCoreServiceProvider
│ ├── Config/fusecore.php
│ └── module.json
│
├── User/ # Auth module
│ ├── App/Models/ # User.php, Profile.php
│ ├── Config/ # Module config (sanctum.php, etc.)
│ ├── Database/Migrations/
│ ├── Resources/React/ # Isolated React
│ ├── Routes/api.php
│ └── module.json # dependencies: []
│
└── {YourModule}/ # Your new module
├── App/
│ ├── Models/
│ ├── Http/Controllers/
│ ├── Services/
│ └── Providers/{YourModule}ServiceProvider.php
├── Config/ # Module-specific config
├── Database/Migrations/
├── Resources/React/
├── Routes/api.php
└── module.json # dependencies: ["User"]
参考指南
架构
| 主题 | 参考资料 | 何时查阅 |
|---|---|---|
| 概览 | architecture.md | 了解 FuseCore 设计 |
| 模块结构 | module-structure.md | 目录组织 |
| 自动发现 | module-discovery.md | 模块的加载方式 |
| module.json | module-json.md | 模块配置 |
实现
| 主题 | 参考资料 | 何时查阅 |
|---|---|---|
| 契约 | contracts.md | ModuleInterface、ReactModuleInterface |
| 特征 | traits.md | HasModule、HasModuleDatabase |
| ServiceProvider | service-provider.md | 模块注册 |
| 路由 | routes.md | API 路由 |
资源
| 主题 | 参考资料 | 何时查阅 |
|---|---|---|
| React 集成 | react-integration.md | 每个模块的前端 |
| 迁移 | migrations.md | 每个模块的数据库 |
| i18n | i18n.md | 多语言设置 |
指南
| 主题 | 参考资料 | 何时查阅 |
|---|---|---|
| 创建模块 | creating-module.md | 分步指南 |
模板(代码示例)
| 模板 | 用途 |
|---|---|
| module.json.md | 模块配置 |
| ServiceProvider.php.md | 模块服务提供者 |
| Controller.php.md | API 控制器 |
| Model.php.md | Eloquent 模型 |
| Migration.php.md | 数据库迁移 |
| ReactStructure.md | React 模块结构 |
| ApiRoutes.php.md | API 路由文件 |
| Resource.php.md | API 资源 |
| Request.php.md | 表单请求 |
| Service.php.md | 业务逻辑服务 |
快速参考
创建新模块
# 1. Create directory structure
mkdir -p FuseCore/{ModuleName}/{App/{Models,Http/Controllers,Services,Providers},Database/Migrations,Resources/React,Routes}
# 2. Create module.json
# 3. Create ServiceProvider with HasModule trait
# 4. Create routes/api.php
# 5. Run: php artisan fusecore:cache-clear
module.json
{
"name": "ModuleName",
"version": "1.0.0",
"enabled": true,
"isCore": false,
"dependencies": ["User"]
}
ServiceProvider
class ModuleNameServiceProvider extends ServiceProvider
{
use HasModule;
public function boot(): void
{
$this->loadModuleMigrations();
}
}
路由
Route::middleware(['api', 'auth:sanctum'])->group(function () {
Route::apiResource('items', ItemController::class);
});
模块检查清单
- 已创建
/FuseCore/{Module}/目录 -
module.json包含名称、版本和依赖项 -
{Module}ServiceProvider.php使用HasModuletrait -
/Routes/api.php中包含路由 -
/Database/Migrations/中包含迁移 -
/App/Models/中包含模型 -
/App/Http/Controllers/中包含控制器 -
/Resources/React/中包含 React(如有需要) -
/Resources/React/i18n/locales/中包含 i18n
SOLID 合规性
| 规则 | FuseCore 实现 |
|---|---|
| 单一职责 | 一个模块 = 一个功能 |
| 开闭原则 | 通过 ModuleInterface 扩展 |
| 里氏替换 | ReactModuleInterface extends ModuleInterface |
| 接口隔离 | 分离契约 |
| 依赖倒置 | 通过 ServiceProvider 注入 |
文件行数限制:所有文件 < 100 行。达到 90 行时拆分。
命名约定
| 类型 | 约定 | 示例 |
|---|---|---|
| 模块文件夹 | PascalCase | BlogPost |
| module.json 名称 | PascalCase | "name": "BlogPost" |
| ServiceProvider | {Module}ServiceProvider | BlogPostServiceProvider |
| 控制器 | {Resource}Controller | PostController |
| 模型 | 单数形式 | Post |
| 迁移 | create_{table}_table | create_posts_table |
| 路由文件 | api.php | 始终为 api.php |
Laravel 13 注意事项
FuseCore L13 技术栈
- Laravel 13(稳定版 13.33)+ 最低要求 PHP 8.3
- React 19 + TypeScript 7(模块前端)—— TS 7.0 没有编译器 API:typescript-eslint(peer
typescript <6.1.0)需要别名"typescript": "npm:@typescript/typescript6@^6.0.2"+"@typescript/native": "npm:typescript@^7.0.2"(npx tsc= 7.0) - Inertia 3(
inertiajs/inertia-laravel^3.0),用于 React ↔ 模块桥接
模块 ServiceProvider 与 L13
在 register() 中绑定,在 boot() 中注册观察者/钩子。L13 提醒:在模型自身启动期间实例化模型(在模型的 boot() 或 trait 的 boot*() 中使用 new static())会抛出 LogicException。
public function register(): void
{
$this->app->bind(PostRepositoryContract::class, EloquentPostRepository::class);
}
public function boot(): void
{
Post::observe(PostObserver::class);
}
各模块的缓存前缀
L13 默认使用连字符。对于 FuseCore,通过 module.json 按模块配置前缀仍然兼容:
{
"name": "BlogPost",
"cache_prefix": "blogpost-"
}
最佳实践
应做
- 一个模块 = 一个完整的
FuseCore/<Module>/文件夹(Contracts/、Services/、Http/、Models/) - 通过 Contracts 声明所有模块间依赖(绝不使用具体类)
- 模块 DTO 使用
final readonly class(PHP 8.3+) - 将所有 Model 逻辑从
register()移至boot() - 对于带 UI 的模块,优先使用 Inertia 3 + React 19
不应做
- 未通过其 Contract 就导入其他模块的类
- 将业务逻辑放在控制器中(应将其提取到模块 Service 中)
- 在模型自身启动期间实例化模型(在
boot()中使用new static()→ L13 中会触发 LogicException) - 每个文件超过 100 行(拆分为子模块或 Services)
- 在模块间共享迁移(每个模块管理自己的表)
评论
支持 Markdown