Use cases and request flows¶
This page follows the most relevant use cases through the code, from the controller down to the database. The
diagrams use v4; older API versions delegate to the same methods (Architecture).
Use cases¶
flowchart LR
consumer["Consumer"]
reviewer["Reviewer /<br/>invited user"]
editor["Editor"]
owner["Owner"]
admin["Administrator"]
subgraph core["MarmotGraph Core"]
direction TB
readReleased(["Read and list released instances"])
query(["Execute a query"])
types(["Explore types and statistics"])
readInProgress(["Read and list instances in progress"])
scope(["Evaluate a scope / release tree status"])
comment(["Comment on an instance"])
create(["Create an instance"])
contribute(["Contribute to an instance"])
delete(["Move or delete an instance"])
invite(["Invite a reviewer"])
release(["Release / unrelease an instance"])
manageSpace(["Manage a space"])
structure(["Define types, properties,<br/>scopes, schemas, tools"])
reindex(["Reindex the graph"])
end
consumer --- readReleased
consumer --- query
consumer --- types
reviewer --- readInProgress
reviewer --- scope
reviewer --- comment
editor --- create
editor --- contribute
editor --- delete
editor --- invite
owner --- release
owner --- manageSpace
admin --- structure
admin --- reindex
Each role includes the use cases of the roles to its left (Roles). An invited user gets the reviewer's use cases for the invited instances only.
| Use case | Endpoint | Section |
|---|---|---|
| Authenticate any request | all | Authentication and authorization |
| Create an instance | POST /instances |
Creating an instance |
| Contribute to an instance | PUT, PATCH /instances/{id} |
Contributing to an instance |
| Release an instance | GET /instances/{id}/release/status, PUT /instances/{id}/release |
Releasing an instance |
| Unrelease or delete | DELETE /instances/{id}/release, DELETE /instances/{id} |
Unreleasing and deleting |
| Read an instance | GET /instances/{id} |
Reading an instance |
| List instances | GET /instances |
Listing instances |
| Execute a query | POST /queries, GET /queries/{id}/instances |
Executing a query |
| Evaluate a scope | GET /instances/{id}/scope |
Evaluating a scope |
| Invite a reviewer | POST /invitations/instances/{id}/pending, POST /invitations/redemption |
Inviting a reviewer |
| Explore types | GET /types |
Listing types |
| Reindex the graph | POST /graph/reindex |
Graph engines |
Authentication and authorization¶
Every request runs through this flow before and during the use cases below.
sequenceDiagram
actor Client
participant Aspect as AuthenticationAspect
participant AuthN as AuthenticationService
participant Ctrl as Controller
participant Svc as Service
participant Perm as PermissionService
participant Ctx as AuthContext(Internal)
participant User as UserInfoInternal
Client->>Aspect: request with Bearer token
alt no token
Aspect-->>Client: UnauthorizedException → 401
end
Aspect->>AuthN: verifyToken(token)
Note right of AuthN: signature and validity,<br/>keys from Keycloak
Aspect->>Ctrl: proceed
Ctrl->>Svc: business operation
Svc->>Perm: canXxx(space, instance)
Perm->>Ctx: getUserWithRoles()
Ctx->>User: user profile and role claims (cached per token)
User-->>Ctx: user, roles
Perm->>Ctx: getInvitations() (cached per user)
alt not permitted
Perm-->>Client: UnauthorizedException → 401
end
Svc-->>Ctrl: result
Ctrl-->>Client: 200
Authentication happens once per controller call. When a v3 controller delegates to v4, the aspect runs again on
the v4 method. Endpoints annotated with @AuthenticationAspect.None skip it.
Creating an instance¶
POST /instances?space=… stores the first contribution of a new instance. The UUID is generated, or taken from the
path with POST /instances/{id}.
sequenceDiagram
actor Client
participant Ctrl as InstancesV4
participant Svc as InstanceService
participant Perm as PermissionService
participant Spaces as SpacesService
participant DB as PostgreSQL
Client->>Ctrl: POST /instances?space=demo (payload)
Ctrl->>Svc: createNewInstance(payload, uuid, space, updateIfExists, skipIfUnchanged, validate)
Note over Svc: aspects: ManipulationThrottle,<br/>ReindexLock (read lock), transaction
Svc->>Svc: resolveSpaceName(space) (myspace → private space)
Svc->>DB: find instance by UUID or by the identifiers of the payload
alt an instance exists
alt updateIfExists
Svc->>Svc: contributeToInstance(payload, existingId, full replacement)
else
Svc->>Perm: checkCanCreate(space) - the conflict is only revealed if the creation is permitted
Svc-->>Client: ConflictException → 409 with the existing id
end
else new instance
Svc->>Perm: checkCanCreate(space) - CREATE + WRITE (+ MANAGE_SPACE for a new space, RELEASE for an auto-release space)
Svc->>Spaces: getOrCreateSpace(space)
Svc->>DB: INSERT instance, current_instance
Svc->>Svc: handle contribution (see next section)
end
Note over Svc,DB: commit, then graph synchronization
Svc-->>Ctrl: instance id
Ctrl->>Svc: getInstance(id, IN_PROGRESS, responseConfiguration)
Svc-->>Ctrl: NormalizedJsonLd
Ctrl-->>Client: 200 with the instance
An @id in the payload isn't the instance's id; it's stored as an additional identifier.
Contributing to an instance¶
PUT /instances/{id} replaces the user's contribution, PATCH merges the given properties into it. Creating an
instance runs the same steps.
sequenceDiagram
participant Svc as InstanceService
participant Perm as PermissionService
participant Json as JsonLdService
participant Proc as InstanceProcessorInternal
participant Valid as InstanceValidationService
participant DB as PostgreSQL
participant Pub as ApplicationEventPublisher
participant Listener as GraphIndexingListener
participant Graph as GraphDB
Svc->>Perm: canWriteInstance(space)
Svc->>Json: normalizePayload(payload)
Svc->>Svc: apply to the user's contribution<br/>(update propertyUpdates timestamps)
alt skipIfUnchanged and the hash of the contribution is unchanged
Svc-->>Svc: done, nothing stored
end
Svc->>DB: save contribution
Svc->>Proc: reconcileInstances([instance])
Proc->>DB: load all contributions and the current payload
Proc-->>Svc: merged payload, alternatives (empty if the hash is unchanged)
Svc->>Proc: processInstances(changed)
Proc->>DB: types, instance (RELEASED → HAS_CHANGED),<br/>current_payload, identifiers, properties,<br/>property occurrences, relations
Proc->>Pub: InstancesChangedEvent(IN_PROGRESS)
opt something changed
Svc->>DB: resolve relations by UUID and by identifier
opt space has autoRelease
Svc->>Perm: canReleaseInstance(space)
Svc->>Proc: release(instance)
end
end
alt validate=true
Svc->>Valid: validateAndStore(instance, payload)
else
Svc->>Valid: removeResults(instance)
end
Note over Svc,DB: commit (triggers update sort keys and summary tables)
Pub-)Listener: after commit (not with nograph)
Listener->>DB: read the instance (new read-only transaction)
Listener->>Graph: upsert(stage, instance)
Reconciliation: for each property across all contributions, the value with the most recent timestamp in
propertyUpdates wins. The other values are stored as alternatives. If the MD5 hash of the result hasn't changed, the
instance is skipped.
Derived data follows from the merged payload: current_identifier, current_relation,
current_property_occurrence, labels, and the summary tables, which are maintained by database triggers.
The identifiers of the stored current_payload are always part of the result, so a contribution can't drop one.
DELETE /instances/{id}/identifiers (ADR-071) removes an identifier from the stored payload and all contributions,
reconciles the instance and deletes its current_identifier row (the registration of identifiers never deletes rows).
It is rejected with a 409 if a current_relation or released_relation has the identifier as target_reference.
Release status¶
stateDiagram-v2
[*] --> UNRELEASED : first contribution
UNRELEASED --> RELEASED : release
RELEASED --> HAS_CHANGED : contribution changes the payload
HAS_CHANGED --> RELEASED : release
RELEASED --> UNRELEASED : unrelease
HAS_CHANGED --> UNRELEASED : unrelease
UNRELEASED --> [*] : delete
RELEASED --> [*] : delete with forceUnrelease
HAS_CHANGED --> [*] : delete with forceUnrelease
Releasing an instance¶
Releasing is done per instance. A client like the editor first checks the release status of the instance's release tree, the instances reached through the scopes of its type, and releases the children before the instance itself.
sequenceDiagram
actor Client
participant Ctrl as InstancesV4
participant Svc as InstanceService
participant Scope as ScopeService
participant Eval as ScopeEvaluationService
participant Perm as PermissionService
participant Proc as InstanceProcessorInternal
participant DB as PostgreSQL
participant Listener as GraphIndexingListener
Client->>Ctrl: GET /instances/{id}/release/status?releaseTreeScope=CHILDREN_ONLY
Ctrl->>Svc: getReleaseStatus(id, CHILDREN_ONLY, scope)
Svc->>Scope: getReleaseStatusOfScope(id, scope, restricted=false)
Scope->>Perm: canReadInstance(space, id, IN_PROGRESS)
Scope->>Eval: evaluate(id, scope, IN_PROGRESS)
Eval->>DB: traverse current_relation along the scope
Scope->>DB: distinct release status of the children
Scope-->>Client: UNRELEASED, HAS_CHANGED or RELEASED
loop each child which isn't RELEASED, then the instance
Client->>Ctrl: PUT /instances/{childId}/release
Ctrl->>Svc: releaseInstance(id)
Svc->>Perm: canReleaseInstance(space)
Svc->>Proc: release(currentInstance)
Proc->>DB: upsert released_instance with the current payload
Proc->>DB: replace released_identifier
Proc->>DB: copy relations from current, resolve outgoing and incoming
Proc->>DB: copy property occurrences from current
Proc->>DB: instance: RELEASED, firstReleaseAt, lastReleaseAt
Proc-)Listener: InstancesChangedEvent(RELEASED)
Note over Proc,DB: commit
Listener->>Listener: GraphDB.upsert (after commit)
end
Released relations can only resolve to released instances, enforced by the foreign key to released_instance
(ADR-014). Releasing the children
first is a convention of the client; the server doesn't enforce an order.
Unreleasing and deleting¶
sequenceDiagram
actor Client
participant Svc as InstanceService
participant Perm as PermissionService
participant Proc as InstanceProcessorInternal
participant DB as PostgreSQL
participant Pub as ApplicationEventPublisher
alt DELETE /instances/{id}/release
Client->>Svc: unreleaseInstance(id)
Svc->>Perm: canUnreleaseInstance(space)
Svc->>Proc: unrelease(instance)
Proc->>DB: detach incoming released relations, delete the released rows
Svc->>Pub: InstanceRemovedEvent(RELEASED)
Svc->>DB: instance: UNRELEASED
else DELETE /instances/{id}?forceUnrelease=…
Client->>Svc: removeInstance(id, forceUnrelease)
Svc->>Perm: canDeleteInstance(space)
opt instance is RELEASED or HAS_CHANGED
alt forceUnrelease
Svc->>Perm: canReleaseInstance(space)
Svc->>Proc: unrelease(instance)
Svc->>Pub: InstanceRemovedEvent(RELEASED)
else
Svc-->>Client: ConflictException → 409
end
end
Svc->>Proc: removeCurrent(instance)
Proc->>DB: detach incoming relations, delete current rows and instance,<br/>remove types no longer in use (ADR-062)
Svc->>Pub: InstanceRemovedEvent(IN_PROGRESS)
end
Links of other instances pointing to a removed instance are kept but become unresolved (ADR-050).
Reading an instance¶
GET /instances/{id}?stage=… reads from PostgreSQL only. What's added to the payload depends on the response
configuration.
sequenceDiagram
actor Client
participant Ctrl as InstancesV4
participant Svc as InstanceService
participant Perm as PermissionService
participant DB as PostgreSQL
Client->>Ctrl: GET /instances/{id}?stage=IN_PROGRESS
Ctrl->>Svc: getInstance(id, stage, responseConfiguration)
Svc->>DB: find instance by UUID
alt not found
Svc-->>Client: InstanceNotFoundException → 404
end
Svc->>Perm: canReadInstance(space, id, stage)
Svc->>DB: current_instance or released_instance with payload
opt returnSummaryOfOutgoingLinks
Svc->>DB: resolved targets of the relations
Svc->>Svc: per link: RESOLVED, RESTRICTED or UNRESOLVED (ADR-056)
end
opt returnAlternatives (in progress)
Svc->>Perm: READ_CONTRIBUTORS? otherwise anonymize alternatives
end
opt returnPermissions, returnReleaseStatus, returnTimestamps,<br/>returnContributors, returnFavorite, returnValidationResults, …
Svc->>DB: load the requested additions
end
Svc-->>Ctrl: NormalizedJsonLd with @id, _space and the additions
Ctrl-->>Client: 200
Listing instances¶
GET /instances is answered by PostgreSQL with criteria queries in InstanceQueries. No graph database is involved,
so the listing behaves the same with every profile.
sequenceDiagram
actor Client
participant Ctrl as InstancesV4
participant Svc as InstanceService
participant Ctx as AuthContext(Internal)
participant Perm as PermissionService
participant Q as InstanceQueries
participant DB as PostgreSQL
Client->>Ctrl: GET /instances?stage&type&space&searchByLabel&releaseStatus&sort&from|marker
Ctrl->>Svc: listInstances(stage, types, spaces, search, favoritesOnly,<br/>withContribution, releaseStatus, sorting, config, page)
opt stage IN_PROGRESS
Svc->>Ctx: getInvitations()
end
alt spaces requested
loop each space
Svc->>Perm: canReadInstance(space, null, stage)
end
else
Svc->>Ctx: restrictToSpaces(stage)
Ctx-->>Svc: readable spaces, or none for global readers
end
Svc->>DB: resolve type names to ids
Svc->>Q: listInstances(stage table, filters, spaces, invitations, sorting, page)
Q->>DB: SELECT … ORDER BY sort_* keys LIMIT size
opt returnTotalResults
Svc->>Q: countInstances(…)
end
opt page is full
Svc->>Q: nextMarker(last, sorting)
end
Svc->>DB: preload validation results, contributors,<br/>favorites, contributions (if requested)
Svc->>Svc: post-process each instance as in "Reading an instance"
Svc-->>Ctrl: Paginated (data, total, nextMarker)
Ctrl-->>Client: 200
The listing either pages with from or, for large result sets, with the marker of the previous page. Sorting uses
the denormalized sort_* columns (ADR-036).
Executing a query¶
Stored queries (GET /queries/{id}/instances) and ad-hoc queries (POST /queries) take the same path. Request
parameters not used by the endpoint are values for the parametrized filters of the query.
sequenceDiagram
actor Client
participant Ctrl as QueriesV4
participant Svc as QueryService
participant Perm as PermissionService
participant Ctx as AuthContext(Internal)
participant Graph as GraphDB
participant Neo as Neo4J
participant NoG as NoGraph
participant DB as PostgreSQL
alt stored query
Client->>Ctrl: GET /queries/{id}/instances?stage&…
Ctrl->>Svc: executeStoredQuery(id, stage, params)
Svc->>DB: load stored_query
Svc->>Perm: hasPermissionOrThrow(READ, query space)
else ad-hoc query
Client->>Ctrl: POST /queries?stage&… (QuerySpecification)
Ctrl->>Svc: runDynamicQuery(query, stage, params)
Svc->>Svc: validate (meta.type required)
end
Svc->>Ctx: restrictToSpaces(stage), getInvitations()
Ctx-->>Svc: access filter (spaces, invited instances) or null
alt access filter is empty
Svc-->>Client: empty page
end
Svc->>Graph: executeQuery(query, stage, filterValues, page, accessFilter, instanceId)
alt profile neo4j
Graph->>Neo: QueryToCypherInternal
Neo-->>Graph: rows
else profile nograph
Graph->>NoG: QueryEvaluatorInternal
NoG->>DB: root candidates, traversals (SQL), payloads
NoG-->>Graph: rows evaluated in memory
end
Graph-->>Svc: GraphQueryResult (data, total, lastRootId)
Svc->>Svc: next marker from lastRootId
Svc-->>Ctrl: PaginatedStream
Ctrl-->>Client: 200
The access filter is an argument to executeQuery, so an adapter always has to enforce it, on every hop
(ADR-015,
ADR-037). Invitations only extend the
filter in progress and when no spaces are requested explicitly.
Evaluating a scope¶
GET /instances/{id}/scope returns the tree of instances reached through the scope of the instance's type. Scopes are
evaluated in PostgreSQL for every profile (ADR-029).
sequenceDiagram
actor Client
participant Ctrl as InstancesV4
participant Scope as ScopeService
participant Perm as PermissionService
participant Eval as ScopeEvaluationService
participant DB as PostgreSQL
Client->>Ctrl: GET /instances/{id}/scope?stage&name
Ctrl->>Scope: getScopeForInstance(id, name, stage, returnPermissions, returnReleaseStatus)
Scope->>Perm: canReadInstance(space, id, stage)
alt name given
Scope->>Eval: evaluate(id, name, stage)
else
Scope->>Eval: evaluateAll(id, stage)
end
Eval->>DB: type of the root, type_scope specification
loop each level of the specification
Eval->>DB: follow *_relation (outgoing or incoming) filtered by type
end
Eval-->>Scope: ScopeElement tree
Scope->>Scope: retain readable instances (drops unreadable subtrees)
opt returnPermissions / returnReleaseStatus
Scope->>DB: release status of the tree
end
Scope-->>Client: 200 with the tree
Inviting a reviewer¶
An editor can invite a known user directly (PUT /invitations/instances/{id}/users/{userId}) or create an invitation
link which any user can redeem.
sequenceDiagram
actor Editor
actor Reviewer
participant Ctrl as InvitationsV4
participant Pending as PendingInvitationService
participant Inv as InvitationsInternal
participant Perm as PermissionService
participant Ctx as AuthContext(Internal)
participant DB as PostgreSQL
Editor->>Ctrl: POST /invitations/instances/{id}/pending (label, scopes)
Ctrl->>Pending: invite(id, request)
Pending->>Perm: canInviteForReview(space, id)
Pending->>Inv: resolveScopes(id, scopes)
Pending->>DB: INSERT pending_invitation (SHA-256 of the token, expiresAt)
Pending-->>Editor: token (only returned once)
Editor-->>Reviewer: shares the link with the token
Reviewer->>Ctrl: POST /invitations/redemption (token)
Ctrl->>Pending: redeem(token)
Pending->>DB: SELECT … FOR UPDATE by token hash, not expired
alt unknown, redeemed or expired
Pending-->>Reviewer: NotFoundException → 404
end
Pending->>Inv: createOrExtendInvitation(user, instance, scopes)
Pending->>DB: DELETE pending_invitation
Pending->>Ctx: evictInvitationsCache(user)
Pending-->>Reviewer: instance id
From then on, PermissionService grants READ and COMMENT on the instance and on the instances in the invited
scopes (ADR-044). Expired invitations are
removed by a scheduled job.
Listing types¶
GET /types combines the type definitions with the counts of the trigger-maintained summary tables.
sequenceDiagram
actor Client
participant Ctrl as TypesV4
participant Types as TypesService
participant Ctx as AuthContext(Internal)
participant Struct as StructureService
participant DB as PostgreSQL
Client->>Ctrl: GET /types?stage&space&withProperties&withIncomingLinks
Ctrl->>Types: getTypes(stage, space, withProperties, withIncomingLinks, withCounts, …, page)
Types->>Ctx: restrictToSpaces(stage)
alt no readable space
Types-->>Client: empty page
end
Types->>DB: count and page types of the spaces
Types->>Struct: getTypesWithCount(typeIds)
opt withProperties
Types->>Struct: getPropertiesForTypes, getTargetTypes
end
opt withIncomingLinks
Types->>Struct: getIncomingLinks
end
Struct->>DB: current_*_summary tables
Types->>Types: drop spaces, target types and incoming links<br/>of spaces the user can't read (ADR-056),<br/>merge explicitly specified properties
Types-->>Client: Paginated TypeInformation
Adding a mutation path¶
A new way of changing instances has to do three things:
- Annotate the service method with
@ReindexLock.Manipulation(and@Transactional, which also applies theManipulationThrottle). - Check the permission in the service.
- Publish
InstancesChangedEventorInstanceRemovedEvent, so the graph stays in sync (ADR-017).