# SHACL shapes for graphs in the terms of the C4 architecture ontology (c4.ttl), its data module (c4-data.ttl) and its
# view module (c4-view.ttl).
#
# A graph exported by the architecture explorer conforms to these shapes. Run them with any SHACL Core engine:
#   rete:     (await rete.open(bytes)).shacl(shapesTurtle)          (rete-graph, JavaScript)
#   pyshacl:  pyshacl -s c4-shapes.ttl -df turtle architecture.ttl
#
# Only SHACL Core, and no logical constraints (sh:or, sh:and, sh:not, sh:xone): some engines, rete-graph
# 0.7.4 among them, skip those silently, and every engine should give the same report for these shapes.
# The shapes do not need the ontology: the exported data names the superclasses itself (a data store is
# also typed c4:Element and c4:Container), so sh:targetClass and sh:class find them in the data graph.
#
# Sections: core architecture · use cases · images · states and transitions · data module (c4d:) · view module (c4v:).
# The data shapes target c4d: classes and properties only, so a graph without schemas meets them trivially.

@prefix c4s:     <https://caviri.github.io/c4-model-agentic-plugin/ontology/c4-shapes.ttl#> .
@prefix c4:      <https://caviri.github.io/c4-model-agentic-plugin/ontology/c4#> .
@prefix c4v:     <https://caviri.github.io/c4-model-agentic-plugin/ontology/c4-view#> .
@prefix c4d:     <https://caviri.github.io/c4-model-agentic-plugin/ontology/c4-data#> .
@prefix sh:      <http://www.w3.org/ns/shacl#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix schema:  <https://schema.org/> .

<https://caviri.github.io/c4-model-agentic-plugin/ontology/c4-shapes.ttl>
    a owl:Ontology ;
    dcterms:title "SHACL shapes for the C4 architecture ontology"@en ;
    dcterms:description "Constraints that every graph exported by the architecture explorer meets: the core architecture, use cases, states and transitions, the data module, and the view module (with icons)."@en ;
    dcterms:creator "caviri" ;
    dcterms:license <https://www.apache.org/licenses/LICENSE-2.0> ;
    owl:versionInfo "0.1.0" ;
    rdfs:seeAlso <https://caviri.github.io/c4-model-agentic-plugin/ontology/c4> , <https://caviri.github.io/c4-model-agentic-plugin/ontology/c4-data> ,
        <https://caviri.github.io/c4-model-agentic-plugin/ontology/c4-view> .

#################################################################
#  Core architecture
#################################################################

c4s:ModelShape a sh:NodeShape ;
    sh:targetClass c4:Model ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:message "A model has exactly one name (rdfs:label)." ] ;
    sh:property [ sh:path dcterms:title ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:description ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:identifier ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:conformsTo ; sh:hasValue <https://caviri.github.io/c4-model-agentic-plugin/ontology/c4> ;
                  sh:message "An exported model says which ontology it uses: dcterms:conformsTo <…/ontology/c4>." ] ;
    sh:property [ sh:path dcterms:source ; sh:maxCount 1 ; sh:nodeKind sh:IRI ] ;
    sh:property [ sh:path c4:branch ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:variantDimension ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:hasPart ; sh:minCount 1 ; sh:class c4:Element ; sh:message "A model has at least one top-level element." ] .

c4s:ElementShape a sh:NodeShape ;
    sh:targetClass c4:Element ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:message "An element has exactly one name (rdfs:label)." ] ;
    sh:property [ sh:path dcterms:identifier ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:message "An element has exactly one id (dcterms:identifier)." ] ;
    sh:property [ sh:path c4:level ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ; sh:maxInclusive 4 ;
                  sh:message "An element has exactly one c4:level, an integer from 1 to 4." ] ;
    sh:property [ sh:path dcterms:isPartOf ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ;
                  sh:message "An element is part of exactly one thing: its parent element, or the model for a top-level box." ] ;
    sh:property [ sh:path dcterms:description ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:summary ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:tag ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:note ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:technology ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:path ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:line ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ] ;
    sh:property [ sh:path c4:link ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path rdfs:seeAlso ; sh:nodeKind sh:IRI ] ;
    sh:property [ sh:path c4:uses ; sh:class c4:Element ] ;
    sh:property [ sh:path c4:inVariant ; sh:class c4:Variant ] ;
    sh:property [ sh:path schema:image ; sh:class schema:ImageObject ] .

