{
  "x-spec-version": "0.2.0",
  "x-run-id": "1778059627159-pdf",
  "x-source-of-truth": {
    "entities": "entities.json",
    "workflows": "workflows.json",
    "stories": "stories.json",
    "nfrs": "nfrs.json",
    "glossary": "glossary.json",
    "open_questions": "open_questions.json"
  },
  "schemaTargets": [
    {
      "id": "ENT-001",
      "name": "AdvancedShipmentNotice",
      "table": "advanced_shipment_notice",
      "primary_key": "id",
      "fields": [
        {
          "name": "id",
          "type": "uuid",
          "required": true,
          "unique": true,
          "primary_key": true
        },
        {
          "name": "asnId",
          "type": "string",
          "required": true,
          "unique": true,
          "primary_key": false
        },
        {
          "name": "supplierId",
          "type": "uuid",
          "required": true,
          "unique": false,
          "primary_key": false
        },
        {
          "name": "status",
          "type": "enum",
          "required": true,
          "unique": false,
          "primary_key": false
        },
        {
          "name": "createdAt",
          "type": "timestamptz",
          "required": true,
          "unique": false,
          "primary_key": false
        },
        {
          "name": "updatedAt",
          "type": "timestamptz",
          "required": true,
          "unique": false,
          "primary_key": false
        }
      ],
      "relationships": [
        {
          "type": "many-to-one",
          "target": "Supplier",
          "target_id": "ENT-005",
          "foreign_key": "supplierId",
          "cascade": "restrict"
        }
      ],
      "indexes_hint": [
        "unique(id)",
        "unique(asnId)",
        "index(asnId)",
        "index(supplierId)"
      ],
      "json_schema_ref": "#/$defs/AdvancedShipmentNotice"
    },
    {
      "id": "ENT-002",
      "name": "AsnLineItem",
      "table": "asn_line_item",
      "primary_key": "id",
      "fields": [
        {
          "name": "id",
          "type": "uuid",
          "required": true,
          "unique": true,
          "primary_key": true
        },
        {
          "name": "poNumber",
          "type": "string",
          "required": true,
          "unique": false,
          "primary_key": false
        },
        {
          "name": "upcNumber",
          "type": "string",
          "required": true,
          "unique": false,
          "primary_key": false
        },
        {
          "name": "sku",
          "type": "string",
          "required": true,
          "unique": false,
          "primary_key": false
        },
        {
          "name": "quantity",
          "type": "integer",
          "required": true,
          "unique": false,
          "primary_key": false
        },
        {
          "name": "createdAt",
          "type": "timestamptz",
          "required": true,
          "unique": false,
          "primary_key": false
        },
        {
          "name": "updatedAt",
          "type": "timestamptz",
          "required": true,
          "unique": false,
          "primary_key": false
        }
      ],
      "relationships": [
        {
          "type": "many-to-one",
          "target": "AdvancedShipmentNotice",
          "target_id": "ENT-001",
          "foreign_key": "asnId",
          "cascade": "restrict"
        }
      ],
      "indexes_hint": [
        "unique(id)"
      ],
      "json_schema_ref": "#/$defs/AsnLineItem"
    },
    {
      "id": "ENT-003",
      "name": "DoorMaster",
      "table": "door_master",
      "primary_key": "id",
      "fields": [
        {
          "name": "id",
          "type": "uuid",
          "required": true,
          "unique": true,
          "primary_key": true
        },
        {
          "name": "doorNumber",
          "type": "string",
          "required": true,
          "unique": false,
          "primary_key": false
        }
      ],
      "relationships": [],
      "indexes_hint": [
        "unique(id)"
      ],
      "json_schema_ref": "#/$defs/DoorMaster"
    },
    {
      "id": "ENT-004",
      "name": "ReceivingConfirmationReport",
      "table": "receiving_confirmation_report",
      "primary_key": "id",
      "fields": [
        {
          "name": "id",
          "type": "uuid",
          "required": true,
          "unique": true,
          "primary_key": true
        },
        {
          "name": "rcrId",
          "type": "string",
          "required": true,
          "unique": false,
          "primary_key": false
        },
        {
          "name": "skuDetails",
          "type": "jsonb",
          "required": true,
          "unique": false,
          "primary_key": false
        },
        {
          "name": "vendorDetails",
          "type": "jsonb",
          "required": true,
          "unique": false,
          "primary_key": false
        },
        {
          "name": "createdAt",
          "type": "timestamptz",
          "required": true,
          "unique": false,
          "primary_key": false
        },
        {
          "name": "updatedAt",
          "type": "timestamptz",
          "required": true,
          "unique": false,
          "primary_key": false
        }
      ],
      "relationships": [],
      "indexes_hint": [
        "unique(id)",
        "index(rcrId)"
      ],
      "json_schema_ref": "#/$defs/ReceivingConfirmationReport"
    },
    {
      "id": "ENT-005",
      "name": "Supplier",
      "table": "supplier",
      "primary_key": "id",
      "fields": [
        {
          "name": "id",
          "type": "uuid",
          "required": true,
          "unique": true,
          "primary_key": true
        },
        {
          "name": "supplierId",
          "type": "uuid",
          "required": true,
          "unique": true,
          "primary_key": false
        },
        {
          "name": "supplierName",
          "type": "string",
          "required": true,
          "unique": false,
          "primary_key": false
        },
        {
          "name": "createdAt",
          "type": "timestamptz",
          "required": true,
          "unique": false,
          "primary_key": false
        },
        {
          "name": "updatedAt",
          "type": "timestamptz",
          "required": true,
          "unique": false,
          "primary_key": false
        }
      ],
      "relationships": [],
      "indexes_hint": [
        "unique(id)",
        "unique(supplierId)",
        "index(supplierId)"
      ],
      "json_schema_ref": "#/$defs/Supplier"
    },
    {
      "id": "ENT-006",
      "name": "StandardAsn",
      "table": "standard_asn",
      "primary_key": "id",
      "fields": [
        {
          "name": "id",
          "type": "uuid",
          "required": true,
          "unique": true,
          "primary_key": true
        },
        {
          "name": "poNumber",
          "type": "string",
          "required": true,
          "unique": false,
          "primary_key": false
        }
      ],
      "relationships": [],
      "indexes_hint": [
        "unique(id)"
      ],
      "json_schema_ref": "#/$defs/StandardAsn"
    },
    {
      "id": "ENT-007",
      "name": "LocalAsn",
      "table": "local_asn",
      "primary_key": "id",
      "fields": [
        {
          "name": "id",
          "type": "uuid",
          "required": true,
          "unique": true,
          "primary_key": true
        },
        {
          "name": "vendorNumber",
          "type": "string",
          "required": true,
          "unique": false,
          "primary_key": false
        }
      ],
      "relationships": [],
      "indexes_hint": [
        "unique(id)"
      ],
      "json_schema_ref": "#/$defs/LocalAsn"
    }
  ],
  "routeTargets": [
    {
      "id": "US-001",
      "method": "POST",
      "path": "/create-asn",
      "handler": "create_asn",
      "auth_role": "warehouse_user",
      "guards": [
        "RULE-006"
      ],
      "linked_entity_id": null,
      "linked_workflow_id": "WF-002",
      "screen": "Create ASN (Standard)",
      "trigger": "Create ASN button"
    },
    {
      "id": "US-002",
      "method": "POST",
      "path": "/create-local-asn",
      "handler": "create_local_asn",
      "auth_role": "warehouse_user",
      "guards": [
        "RULE-006"
      ],
      "linked_entity_id": null,
      "linked_workflow_id": "WF-002",
      "screen": "Create Local ASN",
      "trigger": "Create Local button"
    },
    {
      "id": "US-003",
      "method": "POST",
      "path": "/reserve-slots",
      "handler": "reserve_slots",
      "auth_role": "warehouse_user",
      "guards": [],
      "linked_entity_id": null,
      "linked_workflow_id": "WF-002",
      "screen": "Unreserved ASN List",
      "trigger": "Reserve Slots button"
    },
    {
      "id": "US-004",
      "method": "GET",
      "path": "/print-rcr",
      "handler": "print_rcr",
      "auth_role": "warehouse_user",
      "guards": [
        "RULE-005"
      ],
      "linked_entity_id": null,
      "linked_workflow_id": "WF-002",
      "screen": "Closed ASN View",
      "trigger": "Print RCR button"
    },
    {
      "id": "US-005",
      "method": "POST",
      "path": "/assign-door",
      "handler": "assign_door",
      "auth_role": "warehouse_user",
      "guards": [
        "RULE-004"
      ],
      "linked_entity_id": null,
      "linked_workflow_id": "WF-002",
      "screen": "At Door View",
      "trigger": "Assign Door button"
    },
    {
      "id": "US-006",
      "method": "POST",
      "path": "/mark-asn-completed",
      "handler": "mark_asn_completed",
      "auth_role": "warehouse_user",
      "guards": [
        "RULE-006"
      ],
      "linked_entity_id": null,
      "linked_workflow_id": "WF-002",
      "screen": "Completion Screen",
      "trigger": "Mark Completed button"
    }
  ],
  "uiTargets": [
    {
      "screen": "Create ASN (Standard)",
      "kind": "form",
      "entity": null,
      "entity_id": null,
      "role": "warehouse_user",
      "actions": [
        "create_asn"
      ]
    },
    {
      "screen": "Create Local ASN",
      "kind": "form",
      "entity": null,
      "entity_id": null,
      "role": "warehouse_user",
      "actions": [
        "create_local_asn"
      ]
    },
    {
      "screen": "Unreserved ASN List",
      "kind": "list",
      "entity": null,
      "entity_id": null,
      "role": "warehouse_user",
      "actions": [
        "reserve_slots"
      ]
    },
    {
      "screen": "Closed ASN View",
      "kind": "detail",
      "entity": null,
      "entity_id": null,
      "role": "warehouse_user",
      "actions": [
        "print_rcr"
      ]
    },
    {
      "screen": "At Door View",
      "kind": "detail",
      "entity": null,
      "entity_id": null,
      "role": "warehouse_user",
      "actions": [
        "assign_door"
      ]
    },
    {
      "screen": "Completion Screen",
      "kind": "generic",
      "entity": null,
      "entity_id": null,
      "role": "warehouse_user",
      "actions": [
        "mark_asn_completed"
      ]
    }
  ],
  "ruleTargets": [
    {
      "id": "RULE-001",
      "name": "min_one_line_item",
      "rule_type": "required",
      "ears_pattern": "ubiquitous",
      "ears_text": "The system shall ensure: An ASN must contain at least one line item before it can be submitted.",
      "applies_to": "AsnLineItem",
      "applies_to_id": "ENT-002",
      "description": "An ASN must contain at least one line item before it can be submitted."
    },
    {
      "id": "RULE-002",
      "name": "all_skus_reserved",
      "rule_type": "other",
      "ears_pattern": "ubiquitous",
      "ears_text": "The system shall ensure: All SKUs must be reserved before moving to Reserved state.",
      "applies_to": "AdvancedShipmentNotice",
      "applies_to_id": "ENT-001",
      "description": "All SKUs must be reserved before moving to Reserved state."
    },
    {
      "id": "RULE-003",
      "name": "all_skus_processed",
      "rule_type": "other",
      "ears_pattern": "ubiquitous",
      "ears_text": "The system shall ensure: All SKUs must be processed before ASN can be marked as completed.",
      "applies_to": "AdvancedShipmentNotice",
      "applies_to_id": "ENT-001",
      "description": "All SKUs must be processed before ASN can be marked as completed."
    },
    {
      "id": "RULE-004",
      "name": "door_assignment_required",
      "rule_type": "other",
      "ears_pattern": "ubiquitous",
      "ears_text": "The system shall ensure: A door must be assigned before ASN can move to 'At Door' state.",
      "applies_to": "AdvancedShipmentNotice",
      "applies_to_id": "ENT-001",
      "description": "A door must be assigned before ASN can move to 'At Door' state."
    },
    {
      "id": "RULE-005",
      "name": "rcr_print_after_closure",
      "rule_type": "other",
      "ears_pattern": "event_driven",
      "ears_text": "When the relevant event occurs, the system shall RCR can only be printed after ASN is closed.",
      "applies_to": "ReceivingConfirmationReport",
      "applies_to_id": "ENT-004",
      "description": "RCR can only be printed after ASN is closed."
    },
    {
      "id": "RULE-006",
      "name": "asn_creation_methods",
      "rule_type": "other",
      "ears_pattern": "ubiquitous",
      "ears_text": "The system shall ensure: ASN can be created in two ways: Standard ASN via Purchase Orders or Local ASN based on Vendor.",
      "applies_to": "AdvancedShipmentNotice",
      "applies_to_id": "ENT-001",
      "description": "ASN can be created in two ways: Standard ASN via Purchase Orders or Local ASN based on Vendor."
    }
  ],
  "stateMachines": [
    {
      "id": "asn_lifecycle",
      "x-id": "WF-001",
      "x-bound-entity-id": null,
      "x-bound-entity": null,
      "context": {},
      "initial": "Create",
      "states": {
        "Create": {
          "x-label": "Create",
          "on": {
            "ASN_CREATION_SUBMITTED": {
              "target": "Unreserved",
              "x-trigger": "ASN creation submitted"
            }
          }
        },
        "Unreserved": {
          "x-label": "Unreserved",
          "on": {
            "ALL_SKUS_RESERVED": {
              "target": "Reserved",
              "x-trigger": "all SKUs reserved",
              "guard": "all_skus_reserved"
            }
          }
        },
        "Reserved": {
          "x-label": "Reserved",
          "on": {
            "DOOR_ASSIGNMENT_FROM_DOOR_MASTER": {
              "target": "At_Door",
              "x-trigger": "Door assignment from Door Master"
            }
          }
        },
        "At_Door": {
          "x-label": "At Door",
          "on": {
            "MARK_COMPLETED_BUTTON_WAREHOUSE_USER": {
              "target": "Closed",
              "x-trigger": "Mark Completed button (warehouse user)",
              "guard": "all_skus_processed"
            }
          }
        },
        "Closed": {
          "x-label": "Closed",
          "on": {
            "PRINT_RCR_BUTTON": {
              "target": "RCR",
              "x-trigger": "Print RCR button"
            }
          }
        },
        "RCR": {
          "x-label": "RCR",
          "type": "final"
        }
      }
    },
    {
      "id": "advancedshipmentnotice_lifecycle",
      "x-id": "WF-002",
      "x-bound-entity-id": "ENT-001",
      "x-bound-entity": "AdvancedShipmentNotice",
      "context": {},
      "initial": "unreserved",
      "states": {
        "unreserved": {
          "x-label": "unreserved",
          "type": "final"
        },
        "reserved": {
          "x-label": "reserved",
          "type": "final"
        },
        "at_door": {
          "x-label": "at door",
          "type": "final"
        },
        "closed": {
          "x-label": "closed",
          "type": "final"
        }
      }
    }
  ],
  "nfrAttributes": [
    "functional_suitability",
    "performance_efficiency",
    "compatibility",
    "interaction_capability",
    "reliability",
    "security",
    "maintainability",
    "flexibility",
    "safety"
  ],
  "traceability": {
    "US-001": [
      "WF-002",
      "RULE-006"
    ],
    "US-002": [
      "WF-002",
      "RULE-006"
    ],
    "US-003": [
      "WF-002"
    ],
    "US-004": [
      "WF-002",
      "RULE-005"
    ],
    "US-005": [
      "WF-002",
      "RULE-004"
    ],
    "US-006": [
      "WF-002",
      "RULE-006"
    ]
  }
}