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

2.2 KiB

Inventory Service Architecture

Architecture documentation for Inventory Service.

Architecture Overview

graph TB
    subgraph "API Layer"
        C[Controllers]
        CMD[Commands]
        Q[Queries]
    end
    
    subgraph "Domain Layer"
        II[InventoryItem Aggregate]
        IT[InventoryTransaction]
        R[Recipe]
    end
    
    subgraph "Infrastructure Layer"
        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

Transaction Types

Type Description Example
IN Stock received Purchase Order
OUT Stock sold/used Order fulfillment
ADJUSTMENT Manual correction Stocktake
RESERVE Held for order Order validation
RELEASE Released reservation Order cancelled

Recipe Deduction Flow (F&B)

sequenceDiagram
    participant Order as Order Service
    participant Inv as Inventory Service
    participant DB as Database
    
    Order->>Inv: DeductByRecipe(productId, qty)
    Inv->>DB: Get Recipe for Product
    DB-->>Inv: Ingredients List
    
    loop Each Ingredient
        Inv->>DB: Deduct Ingredient Stock
    end
    
    Inv-->>Order: Success

References