# the line needs the file it is in: its own (an element, a schema, an entity), or its entity's (a field)
c4s:LineNeedsPathShape a sh:NodeShape ;
    sh:targetSubjectsOf c4:line ;
    sh:property [ sh:path [ sh:alternativePath ( c4:path ( c4d:inEntity c4:path ) ) ] ; sh:minCount 1 ;
                  sh:message "c4:line is only meaningful with a c4:path (a field's line is in the file of its entity)." ] .

c4s:ContainerShape a sh:NodeShape ;
    sh:targetClass c4:Container ;
    sh:property [ sh:path dcterms:isPartOf ; sh:class c4:SoftwareSystem ;
                  sh:message "In C4 a container (or data store) is part of a software system." ] .

c4s:ComponentShape a sh:NodeShape ;
    sh:targetClass c4:Component ;
    sh:property [ sh:path dcterms:isPartOf ; sh:class c4:Container ;
                  sh:message "In C4 a component is part of a container (or data store)." ] .

c4s:RelationshipShape a sh:NodeShape ;
    sh:targetClass c4:Relationship ;
    sh:property [ sh:path c4:source ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:Element ; sh:message "A relationship has exactly one source element." ] ;
    sh:property [ sh:path c4:target ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:Element ; sh:message "A relationship has exactly one target element." ] ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:message "A relationship says what happens along it (one rdfs:label)." ] ;
    sh:property [ sh:path c4:summaryLabel ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:inVariant ; sh:class c4:Variant ] ;
    sh:property [ sh:path schema:image ; sh:class schema:ImageObject ] .

c4s:VariantShape a sh:NodeShape ;
    sh:targetClass c4:Variant ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:identifier ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:isPartOf ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:Model ] .

#################################################################
#  Dynamic diagrams and use cases
#################################################################

c4s:ScenarioShape a sh:NodeShape ;
    sh:targetClass c4:Scenario ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:identifier ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:description ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:isPartOf ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:Model ] ;
    sh:property [ sh:path c4:hasStep ; sh:minCount 1 ; sh:class c4:Step ; sh:message "A scenario has at least one step." ] ;
    # use-case metadata: all optional, at most one each, preconditions as many as needed
    sh:property [ sh:path c4:primaryActor ; sh:maxCount 1 ; sh:class c4:Person ; sh:message "The primary actor of a use case is one person (c4:Person)." ] ;
    sh:property [ sh:path c4:goal ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:minLength 1 ] ;
    sh:property [ sh:path c4:trigger ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:minLength 1 ] ;
    sh:property [ sh:path c4:outcome ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:minLength 1 ] ;
    sh:property [ sh:path c4:precondition ; sh:datatype xsd:string ; sh:minLength 1 ] ;
    sh:property [ sh:path schema:image ; sh:class schema:ImageObject ] .

c4s:StepShape a sh:NodeShape ;
    sh:targetClass c4:Step ;
    sh:property [ sh:path schema:position ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ;
                  sh:message "A step has exactly one position (schema:position), an integer from 1." ] ;
    sh:property [ sh:path c4:source ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:Element ; sh:message "A step has exactly one source element." ] ;
    sh:property [ sh:path c4:target ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:Element ; sh:message "A step has exactly one target element." ] ;
    sh:property [ sh:path c4:inScenario ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:Scenario ; sh:message "A step belongs to exactly one scenario." ] ;
    sh:property [ sh:path [ sh:inversePath c4:hasStep ] ; sh:minCount 1 ; sh:maxCount 1 ; sh:message "Exactly one scenario lists the step with c4:hasStep." ] ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:isReply ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path c4:inVariant ; sh:class c4:Variant ] ;
    sh:property [ sh:path schema:image ; sh:class schema:ImageObject ] .

#################################################################
#  Images (schema:ImageObject, linked with schema:image from an element, a relationship, a scenario or a step)
#################################################################

# its address is an IRI (an http(s) URL) or an xsd:anyURI literal (a path next to the model, or a data: URI); SHACL Core
# without sh:or cannot say "one or the other" more closely than sh:IRIOrLiteral
c4s:ImageShape a sh:NodeShape ;
    sh:targetClass schema:ImageObject ;
    sh:property [ sh:path schema:contentUrl ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRIOrLiteral ;
                  sh:message "An image has exactly one address (schema:contentUrl)." ] ;
    sh:property [ sh:path c4:altText ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:minLength 1 ;
                  sh:message "An image has exactly one text alternative (c4:altText): what it shows, for readers who cannot see it." ] ;
    sh:property [ sh:path schema:caption ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:minLength 1 ] ;
    sh:property [ sh:path schema:creditText ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:minLength 1 ] ;
    sh:property [ sh:path c4:imageKind ; sh:maxCount 1 ; sh:in ( "screenshot" "diagram" "photo" "illustration" ) ] ;
    sh:property [ sh:path c4:illustrative ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path [ sh:inversePath schema:image ] ; sh:minCount 1 ; sh:maxCount 1 ;
                  sh:message "An image belongs to exactly one element, relationship, scenario, step, schema or entity (schema:image)." ] ;
    sh:property [ sh:path c4v:order ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ;
                  sh:message "An image has its place among the images of what it shows (one c4v:order)." ] .

