Skip to content

Module Overview — Ecommerce Inventory Operations

1. Scope

Flow này không nằm gọn trong một route, một bảng hay một service. Nó cắt qua:

  • frontend ecommerce routes cho product, inventory, import/export, check, transfer, shipping, internal order,
  • backend ecommerce-api action/event/scheduler,
  • Hasura metadata của domain ecommerce,
  • nhiều lớp data model: product master, warehouse, request, document, shipping, ledger, snapshot, materialized views.

Mental model cần giữ từ đầu:

  • inventory_request = request/intent layer,
  • inventory_document = execution layer,
  • shipping_note = physical ship/receive layer,
  • product_supplying = movement ledger,
  • product_lot_no_stockproduct_sku_stock = derived read models.

2. Bức tranh kiến trúc

text
Product / Warehouse master
  -> Inventory request (check / transfer intent)
  -> Inventory document (import / export execution)
  -> Shipping note (physical delivery / receiving)
  -> product_supplying (ledger)
  -> product_lot_no_stock / product_sku_stock (operational snapshots)
  -> materialized views (dashboard / reporting)

Transfer flow
  inventory_request_transfer
    -> order_transfer
    -> export inventory_document
    -> shipping_note
    -> import inventory_document
    -> order_transfer_completed

3. Frontend Surface

3.1 Route families

FamilyRoute groupBoundary
Product master/e/product*Product, group, supplier, product form
Inventory read/e/inventory*Lot stock, in-stock snapshot, history
Import / Export/e/import-list*, /e/export-request*, /e/inventory-importinventory_document execution
Check / Transfer request/e/check-list*, /e/transfer-list*inventory_request intent
Transfer goods/e/transfer-goods*shipping_note / physical shipping
Internal / transfer order/e/internal-list*, transfer-order*order_kind = material/transfer host layer

3.2 Permission map thực tế

BoundaryGate nổi bật
Product / inventoryproduct_list
Check requestinventory_check_sheet
Transfer requesttransfer_request
Internal orderinternal_order
Transfer goodsroot route dùng transfer_goods, nhưng create/detail/submenu lại còn lệch về transfer_request
Import / exportimport_request_sheet / export_request_sheet, nhưng ROUTE_INVENTORY_IMPORT đang gắn nhầm về export

4. Data Layer Map

LayerObject chínhVai trò
Product / branch / warehouseproduct, branch_product, warehouseMaster data và khả năng bán/tồn theo kho/chi nhánh
Requestinventory_requestÝ định check hoặc transfer
Documentinventory_documentPhiếu thực thi import/export
Shippingshipping_note, shipping_note_products, shipping_note_product_lotChuyển hàng thực nhận
Ledgerproduct_supplyingMovement import/export/hold/release/dispose
Operational snapshotproduct_lot_no_stock, product_sku_stockTồn hiện tại để FE đọc
Reporting snapshotproduct_sku_stock_mv, product_sku_stock_product_mv, product_supplying_hold_mvDashboard/reporting

5. Backend Boundary Map

LớpFile chínhVai trò
Actionchange_inventory_document_status.goAction hẹp để set released/canceled
Eventinventory_request_insert.goNotification khi tạo request
Eventinventory_request_update_status.goCheck balanced, transfer complete/cancel
Eventinventory_document_update_status.goRelease/cancel side effects, transfer import auto-create
Eventshipping_note_insert_update.goMovement ship/receive/cancel
Schedulerproduct_sku_stock.goRefresh materialized views cho dashboard/report

6. Semantic Rules Cần Nhớ

  1. inventory_request chưa phải execution ledger; nhiều side effect thật chỉ chạy ở update-status event.
  2. Import và export FE đang dùng cùng inventory_document engine; import list thậm chí còn reuse query của export.
  3. transfer request không phải điểm cuối; sau đó flow còn đi qua order_transfer, inventory_document, rồi shipping_note.
  4. shipping_note không đồng nghĩa với inventory_document; nó là boundary riêng cho ship/receive vật lý.
  5. product_sku_stock không realtime tuyệt đối cho mọi use case reporting vì còn phụ thuộc materialized-view refresh ở vài nhánh.

7. Rủi ro / Findings

IDMứcFinding
F-01P1FE đang có drift thật về moduleId giữa transfer_goods, transfer_request, import_request_sheet, export_request_sheet.
F-02P1product_supplying ôm quá nhiều semantics nên rất dễ bị hiểu sai là snapshot.
F-03P1inventory_request, inventory_document, shipping_note là ba lớp khác nhau nhưng tên route/menu không luôn phản ánh boundary này.
F-04P1Backend action cho inventory document quá hẹp; nhiều invariant và side effect bị dồn sang FE hoặc event.
F-05P1shipping_note branch RECEIVED có dấu hiệu bug khi note có nhiều SKU/lot nhưng code dùng dữ liệu từ phần tử đầu tiên của product_supplying.
F-06P2Permission Hasura của inventory/shipping/ledger khá rộng, nên correctness hiện phụ thuộc nhiều vào FE và event logic.