{
  "title": "Commerce · Customer, checkout & catalogue",
  "description": "A relational design for customer accounts, checkout, products and inventory. Business domains keep related tables together; keys and endpoint symbols explain how records connect.",
  "graph": {
    "kind": "erd",
    "direction": "LR",
    "nodes": [
      {
        "id": "customers",
        "fields": [
          {
            "id": "id",
            "name": "id",
            "dataType": "uuid",
            "keys": [
              "PK"
            ],
            "nullable": false,
            "description": ""
          },
          {
            "id": "email",
            "name": "email",
            "dataType": "varchar(255)",
            "keys": [
              "UK"
            ],
            "nullable": false,
            "description": ""
          },
          {
            "id": "display_name",
            "name": "display_name",
            "dataType": "varchar(120)",
            "keys": [],
            "nullable": false,
            "description": ""
          },
          {
            "id": "created_at",
            "name": "created_at",
            "dataType": "timestamp",
            "keys": [],
            "nullable": false,
            "description": ""
          }
        ],
        "type": "datastore",
        "label": "Customers",
        "description": "Customer identity. Each order belongs to one customer.",
        "group": "Accounts",
        "category": "database",
        "basis": "unknown",
        "sources": [
          {
            "repository": "Mapfable",
            "path": "",
            "revision": "",
            "note": "Authored commerce schema for explaining relationships. No production database was inspected."
          }
        ]
      },
      {
        "id": "orders",
        "fields": [
          {
            "id": "id",
            "name": "id",
            "dataType": "uuid",
            "keys": [
              "PK"
            ],
            "nullable": false,
            "description": ""
          },
          {
            "id": "customer_id",
            "name": "customer_id",
            "dataType": "uuid",
            "keys": [
              "FK"
            ],
            "nullable": false,
            "description": ""
          },
          {
            "id": "status",
            "name": "status",
            "dataType": "order_status",
            "keys": [],
            "nullable": false,
            "description": ""
          },
          {
            "id": "total_amount",
            "name": "total_amount",
            "dataType": "numeric(12,2)",
            "keys": [],
            "nullable": false,
            "description": ""
          },
          {
            "id": "currency",
            "name": "currency",
            "dataType": "char(3)",
            "keys": [],
            "nullable": false,
            "description": ""
          },
          {
            "id": "placed_at",
            "name": "placed_at",
            "dataType": "timestamp",
            "keys": [],
            "nullable": false,
            "description": ""
          }
        ],
        "type": "datastore",
        "label": "Orders",
        "description": "The purchase record. An order can have several payment attempts and contains one or more line items.",
        "group": "Checkout",
        "category": "database",
        "basis": "unknown",
        "sources": [
          {
            "repository": "Mapfable",
            "path": "",
            "revision": "",
            "note": "Authored commerce schema for explaining relationships. No production database was inspected."
          }
        ]
      },
      {
        "id": "payments",
        "fields": [
          {
            "id": "id",
            "name": "id",
            "dataType": "uuid",
            "keys": [
              "PK"
            ],
            "nullable": false,
            "description": ""
          },
          {
            "id": "order_id",
            "name": "order_id",
            "dataType": "uuid",
            "keys": [
              "FK"
            ],
            "nullable": false,
            "description": ""
          },
          {
            "id": "method",
            "name": "method",
            "dataType": "varchar(32)",
            "keys": [],
            "nullable": false,
            "description": ""
          },
          {
            "id": "amount",
            "name": "amount",
            "dataType": "numeric(12,2)",
            "keys": [],
            "nullable": false,
            "description": ""
          },
          {
            "id": "paid_at",
            "name": "paid_at",
            "dataType": "timestamp",
            "keys": [],
            "nullable": true,
            "description": ""
          },
          {
            "id": "external_ref",
            "name": "external_ref",
            "dataType": "varchar(64)",
            "keys": [
              "UK"
            ],
            "nullable": false,
            "description": ""
          }
        ],
        "type": "datastore",
        "label": "Payments",
        "description": "Separate payment attempts from orders. An order may exist before its first payment attempt.",
        "group": "Checkout",
        "category": "database",
        "basis": "unknown",
        "sources": [
          {
            "repository": "Mapfable",
            "path": "",
            "revision": "",
            "note": "Authored commerce schema for explaining relationships. No production database was inspected."
          }
        ]
      },
      {
        "id": "inventory",
        "fields": [
          {
            "id": "id",
            "name": "id",
            "dataType": "uuid",
            "keys": [
              "PK"
            ],
            "nullable": false,
            "description": ""
          },
          {
            "id": "product_id",
            "name": "product_id",
            "dataType": "uuid",
            "keys": [
              "FK"
            ],
            "nullable": false,
            "description": ""
          },
          {
            "id": "warehouse_code",
            "name": "warehouse_code",
            "dataType": "varchar(16)",
            "keys": [],
            "nullable": false,
            "description": ""
          },
          {
            "id": "quantity",
            "name": "quantity",
            "dataType": "integer",
            "keys": [],
            "nullable": false,
            "description": ""
          },
          {
            "id": "reserved_quantity",
            "name": "reserved_quantity",
            "dataType": "integer",
            "keys": [],
            "nullable": false,
            "description": ""
          },
          {
            "id": "updated_at",
            "name": "updated_at",
            "dataType": "timestamp",
            "keys": [],
            "nullable": false,
            "description": ""
          }
        ],
        "type": "datastore",
        "label": "Inventory",
        "description": "Stock records for a product at a warehouse. Quantity and reservations are stored separately.",
        "group": "Catalogue",
        "category": "database",
        "basis": "unknown",
        "sources": [
          {
            "repository": "Mapfable",
            "path": "",
            "revision": "",
            "note": "Authored commerce schema for explaining relationships. No production database was inspected."
          }
        ]
      },
      {
        "id": "products",
        "fields": [
          {
            "id": "id",
            "name": "id",
            "dataType": "uuid",
            "keys": [
              "PK"
            ],
            "nullable": false,
            "description": ""
          },
          {
            "id": "sku",
            "name": "sku",
            "dataType": "varchar(64)",
            "keys": [
              "UK"
            ],
            "nullable": false,
            "description": ""
          },
          {
            "id": "name",
            "name": "name",
            "dataType": "varchar(160)",
            "keys": [],
            "nullable": false,
            "description": ""
          },
          {
            "id": "price",
            "name": "price",
            "dataType": "numeric(12,2)",
            "keys": [],
            "nullable": false,
            "description": ""
          },
          {
            "id": "active",
            "name": "active",
            "dataType": "boolean",
            "keys": [],
            "nullable": false,
            "description": ""
          },
          {
            "id": "created_at",
            "name": "created_at",
            "dataType": "timestamp",
            "keys": [],
            "nullable": false,
            "description": ""
          }
        ],
        "type": "datastore",
        "label": "Products",
        "description": "The product catalogue. SKUs are unique. A product can appear in many line items and warehouse records.",
        "group": "Catalogue",
        "category": "database",
        "basis": "unknown",
        "sources": [
          {
            "repository": "Mapfable",
            "path": "",
            "revision": "",
            "note": "Authored commerce schema for explaining relationships. No production database was inspected."
          }
        ]
      },
      {
        "id": "order_items",
        "fields": [
          {
            "id": "id",
            "name": "id",
            "dataType": "uuid",
            "keys": [
              "PK"
            ],
            "nullable": false,
            "description": ""
          },
          {
            "id": "order_id",
            "name": "order_id",
            "dataType": "uuid",
            "keys": [
              "FK"
            ],
            "nullable": false,
            "description": ""
          },
          {
            "id": "product_id",
            "name": "product_id",
            "dataType": "uuid",
            "keys": [
              "FK"
            ],
            "nullable": false,
            "description": ""
          },
          {
            "id": "quantity",
            "name": "quantity",
            "dataType": "integer",
            "keys": [],
            "nullable": false,
            "description": ""
          },
          {
            "id": "unit_price",
            "name": "unit_price",
            "dataType": "numeric(12,2)",
            "keys": [],
            "nullable": false,
            "description": ""
          },
          {
            "id": "discount_amount",
            "name": "discount_amount",
            "dataType": "numeric(12,2)",
            "keys": [],
            "nullable": false,
            "description": ""
          }
        ],
        "type": "datastore",
        "label": "Order items",
        "description": "Purchased quantities and prices. Each row references exactly one order and one product.",
        "group": "Line items",
        "category": "database",
        "basis": "unknown",
        "sources": [
          {
            "repository": "Mapfable",
            "path": "",
            "revision": "",
            "note": "Authored commerce schema for explaining relationships. No production database was inspected."
          }
        ]
      }
    ],
    "edges": [
      {
        "id": "order_customer",
        "source": "orders",
        "target": "customers",
        "sourceField": "customer_id",
        "targetField": "id",
        "sourceCardinality": "many",
        "targetCardinality": "one",
        "label": "placed by",
        "description": "",
        "basis": "unknown",
        "sources": [
          {
            "repository": "Mapfable",
            "path": "",
            "revision": "",
            "note": "Authored commerce schema for explaining relationships. No production database was inspected."
          }
        ]
      },
      {
        "id": "payment_order",
        "source": "payments",
        "target": "orders",
        "sourceField": "order_id",
        "targetField": "id",
        "sourceCardinality": "many",
        "targetCardinality": "one",
        "label": "payment for",
        "description": "",
        "basis": "unknown",
        "sources": [
          {
            "repository": "Mapfable",
            "path": "",
            "revision": "",
            "note": "Authored commerce schema for explaining relationships. No production database was inspected."
          }
        ]
      },
      {
        "id": "item_order",
        "source": "order_items",
        "target": "orders",
        "sourceField": "order_id",
        "targetField": "id",
        "sourceCardinality": "one_or_many",
        "targetCardinality": "one",
        "label": "belongs to",
        "description": "",
        "basis": "unknown",
        "sources": [
          {
            "repository": "Mapfable",
            "path": "",
            "revision": "",
            "note": "Authored commerce schema for explaining relationships. No production database was inspected."
          }
        ]
      },
      {
        "id": "item_product",
        "source": "order_items",
        "target": "products",
        "sourceField": "product_id",
        "targetField": "id",
        "sourceCardinality": "many",
        "targetCardinality": "one",
        "label": "references",
        "description": "",
        "basis": "unknown",
        "sources": [
          {
            "repository": "Mapfable",
            "path": "",
            "revision": "",
            "note": "Authored commerce schema for explaining relationships. No production database was inspected."
          }
        ]
      },
      {
        "id": "stock_product",
        "source": "inventory",
        "target": "products",
        "sourceField": "product_id",
        "targetField": "id",
        "sourceCardinality": "many",
        "targetCardinality": "one",
        "label": "stock of",
        "description": "",
        "basis": "unknown",
        "sources": [
          {
            "repository": "Mapfable",
            "path": "",
            "revision": "",
            "note": "Authored commerce schema for explaining relationships. No production database was inspected."
          }
        ]
      }
    ]
  },
  "investigation": null
}
