docs/00-overview.md

This commit is contained in:
Yangxt
2026-09-29 13:08:21 +08:00
parent c30f7e2e7b
commit cb9b7a4bd4
20 changed files with 1383 additions and 0 deletions
+109
View File
@@ -0,0 +1,109 @@
# 06 Laravel 后端结构
## 分层
不要把所有业务代码写进 Controller。推荐:
```
Controller
↓
FormRequest
↓
Service / Action
↓
Domain Logic
↓
Model / Repository
↓
Database
```
Controller 只负责:
- 接收请求
- 参数验证(通过 FormRequest)
- 调用业务服务
- 返回 API Resource
复杂业务必须进入 Service / Action。
## Action 命名示例
- CreateInboundAction
- ReceiveInboundAction
- PutawayInboundAction
- AllocateOutboundAction
- CreateWaveAction
- PickOrderAction
- PackOrderAction
- ShipOrderAction
- AdjustInventoryAction
- StocktakeAction
## 目录结构
```
app/
├── Domain/ # WMS 核心业务规则(状态机、领域规则、值对象、枚举)
│ ├── Inventory/
│ ├── Order/
│ ├── Inbound/
│ ├── Outbound/
│ ├── Warehouse/
│ ├── Picking/
│ ├── Packing/
│ ├── Shipment/
│ ├── Return/
│ └── Logistics/
│
├── Application/ # 应用层用例
│ ├── Inventory/
│ │ ├── Actions/
│ │ ├── Services/
│ │ └── DTOs/
│ ├── Order/
│ ├── Inbound/
│ └── Outbound/
│
├── Http/
│ ├── Controllers/
│ ├── Requests/
│ └── Resources/
│
├── Models/ # Eloquent 模型(数据持久化)
│
├── Jobs/
├── Events/
├── Listeners/
├── Policies/
├── Console/
├── Support/ # 通用支持:TenantContext、ApiResponse 等
│
└── Infrastructure/ # 外部适配
├── Cache/
├── Queue/
├── Logistics/
└── Platforms/
├── Amazon/
├── TikTokShop/
├── Temu/
├── Shopee/
└── Mirakl/
```
## 职责划分
| 层 | 职责 |
| --- | --- |
| Laravel(Http / Application) | 应用层:请求、用例编排、事务边界 |
| Domain | WMS 核心业务规则 |
| Eloquent(Models) | 数据持久化 |
| Queue(Jobs) | 异步任务 |
| Adapter(Infrastructure) | 第三方平台、物流商 |
| TenantContext | 多租户隔离 |
## 依赖方向
- Http → Application → Domain;Infrastructure 实现 Domain / Application 定义的接口。
- Domain 不依赖 Http、不依赖具体第三方平台。
- 模块之间避免强耦合,跨模块协作优先通过 Application Service 或 Events。