#################################################################
#  States and transitions
#################################################################

c4s:StateShape a sh:NodeShape ;
    sh:targetClass c4:State ;
    sh:property [ sh:path dcterms:isPartOf ; sh:class c4:Element ; sh:message "A state is part of the element that owns its lifecycle." ] ;
    sh:property [ sh:path c4:initial ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path c4:final ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path c4:transitionsTo ; sh:class c4:State ] .

c4s:TransitionShape a sh:NodeShape ;
    sh:targetClass c4:Transition ;
    sh:property [ sh:path c4:source ; sh:class c4:State ; sh:message "A transition starts at a state." ] ;
    sh:property [ sh:path c4:target ; sh:class c4:State ; sh:message "A transition ends at a state." ] .

c4s:TransitionsFromStateShape a sh:NodeShape ;
    sh:targetSubjectsOf c4:transitionsTo ;
    sh:class c4:State ;
    sh:message "Only a state transitions to another state." .

c4s:InitialFinalShape a sh:NodeShape ;
    sh:targetSubjectsOf c4:initial , c4:final ;
    sh:class c4:State ;
    sh:message "Only a state is initial or final." .

#################################################################
#  Data module (c4d:): schemas, entities, fields, indexes, relations, what steps and relationships read and write
#################################################################

c4s:SchemaShape a sh:NodeShape ;
    sh:targetClass c4d:Schema ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:message "A schema has exactly one name (rdfs:label)." ] ;
    sh:property [ sh:path dcterms:identifier ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:message "A schema has exactly one id (dcterms:identifier)." ] ;
    sh:property [ sh:path c4d:schemaKind ; sh:minCount 1 ; sh:maxCount 1 ;
                  sh:in ( "relational" "document" "json-schema" "ontology" "object-store" "queue" "api" "other" ) ;
                  sh:message "A schema has one kind: relational, document, json-schema, ontology, object-store, queue, api or other." ] ;
    sh:property [ sh:path c4d:livesIn ; sh:maxCount 1 ; sh:class c4:Element ; sh:message "A schema lives in one element of the architecture (c4d:livesIn)." ] ;
    sh:property [ sh:path dcterms:isPartOf ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:Model ] ;
    sh:property [ sh:path dcterms:description ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4d:format ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4d:namespace ; sh:maxCount 1 ; sh:datatype xsd:anyURI ] ;
    sh:property [ sh:path c4d:hasEntity ; sh:class c4d:Entity ] ;
    sh:property [ sh:path c4:path ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:line ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ] ;
    sh:property [ sh:path c4:link ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path rdfs:seeAlso ; sh:nodeKind sh:IRI ] ;
    sh:property [ sh:path c4:technology ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:note ; sh:datatype xsd:string ] ;
    sh:property [ sh:path schema:image ; sh:class schema:ImageObject ] .

c4s:EntityShape a sh:NodeShape ;
    sh:targetClass c4d:Entity ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:message "An entity has exactly one name (rdfs:label), as its source writes it." ] ;
    sh:property [ sh:path dcterms:identifier ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:message "An entity has exactly one id (dcterms:identifier)." ] ;
    sh:property [ sh:path c4d:inSchema ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4d:Schema ; sh:message "An entity belongs to exactly one schema (c4d:inSchema)." ] ;
    sh:property [ sh:path [ sh:inversePath c4d:hasEntity ] ; sh:minCount 1 ; sh:maxCount 1 ; sh:message "Exactly one schema lists the entity (c4d:hasEntity)." ] ;
    sh:property [ sh:path c4d:entityKind ; sh:maxCount 1 ;
                  sh:in ( "table" "view" "class" "object" "enum" "collection" "document" "bucket" "message" "type" ) ;
                  sh:message "An entity's kind is table, view, class, object, enum, collection, document, bucket, message or type." ] ;
    sh:property [ sh:path dcterms:description ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4d:hasField ; sh:class c4d:Field ] ;
    sh:property [ sh:path c4d:hasIndex ; sh:class c4d:Index ] ;
    sh:property [ sh:path c4d:allowedValue ; sh:nodeKind sh:Literal ] ;
    sh:property [ sh:path c4d:definedBy ; sh:class c4:Element ; sh:message "An entity is defined by elements of the architecture (c4d:definedBy: code elements, components)." ] ;
    sh:property [ sh:path c4d:represents ; sh:maxCount 1 ; sh:nodeKind sh:IRIOrLiteral ] ;
    sh:property [ sh:path c4:path ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:line ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ] ;
    sh:property [ sh:path c4:link ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path rdfs:seeAlso ; sh:nodeKind sh:IRI ] ;
    sh:property [ sh:path c4:note ; sh:datatype xsd:string ] ;
    sh:property [ sh:path schema:image ; sh:class schema:ImageObject ] .

