mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-05 23:26:38 +08:00
refactor(layout): consolidate backend codebase into backend/ package and clean root directory
- Moved cmd/, core/, plugins/, pkg/, downstream/, and main.go into backend/ directory - Batch updated all Go source files to import github.com/Rain-kl/Wavelet/backend/... - Updated Makefile, scripts/swagger.sh, architecture guards, and platform skills - Passed all quality gates (100% tests, 0 lint issues, clean build)
This commit is contained in:
@@ -15,7 +15,7 @@ description: "Wavelet 项目专用:当新增或修改数据库表结构、索
|
||||
每个插件在自身包内维护专属的 `migrations/` 目录,通过 Go 语言内置 `//go:embed` 打包为嵌入式文件系统,并在 `Apply(ctx *core.Context)` 时通过微内核扩展点 `ctx.Migrations().Register(...)` 自主注入。
|
||||
|
||||
```
|
||||
plugins/domain/order/
|
||||
backend/plugins/domain/order/
|
||||
├── plugin.go
|
||||
├── models.go
|
||||
└── migrations/
|
||||
@@ -33,7 +33,7 @@ package order
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"github.com/Rain-kl/Wavelet/core"
|
||||
"github.com/Rain-kl/Wavelet/backend/core"
|
||||
)
|
||||
|
||||
//go:embed migrations/*.sql
|
||||
@@ -183,6 +183,6 @@ go test ./plugins/...
|
||||
|
||||
```bash
|
||||
# 检查每个有 migrations/ 目录的插件是否同时有 go:embed + Register()
|
||||
grep -rn 'go:embed.*migrations' plugins/domain/*/plugin.go plugins/drivers/*/plugin.go
|
||||
grep -rn 'Migrations()\.Register' plugins/domain/*/plugin.go plugins/drivers/*/plugin.go
|
||||
grep -rn 'go:embed.*migrations' backend/plugins/domain/*/plugin.go backend/plugins/drivers/*/plugin.go
|
||||
grep -rn 'Migrations()\.Register' backend/plugins/domain/*/plugin.go backend/plugins/drivers/*/plugin.go
|
||||
```
|
||||
@@ -84,7 +84,7 @@ import (
|
||||
"bytes"
|
||||
|
||||
"github.com/Rain-kl/Wavelet/internal/apps/upload"
|
||||
"github.com/Rain-kl/Wavelet/pkg/model"
|
||||
"github.com/Rain-kl/Wavelet/backend/pkg/model"
|
||||
)
|
||||
|
||||
func ingestMirrorFile(ctx context.Context, userID uint64, data []byte, hash, filename, mime, ext string) (model.Upload, error) {
|
||||
|
||||
@@ -14,10 +14,10 @@ description: "Wavelet 项目专用:当新增或修改业务 API、Handler、
|
||||
在 Cordis 架构中,**业务 API 不再集中在旧的 `internal/router/` 或 `internal/apps/` 目录**。
|
||||
所有业务能力均封装为**高内聚、扁平自包含的插件 (Plugin)**。每个插件自主管理自身的路由声明、中间件挂载、服务逻辑、数据模型与迁移脚本。
|
||||
|
||||
### 插件目录推荐结构 (`plugins/domain/<name>/` 或下游 `custom_plugins/<name>/`)
|
||||
### 插件目录推荐结构 (`backend/plugins/domain/<name>/` 或下游 `custom_plugins/<name>/`)
|
||||
|
||||
```text
|
||||
plugins/domain/order/
|
||||
backend/plugins/domain/order/
|
||||
├── plugin.go # 插件入口:实现 core.Plugin,通过 ctx.Router() 挂载路由
|
||||
├── handlers.go # HTTP 控制器:参数校验、上下文提取、调用 Service、信封响应
|
||||
├── service.go # 业务服务层:纯 Go 逻辑,仅依赖 context.Context
|
||||
@@ -39,8 +39,8 @@ plugins/domain/order/
|
||||
package order
|
||||
|
||||
import (
|
||||
"github.com/Rain-kl/Wavelet/core"
|
||||
"github.com/Rain-kl/Wavelet/core/contracts"
|
||||
"github.com/Rain-kl/Wavelet/backend/core"
|
||||
"github.com/Rain-kl/Wavelet/backend/core/contracts"
|
||||
)
|
||||
|
||||
type Plugin struct {
|
||||
|
||||
@@ -26,7 +26,7 @@ description: "Wavelet 项目专用:新增或修改基于 Cordis 插件的 Asyn
|
||||
|
||||
### 步骤 1:定义任务 Payload 结构与类型常量
|
||||
|
||||
在插件内(如 `plugins/domain/order/tasks.go`):
|
||||
在插件内(如 `backend/plugins/domain/order/tasks.go`):
|
||||
|
||||
```go
|
||||
package order
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
## 1. 任务定义与 Handler 编写
|
||||
|
||||
在对应的业务插件中(如 `plugins/domain/user/tasks.go`):
|
||||
在对应的业务插件中(如 `backend/plugins/domain/user/tasks.go`):
|
||||
|
||||
```go
|
||||
package user
|
||||
@@ -61,8 +61,8 @@ package user
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/Rain-kl/Wavelet/core"
|
||||
"github.com/Rain-kl/Wavelet/core/extpoints"
|
||||
"github.com/Rain-kl/Wavelet/backend/core"
|
||||
"github.com/Rain-kl/Wavelet/backend/core/extpoints"
|
||||
)
|
||||
|
||||
func (p *Plugin) Apply(ctx *core.Context) error {
|
||||
|
||||
@@ -15,7 +15,7 @@ Wavelet 的消息推送机制采用了**元数据驱动 + 统一触发器 + 异
|
||||
|
||||
| 目录/包名 | 职责定位 | 包含内容与设计细节 |
|
||||
| :--- | :--- | :--- |
|
||||
| **`plugins/domain/message_gateway/push/`** | 推送基础设施层 | 静态定义、不依赖系统数据库和任何框架。定义了统一接口 `Pusher` 和多实现(Lark, Webhook, Email 等),提供配置验证及发送功能。 |
|
||||
| **`backend/plugins/domain/message_gateway/push/`** | 推送基础设施层 | 静态定义、不依赖系统数据库和任何框架。定义了统一接口 `Pusher` 和多实现(Lark, Webhook, Email 等),提供配置验证及发送功能。 |
|
||||
| **`internal/apps/admin/push/`** | 通知服务与后台任务层 | 包含以下核心文件:<br>1. `events.go`:定义通知事件的结构模型(`NotificationMessage`, `EventMetadata`)、内置事件的动态注册中心(`BuiltInEvents` 及 `RegisterBuiltInEvent` 函数)以及统一触发器类 `EventTrigger`(包括其底层的派发引擎逻辑)。<br>2. `tasks.go`:定义 Asynq 后台异步发送任务、处理器 `PushHandler` 及其校验逻辑,并记录推送历史审计。<br>3. `routers.go`:管理端接口,负责获取事件配置列表和更新配置。 |
|
||||
| **`internal/apps/admin/push/custom_events/`** | 自定义通知事件包 | 事件元数据定义与 push 侧处理逻辑;**一个 Go 文件代表一个事件**。在 `register.go` 统一装配,禁止 `init()` 副作用。 |
|
||||
| **`internal/listener/`** | 域事件分发层 | 核心域发射事件(如 `EmitAdminLoggedIn`),push 在 bootstrap 阶段通过 `OnAdminLoggedIn` 订阅,避免 auth/user 直接依赖 push。 |
|
||||
@@ -39,7 +39,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/Rain-kl/Wavelet/internal/apps/admin/push"
|
||||
"github.com/Rain-kl/Wavelet/pkg/listener"
|
||||
"github.com/Rain-kl/Wavelet/backend/pkg/listener"
|
||||
)
|
||||
|
||||
var NewUserRegistered = push.EventMetadata{
|
||||
@@ -84,7 +84,7 @@ func Register() {
|
||||
在业务逻辑完成处(如 `internal/apps/user/routers.go`)仅 import `internal/listener` 并发射事件:
|
||||
|
||||
```go
|
||||
import "github.com/Rain-kl/Wavelet/pkg/listener"
|
||||
import "github.com/Rain-kl/Wavelet/backend/pkg/listener"
|
||||
|
||||
func Register(c *gin.Context) {
|
||||
// ... 注册成功逻辑 ...
|
||||
|
||||
Reference in New Issue
Block a user