Extending the C4 architecture ontology¶
You will want facts the core does not have: where containers are deployed, how sensitive a data store is, who owns a component, which compliance controls apply. Add them as an extension: a small ontology of your own that builds on c4:, plus SHACL shapes, plus the rdf hook in the explorer's model. The rules below keep extensions interoperable; the worked example shows all of them.
1. Use a namespace of your own¶
Never add terms to c4: (or c4d:, c4v:). Those namespaces belong to this ontology: a term you add there could collide with a future version, and no one else's tools would know it. Mint your own namespace under a domain you control, and give it a short preferred prefix:
<https://w3id.org/acme/arch-ops> a owl:Ontology ;
owl:imports <https://caviri.github.io/c4-model-agentic-plugin/ontology/c4> ;
vann:preferredNamespacePrefix "ops" ;
vann:preferredNamespaceUri "https://w3id.org/acme/arch-ops#" .
The explorer's validator enforces it: an rdf property in c4: or c4v:, or one the export already writes from the model's own fields (rdfs:label, dcterms:*), is an error. The export never writes an rdf property in c4d: either.
2. Specialise, do not change¶
Prefer a subclass or a subproperty over changing a core term, and never redefine one. ops:Microservice rdfs:subClassOf c4:Container keeps every query over c4:Container working; a new restriction on c4:Container itself would change the meaning for everyone who loads your file.
Ask whether the specialisation is really true: make something a subproperty of c4:uses only if every use of it is a runtime interaction, because under inference every query over c4:uses will count it.
3. Label, define and source every term¶
Every class and property gets an rdfs:label and a skos:definition (with a language tag), rdfs:isDefinedBy your ontology, and a dcterms:source where the definition comes from (a standard, a document, a page). An undefined term is guessed at, and two teams will guess differently.
4. Name terms consistently¶
- Classes:
UpperCamelCasesingular nouns (DeploymentNode, notdeployment_nodes). - Properties:
lowerCamelCase; a verb phrase for relations (startsAfter,hasStep), a noun for attributes (hostPort), and an adjective oris…for booleans (isReply). - Never let a class and a property differ only in case (
Stepandstep): several tools and file systems cannot tell them apart. - Name inverse pairs so that the direction is clear (
hasStep/inScenario), and declareowl:inverseOf.
5. Domain and range infer; SHACL validates¶
rdfs:domain and rdfs:range do not check anything. If ops:owner has the domain c4:Component and someone writes it on a person, a reasoner concludes that the person is a component, without complaint. So:
- add a domain or range only where that conclusion is always right, and say so in a comment;
- put every check in SHACL shapes that you ship with the ontology (
sh:targetSubjectsOf ops:owner ; sh:class c4:Componentreports the mistake instead).
Keep the shapes to SHACL Core, and avoid sh:or, sh:and, sh:not and sh:xone if your graphs are checked with rete (0.7.4 skips them silently).
6. Reuse established vocabularies¶
Before inventing a term, look for one: Dublin Core (dcterms: for titles, creators, licences, references), schema.org, PROV-O (prov: for where things came from and who did what), DCAT (dcat: for datasets and data services), ODRL (odrl: for permissions and policies), SKOS (skos: for controlled vocabularies), FOAF and ORG (foaf:, org: for people and teams). In the rdf hook you can use them directly: rdfs, dcterms, schema, xsd are built in, others you declare.
To relate your term to someone else's, use SKOS mapping properties (skos:closeMatch, skos:broadMatch, skos:relatedMatch) or rdfs:seeAlso. Use owl:equivalentClass or owl:equivalentProperty only for terms that are the same in every situation: a reasoner merges them, with every axiom of both, and a near-equivalence produces wrong conclusions in other people's data. That is why this ontology's own links to schema.org live in alignments.ttl as SKOS mappings.
7. Choose stable IRIs¶
- An IRI is forever: data written today will still use it. Do not put a version, a branch or a hosting provider's name in the namespace if you can avoid it. A permanent redirect service such as w3id.org (or purl.org) lets you move the documents later without changing the IRIs, and can serve Turtle or HTML depending on what the client asks for.
- Hash or slash. A hash namespace (
…/ops#Microservice) puts all terms in one document, fetched whole; good for a small vocabulary. A slash namespace (…/ops/Microservice) gives each term its own URL; better for large vocabularies, but it needs a server that answers every term (with a 303 redirect or content negotiation). - Make the namespace resolve to something useful: at least the Turtle file, ideally a page that documents each term at its anchor.
8. Version and deprecate¶
owl:versionInfo "1.2.0"on the ontology, with semantic versioning: a new term is a minor version, a changed meaning or a removed term a major one.owl:versionIRI <https://w3id.org/acme/arch-ops/1.2.0>for each release, and keep that release's file published there, so that a graph can say exactly which version it used (dcterms:conformsTo).- Do not delete or reuse terms. Mark a replaced one
owl:deprecated truewithdcterms:isReplacedByits successor, keep it for at least one minor version, and list the change in a changelog or rename table.
9. Ship shapes, and use the hook¶
An extension is three things: the ontology file, a shapes file, and the model fields that produce the data. In the explorer's model, declare your prefix once and put an rdf object on any node, edge, scenario, schema, entity or relation (see the explorer's data model and RDF graph references). The terms go into every export (JSON-LD, Turtle, N-Triples, .rete) as written, and come back out when a page is recreated from the graph. Check the result with both shape files: pyshacl -s c4-shapes.ttl -s your-shapes.ttl -df turtle architecture.ttl.
Worked example: deployment and data classification¶
examples/deployment.ttl adds deployment facts and data classification to the example project, using only what its docker-compose.yml and database schema say. examples/deployment-shapes.ttl checks them.
| Term | Kind | What |
|---|---|---|
dep:ObjectStore |
class, rdfs:subClassOf c4:DataStore |
S3-like storage (rule 2: a subclass, not a change) |
dep:serviceName |
datatype property | the unit that deploys a container: a Compose service, a Kubernetes Deployment |
dep:hostPort |
datatype property, xsd:integer |
a port published on the host |
dep:startsAfter |
object property, container → container | start-up order (Compose depends_on); deliberately not a subproperty of c4:uses (rule 2) |
dep:protocol |
datatype property on c4:Relationship |
the wire protocol as deployed |
dep:classification |
object property, data store → dep:DataClassification |
dep:Public, dep:Internal or dep:Confidential |
The model fields. Added to the example's model.js (the rest of each node unchanged):
rdf: { prefixes: { dep: 'https://example.org/ontology/deployment#' } },
{ id: 'web', /* … */ rdf: { 'dep:serviceName': 'web', 'dep:hostPort': 3000, 'dep:startsAfter': { '@id': ':api' } } },
{ id: 'api', /* … */ rdf: { 'dep:serviceName': 'api', 'dep:hostPort': 8000,
'dep:startsAfter': [{ '@id': ':postgres' }, { '@id': ':redis' }, { '@id': ':minio-init' }] } },
{ id: 'worker', /* … */ rdf: { 'dep:serviceName': 'worker',
'dep:startsAfter': [{ '@id': ':postgres' }, { '@id': ':redis' }, { '@id': ':minio-init' }] } },
{ id: 'postgres', /* … */ rdf: { 'dep:serviceName': 'postgres', 'dep:hostPort': 5432,
'dep:classification': { '@id': 'dep:Confidential' } } }, // users.password_hash
{ id: 'redis', /* … */ rdf: { 'dep:serviceName': 'redis', 'dep:hostPort': 6379, 'dep:classification': { '@id': 'dep:Internal' } } },
{ id: 'minio', /* … */ rdf: { 'rdf:type': { '@id': 'dep:ObjectStore' }, 'dep:serviceName': 'minio',
'dep:hostPort': [9000, 9001], 'dep:classification': { '@id': 'dep:Internal' } } },
{ id: 'minio-init', /* … */ rdf: { 'dep:serviceName': 'minio-init', 'dep:startsAfter': { '@id': ':minio' } } },
// edges
{ from: 'minio-init', to: 'minio', label: 'creates buckets', dashed: true, rdf: { 'dep:protocol': 'S3 API' } },
// scenarios: reuse Dublin Core rather than inventing a term (rule 6)
{ id: 'export', /* … */ rdf: { 'dcterms:references': { '@id': 'https://cocodataset.org/#format-data' } } }
{ '@id': ':api' } points at the node api of the same model; { '@id': 'dep:Confidential' } at a term of the extension; a plain value is a literal; a list gives one triple per value.
The exported Turtle (excerpt of architecture.ttl; the export declares the prefix with SHACL's own vocabulary, so the way back knows it):
@prefix dep: <https://example.org/ontology/deployment#> .
@prefix : <urn:architecture:image-annotation-tool:> .
:prefix:dep a sh:PrefixDeclaration ;
sh:prefix "dep" ;
sh:namespace "https://example.org/ontology/deployment#"^^xsd:anyURI .
:minio a c4:Element, c4:Container, c4:DataStore, dep:ObjectStore ;
rdfs:label "MinIO" ;
c4:level 2 ;
dcterms:isPartOf :iat ;
dep:serviceName "minio" ;
dep:hostPort 9000, 9001 ;
dep:classification dep:Internal .
:api a c4:Element, c4:Container ;
rdfs:label "API service" ;
dep:serviceName "api" ;
dep:hostPort 8000 ;
dep:startsAfter :postgres, :redis, :minio-init .
:rel:69 a c4:Relationship ;
c4:source :minio-init ;
c4:target :minio ;
rdfs:label "creates buckets" ;
c4v:dashed true ;
dep:protocol "S3 API" .
The graph conforms to c4-shapes.ttl and examples/deployment-shapes.ttl together, and a page recreated from it carries the same rdf fields.
A query over it. Which published ports lead to confidential data, directly or through a container that uses it?
PREFIX c4: <https://caviri.github.io/c4-model-agentic-plugin/ontology/c4#>
PREFIX dep: <https://example.org/ontology/deployment#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT DISTINCT ?store ?service ?port
WHERE {
?s dep:classification dep:Confidential ; rdfs:label ?store .
{ ?part dcterms:isPartOf* ?c ; c4:uses ?s . } UNION { ?s dep:serviceName ?x . BIND(?s AS ?c) }
?c dep:serviceName ?service ; dep:hostPort ?port .
}
ORDER BY ?store ?service ?port
| store | service | port |
|---|---|---|
| PostgreSQL | api | 8000 |
| PostgreSQL | postgres | 5432 |
The second row is a finding: the database is published on the host as well as reachable through the API.
Extending the data module¶
The data module (c4-data.ttl, c4d:) describes schemas, entities, fields and relations in general terms, so that a PostgreSQL schema, a JSON Schema and an ontology can be drawn and queried together. What is particular to your stores or your organisation goes in your own namespace, by the same rules.
An entity kind of your own. The kinds (c4d:entityKind: table, view, class, object, enum, collection, document, bucket, message, type) are a closed list that the validator and the shapes check, so do not invent a new value. Give the entity the closest kind and add a subclass of your own through the rdf hook (rule 2):
ops:MaterializedView a owl:Class ;
rdfs:subClassOf c4d:View ;
rdfs:label "Materialized view"@en ;
skos:definition "A view whose rows the database stores and refreshes on demand."@en ;
rdfs:isDefinedBy <https://w3id.org/acme/arch-ops> .
{ id: 'task-stats', schema: 'pg', name: 'task_stats', kind: 'view', rdf: { 'rdf:type': { '@id': 'ops:MaterializedView' } }, fields: [ /* … */ ] }
The export types it c4d:DataItem, c4d:Entity, c4d:Table, c4d:View, ops:MaterializedView; every query over tables and views still finds it, and the page draws it as a view.
Facts about schemas, entities and relations. The rdf hook works on them as on nodes: classification, owner, retention.
{ id: 'users', schema: 'pg', name: 'users', /* … */ rdf: { 'dep:classification': { '@id': 'dep:Confidential' } } }
A team's own data dictionary: link, do not copy. Many teams keep a data dictionary or a business glossary (in a catalogue, as SKOS concepts, as a DCAT catalogue). Do not repeat its definitions in the model: point each entity and field at its term with iri (c4d:represents), and keep the dictionary in its own graph. Fields have no rdf hook on purpose: what a field means lives in the dictionary, what the store does with it (type, key, reference) lives here.
{ name: 'email', type: 'TEXT', required: true, unique: true, iri: 'https://dict.example.org/terms/person-email' }
# the dictionary, maintained elsewhere (SKOS)
<https://dict.example.org/terms/person-email> a skos:Concept ;
skos:prefLabel "Person e-mail address"@en ;
dict:personalData true .
Loaded together, one query answers "which columns, in which stores, hold personal data, and which steps write them":
PREFIX c4d: <https://caviri.github.io/c4-model-agentic-plugin/ontology/c4-data#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dict: <https://dict.example.org/ns#>
SELECT ?store ?entity ?field ?step
WHERE {
?f c4d:represents ?term ; rdfs:label ?field ; c4d:inEntity ?e .
?term dict:personalData true .
?e rdfs:label ?entity ; c4d:inSchema/c4d:livesIn/rdfs:label ?store .
OPTIONAL { ?s c4d:writes ?f ; rdfs:label ?step }
}
When the dictionary is the schema (an ontology or a JSON-LD context of your own), describe it as a schema of kind ontology or other with its namespace, its classes as entities and its properties as fields, each with its iri, and link the tables that store them with maps relations: the Data view then draws the vocabulary next to the tables, and the graph says which table stores which class.
Shapes. A shape of yours that targets c4d: classes (every c4d:Table of a schema in a confidential store has an owner, say) goes in your shapes file, next to c4-shapes.ttl; never edit c4-shapes.ttl itself.
Source
This page is ontology/EXTENDING.md in the repository.