{
  "$schema": "../../../skill/references/schemap.schema.json",
  "kind": "architecture",
  "title": "Shop database",
  "subtitle": "PostgreSQL tables and foreign keys",
  "direction": "RIGHT",
  "groups": [
    { "id": "identity", "label": "Identity" },
    { "id": "catalog", "label": "Catalogue" },
    { "id": "sales", "label": "Sales" }
  ],
  "nodes": [
    {
      "id": "users",
      "type": "database",
      "group": "identity",
      "card": {
        "title": "users",
        "rows": [
          { "label": "id", "value": "uuid PK", "mono": true },
          { "label": "email", "value": "citext unique", "mono": true },
          { "label": "created_at", "value": "timestamptz", "mono": true }
        ]
      }
    },
    {
      "id": "addresses",
      "type": "database",
      "group": "identity",
      "card": {
        "title": "addresses",
        "rows": [
          { "label": "id", "value": "uuid PK", "mono": true },
          { "label": "user_id", "value": "uuid FK", "mono": true },
          { "label": "country", "value": "char(2)", "mono": true }
        ]
      }
    },
    {
      "id": "products",
      "type": "database",
      "group": "catalog",
      "card": {
        "title": "products",
        "rows": [
          { "label": "id", "value": "uuid PK", "mono": true },
          { "label": "sku", "value": "text unique", "mono": true },
          { "label": "price_cents", "value": "int", "mono": true }
        ]
      }
    },
    {
      "id": "categories",
      "type": "database",
      "group": "catalog",
      "card": {
        "title": "categories",
        "rows": [
          { "label": "id", "value": "int PK", "mono": true },
          { "label": "parent_id", "value": "int FK null", "mono": true }
        ]
      }
    },
    {
      "id": "orders",
      "type": "database",
      "group": "sales",
      "card": {
        "title": "orders",
        "rows": [
          { "label": "id", "value": "uuid PK", "mono": true },
          { "label": "user_id", "value": "uuid FK", "mono": true },
          { "label": "address_id", "value": "uuid FK", "mono": true },
          { "label": "status", "value": "order_status", "mono": true }
        ]
      }
    },
    {
      "id": "items",
      "type": "database",
      "group": "sales",
      "card": {
        "title": "order_items",
        "rows": [
          { "label": "order_id", "value": "uuid FK", "mono": true },
          { "label": "product_id", "value": "uuid FK", "mono": true },
          { "label": "qty", "value": "int", "mono": true }
        ]
      }
    },
    {
      "id": "payments",
      "type": "database",
      "group": "sales",
      "card": {
        "title": "payments",
        "rows": [
          { "label": "order_id", "value": "uuid FK", "mono": true },
          { "label": "provider_ref", "value": "text", "mono": true }
        ]
      }
    }
  ],
  "edges": [
    { "id": "f1", "from": "addresses", "to": "users", "label": "user_id" },
    { "id": "f2", "from": "orders", "to": "users", "label": "user_id", "tone": "main" },
    { "id": "f3", "from": "orders", "to": "addresses", "label": "address_id" },
    { "id": "f4", "from": "items", "to": "orders", "label": "order_id", "tone": "main" },
    { "id": "f5", "from": "items", "to": "products", "label": "product_id" },
    { "id": "f6", "from": "products", "to": "categories", "label": "category_id" },
    { "id": "f7", "from": "payments", "to": "orders", "label": "order_id" }
  ],
  "views": [
    {
      "id": "order",
      "label": "An order",
      "caption": "Everything one order touches",
      "nodes": ["orders", "items", "products", "payments", "users", "addresses"]
    }
  ]
}
