Files
pos-system/services/inventory-service-net/docs/vi/ARCHITECTURE.md

2.3 KiB

Kiến Trúc Inventory Service

Tài liệu kiến trúc cho Inventory Service.

Tổng Quan Kiến Trúc

graph TB
    subgraph "Tầng API"
        C[Controllers]
        CMD[Commands]
        Q[Queries]
    end
    
    subgraph "Tầng Domain"
        II[InventoryItem Aggregate]
        IT[InventoryTransaction]
        R[Recipe]
    end
    
    subgraph "Tầng Infrastructure"
        DB[(PostgreSQL)]
        REPO[InventoryRepository]
        CTX[InventoryContext]
    end
    
    C --> CMD --> II
    C --> Q --> REPO --> CTX --> DB
    
    style II fill:#50c878,stroke:#2d8659,color:#fff
    style DB fill:#ff6b6b,stroke:#c0392b,color:#fff

Database Schema

erDiagram
    inventory_items {
        uuid id PK
        uuid product_id FK
        uuid shop_id FK
        int quantity
        int reserved_quantity
        int reorder_level
        timestamp updated_at
    }
    
    inventory_transactions {
        uuid id PK
        uuid inventory_item_id FK
        varchar transaction_type
        int quantity
        uuid reference_id
        varchar notes
        timestamp created_at
    }
    
    recipes {
        uuid id PK
        uuid product_id FK
        uuid ingredient_id FK
        decimal quantity_required
        varchar unit
    }
    
    inventory_items ||--o{ inventory_transactions : has
    recipes }o--|| inventory_items : uses

Loại Giao Dịch

Loại Mô tả Ví dụ
IN Nhập kho Đơn mua hàng
OUT Bán/sử dụng Thực hiện đơn hàng
ADJUSTMENT Điều chỉnh thủ công Kiểm kê
RESERVE Giữ cho đơn hàng Validate đơn hàng
RELEASE Giải phóng giữ hàng Hủy đơn hàng

Luồng Trừ Kho Theo Công Thức (F&B)

sequenceDiagram
    participant Order as Order Service
    participant Inv as Inventory Service
    participant DB as Database
    
    Order->>Inv: DeductByRecipe(productId, qty)
    Inv->>DB: Lấy Công Thức Sản Phẩm
    DB-->>Inv: Danh Sách Nguyên Liệu
    
    loop Mỗi Nguyên Liệu
        Inv->>DB: Trừ Tồn Kho Nguyên Liệu
    end
    
    Inv-->>Order: Thành Công

Tài Nguyên