Source: https://skl.ai/examples/ Example # An example, end to end A small sales system, written in SKL: its orders, how one is placed, priced, and shipped, the user interface people use, a partner that describes orders its own way, and a change made while it runs. On this page The system · Orders and their statuses · Placing an order · Pricing and shipping · The user interface · A partner’s system · A change while it runs ## The system A business takes orders, prices them, ships them, and works with a partner whose system describes orders its own way. Here is each part, the spec it’s written as, and what happens when it’s used. | Part of the system | In SKL | When it’s used | | --- | --- | --- | | An order | A class, `Order`, and its properties, each declared once | Every save is checked against its constraints | | Its statuses | A set of terms, `orderStatuses`, each with its labels | Software reads the term, and people read its label | | Placing an order | A capability, `placeOrder`, and its switch | The switch picks a binding, and the SKL Kernel saves the order | | Pricing it | A capability, `priceOrder`, written as code | The code runs only while its fingerprint matches | | Shipping it | A capability, `bookShipment`, and its switch | The switch picks a carrier’s web API by destination | | The user interface | A page, its form, and its button | What it shows is read by query, and its button calls a capability | | A partner | Mappings between their orders and yours | Their records are read as yours, and yours as theirs | ## Orders and their statuses An order holds a customer, a total, and a status. The class says which properties it holds and what each must meet; each property is declared once, on its own, so every class that holds a total means the same thing by it. A class StructureConstraintsVocabulary Table | Address | `example.org/Order/v/1` | | --- | --- | | Stable ID | `example.org/Order` | | Kind | Class | | Local ID | Order | | Label | Order | | Namespace | `example.org/sales` | | Has Property | | Path | Min Count Constraint | Max Count Constraint | In Constraint | | --- | --- | --- | --- | | `example.org/customer` | 1 | 1 | | | `example.org/total` | 1 | 1 | | | `example.org/status` | | | `example.org/orderStatuses` | JSON-LD ``` { "@context": { "skl": "https://skl.ai/" }, "@graph": [ { "@id": "https://example.org/Order/v/1", "skl:sID": { "@id": "https://example.org/Order" }, "@type": "skl:Class", "skl:localId": "Order", "skl:label": "Order", "skl:namespace": { "@id": "https://example.org/sales" }, "skl:hasProperty": [ { "skl:path": { "@id": "https://example.org/customer" }, "skl:constraint/minCount": 1, "skl:constraint/maxCount": 1 }, { "skl:path": { "@id": "https://example.org/total" }, "skl:constraint/minCount": 1, "skl:constraint/maxCount": 1 }, { "skl:path": { "@id": "https://example.org/status" }, "skl:constraint/in": { "@id": "https://example.org/orderStatuses" } } ] } ] } ``` Turtle ``` @prefix skl: . @prefix ex: . @prefix constraint: . a skl:Class ; skl:hasProperty [ skl:path ex:customer ; constraint:maxCount 1 ; constraint:minCount 1 ], [ skl:path ex:total ; constraint:maxCount 1 ; constraint:minCount 1 ], [ skl:path ex:status ; constraint:in ex:orderStatuses ] ; skl:label "Order" ; skl:localId "Order" ; skl:namespace ex:sales ; skl:sID ex:Order . ``` RDF/XML ``` Order Order 1 1 1 1 ``` Order: exactly one customer, exactly one total, and a status from the set of order statuses. A property StructureConstraints Table | Address | `example.org/total/v/1` | | --- | --- | | Stable ID | `example.org/total` | | Kind | Property | | Local ID | total | | Label | Total | | Datatype Constraint | `xsd:decimal` | | Min Inclusive Constraint | 0 | JSON-LD ``` { "@context": { "skl": "https://skl.ai/", "xsd": "http://www.w3.org/2001/XMLSchema#" }, "@graph": [ { "@id": "https://example.org/total/v/1", "skl:sID": { "@id": "https://example.org/total" }, "@type": "skl:Property", "skl:localId": "total", "skl:label": "Total", "skl:constraint/datatype": { "@id": "xsd:decimal" }, "skl:constraint/minInclusive": 0 } ] } ``` Turtle ``` @prefix skl: . @prefix xsd: . @prefix ex: . @prefix constraint: . a skl:Property ; constraint:datatype xsd:decimal ; constraint:minInclusive 0 ; skl:label "Total" ; skl:localId "total" ; skl:sID ex:total . ``` RDF/XML ``` 0 Total total ``` A total is a decimal number, and never below 0. A status is a term from a set. The term has an address of its own and a code, `7Q2M9K`, which a record carries in JSON. The code can be any code your systems use: it carries no meaning, and nothing reads it from the wording. What people read is a label, kept apart from the term and pointing at it, so the wording can change, or come in another language, while the code stays. A term Vocabulary Table | Address | `example.org/def/4KD8RW` | | --- | --- | | Kind | Term Definition | | Local ID | 7Q2M9K | | In Vocab Set | `example.org/orderStatuses` | | Definition | The order waits for a person to review it. | JSON-LD ``` { "@context": { "skl": "https://skl.ai/" }, "@graph": [ { "@id": "https://example.org/def/4KD8RW", "@type": "skl:vocab/TermDefinition", "skl:localId": "7Q2M9K", "skl:vocab/inVocabSet": { "@id": "https://example.org/orderStatuses" }, "skl:vocab/definition": "The order waits for a person to review it." } ] } ``` Turtle ``` @prefix skl: . @prefix ex: . @prefix vocab: . a vocab:TermDefinition ; skl:localId "7Q2M9K" ; vocab:definition "The order waits for a person to review it." ; vocab:inVocabSet ex:orderStatuses . ``` RDF/XML ``` 7Q2M9K The order waits for a person to review it. ``` 7Q2M9K: the code a record carries. Its label Vocabulary Table | Address | `example.org/label/9PX2LM` | | --- | --- | | Kind | Term Label | | Label | Held for review | | In Language | English | | Definition Reference | `example.org/def/4KD8RW` | JSON-LD ``` { "@context": { "skl": "https://skl.ai/" }, "@graph": [ { "@id": "https://example.org/label/9PX2LM", "@type": "skl:vocab/TermLabel", "skl:label": "Held for review", "skl:inLanguage": { "@id": "skl:vocab/def/06G9CF0MMWGZEFK95Q7WW7N30X" }, "skl:vocab/definitionReference": { "@id": "https://example.org/def/4KD8RW" } } ] } ``` Turtle ``` @prefix skl: . @prefix vocab: . a vocab:TermLabel ; skl:inLanguage ; skl:label "Held for review" ; vocab:definitionReference . ``` RDF/XML ``` Held for review ``` Held for review: what people read, in English. ## Placing an order Place order is a capability: it says what it takes and what it returns. It doesn’t say how it’s answered. A switch of its own does, picking a binding for each call, and the binding names what answers it, here the SKL Kernel’s own save. A capability Capabilities Table | Address | `example.org/placeOrder/v/1` | | --- | --- | | Stable ID | `example.org/placeOrder` | | Kind | Invocable Router | | Local ID | placeOrder | | Label | Place order | | Inputs | `example.org/PlaceOrderInputs` | | Outputs | `example.org/Order` | | Router Switch | `example.org/placeOrderSwitch` | JSON-LD ``` { "@context": { "skl": "https://skl.ai/" }, "@graph": [ { "@id": "https://example.org/placeOrder/v/1", "skl:sID": { "@id": "https://example.org/placeOrder" }, "@type": "skl:invocable/Router", "skl:localId": "placeOrder", "skl:label": "Place order", "skl:inputs": { "@id": "https://example.org/PlaceOrderInputs" }, "skl:outputs": { "@id": "https://example.org/Order" }, "skl:routerSwitch": { "@id": "https://example.org/placeOrderSwitch" } } ] } ``` Turtle ``` @prefix skl: . @prefix ex: . @prefix invocable: . a invocable:Router ; skl:inputs ex:PlaceOrderInputs ; skl:label "Place order" ; skl:localId "placeOrder" ; skl:outputs ex:Order ; skl:routerSwitch ex:placeOrderSwitch ; skl:sID ex:placeOrder . ``` RDF/XML ``` Place order placeOrder ``` Place order takes an order’s inputs and returns an order. Its switch is named, not written in. The switch reads the totalPlace order’s switch - Over 5,000 `saveAsHeld`The SKL Kernel’s save, with the status Held for review - Any other order `saveAsConfirmed`The SKL Kernel’s save, with the status Confirmed One call, two ways to answer it. The switch reads the call’s total and picks a binding; each binding says what answers the call and how its inputs are mapped. Its switch CapabilitiesVersions Table | Address | `example.org/placeOrderSwitch/v/1` | | --- | --- | | Stable ID | `example.org/placeOrderSwitch` | | Kind | Switch | | Case | | Kind | Order | Condition | Target Item | | --- | --- | --- | --- | | Kind | Comparison | | --- | --- | | Relative Path | total | | Operator | Gt | | Value | 5000 | `example.org/saveAsHeld` | Default Case | `example.org/saveAsConfirmed` | JSON-LD ``` { "@context": { "skl": "https://skl.ai/" }, "@graph": [ { "@id": "https://example.org/placeOrderSwitch/v/1", "skl:sID": { "@id": "https://example.org/placeOrderSwitch" }, "@type": "skl:Switch", "skl:case": [ { "@type": "skl:SwitchCase", "skl:order": 1, "skl:condition": { "@type": "skl:condition/Comparison", "skl:relativePath": { "@list": ["total"] }, "skl:condition/operator": "Gt", "skl:condition/value": 5000 }, "skl:targetItem": { "@id": "https://example.org/saveAsHeld" } } ], "skl:defaultCase": { "@id": "https://example.org/saveAsConfirmed" } } ] } ``` Turtle ``` @prefix skl: . @prefix ex: . @prefix condition: . a skl:Switch ; skl:case [ a skl:SwitchCase ; skl:condition [ a condition:Comparison ; condition:operator "Gt" ; condition:value 5000 ; skl:relativePath ( "total" ) ] ; skl:order 1 ; skl:targetItem ex:saveAsHeld ] ; skl:defaultCase ex:saveAsConfirmed ; skl:sID ex:placeOrderSwitch . ``` RDF/XML ``` 1 Gt 5000 total ``` Version 1 of the switch: an order over 5,000 is held for review, and any other is confirmed. A binding MappingsCapabilities Table | Address | `example.org/saveAsHeld/v/1` | | --- | --- | | Stable ID | `example.org/saveAsHeld` | | Kind | Invocable Binding | | Source Item | `example.org/placeOrder` | | Target Item | Save | | Inputs Mapping | `example.org/orderAsHeld` | JSON-LD ``` { "@context": { "skl": "https://skl.ai/" }, "@graph": [ { "@id": "https://example.org/saveAsHeld/v/1", "skl:sID": { "@id": "https://example.org/saveAsHeld" }, "@type": "skl:mapping/InvocableBinding", "skl:sourceItem": { "@id": "https://example.org/placeOrder" }, "skl:targetItem": { "@id": "skl:kernel/save" }, "skl:mapping/inputsMapping": { "@id": "https://example.org/orderAsHeld" } } ] } ``` Turtle ``` @prefix skl: . @prefix ex: . @prefix mapping: . @prefix kernel: . a mapping:InvocableBinding ; mapping:inputsMapping ex:orderAsHeld ; skl:sID ex:saveAsHeld ; skl:sourceItem ex:placeOrder ; skl:targetItem kernel:save . ``` RDF/XML ``` ``` Save as held: when the switch picks it, the SKL Kernel’s save answers the call, with the inputs mapped to an order whose status is Held. ### A call, and its answer Apps, AI agents, and other systems call Place order the same way. The SKL Kernel checks the call against what Place order takes, runs what the switch picks, and checks the answer against what it returns. The call ``` { "customer": "https://example.org/customer/318", "total": 4200 } ``` An order of 4,200. The answer ``` { "@id": "https://example.org/order/1042", "@type": "Order", "customer": "https://example.org/customer/318", "total": 4200, "status": "3VR8TX" } ``` The saved order, confirmed, in the shape Place order returns. A callPlace orderno total The answerRefused: a total is required, so nothing is saved A call that leaves out the total is refused before anything runs. ## Pricing and shipping Pricing an order is code. The spec names the file and the function, and records the code’s fingerprint: change the file, and it won’t run until its spec records the change. Code runs locked down unless a policy says the namespace it comes from is trusted. A capability, written as code Capabilities Table | Address | `example.org/priceOrder/v/1` | | --- | --- | | Stable ID | `example.org/priceOrder` | | Kind | CodeBlock | | Local ID | priceOrder | | Label | Price order | | Inputs | `example.org/PriceOrderInputs` | | Outputs | `example.org/Price` | | Kind | Code Body | | --- | --- | | Data Location | file://src/price-order.ts | | Code Body Entry Point | priceOrder | | Hash | 3b7f0e2a9c41… | JSON-LD ``` { "@context": { "skl": "https://skl.ai/", "xsd": "http://www.w3.org/2001/XMLSchema#" }, "@graph": [ { "@id": "https://example.org/priceOrder/v/1", "skl:sID": { "@id": "https://example.org/priceOrder" }, "@type": "skl:invocable/CodeBlock", "skl:localId": "priceOrder", "skl:label": "Price order", "skl:inputs": { "@id": "https://example.org/PriceOrderInputs" }, "skl:outputs": { "@id": "https://example.org/Price" }, "skl:codeBody": { "@type": "skl:CodeBody", "skl:dataLocation": { "@value": "file://src/price-order.ts", "@type": "xsd:anyURI" }, "skl:codeBodyEntryPoint": "priceOrder", "skl:content/hash": "3b7f0e2a9c41…" } } ] } ``` Turtle ``` @prefix skl: . @prefix xsd: . @prefix ex: . @prefix invocable: . @prefix content: . a invocable:CodeBlock ; skl:codeBody [ a skl:CodeBody ; skl:codeBodyEntryPoint "priceOrder" ; content:hash "3b7f0e2a9c41…" ; skl:dataLocation "file://src/price-order.ts"^^xsd:anyURI ] ; skl:inputs ex:PriceOrderInputs ; skl:label "Price order" ; skl:localId "priceOrder" ; skl:outputs ex:Price ; skl:sID ex:priceOrder . ``` RDF/XML ``` Price order priceOrder priceOrder 3b7f0e2a9c41… file://src/price-order.ts ``` Price order runs one exported function from one file, only while the file’s fingerprint matches. Shipping an order is another system’s job. Import a carrier’s OpenAPI description, and each of its operations becomes a spec the SKL Kernel can call. Book shipment is a capability like Place order, and its switch picks a carrier’s web API by where the order goes. A web API operation Capabilities Table | Address | `example.org/carrier/createShipment/v/1` | | --- | --- | | Stable ID | `example.org/carrier/createShipment` | | Kind | Http | | Local ID | createShipment | | HTTP Method | POST | | HTTP Path | /shipments | | In API | `example.org/carrier/api` | | Inputs | `example.org/carrier/CreateShipmentInputs` | | Outputs | `example.org/carrier/Shipment` | JSON-LD ``` { "@context": { "skl": "https://skl.ai/" }, "@graph": [ { "@id": "https://example.org/carrier/createShipment/v/1", "skl:sID": { "@id": "https://example.org/carrier/createShipment" }, "@type": "skl:invocable/operation/Http", "skl:localId": "createShipment", "skl:invocable/httpMethod": { "@id": "skl:vocab/def/06G9CF0MMR9D59Z2DVV5YAKNVC" }, "skl:invocable/httpPath": "/shipments", "skl:interface/inApi": { "@id": "https://example.org/carrier/api" }, "skl:inputs": { "@id": "https://example.org/carrier/CreateShipmentInputs" }, "skl:outputs": { "@id": "https://example.org/carrier/Shipment" } } ] } ``` Turtle ``` @prefix skl: . @prefix operation: . @prefix interface: . @prefix invocable: . a operation:Http ; skl:inputs ; interface:inApi ; invocable:httpMethod ; invocable:httpPath "/shipments" ; skl:localId "createShipment" ; skl:outputs ; skl:sID . ``` RDF/XML ``` /shipments createShipment ``` POST /shipments on a carrier’s web API, imported from its OpenAPI description. The switch reads the destinationBook shipment’s switch - In the country `carrier/createShipment`A carrier’s web API, called as it is - Abroad `freight/createConsignment`A freight company’s web API, through a binding that maps the shipment to its consignment, and its answer back Two web APIs that answer the same capability. Each is called as it is; the binding says how to map what one expects and returns. A binding MappingsCapabilities Table | Address | `example.org/bookAbroad/v/1` | | --- | --- | | Stable ID | `example.org/bookAbroad` | | Kind | Invocable Binding | | Source Item | `example.org/bookShipment` | | Target Item | `example.org/freight/createConsignment` | | Inputs Mapping | `example.org/shipmentToConsignment` | | Outputs Mapping | `example.org/consignmentToShipment` | JSON-LD ``` { "@context": { "skl": "https://skl.ai/" }, "@graph": [ { "@id": "https://example.org/bookAbroad/v/1", "skl:sID": { "@id": "https://example.org/bookAbroad" }, "@type": "skl:mapping/InvocableBinding", "skl:sourceItem": { "@id": "https://example.org/bookShipment" }, "skl:targetItem": { "@id": "https://example.org/freight/createConsignment" }, "skl:mapping/inputsMapping": { "@id": "https://example.org/shipmentToConsignment" }, "skl:mapping/outputsMapping": { "@id": "https://example.org/consignmentToShipment" } } ] } ``` Turtle ``` @prefix skl: . @prefix ex: . @prefix mapping: . a mapping:InvocableBinding ; mapping:inputsMapping ex:shipmentToConsignment ; mapping:outputsMapping ex:consignmentToShipment ; skl:sID ex:bookAbroad ; skl:sourceItem ex:bookShipment ; skl:targetItem . ``` RDF/XML ``` ``` Book abroad: a freight company answers Book shipment, with the shipment mapped to its consignment on the way out, and its answer mapped back. ## The user interface The page people use to review a held order is a spec too: what it shows, for which order, and which capability its button calls. Its form comes from the Order class, so a property added to the class appears on the form without a code change, and the status shows its label rather than its code. A page, as specs - Pagefor one order - A formits fields from the Order class - A buttoncalls Confirm order - Stylesthe product’s set of styles Picture: The page as people see it: order 1042’s form, with its customer, total, and status, and a Confirm order button. The page people use to review an order. Its fields come from the Order class, the status shows its label, and the button calls a capability, with the same checks as any other call. ## A partner’s system A partner sells the same orders and describes them its own way: a sales order, a customer’s name in two fields, an amount, and statuses of its own. Neither system changes its data model. Mappings say how the two correspond, and each mapping runs one way, so the way back is written too. | Way | Source | Target | Written as | | --- | --- | --- | --- | | Out: yours to theirs | `Order` | `SalesOrder` | A correspondence between classes | | Out: yours to theirs | `customerName` | `given_name` | A transformation | | Out: yours to theirs | `customerName` | `family_name` | A transformation | | Out: yours to theirs | `total` | `amount` | A correspondence between properties | | Back: theirs to yours | `given_name`, `family_name` | `customerName` | One transformation, joining two fields into one | | Back: theirs to yours | `IN_TRANSIT` | Shipped, `5NB2HD` | A correspondence between terms | A transformation Mappings Table | Address | `example.org/joinCustomerName/v/1` | | --- | --- | | Stable ID | `example.org/joinCustomerName` | | Kind | Transformation | | Type | Property Mapping | | Source Item | `example.org/partner/given_name``example.org/partner/family_name` | | Target Item | `example.org/customerName` | | Semantic Correspondence | Derived | | Structural Correspondence | Aggregating | | Inputs Mapping | `example.org/joinName` | JSON-LD ``` { "@context": { "skl": "https://skl.ai/" }, "@graph": [ { "@id": "https://example.org/joinCustomerName/v/1", "skl:sID": { "@id": "https://example.org/joinCustomerName" }, "@type": "skl:mapping/Transformation", "skl:type": { "@id": "skl:vocab/def/06G9CF0MMYAY1AQRGRZ2PQ8TCU" }, "skl:sourceItem": [ { "@id": "https://example.org/partner/given_name" }, { "@id": "https://example.org/partner/family_name" } ], "skl:targetItem": { "@id": "https://example.org/customerName" }, "skl:mapping/semanticCorrespondence": { "@id": "skl:vocab/def/06G9CF0MMW367G0F4M4FBBZ5Z6" }, "skl:mapping/structuralCorrespondence": { "@id": "skl:vocab/def/06G9CF0MMXYRJVFBN45BG8HXPP" }, "skl:mapping/inputsMapping": { "@id": "https://example.org/joinName" } } ] } ``` Turtle ``` @prefix skl: . @prefix ex: . @prefix mapping: . a mapping:Transformation ; mapping:inputsMapping ex:joinName ; mapping:semanticCorrespondence ; mapping:structuralCorrespondence ; skl:sID ex:joinCustomerName ; skl:sourceItem , ; skl:targetItem ex:customerName ; skl:type . ``` RDF/XML ``` ``` On the way back, the partner’s two name fields are joined into one. A correspondence MappingsVocabulary Table | Address | `example.org/inTransitIsShipped/v/1` | | --- | --- | | Stable ID | `example.org/inTransitIsShipped` | | Kind | Atomic Mapping | | Type | Vocabulary Translation | | Source Item | `example.org/partner/def/2RM8TZ` | | Target Item | `example.org/def/7HW3QN` | | Semantic Correspondence | Equivalent | JSON-LD ``` { "@context": { "skl": "https://skl.ai/" }, "@graph": [ { "@id": "https://example.org/inTransitIsShipped/v/1", "skl:sID": { "@id": "https://example.org/inTransitIsShipped" }, "@type": "skl:mapping/Atomic", "skl:type": { "@id": "skl:vocab/def/06G9CF0MMY5AZX5ZHRXQSW39AF" }, "skl:sourceItem": { "@id": "https://example.org/partner/def/2RM8TZ" }, "skl:targetItem": { "@id": "https://example.org/def/7HW3QN" }, "skl:mapping/semanticCorrespondence": { "@id": "skl:vocab/def/06G9CF0MMZ5YFANDNF3TYP5YEM" } } ] } ``` Turtle ``` @prefix skl: . @prefix ex: . @prefix mapping: . a mapping:Atomic ; mapping:semanticCorrespondence ; skl:sID ex:inTransitIsShipped ; skl:sourceItem ; skl:targetItem ; skl:type . ``` RDF/XML ``` ``` The partner’s IN_TRANSIT is read as your Shipped. The correspondence points at both terms by address, so neither system’s code has to change. ## A change while it runs The business decides to review more orders. Someone lowers the switch’s limit from 5,000 to 2,000 in a draft. Calls keep following version 1 until the draft is committed as version 2; the next order of 4,200 is then held for review, with no rebuild and no deploy. Version 1 is kept, so the two can be compared and version 1 brought back. A draft lowers the limit to 2,000 Calls still follow version 1 The draft is committed as version 2 The next order of 4,200 is held for review Version 1 can be brought back The change VersionsCapabilities ``` - "@id": "https://example.org/placeOrderSwitch/v/1", + "@id": "https://example.org/placeOrderSwitch/v/2", … - "skl:condition/value": 5000 + "skl:condition/value": 2000 ``` Version 2 of the switch: a new version of the same identity, with a lower limit. Next ### Patterns Six ways to build with SKL Next ### Why SKL How SKL compares, and what it works with ## Hear when it’s published The fourth generation of SKL and the SKL Kernel will be open sourced here in 2027, with SKL Ontology 4.x, the shared specs SKL starts from. Tell us what you would build with it.