# Item

## Description

Item is the fundamental SKU-level entity in the ERP system — the sellable, purchasable, and trackable unit referenced by all downstream modules (Sales, Purchasing, Inventory, Manufacturing). Each item has a lifecycle state machine (DRAFT → ACTIVE ↔ INACTIVE), a globally unique SKU identifier, an optional barcode, and an assigned unit of measure.

Items can be created in either DRAFT or ACTIVE status. DRAFT items require explicit activation before participating in transactions.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> Draft: createItem (draft)
    [*] --> Active: createItem (active)
    Draft --> Active: activateItem
    Active --> Inactive: deactivateItem
    Inactive --> Active: reactivateItem
    Draft --> [*]: deleteItem
```

| Operation | From | To | Command |
|-----------|------|----|---------|
| activate | DRAFT | ACTIVE | [activateItem](../command/ActivateItem.md) |
| deactivate | ACTIVE | INACTIVE | [deactivateItem](../command/DeactivateItem.md) |
| reactivate | INACTIVE | ACTIVE | [reactivateItem](../command/ReactivateItem.md) |

### Command Definitions

- [createItem](../command/CreateItem.md) - Create a new item in DRAFT or ACTIVE status
- [updateItem](../command/UpdateItem.md) - Update mutable fields (name, barcode, UoM) of an existing item
- [activateItem](../command/ActivateItem.md) - Transition item from DRAFT to ACTIVE
- [deactivateItem](../command/DeactivateItem.md) - Transition item from ACTIVE to INACTIVE
- [reactivateItem](../command/ReactivateItem.md) - Transition item from INACTIVE to ACTIVE
- [deleteItem](../command/DeleteItem.md) - Permanently delete a DRAFT item

### Query Definitions

- [GetItem](../query/GetItem.md) - Retrieve an item by id, sku, or barcode

### Models

- Item

### Invariants

- SKU is required and must be globally unique across all items regardless of status
- SKU is immutable after assignment (cannot be changed once set)
- Barcode must be unique across all items when provided
- Barcode can be updated after creation
- Only DRAFT items can be deleted; ACTIVE and INACTIVE items are preserved for audit trails
- Only ACTIVE items can be referenced in new transactions (sales orders, purchase orders)
- Name is required at creation time
- UoM can be updated only in DRAFT status — once activated, UoM is locked to preserve transaction consistency

### Relationships

- **References Unit**: Each item references a Unit from the primitives module as its unit of measure
- **Referenced By Taxonomy Assignments**: Items are linked to TaxonomyNodes via ItemTaxonomyAssignment (many-to-many)
- **Referenced By Downstream Modules**: Items are referenced by Sales, Purchasing, Inventory, and Manufacturing modules
