Loading Lion artifact…
Inspect Lion Program Source (JSON)
[
  "begin",
  [
    "relation",
    "region",
    [
      "id",
      "name"
    ],
    {
      "certified": true,
      "description": "Sales regions",
      "key": [
        "id"
      ]
    }
  ],
  [
    "relation",
    "supplier",
    [
      "id",
      "name",
      "region_id",
      "budget"
    ],
    {
      "certified": true,
      "description": "Approved suppliers with annual budgets",
      "key": [
        "id"
      ],
      "references": {
        "region_id": [
          "region",
          "id"
        ]
      }
    }
  ],
  [
    "relation",
    "shipment",
    [
      "id",
      "supplier_id",
      "units"
    ],
    {
      "certified": true,
      "description": "Fulfilled supply shipments",
      "key": [
        "id"
      ],
      "references": {
        "supplier_id": [
          "supplier",
          "id"
        ]
      }
    }
  ],
  [
    "relation",
    "filter",
    [
      "k",
      "v"
    ],
    {
      "key": [
        "k"
      ]
    }
  ],
  [
    "fact",
    [
      "region",
      "na",
      "North America"
    ],
    [
      "region",
      "eu",
      "Europe"
    ],
    [
      "supplier",
      "s1",
      "Acme Robotics",
      "na",
      1200
    ],
    [
      "supplier",
      "s2",
      "Northstar Bio",
      "na",
      900
    ],
    [
      "supplier",
      "s3",
      "Alpen Optics",
      "eu",
      1500
    ],
    [
      "shipment",
      "sh1",
      "s1",
      40
    ],
    [
      "shipment",
      "sh2",
      "s1",
      35
    ],
    [
      "shipment",
      "sh3",
      "s2",
      25
    ],
    [
      "shipment",
      "sh4",
      "s3",
      80
    ],
    [
      "shipment",
      "sh5",
      "s3",
      50
    ],
    [
      "filter",
      "active_region",
      "all"
    ]
  ],
  [
    "relation",
    "shipped_per_supplier",
    [
      "supplier_id",
      "units"
    ],
    {
      "key": [
        "supplier_id"
      ]
    }
  ],
  [
    "rule",
    [
      "shipped_per_supplier",
      "?sid",
      [
        "aggregate/sum",
        "?u"
      ]
    ],
    [
      "shipment",
      "?_id",
      "?sid",
      "?u"
    ]
  ],
  [
    "define",
    "view",
    [
      "lambda",
      [],
      [
        "begin",
        [
          "define",
          "reg",
          [
            "array/head",
            [
              "find",
              "?v",
              [
                "filter",
                "active_region",
                "?v"
              ]
            ]
          ]
        ],
        [
          "define",
          "rows",
          [
            "cond",
            [
              [
                "=",
                "reg",
                "all"
              ],
              [
                "find",
                {
                  "budget": "?b",
                  "region": "?rname",
                  "supplier": "?sname",
                  "units": "?u"
                },
                [
                  "and",
                  [
                    "supplier",
                    "?sid",
                    "?sname",
                    "?rid",
                    "?b"
                  ],
                  [
                    "region",
                    "?rid",
                    "?rname"
                  ],
                  [
                    "shipped_per_supplier",
                    "?sid",
                    "?u"
                  ]
                ]
              ]
            ],
            [
              "else",
              [
                "find",
                {
                  "budget": "?b",
                  "region": "?rname",
                  "supplier": "?sname",
                  "units": "?u"
                },
                [
                  "and",
                  [
                    "supplier",
                    "?sid",
                    "?sname",
                    "reg",
                    "?b"
                  ],
                  [
                    "region",
                    "reg",
                    "?rname"
                  ],
                  [
                    "shipped_per_supplier",
                    "?sid",
                    "?u"
                  ]
                ]
              ]
            ]
          ]
        ],
        [
          "define",
          "total_budget",
          [
            "array/reduce",
            "rows",
            0,
            [
              "lambda",
              [
                "acc",
                "r"
              ],
              [
                "number/add",
                "acc",
                [
                  "object/get",
                  "r",
                  "budget"
                ]
              ]
            ]
          ]
        ],
        [
          "define",
          "total_units",
          [
            "array/reduce",
            "rows",
            0,
            [
              "lambda",
              [
                "acc",
                "r"
              ],
              [
                "number/add",
                "acc",
                [
                  "object/get",
                  "r",
                  "units"
                ]
              ]
            ]
          ]
        ],
        [
          "ui/stack",
          {
            "gap": "lg"
          },
          [
            "ui/hero",
            {
              "badges": [
                "quote",
                [
                  {
                    "label": "Certified Ontology",
                    "tone": "ok"
                  },
                  {
                    "label": "Zero Join Fanout",
                    "tone": "ok"
                  },
                  {
                    "label": "Interactive Lion UI",
                    "tone": "accent"
                  }
                ]
              ],
              "eyebrow": "Governed Enterprise Ontology Artifact",
              "subtitle": "Foreign-key governed relations with fanout-safe pre-aggregation, interactive region filtering, and live entity lineage graph.",
              "title": "Supply Chain Budget & Fulfillment Explorer"
            }
          ],
          [
            "ui/grid",
            {
              "cols": 3,
              "gap": "md"
            },
            [
              "ui/card",
              [
                "ui/select",
                {
                  "label": "Filter Sales Region",
                  "onChange": [
                    "quote",
                    [
                      "fact",
                      [
                        "filter",
                        "active_region",
                        "value"
                      ]
                    ]
                  ],
                  "options": [
                    "quote",
                    [
                      {
                        "label": "All Regions",
                        "value": "all"
                      },
                      {
                        "label": "North America",
                        "value": "na"
                      },
                      {
                        "label": "Europe",
                        "value": "eu"
                      }
                    ]
                  ],
                  "value": "reg"
                }
              ]
            ],
            [
              "ui/metric",
              {
                "caption": "Pre-aggregated to prevent join fanout",
                "label": "Certified Budget ($k)",
                "tone": "ok",
                "value": "total_budget"
              }
            ],
            [
              "ui/metric",
              {
                "caption": "Rolled up per supplier before join",
                "label": "Units Shipped",
                "tone": "accent",
                "value": "total_units"
              }
            ]
          ],
          [
            "ui/section",
            {
              "step": "01",
              "subtitle": "Shipments pre-aggregate into shipped_per_supplier (keyed by supplier_id) before joining supplier budgets, eliminating classic SQL/BI join fanout bugs.",
              "title": "Governed Foreign-Key Schema & Safe Pre-Aggregation"
            },
            [
              "ui/graph",
              {
                "edges": [
                  "quote",
                  [
                    {
                      "from": "supplier",
                      "label": "region_id -> id",
                      "to": "region",
                      "tone": "ok"
                    },
                    {
                      "from": "shipment",
                      "label": "supplier_id -> id",
                      "to": "supplier",
                      "tone": "accent"
                    },
                    {
                      "from": "shipped_per_supplier",
                      "label": "pre-aggregates",
                      "to": "shipment",
                      "tone": "ok"
                    }
                  ]
                ],
                "height": 230,
                "layout": "layered",
                "nodes": [
                  "quote",
                  [
                    {
                      "group": "derived",
                      "id": "shipped_per_supplier",
                      "label": "shipped_per_supplier",
                      "subtitle": "key: supplier_id",
                      "tone": "ok"
                    },
                    {
                      "group": "fact",
                      "id": "shipment",
                      "label": "shipment",
                      "subtitle": "key: id"
                    },
                    {
                      "group": "dim",
                      "id": "supplier",
                      "label": "supplier",
                      "subtitle": "key: id",
                      "tone": "accent"
                    },
                    {
                      "group": "dim",
                      "id": "region",
                      "label": "region",
                      "subtitle": "key: id",
                      "tone": "ok"
                    }
                  ]
                ],
                "title": "Foreign-Key Schema & Safe Pre-Aggregation Graph"
              }
            ]
          ],
          [
            "ui/section",
            {
              "step": "02",
              "subtitle": "Switch the sales region selector above to dynamically recompute certified budget and shipped units without double-counting.",
              "title": "Fanout-Safe Supplier Rollup"
            },
            [
              "ui/table",
              {
                "columns": [
                  "quote",
                  [
                    {
                      "key": "supplier",
                      "label": "Supplier"
                    },
                    {
                      "key": "region",
                      "label": "Region"
                    },
                    {
                      "key": "budget",
                      "label": "Budget ($k)"
                    },
                    {
                      "key": "units",
                      "label": "Units Shipped"
                    }
                  ]
                ],
                "rows": "rows",
                "title": "Certified Supplier Metrics"
              }
            ]
          ]
        ]
      ]
    ],
    {
      "persist": true
    }
  ],
  [
    "view"
  ]
]