Version 8.8.0

All pages

Boundaries

Import rules between packages: a change that breaks them is wrong even when it works.

Enforcement

npm run check:boundaries (checkBoundaries.ts) runs in npm run check and in CI. It reads every workspace package's imports and fails on:

Test files follow their subject's rules and, like the vitest configs, may use the root package.json's shared test tooling. A package's Vite and Vitest configs may import the root's shared setup: vitest.shared.ts and the Solid client switch, scripts/solidClient.ts.

An example

A screen in ui may import application (the table below):

// packages/ui/src/ui/DeckListContainer.tsx
import type { UseCases } from "@solid-memo/application/useCases";

It may not import an adapter, such as the guest's pod in solid:

// packages/ui/src/ui/SomeScreen.tsx
import { createLocalPod } from "@solid-memo/solid/localPod";

The check names the file and rule per problem, and fails:

packages/ui/src/ui/SomeScreen.tsx: @solid-memo/ui may not import @solid-memo/solid.
packages/ui/src/ui/SomeScreen.tsx: imports @solid-memo/solid, which package.json does not declare.
2 boundary problem(s).

The fix is a use case on UseCases, with composition wiring the adapter behind its port. A rule that allows only some files names them; importing the composition root anywhere in apps/web but its entry point gives:

apps/web/src/App.tsx: only files matching /^src\/main\.tsx$/ may import @solid-memo/composition.

With no problem, the check prints "Every package keeps to its boundaries."

Layers

