Skip to content

Schemas and data

The map shows what runs and what talks to what. The Data tab shows what the system keeps and passes around: database tables, JSON files and API payloads, ontology classes, JSON-LD terms, object-store keys and queue messages, in one diagram drawn like a database diagram. Each card is a table, a class, an object, a bucket or a message, with a row per field. Lines join fields: the column that holds an identifier to the field it identifies, also when the two live in different stores. Every schema sits in a box of the map, and every scenario step says which fields it reads and writes.

Open the Data view in the live example

The Data view of the example: seven schemas as tinted frames (PostgreSQL schema, Annotation vocabulary, Task JSON-LD context, API JSON payloads, MinIO buckets, COCO export file, RQ job messages), each table, class, object, bucket and message as a card with a row per field, lines between the fields, and the panel listing the schemas and how to read the lines

The example's data layer: 7 schemas, 30 entities, 140 fields. With nothing selected, the panel lists the schemas, where each one lives, and how to read the lines.

Why one diagram

A system rarely keeps its data in one place, and the links between its stores are written in code, not in any schema file. In the example, an image annotation tool:

  • images.storage_key in PostgreSQL is the key of an object in the MinIO bucket images;
  • the export job that goes through Redis carries exports.id as its argument;
  • the COCO file the worker writes copies images.id into image.id and annotations.id into annotation.id;
  • the table annotations stores what the project's domain ontology calls iat:Annotation, and a JSON-LD context maps the API's task JSON to the same vocabulary.

No store enforces any of these, and no single schema file states them. The Data view draws them all, dashed where nothing enforces them, and ties each schema to the rest of the model:

  • Where it lives. A schema names the box it lives in: a data store, a container or a component (in PostgreSQL, in API service). Its frame says so, and that box on the map carries a data badge.
  • Where it is defined. A table, object or message names the code that defines or maps it (the ORM model, the serialiser, the job that writes the file) and its source file and line.
  • Where it is used. Scenario steps and arrows list the entities and fields they read and write. A table's panel gathers them per flow and step, and the flows can be painted over the tables.
  • What its values mean. A status column can point at the state machine whose states its values are (tasks.status → the task lifecycle).

The example's data layer, all taken from its code:

Schema Kind Lives in Entities Defined in
PostgreSQL schema relational, SQL PostgreSQL 6 tables db/migrations/001_init.sql
MinIO buckets object store MinIO 3 buckets docker-compose.yml (the buckets) and the code that builds each key
RQ job messages queue Redis 2 messages api/app/queue.py
COCO export file JSON Schema MinIO 4 objects schemas/coco-export.schema.json
API JSON payloads API API service 5 objects the routers' *_to_dict() functions
Annotation vocabulary ontology, OWL the system (no service loads it) 9 classes schemas/annotation-vocabulary.ttl
Task JSON-LD context JSON-LD context API service 1 document schemas/task.context.jsonld

That is 30 entities with 140 fields, 34 field references (18 of them across schemas, all soft), 41 relations (31 maps, 7 contains, 3 extends), and reads / writes on 45 of the 93 scenario steps and on 7 arrows.

Reading the diagram

  • Frames are schemas, tinted by kind (relational blue, ontology violet, JSON Schema and queue gold, document and API teal, object store brown) or by the schema's own color. The title gives the kind, the format, the count, the name and where it lives: RELATIONAL · SQL · 6 TABLES, PostgreSQL schema in PostgreSQL.
  • Cards are entities: the kind (TABLE, CLASS, OBJECT, BUCKET, MESSAGE, ENUM, DOCUMENT), the name, then one row per field in source order. Badges mark the identifier (PK), a reference (FK, with a dashed outline when it is soft) and a unique field (UQ); the type follows in monospace, with [] for a list and {5} when the field has five allowed values. An enum lists its values. A name or type too long for the card is cut with "…"; the tooltip and the panel show it whole.
  • Lines start at a field's row and end at the row it identifies (or at the card's header when it names the whole entity). With nothing selected the panel shows this legend:
