Skip to content

The stories as an RDF graph

Optional. A user stories page can also be written as an RDF graph, in the terms of the user stories module of the plugin's C4 ontology (c4us:, ${CLAUDE_PLUGIN_ROOT}/ontology/c4-stories.ttl, published with its term reference at https://caviri.github.io/c4-model-agentic-plugin/ontology/c4-stories/), linked into the architecture graph the explorer exports: a story's actor is the explorer's person, its journey the explorer's scenario and steps, and a screen points at the step where it is seen. Load the two graphs together and SPARQL answers questions neither answers alone: which stories touch this container, which code backs the most stories, which screens a step shows.

Nothing else in the skill needs the graph. Make it when the user asks for RDF, a knowledge graph, .rete, or the stories next to the architecture graph.

Making it

Where What it writes
build-stories.mjs … --rdf stories.jsonld, stories.ttl and stories.rete (when a builder is found) next to the page, after building it
stories-rdf.mjs <page> [--out dir] the same, from a page already built (or a story downloaded from it)
stories-rdf.mjs <page> --with-feedback [--notes files…] stories-and-feedback.*: the stories and the readers' notes (those inside the page, and those in story files or feedback JSON)
build-stories.mjs … --notes files… --rdf --with-feedback the page with the notes inside, and stories-and-feedback.*
extract-feedback.mjs <pages, JSON> --out dir --rdf with the usual feedback files, stories-and-feedback.* in that folder
the page: Download ▾ → Stories as an RDF graph <project>-stories.jsonld, in the browser
the page: Download ▾ → Stories and feedback as an RDF graph <project>-stories-and-feedback.jsonld: every note the browser holds for the page
node "${CLAUDE_PLUGIN_ROOT}/skills/user-stories/scripts/stories-rdf.mjs" \
  communications/user-stories/index.html [--out dir] [--with-feedback] [--notes files…] [--model model.js] [--no-rete] [--check]
  • The graph is made from the page's data (its STORIES and NOTES blocks, read as data; nothing in the page runs) by the mapping inside the plugin's own template, the same code the page's Download menu runs: the two give the same triples.
  • --model (default: ../architecture-explorer/model.js from the page) checks that every architecture IRI the stories point at is in the explorer's graph, and that the page uses that graph's base. A link that does not resolve is an error: rebuild the page with build-stories.mjs after changing the model. Without a model, the links are not checked (a warning says so).
  • .rete: the rete CLI (which adds a dataset card), else the rete-graph npm package wherever it resolves (the working directory, the output folder, the plugin's mcp/); otherwise skipped with the command to run. --no-rete skips it.
  • --check builds and checks, and writes nothing.
  • The output is deterministic: no clock, notes oldest first. The same page gives the same bytes.

Feedback is people's words

A stories graph holds notes only when asked (--with-feedback, or the page's second RDF download), in files of their own (stories-and-feedback.*), and says so: c4us:withFeedback true on the collection. Notes carry the reader's name as they typed it, their comment, their pins and, when they turned transcription on, the transcript of their voice. The audio itself is never in a graph: only that there is one, its length and its file name (audio/<note>.<ext>, as extract-feedback.mjs writes it). The drawing is not in it either, only the number of marks and the pins.

Ask the user before committing a feedback graph or publishing it anywhere; the stories graph alone has nobody's words but the project's.

The IRIs

The stories use the base of the architecture graph (MODEL.rdf.base, else the repository URL with #, else urn:architecture:<project>:), which build-stories.mjs writes into the page as STORIES.rdf.base together with the model's IRI. Their own resources carry a kind, as the explorer's do, so they never collide with an element's IRI (<base><id>):

Resource IRI
the collection <base>stories:<page key>
a persona <base>persona:<id>
a story <base>story:<id>
an acceptance criterion <base>criterion:<story>:<n>
a code reference <base>evidence:<story>:<n>
a screen <base>screen:<story>:<screen id>
a view of a screen <base>screenview:<story>:<screen id>:<view>
a note <base>note:<note id>
a pin <base>pin:<note id>:<n>
links into the architecture <base><person id>, <base>scenario:<id>, <base>step:<scenario id>:<n>, <base>model:<project> (as in references/rdf-graph.md of the explorer skill)

Ids are percent-encoded (encodeURIComponent), n counts from 1. A page built without a model gets urn:stories:<page key>: and no links into an architecture.

The mapping

Collection (c4us:StoryCollection): rdfs:label the project, dcterms:identifier the page key, dcterms:description the summary, dcterms:conformsTo the module, c4us:architecture the explorer's c4:Model, c4us:withFeedback, c4us:persona its personas, dcterms:hasPart its stories, c4us:hasNote its notes; rdfs:seeAlso the explorer when STORIES.explorer is a full URL.

Persona (c4us:Persona), one per persona the page has (those of stories.js, then the model's people who are actors): rdfs:label, dcterms:identifier, dcterms:description, one c4us:personaGoal per goal, schema:position, and c4us:portrays the explorer's c4:Person when the id is a person of the model.

Story (c4us:UserStory):

stories.js triples
id, title dcterms:identifier, rdfs:label; schema:position its place on the page; dcterms:isPartOf the collection
actor c4us:actor: the model's person (<base><id>), else the persona; and c4us:persona the persona when there is one
want, soThat c4us:want, c4us:soThat
status, notes, tags c4us:status, c4us:note, one schema:keywords per tag
scenario, steps c4us:scenario the explorer's scenario; c4us:firstStep, c4us:lastStep and one c4us:coversStep per step of the range, the explorer's steps
goal, trigger, preconditions, outcome c4us:goal, c4us:trigger, one c4us:precondition each, c4us:outcome: only those the story gives itself. A story that covers its whole scenario shows that scenario's, which the architecture graph has (c4:goal …)
acceptance one c4us:AcceptanceCriterion each (c4us:acceptanceCriterion): c4us:statement, schema:position, and when it reads Given …, when …, then … its parts as c4us:given, c4us:when, c4us:then
source one c4us:CodeReference each (c4us:evidence): c4:path, c4:line, rdfs:label, schema:position, rdfs:seeAlso the line in the repository's web view
screens one c4us:Screen each (c4us:screen, below)

Screen (c4us:Screen): dcterms:identifier its id, rdfs:label its title when it has one, schema:position its number on the page (in the order of the journey), c4us:seenAtStep the explorer's step, c4us:screenKind, c4us:illustrative (only when true), and one c4us:ScreenView per view (c4us:hasView; the screen's own picture is also c4us:defaultView).

Screen view (c4us:ScreenView): c4us:viewName, schema:position, schema:contentUrl (an http(s) IRI, or a path relative to stories.js as an xsd:anyURI literal; nothing for a data: URL), schema:caption, c4us:altText, c4us:pixelWidth, c4us:pixelHeight. It is not a schema:ImageObject, so the explorer's image shapes do not apply to it.

Note (c4us:Note), only with feedback: dcterms:identifier, dcterms:isPartOf the collection, c4us:aboutStory, c4us:onScreen, c4us:onView (the view it was drawn on; its default view when it names none), dcterms:creator the name typed, dcterms:created and dcterms:modified (xsd:dateTime), c4us:noteStatus (open, resolved), c4us:comment, c4us:markCount, one c4us:Pin per pin (c4us:pin: schema:position its number, c4us:x and c4us:y as xsd:decimal fractions of the view's picture, c4us:pinText), c4us:hasRecording true, c4us:recordingDuration (seconds, xsd:decimal) and c4us:recordingFile when there is a voice note, and c4us:transcript (one line per phrase, [m:ss.s] text). Deleted notes, and notes for a story the page does not have, are left out.

Validate

pyshacl -s ontology/c4-stories-shapes.ttl -df turtle communications/user-stories/stories.ttl

${CLAUDE_PLUGIN_ROOT}/ontology/c4-stories-shapes.ttl is SHACL Core without logical constraints, so rete checks it too. It checks a stories graph on its own: the links into the architecture only need to be IRIs there; stories-rdf.mjs checks that they resolve. The merged graph (architecture and stories) still conforms to c4-shapes.ttl.

Queries

Load the architecture graph and the stories graph together. Prefixes:

PREFIX c4:      <https://caviri.github.io/c4-model-agentic-plugin/ontology/c4#>
PREFIX c4us:    <https://caviri.github.io/c4-model-agentic-plugin/ontology/c4-stories#>
PREFIX rdfs:    <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX schema:  <https://schema.org/>

The stories that touch a container: a step they cover starts or ends in it, or in a part of it (all six of the example's touch the API service):

SELECT DISTINCT ?title WHERE {
  ?story a c4us:UserStory ; rdfs:label ?title ; c4us:coversStep ?step .
  ?step c4:source|c4:target ?el .
  ?el dcterms:isPartOf* ?box .
  ?box dcterms:identifier "api" .
} ORDER BY ?title

Each story: who it is for, its scenario and range, and how many criteria (Approve a task | Reviewer | Review: reject, rework, approve | 25 | 30 | 6):

SELECT ?title ?actor ?scenario ?first ?last (COUNT(DISTINCT ?c) AS ?criteria) WHERE {
  ?story a c4us:UserStory ; rdfs:label ?title ; c4us:actor ?a .
  ?a rdfs:label ?actor .
  OPTIONAL { ?story c4us:scenario/rdfs:label ?scenario ;
                    c4us:firstStep/schema:position ?first ; c4us:lastStep/schema:position ?last . }
  OPTIONAL { ?story c4us:acceptanceCriterion ?c . }
} GROUP BY ?title ?actor ?scenario ?first ?last ORDER BY ?title

The screens, the step where each is seen, and their views (annotate-next | s1 | 15 | Annotator | AnnotatePage | Submit for review | desktop, phone):

SELECT ?story ?screen ?n ?from ?to ?label (GROUP_CONCAT(?view; separator=", ") AS ?views) WHERE {
  ?s c4us:screen ?sc ; dcterms:identifier ?story .
  ?sc dcterms:identifier ?screen ; c4us:seenAtStep ?step ; c4us:hasView/c4us:viewName ?view .
  ?step schema:position ?n ; c4:source/rdfs:label ?from ; c4:target/rdfs:label ?to .
  OPTIONAL { ?step rdfs:label ?label }
} GROUP BY ?story ?screen ?n ?from ?to ?label ORDER BY ?story ?n

The files that back the most stories (api/app/routes/tasks.py | 3):

SELECT ?path (COUNT(DISTINCT ?story) AS ?stories) WHERE {
  ?story c4us:evidence/c4:path ?path .
} GROUP BY ?path ORDER BY DESC(?stories) ?path LIMIT 5

With feedback: the open notes, with their story, view, author and number of pins:

SELECT ?story ?view ?author ?comment (COUNT(?pin) AS ?pins) WHERE {
  ?note a c4us:Note ; c4us:noteStatus "open" ; c4us:aboutStory/dcterms:identifier ?story ; dcterms:creator ?author .
  OPTIONAL { ?note c4us:comment ?comment }
  OPTIONAL { ?note c4us:onView/c4us:viewName ?view }
  OPTIONAL { ?note c4us:pin ?pin }
} GROUP BY ?story ?view ?author ?comment

Every query above was run on the example's graphs (examples/image-annotation-tool/communications/architecture-explorer/architecture.ttl with user-stories/stories.ttl).


Source

This page is skills/user-stories/references/stories-graph.md, the guide the skill reads while it works. Edit it there; the documentation includes it as is. Terms: User stories terms (c4us:). Overview: User stories and feedback.