PackageMay importOnly from
turtle—
markdown—
vocabturtleturtle: tooling/ only
build-toolsvocab, turtle, markdownvocab: tooling/root alone (the repository's folders); turtle for the docs' index (markdown.md); markdown to render the docs (markdown.md)
domainvocab
applicationdomain, vocab
shacldomain, vocab, turtle, markdownturtle, markdown: node/ only
solid-clientdomain, vocab
solidapplication, domain, vocab, shacl, solid-client
inrupt-clientsolid-client, domain, solidsolid: tests only, for the contract. No package the app is made of imports it: the build puts its modules in place of those solid-client declares (below)
browserapplication, domain
uiapplication, domain, vocab, markdownmarkdown: src/ui/ only
compositionapplication, domain, vocab, solid, solid-client, browser
webapplication, domain, vocab, ui, composition, studio, build-toolscomposition, and studio with a dynamic import(): src/main.tsx only; build-tools: vite.config.ts (the site's build, which renders the docs) and tests only
studioapplication, domain, vocab, ui
e2e-podapplication, domain, vocab, solid, solid-client, solid-memo-clientsolid-memo-client: signedInClient.ts only, which signs in to a Linked Web Storage server
solid-memo-clientsolid-client, solidsolid: tests only, for the contract. No package the app is made of imports it: the build puts its modules in place of those solid-client declares when SOLID_CLIENT names it
e2e-journeysui, studioui and studio: harness/strings.ts only, for their messages

Browser code is the src/ of markdown, vocab, domain, application, shacl, solid-client, solid, browser, composition, ui, web, studio, inrupt-client and solid-memo-client.

Vendor libraries

Each library is a dependency of, and allowed in, only the packages listed:

LibraryPackageNotes
@inrupt/solid-client, @inrupt/solid-client-authn-browserinrupt-client, shacl(below); shacl uses @inrupt/solid-client in src/turtleDocument.ts only, to parse shapes; its access control only in inrupt-client's src/access.ts (below)
@inrupt/solid-client-authn-coresolidtests only: the sign-in library's own DPoP proof, for authFetch's tests
@tanstack/react-query, preactui, web, studiocomponents; in web, main.tsx, which renders the page, and App.tsx, the page; in studio, its screens
@fontsource/*, @fontsource-variable/*ui, build-toolsin ui, src/style.css only; in build-tools, @fontsource-variable/fredoka in src/drawDiagrams.ts only, to embed Fredoka in the diagrams (markdown.md)
rdf-validate-shacl, rdf-validate-datatypeshaclsrc/engine.ts only, loaded lazily; rdf-validate-datatype for its registry of datatype checks (validation.md)
markdown-it, markdown-it-cjk-friendlymarkdownsrc/parse.ts only; the package's API is its own types, never markdown-it's tokens (markdown.md)
n3turtle, the node tooling of shacl, e2e-pod, solid-memo-client, inrupt-client and solidin e2e-pod, the server contract and the tests; in solid-memo-client, in the browser too; in inrupt-client, src/linearDataset.ts only, in the browser too: the Turtle parser Inrupt's library is given, and the terms of a dataset's quads (below); in solid, tests only
jsonld-streaming-parserinrupt-client, solid-memo-clientthe JSON-LD parser, in each client's src/resources.ts only; in solid, the contract's tests only
oauth4webapisolid-memo-clientSolid-OIDC sign-in
fake-indexeddbbrowser, composition, solid-memo-clienttests only: IndexedDB in node, for the guest's pod's store and the sign-in session
@playwright/teste2e-journeysdrives the built app in Chromium, Firefox and WebKit; the harness talks to the Solid server with its request API
axe-coree2e-journeyspages/App.ts only, which loads its build into the page: checks the screen each journey step ends on for accessibility (testing.md)
mermaid, playwrightbuild-toolssrc/drawDiagrams.ts only, both node-only in the check: Mermaid draws the docs' diagrams in Chromium, which playwright starts (markdown.md); development tools, not shipped (vendor-code.md)

The Solid client libraries

The rest of the code reaches a Solid client only through the modules packages/adapters/solid-client/ declares or holds, so either client takes the place of the other there alone (vendor-code.md). solid-client, the seam, imports no library:

ModuleWhat it has
interface.tsthe types the other modules take and give, HttpError, the sign-in client's interface and the grant's type
rdf.ts, resources.ts, session.ts, access.tswhat a client gives, declared with no body: the data model (datasets and their subjects, read and built, many subjects set or removed in one pass), reading and writing pods (conditional reads and writes among them, and the Turtle and JSON-LD parsers), the sign-in client, and the public-read grant (below)
readLimits.tsthe limits a read of a release, or of an instance's documents outside the user's own pod, takes in, the bounds every read keeps on a Turtle text's base and prefix declarations, on the long IRIs the parser resolves, on how deep it nests and on the length of each term, the fetch that holds a body to them, the tally that holds its triples to them, and the parts a parser is given a text in, to be stopped between them
linkHeader.tsthe bound on the Link and WAC-Allow headers of a response, dropped past it before any parser reads them
sparqlUpdate.tsthe SPARQL Update bodies of the app's PATCH requests
turtleWriter.ts, writableTerms.tsthe Turtle a write sends, and the terms it can't write as they are
providerRedirect.tsthe sessionStorage key a sign-in client marks the tab under while it waits on the identity provider, the same whichever client is in place

The Vite plugin in scripts/solidClient.ts resolves every import of a declared module to the module of the same name in the client SOLID_CLIENT names: unset, empty or inrupt, packages/adapters/inrupt-client/, on Inrupt's libraries; solid-memo-client, packages/adapters/solid-memo-client/, on none (solid-memo-client.md). Each client checks that it gives every declaration with its type (clientTypes.test.ts), and no package imports either. Inrupt's client also has these:

ModuleWhat it has
linearDataset.tsa document read into a dataset in one pass, where the library takes time in the square of its size, a dataset's quads made one by one, where the library spreads a subject's into one call, a property's literals and blank nodes as terms in one pass, where the library joins its list at each language and datatype, and the Turtle parser it and parseQuads read with, on n3, for resources.ts and rdf.ts alone
inrupt.tsthe library's objects behind the interface's types, for the other modules alone

shacl may not import solid, so it reads a shape's Turtle with a module of its own, turtleDocument.ts, as pod documents are read.

With SOLID_CLIENT=solid-memo-client, the plugin puts that client's turtleDocument.ts in place of shacl's too. solid-memo-client and solid-client import no @inrupt/ package, tests included (VENDOR_NEVER_IN), and no package imports either client (the layer table).

npm run check:boundaries (checkBoundaries.ts, VENDOR_ONLY_IN) lets only inrupt-client's files and shacl's Turtle reader, outside tests, import any @inrupt/ package, with any import: named, a namespace, a subpath such as @inrupt/solid-client/universal, or a dynamic import(). Such an import elsewhere is reported once, not again by the access-control rule. Tests mock the declared modules (@solid-memo/solid-client/resources), not the libraries, and both clients' own tests run the contract in packages/adapters/solid/src/testing/contract/ (vendor-code.md).

Files without a vendor library

A deck saved as a file, or read from one (studio.md), needs no library of its own:

Access control

The app changes access in two places only: a published release becomes readable by everyone (studio.md), and so does a public type index the app creates, never one already there that it adopts (data-model.md). Only two adapters make that write: the ReleasePublisher port's, solidReleasePublisher.ts, and the InstanceRepository port's, solidInstanceRepository.ts. Each makes it with the grant it's given, through accessControlFetch.ts, which lets the grant write only that document's own ACL or ACR. client/access.ts has @inrupt/solid-client's universalAccess.setPublicAccess, read only, for the document, writing its own ACL (Web Access Control) or ACR (Access Control Policies). That fetch refuses another origin, or a write of anything but <document>.acl or <document>.acr, whatever the server names as the document's access control. No folder's access control changes. With SOLID_CLIENT=solid-memo-client, the grant is solid-memo-client's access.ts, which writes the document's own ACL or ACR with fetch and n3 (solid-memo-client.md).

npm run check:boundaries (checkBoundaries.ts, VENDOR_ONLY_FROM) lets only client/access.ts, outside tests, import @inrupt/solid-client's access control (universalAccess, the acp_* modules, the ACL functions) or all of the library (import * as). Another client module may import the rest of the library, never its access control. At run time, the pod fence refuses any other module's ACL or ACR write.

Reading pod data

What the app reads of a pod or a release is data anyone may have written, so it's read within bounds: how many values of a property, how long a text, which IRIs (shapes.md). The raw getters of client/rdf.ts read every value of a property, with no bound. They're getUrlAll, getStringNoLocale, getLiteralAll, getTermAll, getInteger and the other get… readers of a property, getPropertyAll and propertiesOf. So are the readers one value at a time, eachUrl, eachStringNoLocale and eachStringByLocale.

npm run check:boundaries (RAW_GETTERS and RAW_GETTERS_ONLY_IN) lets only these files import them, tests and test helpers aside:

A mapper or an adapter reads through records.ts: a record, the terms beside it, one field alone, or whether a subject has a class or a value (shapes.md).

The pod fence

Every pod adapter's one fetch (appUseCases.ts) passes two fences before the guest's pod or the network:

The fences check the address a request asks for, not one a server redirects it to. Behind them, the fetch that carries the user's credentials follows no redirect, so a write never reaches an address the pod fence didn't check. A write that redirects is refused (redirectRefused), and a read that redirects is sent again as no one (authentication.md). That fetch also refuses any address, read or write, that the proof of the user's login would name another server for (credentialsRefused).

A read of another server, as the user or as no one, has deadlines (readDeadline.ts, withReadDeadline). The server has 10 seconds to start to answer, and 10 seconds for each next part of the body. A read of a server that isn't the user's pod has two minutes for the whole read as well, its body included. That holds for a read as no one, and for every read as the user outside their storages and the folders they entered on this page: an instance registered elsewhere, its meta.ttl, its deck documents and its releases among them. Past any of them, the read is aborted and fails with podNoAnswer, which the app tries again (style.md). The deadlines start once a read is sent: a read the rate-limit gate holds while its server's wait lasts isn't given up for the wait (architecture.md). Without them, a server that never answers, or answers and then sends its body slowly or not at all, keeps a screen loading for good. A read of the user's own pod, a document or a folder, takes as long in all as its body keeps coming, so a large document on a slow connection still downloads. The reads that find the user's storages, their profile among them, have the two minutes, since every other read as the user waits on them. While their storages can't be found, every read has the two minutes. A catalog may name a deck's documents on any server, and the data check and the statistics wait on reading them. The check gives the documents outside the instance's folder one minute in all, every read of them included, and names those it couldn't read; every other read ends at its own deadline (validation.md). The statistics leave a deck whose documents fail to be read out until a later read. Two minutes is far longer than the largest release in the library takes to download. The deck library holds a read of a release added from a link to two minutes of its own too, its check left out (deck-library.md). The guest's pod, in this browser, has no deadline. A write has none either: one cut off might still be saved, and only its answer says whether it was. Adding an answer to the log is the one exception: it's added whole, so one given up is added again later (data-model.md).

The release publisher alone gets a second fetch for its access control, through the same fences, whose pod fence lets a document's own ACL or ACR (<document>.acl, <document>.acr) through, never a folder's. It's used only inside the publisher's check, which allows the release's two (Access control). A Studio trial's fetch allows only GET and HEAD (studio.md).

The credential gate

The login's fetch sends the user's access token to any address it's given. So the adapters that read and write an instance's data get another fetch (appUseCases.ts). They're the decks, cards, review states, answers, preferences, palettes, the digest, the drafts, the instance check, the graph, a deck's export, a Studio trial, and deleting an instance's data. Behind the pod fence that fetch passes the credential gate (ownPodGate.ts, createOwnPodGate):

The profile, the storages, the type indexes and the instances' registrations are read and written through the pod fetch, without the gate. They're how the gate finds the user's own pod, and an instance added by its address isn't registered until it's read. So is copying an instance, and publishing a release; the releases a catalog links, which the Studio lists for any instance it shows, are read through the gate as the instance's data is. A release already at the address being published to, or one being made public, is read under RELEASE_LIMITS, since the instance may be on another server. Its access control, read as it's made public, is read under ACCESS_CONTROL_LIMITS on its bytes, its triples, their characters and its declarations before the grant parses it, and held to MAX_ACCESS_CONTROL_SUBJECTS subjects. These limits are small, because the grant's library takes time that grows with the square of an access control's subjects. The subject limit holds as well for a folder's access control the server falls back to, which may be the user's own. So a release under a folder shared through more rules than that can't be made public: the grant fails. A read the grant makes of the release, or of a folder above it, is held to RELEASE_LIMITS. Once a request gets no answer or goes past its limits, the grant fails. An instance's meta.ttl is read through the pod fetch too, under FOREIGN_LIMITS, since a folder added by its address is read as soon as it's added. A release a draft follows is read through createOwnPodFetch, which asks the same folders (studio.md). A new draft copies a release or a deck's cards into the instance, and a move or copy of cards copies a deck's cards and review states into another of its decks (studio.md). So each is read as no one outside the instance's pod: in neither the instance nor a storage of the user's that holds it.

For the profile and the type indexes, the profile's own places stand in for the gate (profilePlaces.ts): the WebID's origin, its document's, and the storages the WebID document names. A document the profile links (rdfs:seeAlso, foaf:isPrimaryTopicOf, pim:preferencesFile) is read as the user only in one of the user's own storages, or in the WebID's own pod when none is found. When that pod would be the whole origin, as for a WebID document at its root, no such document is read. One anywhere else isn't read at all, nor taken as part of the profile. A storage such a document names counts only inside a storage already found. A type index outside them may be someone else's, so the app takes it as no index at all: it reads nothing in it, writes nothing there, and offers to create the user's own, as for a missing index. Nothing such an index registers is the user's, so no instance in it joins the folders the gate sends credentials to. A profile whose index is on another server names that storage (pim:storage) in the WebID document for the app to use it. Of several links to an index, the app takes one in those places. These places say where the profile may be read, not where the app may point it. One server may keep many users' pods on the WebID's origin, so the app takes a type index, linked or entered by its address, only when it's in one of the user's own storages (data-model.md). It reads the preferences file and writes a link into an extended profile only there too. When no storage can be found, it still reads the indexes in those places, but writes only to one in the WebID's own pod. It writes to none when that pod would be the whole origin, or when the lookup failed.

Documents the app didn't write

A document the app reads from elsewhere is read, parsed and checked off the page, in a worker (validation.md). That's a release from a link, a deck file, a release file, the documents an instance's check reads, and every document outside the user's storages that the app reads to show or study. The worker's code is solid's own: its entry, offPageWorker.ts, runs the adapters' code (offPageJobs.ts) behind a message interface (offPageProtocol.ts). composition starts the worker (offPageWorker.ts, the one module that imports it, with Vite's ?worker) and puts the ports' side in the page in place of the adapters' (offPageAdapters.ts).

Further rules

Adding a dependency

  1. Add it to the one package it belongs to (npm install <lib> -w @solid-memo/<package>).
  2. If it performs I/O, put it behind a port in the module of packages/core/application/src/ports/ for what is behind it, implemented in an adapter package.
  3. Add it to the vendor table above.