Line Means
crow's foot at one end, two bars at the other a reference: any number of rows hold the identifier of exactly one row; a circle means zero is allowed
dashed soft: the store does not enforce it (a key into another store, an id copied into a file, a job argument)
hollow triangle extends: a subclass, allOf, inheritance
filled diamond contains: a part, a nested object, the file inside a bucket
dotted, no ends maps: the same thing in another schema (a table and its ontology class, a JSON key and its property)
open arrow an association (an object property), named on the line
  • Lines drawn always or on demand. The lines buttons choose which kinds are always drawn: refs, contains · extends and maps. By default references, contains and extends are, and maps lines only where one of their ends is selected, under the pointer, or touched by a flow that is on. That keeps the overview readable when many tables have a class or a JSON-LD term of their own. J draws every line, and again goes back. The cards never move when this changes.
  • Keys only (K) keeps the identifiers, references, unique fields and every field a line ends at, and says how many others each card hides. For large schemas.
  • Layout is automatic: inside a schema, a referenced table stands left of the tables that point at it, rows line up with the rows they join, and lines run in the gutters, never across a card. at: [column, row] on every entity of a schema places them by hand.

Select a table, follow a field

Click a card: it, the cards it joins and the lines between them stay bright, with the rows those lines end at marked, and the rest fades. Ctrl / Cmd / Shift + click adds a card to the selection; a double-click zooms to a card and what it joins. Click a row to follow one field: it, and the fields it references or that reference it. Click a line for its two ends, a frame's title for the schema; Esc clears.

The tasks table selected in the Data view: it, the images, users, annotations and reviews tables it joins and the lines between them stay bright, exports fades; the panel shows tasks with its description, its Location (schema PostgreSQL schema, lives in Image Annotation Tool › PostgreSQL, defined in ORM models + session), its source line and its fields

The table tasks selected. The panel starts with its Location: the schema, the box it lives in and the code that defines it, each a button to that box on the map. Then its source line (db/migrations/001_init.sql:23) and its fields, each with its key, default, allowed values, reference and lifecycle.

The panel of an entity has its schema, kind and description; Location; the source link; Fields; indexes; Points at and Pointed at by (every line, with its kind, label and cardinality); and Used in.

The images table selected, its panel scrolled to Used in: the steps of the four flows that read or write it, each flow in its colour, with the step number, its label, what it reads or writes and between which boxes

The table images, its panel scrolled to Used in: per flow, in the flow's colour, every step that reads or writes the table, with the step number, the fields (writes thumbnail_key, width, height) and from which box to which. A click opens the Dynamic view on that step. Arrows that read or write it are listed too.

A field's panel has the same for one row, plus its Lifecycle when its values are a state machine's states: tasks.status lists Task lifecycle and its five states, as buttons to the map.

Flows on the data

flows ▾ (W) works in the Data view as it does on the map. Each scenario that is on paints what its steps read and write, in its colour: a ring around a card a step reads or writes whole, a tint and a bar on each row it touches, and chips with the step numbers at the end of the row: 7W step 7 writes it, 12R step 12 reads it, 7W·14R both. With nothing selected, what the flows touch stays bright. The Data view has its own legend: the steps with data per flow, Dynamic › to open the flow, × to turn it off.

The upload flow (blue) and the export flow (teal) painted on the PostgreSQL schema: rings around images, tasks and exports, chips with step numbers such as 7W, 12R, 17W and 11R·14R on the rows, and the flows legend at the top