# an enumeration is its values (the validator warns about an enum without values)
c4s:EnumerationShape a sh:NodeShape ;
    sh:targetClass c4d:Enumeration ;
    sh:property [ sh:path c4d:allowedValue ; sh:minCount 1 ; sh:message "An enumeration lists its values (c4d:allowedValue)." ] .

c4s:FieldShape a sh:NodeShape ;
    sh:targetClass c4d:Field ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:minLength 1 ; sh:message "A field has exactly one name (rdfs:label)." ] ;
    sh:property [ sh:path c4d:inEntity ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4d:Entity ; sh:message "A field belongs to exactly one entity (c4d:inEntity)." ] ;
    sh:property [ sh:path [ sh:inversePath c4d:hasField ] ; sh:minCount 1 ; sh:maxCount 1 ; sh:message "Exactly one entity lists the field (c4d:hasField)." ] ;
    sh:property [ sh:path schema:position ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ;
                  sh:message "A field has its place among the fields of its entity (one schema:position, an integer from 1)." ] ;
    sh:property [ sh:path c4d:declaredType ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4d:isPrimaryKey ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path c4d:isRequired ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path c4d:isUnique ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path c4d:isMultiValued ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path c4d:defaultValue ; sh:maxCount 1 ; sh:nodeKind sh:Literal ] ;
    sh:property [ sh:path c4d:allowedValue ; sh:nodeKind sh:Literal ] ;
    sh:property [ sh:path c4d:references ; sh:maxCount 1 ; sh:class c4d:DataItem ;
                  sh:message "A field references at most one entity or field of this graph (c4d:references)." ] ;
    sh:property [ sh:path c4d:referenceLabel ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4d:isSoft ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path c4d:onDelete ; sh:maxCount 1 ; sh:in ( "cascade" "set null" "restrict" "no action" "set default" ) ;
                  sh:message "A field's c4d:onDelete is cascade, set null, restrict, no action or set default." ] ;
    sh:property [ sh:path c4d:holdsStateOf ; sh:maxCount 1 ; sh:class c4:Element ; sh:message "A field holds the state of one element: the owner of a lifecycle (c4d:holdsStateOf)." ] ;
    sh:property [ sh:path c4d:represents ; sh:maxCount 1 ; sh:nodeKind sh:IRIOrLiteral ] ;
    sh:property [ sh:path dcterms:description ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:line ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ] .

# only a field has a reference; its label and onDelete describe that reference (the validator warns otherwise)
c4s:ReferenceFromFieldShape a sh:NodeShape ;
    sh:targetSubjectsOf c4d:references ;
    sh:class c4d:Field ;
    sh:message "Only a field references an entity or a field (c4d:references); a relation has c4d:from and c4d:to." .

c4s:ReferenceDetailsShape a sh:NodeShape ;
    sh:targetSubjectsOf c4d:onDelete , c4d:referenceLabel ;
    sh:property [ sh:path c4d:references ; sh:minCount 1 ; sh:message "c4d:onDelete and c4d:referenceLabel describe the field's reference (c4d:references)." ] .

# a lifecycle: the element a field holds the state of has states (the validator warns otherwise)
c4s:HoldsStateOfShape a sh:NodeShape ;
    sh:targetObjectsOf c4d:holdsStateOf ;
    sh:property [ sh:path [ sh:inversePath dcterms:isPartOf ] ; sh:qualifiedValueShape [ sh:class c4:State ] ; sh:qualifiedMinCount 1 ;
                  sh:message "A field holds the state of an element that has states (c4:State parts)." ] .