The upload flow (blue) and the export flow (teal) on the PostgreSQL schema (#view=data&flows=upload,export&dzoom=pg). Step 8 of the upload inserts rows into images and tasks (8W on their headers); step 17 writes the thumbnail's key and size. The export inserts its row in exports at step 4 (4W), updates its status at steps 10 and 15, and reads annotations at step 12.

The same links show from the other side:

  • A box that a schema lives in carries a data badge on the map: a table glyph and the number of entities, in the schema's colour. A click opens the Data view on that schema. Its panel has a Data section with its schemas and entities, and a box whose code defines entities lists them under Defines or maps.
  • A Dynamic step that reads or writes data lists it as chips (W images.thumbnail_key) in the panel, in the panel of the sequence inside a box, and in a Data column of the step table. A chip opens the Data view on that field.
  • Search (/) finds entities (by name, id, kind or IRI) and fields (by name, type, IRI or entity.field); in the Data view they are listed first.
  • export ▾ → This view saves the whole Data view as SVG, PNG or an HTML page.
Key Action
A The Data view (only when the model has entities)
K Keys only
J Every line, or back to the default (maps lines on demand)
W The flows menu: paint scenarios on the data
F, +, - Fit, zoom in, zoom out
Esc Clear the selection

The URL keeps the state, so any view of the data can be linked:

Parameter Meaning
view=data The Data view (#data alone works too)
entity=tasks, entity=a,b The entities selected (the last one is the primary)
field=tasks.status One field selected
schema=pg, line=f:images.uploaded_by, line=r:3 A schema, or a line: a field's reference, or relations[3]
keys=1 Keys only
lines=all, lines=refs,maps, lines=none The kinds of line drawn always (refs, struct for contains and extends, maps)
dzoom=pg Open zoomed to that schema or entity instead of fitted
flows=upload,export Scenarios painted on the data

For example #view=data&field=tasks.status or #view=data&flows=upload,export&dzoom=pg on the live example.

Write the data layer

The Data tab appears when the model has entities. Three optional arrays describe the data, and two optional fields on steps and arrows link it to the flows:

schemas: [
  { id: 'pg', name: 'PostgreSQL schema', kind: 'relational', format: 'sql', in: 'postgres',
    path: 'db/migrations/001_init.sql', desc: '…' }
],
entities: [
  { id: 'tasks', schema: 'pg', name: 'tasks', code: 'models', path: 'db/migrations/001_init.sql', line: 23,
    fields: [
      { name: 'id', type: 'SERIAL', pk: true },
      { name: 'image_id', type: 'INTEGER', required: true, unique: true, ref: 'images.id', onDelete: 'cascade' },
      { name: 'status', type: 'TEXT', required: true, default: "'pending'",
        values: ['pending', 'in_progress', 'submitted', 'approved', 'rejected'], states: 'lifecycle' }
    ],
    indexes: [{ name: 'tasks_status_idx', fields: ['status', 'created_at'] }] },
  { id: 'images', schema: 'pg', name: 'images', code: 'models', fields: [
    { name: 'id', type: 'SERIAL', pk: true },
    { name: 'storage_key', type: 'TEXT', required: true,
      ref: 'bucket-images.key', refLabel: 'object key', soft: true } ] }   // a key in MinIO
],
relations: [{ from: 'tasks', to: 'iat-task', kind: 'maps' }],   // the table and the ontology class it stores

// on a scenario step
{ from: 'thumb', to: 'postgres', label: 'UPDATE images: thumbnail_key, w, h',
  writes: ['images.thumbnail_key', 'images.width', 'images.height'] }
  • schemas[]: a data model and the box it lives in. kind is relational, document, json-schema, ontology, object-store, queue, api or other.
  • entities[]: tables, views, classes, objects, enums, collections, documents, buckets, messages, with their fields in source order. code names the boxes that define or map them; iri the ontology class or JSON Schema $id.
  • fields[]: type as written, pk, required, unique, many, default, values; ref to the entity or field whose identifier it holds (soft: true when nothing enforces it); states to a lifecycle box.
  • relations[]: what is not one field's reference: contains (nesting), extends (inheritance), maps (the same thing in another schema), assoc, or a composite ref, with optional cardinalities.
  • reads and writes, on steps and arrows: '<entity>' for whole rows or objects, '<entity>.<field>' for what a statement names.

The data model reference has every field, and how to model each kind of source: SQL and ORMs, JSON Schema and OpenAPI, OWL / RDFS / SHACL, JSON-LD contexts, object stores, queues, document stores and GraphQL. When it explores a project, Claude asks which schemas matter, whether internal tables belong in the diagram, and how to treat sensitive columns. It records structure only: tables, fields, types, constraints and allowed values, never rows, sample values or secrets.

Import schema files

import-schema.mjs turns schema files into the three arrays, with path and line filled in:

Input Read as
*.sql, *.ddl SQL DDL: PostgreSQL first, MySQL and SQLite tolerated. Several files are migrations, applied in order (ALTER TABLE, renames)
*.json, *.yaml JSON Schema (2020-12, 2019-09, draft-07, draft-04) or OpenAPI 3 / Swagger 2, told apart by content. YAML needs the yaml or js-yaml npm package
*.ttl, *.nt OWL and RDFS ontologies, SHACL shapes, SKOS concept schemes (built-in reader, with line numbers)
*.jsonld a JSON-LD context (a document entity with a field per term), or a JSON-LD ontology (needs rete-graph or jsonld)

On the example's migration, from examples/image-annotation-tool:

$ node ../../skills/architecture-explorer/scripts/import-schema.mjs db/migrations --in postgres > data-layer.js
SCHEMA   db · relational (sql, PostgreSQL) · in postgres · 6 tables · 40 columns · 7 refs · 3 indexes · from db/migrations/001_init.sql
  users                    4 columns    pk id · role ∈ 3
  images                   9 columns    pk id · ref uploaded_by → users.id
  tasks                    6 columns    pk id · ref image_id → images.id (cascade), assignee_id → users.id · status ∈ 5 · 1 index
  annotations              8 columns    pk id · ref task_id → tasks.id (cascade) · 1 index
  reviews                  6 columns    pk id · ref task_id → tasks.id (cascade), reviewer_id → users.id · decision ∈ 2 · 1 index
  exports                  7 columns    pk id · ref requested_by → users.id · status ∈ 4
LINKS    0 relations

The summary goes to stderr; the fragment, to paste into window.MODEL, to stdout:

  // Data layer imported by import-schema.mjs from db/migrations/001_init.sql:
  // node ../../skills/architecture-explorer/scripts/import-schema.mjs db/migrations --in postgres
  // Paste into window.MODEL = { … }; then add `code` (ORM classes), `states` (lifecycle boxes) and step reads / writes by hand.
  schemas: [
    { id: 'db', name: 'PostgreSQL schema', kind: 'relational', format: 'sql', in: 'postgres', tech: 'PostgreSQL', path: 'db/migrations/001_init.sql',
      desc: 'Initial schema for the image annotation tool.' },
  ],
  entities: [
    …
    { id: 'tasks', schema: 'db', name: 'tasks', path: 'db/migrations/001_init.sql', line: 23,
      desc: 'One task per image. The task status is the annotation lifecycle.',
      fields: [
        { name: 'id', type: 'SERIAL', pk: true, line: 24 },
        { name: 'image_id', type: 'INTEGER', required: true, unique: true, ref: 'images.id', onDelete: 'cascade', line: 25 },
        { name: 'assignee_id', type: 'INTEGER', ref: 'users.id', line: 26 },
        { name: 'status', type: 'TEXT', required: true, default: "'pending'", values: ['pending', 'in_progress', 'submitted', 'approved', 'rejected'],
          line: 27 },
        …

Several files in one run make one fragment, and the importer finds the links between them as maps relations: a JSON-LD context term whose IRI is an imported property or class, a JSON Schema $id equal to a class IRI, a maps: iat:Annotation marker in an SQL comment (or x-maps in a JSON Schema), and with --match-names equal names. --in takes a value per schema:

$ node ../../skills/architecture-explorer/scripts/import-schema.mjs db/migrations schemas/annotation-vocabulary.ttl \
    schemas/task.context.jsonld schemas/coco-export.schema.json \
    --in sql=postgres --in ttl=iat --in context=api --in json=minio > data-layer.js
…
SCHEMA   task-context · other (jsonld-context) · in api · 1 document · 16 fields · 1 ref · 11 relations · from schemas/task.context.jsonld
  document task.context.jsonld  16 fields     ref status → iat-task-status · status ∈ 5
…
LINKS    17 relations · 11 maps by IRI · 5 more would match an ontology class by name (--match-names)

What no file says is added by hand (or by Claude): in where it was not given, code, states, the soft references across stores, the maps between a table and its class, and the steps' reads and writes. node import-schema.mjs --help lists every option (--schema, --name, --id-prefix, --no-guess, --json, --root …).

Check for drift

--check <model.js> compares the source with the entities the model already has, instead of printing a fragment. On the example the model matches its migration:

$ node ../../skills/architecture-explorer/scripts/import-schema.mjs db/migrations --check communications/architecture-explorer/model.js
…
OK       communications/architecture-explorer/model.js matches the source: 6 entities compared (schema db ↔ pg)

In a copy of the example with a second migration the model does not know yet:

-- db/migrations/002_task_priority.sql
-- Tasks get a priority; the batch column gets a shorter name.
ALTER TABLE tasks ADD COLUMN priority INTEGER NOT NULL DEFAULT 0;
CREATE INDEX tasks_priority_idx ON tasks (priority DESC, created_at);
ALTER TABLE images RENAME COLUMN batch_name TO batch;
$ node <plugin>/skills/architecture-explorer/scripts/import-schema.mjs db/migrations --check communications/architecture-explorer/model.js
SCHEMA   db · relational (sql, PostgreSQL) · no "in" yet · 6 tables · 41 columns · 7 refs · 4 indexes · from db/migrations/001_init.sql, db/migrations/002_task_priority.sql
…
DRIFT    pg: table "images": batch (TEXT) is in the source (line 12) but not in the model.
DRIFT    pg: table "images": batch_name is in the model but not in the source.
DRIFT    pg: table "tasks": priority (INTEGER) is in the source but not in the model.
DRIFT    pg: table "tasks": indexes ["(status,created_at)"] in the model, ["(priority,created_at)","(status,created_at)"] in the source.
NOTE     pg: images.storage_key has a ref into another schema (bucket-images.key) that the source cannot state: kept.
NOTE     pg: images.thumbnail_key has a ref into another schema (bucket-thumbnails.key) that the source cannot state: kept.
NOTE     pg: exports.storage_key has a ref into another schema (bucket-exports.key) that the source cannot state: kept.
DRIFT    4 difference(s) between the source and communications/architecture-explorer/model.js (schema db ↔ pg)

It exits with 1 when it finds drift, so it can run in CI next to the migrations. It compares entities and fields, types, keys, references, defaults, allowed values and indexes. A reference into another store, which the source cannot state, is kept and noted. A renamed column shows as one field missing and one extra.

In the RDF graph

The data layer is part of the page's RDF graph, in the ontology's data module, c4d: (c4-data.ttl): c4d:Schema (c4d:livesIn an element), c4d:Entity (with c4d:Table, c4d:View and c4d:Enumeration for those kinds), c4d:Field (in order, by schema:position, with c4d:references, c4d:isSoft, c4d:holdsStateOf), c4d:Index, c4d:Relation, and c4d:reads / c4d:writes on steps and relationships. An entity that stores an ontology class c4d:represents it; it is not made a subclass of it. Mappings to CSVW, SHACL, OWL and DCAT are SKOS mappings in alignments.ttl, and the shapes in c4-shapes.ttl check every reference, kind and multiplicity. The graph keeps everything, field order included: a page rebuilt from it draws the same Data view.

Where each schema lives, on the example's graph (5,037 triples):

PREFIX c4d: <https://caviri.github.io/c4-model-agentic-plugin/ontology/c4-data#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?schema ?kind ?lives (COUNT(?e) AS ?entities)
WHERE {
  ?s a c4d:Schema ; rdfs:label ?schema ; c4d:schemaKind ?kind .
  OPTIONAL { ?s c4d:livesIn/rdfs:label ?lives }
  OPTIONAL { ?e c4d:inSchema ?s }
}
GROUP BY ?s ?schema ?kind ?lives ORDER BY ?schema
schema kind lives entities
API JSON payloads api API service 5
Annotation vocabulary ontology Image Annotation Tool 9
COCO export file json-schema MinIO 4
MinIO buckets object-store MinIO 3
PostgreSQL schema relational PostgreSQL 6
RQ job messages queue Redis 2
Task JSON-LD context other API service 1

The RDF graph reference has the mapping field by field and more tested queries: which steps write a column of a table, which entities store an ontology class, every soft reference across stores (20 on the example), the fields whose values are a lifecycle's states, and where the tables are defined in the code. The ontology guide explains the module, and Extending the ontology shows how to add an entity kind of your own or link fields to a team's data dictionary.

Schema history

The architecture history versions the data layer like boxes and arrows: schemas, entities, fields and relations each get their element changes, every added or removed triple its reifier, and the timeline, diff and pull request reports list them under Schemas, Entities, Fields and Relations, with who changed what in which commit. An entity that disappears while one with the same fields appears in the same schema is reported as a probable rename.

In compare mode the Data view marks the changes in the colours of the map: added cards and rows in green, changed ones in amber, removed ones as red dashed ghosts brought back from the earlier version, struck through. The panel lists every change; a click on a table or a field opens the Data view on it.

Compare mode in the Data view on demonstration data, from v0.1 to pull request #5, with the images table selected: three new rows in green (thumbnail_key, width, height) and the line from thumbnail_key to the thumbnails bucket in green; the tasks table in amber, the tables not linked to images faded; the panel shows the images table with its fields, above the history bar with its DEMO DATA badge

Compare mode on demonstration data (fictional authors and invented dates): the thumbnail worker's pull request adds three columns to images. The table is amber, its new rows green; the other tables are amber too, because the new columns moved their lines in the migration, and their source lines moved with them.

Compare mode in the Data view on demonstration data, from pull request #6 to v1.0: the table export_jobs as a red dashed ghost, the table exports in green, the lines that now point at exports in amber, and the panel listing "exports (was export-jobs)"

The same demonstration history, from pull request #6 to v1.0: the table export_jobs is renamed exports. The old table is a red ghost, the new one green, and the change list says exports (was export-jobs).

When the history regenerates a model for a commit that has none, prepare lists the schemas and entities whose path changed (a migration, a JSON Schema) next to the boxes, so only those are updated. The example's own history uses it: the three earlier versions got their data layer afterwards, regenerated from the code at each commit (the PostgreSQL tables, MinIO buckets, RQ messages, API JSON and the COCO file, then defined only by build_coco() in worker/jobs/export_coco.py), and marked as regenerated. Open #view=data&ver=30df7d5&cmp=24b46bd to see what the data commit (30df7d5) added: the annotation vocabulary and the task JSON-LD context in green with their 33 relations, and the COCO file in amber, now described by its JSON Schema.

ChatGPT and Claude (MCP)

The MCP server has the same data layer:

  • import_schema runs the same importer on schema text the assistant read with github_read_file (SQL, JSON Schema, OpenAPI in JSON, OWL / RDFS / SHACL, JSON-LD), several files in one call, and returns the three arrays. Given the model too, it reports the drift and the validator's verdict on the merged model.
  • list_schemas and get_entity read a model's data layer: the schemas, where each lives, and one entity with its fields, lines in and out, and the steps and arrows that read or write it.
  • show_explorer opens the Data tab (view.tab: "data", view.entity: "tasks.status"), and in the chat's view and in a browser with WebMCP the agent can call show_data to open it on an entity, a field or a schema, optionally keys only.