c4s:IndexShape a sh:NodeShape ;
    sh:targetClass c4d:Index ;
    sh:property [ sh:path rdfs:label ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4d:indexFields ; sh:minCount 1 ; sh:maxCount 1 ; sh:message "An index covers a list of fields (c4d:indexFields)." ] ;
    sh:property [ sh:path ( c4d:indexFields [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:minCount 1 ; sh:class c4d:Field ;
                  sh:message "An index covers fields of this graph." ] ;
    sh:property [ sh:path c4d:isUnique ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path [ sh:inversePath c4d:hasIndex ] ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4d:Entity ;
                  sh:message "An index belongs to exactly one entity (c4d:hasIndex)." ] .

c4s:RelationShape a sh:NodeShape ;
    sh:targetClass c4d:Relation ;
    sh:property [ sh:path c4d:from ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4d:DataItem ; sh:message "A relation starts at exactly one entity or field of this graph (c4d:from)." ] ;
    sh:property [ sh:path c4d:to ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4d:DataItem ; sh:message "A relation ends at exactly one entity or field of this graph (c4d:to)." ] ;
    sh:property [ sh:path c4d:relationKind ; sh:maxCount 1 ; sh:in ( "ref" "contains" "extends" "maps" "assoc" ) ;
                  sh:message "A relation's kind is ref, contains, extends, maps or assoc." ] ;
    sh:property [ sh:path rdfs:label ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4d:fromCardinality ; sh:maxCount 1 ; sh:in ( "1" "0..1" "0..*" "1..*" "*" ) ] ;
    sh:property [ sh:path c4d:toCardinality ; sh:maxCount 1 ; sh:in ( "1" "0..1" "0..*" "1..*" "*" ) ] ;
    sh:property [ sh:path c4d:isSoft ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path dcterms:description ; sh:maxCount 1 ; sh:datatype xsd:string ] .

c4s:CardinalityPairShape a sh:NodeShape ;
    sh:targetSubjectsOf c4d:fromCardinality , c4d:toCardinality ;
    sh:property [ sh:path c4d:fromCardinality ; sh:minCount 1 ; sh:message "A relation's multiplicities come in pairs: c4d:fromCardinality and c4d:toCardinality." ] ;
    sh:property [ sh:path c4d:toCardinality ; sh:minCount 1 ; sh:message "A relation's multiplicities come in pairs: c4d:fromCardinality and c4d:toCardinality." ] .

# reads and writes: on steps and relationships, of entities and fields
c4s:DataUseShape a sh:NodeShape ;
    sh:targetClass c4:Step , c4:Relationship ;
    sh:property [ sh:path c4d:reads ; sh:class c4d:DataItem ; sh:message "A step or a relationship reads entities and fields of this graph (c4d:reads)." ] ;
    sh:property [ sh:path c4d:writes ; sh:class c4d:DataItem ; sh:message "A step or a relationship writes entities and fields of this graph (c4d:writes)." ] .

c4s:DataUseOnStepsShape a sh:NodeShape ;
    sh:targetSubjectsOf c4d:reads , c4d:writes ;
    sh:property [ sh:path rdf:type ; sh:qualifiedValueShape [ sh:in ( c4:Step c4:Relationship ) ] ; sh:qualifiedMinCount 1 ;
                  sh:message "Only a step or a relationship reads or writes data (c4d:reads, c4d:writes)." ] .

c4s:SchemaTermsShape a sh:NodeShape ;
    sh:targetSubjectsOf c4d:livesIn , c4d:schemaKind , c4d:hasEntity ;
    sh:class c4d:Schema ;
    sh:message "Only a schema lives in an element, has a schema kind, and has entities." .

#################################################################
#  View module (c4v:): what the explorer needs to redraw the diagrams
#################################################################

c4s:ModelViewShape a sh:NodeShape ;
    sh:targetClass c4:Model ;
    sh:property [ sh:path c4v:subtitle ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4v:toolbarTitle ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4v:placeholder ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path c4v:startLevel ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ; sh:maxInclusive 4 ] ;
    sh:property [ sh:path c4v:edgeStyle ; sh:maxCount 1 ; sh:in ( "orthogonal" "straight" ) ] ;
    sh:property [ sh:path c4v:theme ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4v:openElements ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:openElements [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:class c4:Element ] ;
    sh:property [ sh:path c4v:defaultPins ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:defaultPins [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:class c4:Element ] ;
    sh:property [ sh:path c4v:levelNames ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:levelNames [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4v:legendEntry ; sh:class c4v:LegendEntry ] ;
    sh:property [ sh:path c4v:dismissal ; sh:class c4v:Dismissal ] ;
    sh:property [ sh:path c4v:sourceHost ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4v:fileTemplate ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4v:dirTemplate ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4v:lineTemplate ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4v:linkLabel ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4v:base ; sh:maxCount 1 ; sh:datatype xsd:anyURI ] ;
    sh:property [ sh:path c4v:vocabulary ; sh:maxCount 1 ; sh:datatype xsd:anyURI ] ;
    sh:property [ sh:path c4v:iconStyle ; sh:maxCount 1 ; sh:in ( "mono" "brand" ) ] ;
    sh:property [ sh:path c4v:showIcons ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path c4v:iconDefinition ; sh:class c4v:IconDefinition ] ;
    # extension prefixes, declared with SHACL's own vocabulary
    sh:property [ sh:path sh:declare ; sh:class sh:PrefixDeclaration ] .

c4s:PrefixDeclarationShape a sh:NodeShape ;
    sh:targetClass sh:PrefixDeclaration ;
    sh:property [ sh:path sh:prefix ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path sh:namespace ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:anyURI ] .

c4s:DismissalShape a sh:NodeShape ;
    sh:targetClass c4v:Dismissal ;
    sh:property [ sh:path c4v:coherenceRule ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4v:focusKey ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:description ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:creator ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:date ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:pattern "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" ] ;
    sh:property [ sh:path c4v:order ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ] ;
    sh:property [ sh:path [ sh:inversePath c4v:dismissal ] ; sh:minCount 1 ; sh:class c4:Model ] .

c4s:LegendEntryShape a sh:NodeShape ;
    sh:targetClass c4v:LegendEntry ;
    sh:property [ sh:path c4v:legendKey ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path [ sh:inversePath c4v:legendEntry ] ; sh:minCount 1 ; sh:class c4:Model ] .

# order: every element, relationship, scenario and variant has its place in the model's lists
c4s:ElementViewShape a sh:NodeShape ;
    sh:targetClass c4:Element ;
    sh:property [ sh:path c4v:order ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ;
                  sh:message "An element has its position in the model (one c4v:order), so the diagrams can be redrawn." ] ;
    sh:property [ sh:path c4v:style ; sh:maxCount 1 ;
                  sh:in ( "person" "system" "container" "store" "code" "ext" "sibling" "state" "highlight" "plain" "teal" "orange" "green" "violet" "rose" "blue" "gold" "brown" ) ] ;
    sh:property [ sh:path c4v:dashed ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path c4v:column ; sh:maxCount 1 ; sh:nodeKind sh:Literal ] ;
    sh:property [ sh:path c4v:row ; sh:maxCount 1 ; sh:nodeKind sh:Literal ] ;
    sh:property [ sh:path c4v:noteList ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:noteList [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4v:technologyList ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:technologyList [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4v:variantList ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:variantList [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:class c4:Variant ] .

c4s:ColumnNeedsRowShape a sh:NodeShape ;
    sh:targetSubjectsOf c4v:column ;
    sh:property [ sh:path c4v:row ; sh:minCount 1 ; sh:message "A grid position has both c4v:column and c4v:row." ] .

c4s:RowNeedsColumnShape a sh:NodeShape ;
    sh:targetSubjectsOf c4v:row ;
    sh:property [ sh:path c4v:column ; sh:minCount 1 ; sh:message "A grid position has both c4v:column and c4v:row." ] .

c4s:RelationshipViewShape a sh:NodeShape ;
    sh:targetClass c4:Relationship ;
    sh:property [ sh:path c4v:order ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ] ;
    sh:property [ sh:path c4v:style ; sh:maxCount 1 ; sh:in ( "ink" "accent" "teal" "orange" "green" "violet" "rose" "blue" "gold" "brown" ) ] ;
    sh:property [ sh:path c4v:dashed ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path c4v:variantList ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:variantList [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:class c4:Variant ] .

c4s:ScenarioViewShape a sh:NodeShape ;
    sh:targetClass c4:Scenario ;
    sh:property [ sh:path c4v:order ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ] ;
    sh:property [ sh:path c4v:tone ; sh:maxCount 1 ; sh:in ( "teal" "orange" "green" "violet" "rose" "blue" "gold" "brown" ) ] ;
    sh:property [ sh:path c4v:preconditionList ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:preconditionList [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:datatype xsd:string ] .

c4s:StepViewShape a sh:NodeShape ;
    sh:targetClass c4:Step ;
    sh:property [ sh:path c4v:variantList ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:variantList [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:class c4:Variant ] .

c4s:VariantViewShape a sh:NodeShape ;
    sh:targetClass c4:Variant ;
    sh:property [ sh:path c4v:order ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ] ;
    sh:property [ sh:path c4v:shortName ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4v:tone ; sh:maxCount 1 ; sh:in ( "teal" "orange" "green" "violet" "rose" "blue" "gold" "brown" ) ] .

# the data module as the explorer draws it: the order of schemas, entities, indexes and relations, an entity's place in
# its schema's cluster, a schema's tint, and the order of multi-valued data fields
c4s:SchemaViewShape a sh:NodeShape ;
    sh:targetClass c4d:Schema ;
    sh:property [ sh:path c4v:order ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ;
                  sh:message "A schema has its position in the model (one c4v:order), so the Data view can be redrawn." ] ;
    sh:property [ sh:path c4v:tone ; sh:maxCount 1 ; sh:in ( "teal" "orange" "green" "violet" "rose" "blue" "gold" "brown" ) ] ;
    sh:property [ sh:path c4v:noteList ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:noteList [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4v:technologyList ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:technologyList [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:datatype xsd:string ] .

c4s:EntityViewShape a sh:NodeShape ;
    sh:targetClass c4d:Entity ;
    sh:property [ sh:path c4v:order ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ;
                  sh:message "An entity has its position in the model (one c4v:order), so the Data view can be redrawn." ] ;
    sh:property [ sh:path c4v:dashed ; sh:maxCount 1 ; sh:datatype xsd:boolean ] ;
    sh:property [ sh:path c4v:column ; sh:maxCount 1 ; sh:nodeKind sh:Literal ] ;
    sh:property [ sh:path c4v:row ; sh:maxCount 1 ; sh:nodeKind sh:Literal ] ;
    sh:property [ sh:path c4v:noteList ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:noteList [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4v:valueList ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:valueList [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:nodeKind sh:Literal ] ;
    sh:property [ sh:path c4v:definedByList ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:definedByList [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:class c4:Element ] .

c4s:FieldViewShape a sh:NodeShape ;
    sh:targetClass c4d:Field ;
    sh:property [ sh:path c4v:valueList ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:valueList [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:nodeKind sh:Literal ] .

c4s:IndexViewShape a sh:NodeShape ;
    sh:targetClass c4d:Index ;
    sh:property [ sh:path c4v:order ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ] .

c4s:RelationViewShape a sh:NodeShape ;
    sh:targetClass c4d:Relation ;
    sh:property [ sh:path c4v:order ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 1 ;
                  sh:message "A relation has its position in the model (one c4v:order)." ] .

c4s:DataUseViewShape a sh:NodeShape ;
    sh:targetClass c4:Step , c4:Relationship ;
    sh:property [ sh:path c4v:readList ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:readList [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:class c4d:DataItem ] ;
    sh:property [ sh:path c4v:writeList ; sh:maxCount 1 ] ;
    sh:property [ sh:path ( c4v:writeList [ sh:zeroOrMorePath rdf:rest ] rdf:first ) ; sh:class c4d:DataItem ] .

# icons: one reference and at most one colour on an element, a relationship, a scenario, a schema or an entity; the
# model's own icons as c4v:IconDefinition resources
c4s:IconShape a sh:NodeShape ;
    sh:targetSubjectsOf c4v:icon ;
    sh:property [ sh:path c4v:icon ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:minLength 1 ;
                  sh:message "One icon per box, arrow, scenario, schema or entity (c4v:icon): a reference such as database, si:postgresql or tabler:cloud." ] ;
    sh:property [ sh:path rdf:type ; sh:qualifiedValueShape [ sh:in ( c4:Element c4:Relationship c4:Scenario c4d:Schema c4d:Entity c4:DeploymentNode c4:InfrastructureNode ) ] ; sh:qualifiedMinCount 1 ;
                  sh:message "Only an element, a relationship, a scenario, a schema, an entity, a deployment node or an infrastructure node has an icon (c4v:icon)." ] .

c4s:IconColorShape a sh:NodeShape ;
    sh:targetSubjectsOf c4v:iconColor ;
    sh:property [ sh:path c4v:iconColor ; sh:maxCount 1 ; sh:in ( "brand" "teal" "orange" "green" "violet" "rose" "blue" "gold" "brown" ) ;
                  sh:message "An icon's colour (c4v:iconColor) is brand or a tone: teal, orange, green, violet, rose, blue, gold or brown." ] ;
    sh:property [ sh:path c4v:icon ; sh:minCount 1 ; sh:message "c4v:iconColor colours the icon (c4v:icon) of the same resource." ] .

c4s:IconDefinitionShape a sh:NodeShape ;
    sh:targetClass c4v:IconDefinition ;
    sh:property [ sh:path c4v:iconKey ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:minLength 1 ;
                  sh:message "An icon definition has exactly one key (c4v:iconKey): what a c4v:icon names." ] ;
    sh:property [ sh:path c4v:svg ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ; sh:minLength 1 ;
                  sh:message "An icon definition has exactly one SVG (c4v:svg)." ] ;
    sh:property [ sh:path rdfs:label ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:source ; sh:maxCount 1 ; sh:nodeKind sh:IRIOrLiteral ] ;
    sh:property [ sh:path dcterms:license ; sh:maxCount 1 ; sh:nodeKind sh:IRIOrLiteral ] ;
    sh:property [ sh:path [ sh:inversePath c4v:iconDefinition ] ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:Model ;
                  sh:message "An icon definition belongs to the model (c4v:iconDefinition)." ] .

#################################################################
#  Deployment
#################################################################

c4s:DeploymentEnvironmentShape a sh:NodeShape ;
    sh:targetClass c4:DeploymentEnvironment ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:identifier ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:isPartOf ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:Model ;
                  sh:message "A deployment environment is part of one model." ] .

c4s:DeploymentNodeShape a sh:NodeShape ;
    sh:targetClass c4:DeploymentNode ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:identifier ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:environment ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:DeploymentEnvironment ;
                  sh:message "A deployment node belongs to one deployment environment." ] ;
    sh:property [ sh:path c4:deployedIn ; sh:maxCount 1 ; sh:class c4:DeploymentNode ; sh:message "A deployment node is nested in at most one deployment node." ] ;
    sh:property [ sh:path c4:instances ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 2 ;
                  sh:message "c4:instances (×N) is a whole number above 1; one copy is not written." ] .

c4s:ContainerInstanceShape a sh:NodeShape ;
    sh:targetClass c4:ContainerInstance ;
    sh:property [ sh:path c4:instanceOf ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:Container ;
                  sh:message "A container instance runs exactly one container or data store of the model." ] ;
    sh:property [ sh:path dcterms:identifier ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:environment ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:DeploymentEnvironment ] ;
    sh:property [ sh:path c4:deployedIn ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:DeploymentNode ;
                  sh:message "An instance runs in exactly one deployment node." ] ;
    sh:property [ sh:path c4:instances ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 2 ] .

c4s:SoftwareSystemInstanceShape a sh:NodeShape ;
    sh:targetClass c4:SoftwareSystemInstance ;
    sh:property [ sh:path c4:instanceOf ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:SoftwareSystem ;
                  sh:message "A software system instance runs exactly one software system of the model." ] ;
    sh:property [ sh:path dcterms:identifier ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:environment ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:DeploymentEnvironment ] ;
    sh:property [ sh:path c4:deployedIn ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:DeploymentNode ] ;
    sh:property [ sh:path c4:instances ; sh:maxCount 1 ; sh:datatype xsd:integer ; sh:minInclusive 2 ] .

c4s:InfrastructureNodeShape a sh:NodeShape ;
    sh:targetClass c4:InfrastructureNode ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path dcterms:identifier ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:environment ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:DeploymentEnvironment ] ;
    sh:property [ sh:path c4:deployedIn ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:DeploymentNode ;
                  sh:message "An infrastructure node sits in exactly one deployment node." ] .

c4s:DeploymentRelationshipShape a sh:NodeShape ;
    sh:targetClass c4:DeploymentRelationship ;
    sh:property [ sh:path c4:deploymentSource ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ;
                  sh:or ( [ sh:class c4:DeploymentNode ] [ sh:class c4:InfrastructureNode ] [ sh:class c4:ContainerInstance ] [ sh:class c4:SoftwareSystemInstance ] ) ;
                  sh:message "A deployment relationship starts at one deployment node, infrastructure node or instance." ] ;
    sh:property [ sh:path c4:deploymentTarget ; sh:minCount 1 ; sh:maxCount 1 ; sh:nodeKind sh:IRI ;
                  sh:or ( [ sh:class c4:DeploymentNode ] [ sh:class c4:InfrastructureNode ] [ sh:class c4:ContainerInstance ] [ sh:class c4:SoftwareSystemInstance ] ) ;
                  sh:message "A deployment relationship ends at one deployment node, infrastructure node or instance." ] ;
    sh:property [ sh:path rdfs:label ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
    sh:property [ sh:path c4:environment ; sh:minCount 1 ; sh:maxCount 1 ; sh:class c4:DeploymentEnvironment ] .
