Code base tour¶
.
├── src/main/java/org/marmotgraph/core application code
├── src/main/resources/db/migration Flyway migrations
├── src/test/java tests, see "Test overview"
├── sdks/python, sdks/java client SDKs
├── utils/devSetup local infrastructure and demo data
├── docs, docs-theme, zensical.toml this documentation
├── ARCHITECTURE.md decision records
├── FEATURES.md authoritative list of features
└── ERM.puml entity-relationship diagram (PlantUML)
Package dependencies¶
The packages below org.marmotgraph.core and the direction in which they may depend on each other. common and
utils are available everywhere.
flowchart TB
subgraph api["api"]
direction LR
v3beta["v3beta"] --> v3["v3"] --> v4["v4"]
apiInternal["internal<br/>security, advices, logging,<br/>openApi, web"]
apiModels["models"]
end
subgraph services["services"]
direction LR
domain["instances, queries, scope,<br/>structure, validation,<br/>invitation, comment, favorite,<br/>tool, apiExample, tenant, jsonld"]
authz["authorization<br/>authentication"]
sync["graph<br/>(synchronization)"]
end
graphPkg["graph<br/>GraphDB, neo4j, nograph, vocabulary"]
persistence["persistence<br/>entities, repositories, converters"]
setup["setup"]
common["common / utils"]
api --> services
domain --> authz
domain --> sync
sync --> graphPkg
domain --> graphPkg
services --> persistence
graphPkg --> persistence
setup --> services
api -.-> common
services -.-> common
graphPkg -.-> common
persistence -.-> common
Only services/queries (to execute queries) and services/graph (to synchronize and reindex) talk to GraphDB. Every
other read, including the listing of instances, goes to PostgreSQL directly.
api¶
| Location | Content |
|---|---|
api/v4 |
One controller per domain: InstancesV4, QueriesV4, TypesV4, PropertiesV4, SpacesV4, InvitationsV4, CommentsV4, StatisticsV4, GraphV4, CacheV4, SetupV4, TenantsV4, UsersV4, ToolsV4, ApiExamplesV4, JsonLDV4 |
api/v3, api/v3/models |
Delegators to v4 and format adaptations, such as InstanceFormatV3, QuerySpecificationV3 and ScopeElementV3 |
api/v3beta |
Delegators for the legacy API |
api/models |
Request and response models which only exist at the API level: ExposedStage, TypeInSpace, SuggestionResult, AuthenticationConfiguration |
api/internal/security |
AuthenticationAspect, WebSecurityConfig |
api/internal/advices |
RestControllerAdvice (exceptions to HTTP status codes), V3ResponseAdvice (v3 response format), GlobalControllerAdvice, ApiDocsExamplesAdvice (examples in /v3/api-docs, ADR-068) |
api/internal/openApi |
OpenAPI groups (OpenAPIv3), tenant-specific specifications (TenantApiDocs), tagging annotations (@Admin, @Simple, @Advanced, @Extra, @Tenants) and @ApiExampleRefs |
api/internal/logging |
MetricsAspect, RequestLoggingFilter |
api/internal/web |
DefaultPage and DocumentationConfig, which serves the bundled documentation at /docs (ADR-060) |
api/internal |
Version |
The shared response wrappers ResultWithExecutionDetails, PaginatedResult and PaginatedStreamResult are in
common/model, since services return Paginated and PaginatedStream themselves.
services¶
| Package | Key classes | Responsibility |
|---|---|---|
instances |
InstanceService, internal/InstanceProcessorInternal |
Lifecycle, listing, reconciliation, release, release status |
queries |
QueryService |
Stored and ad-hoc queries, access filter for query execution |
scope |
ScopeService, ScopeEvaluationService |
Scope definitions and on-demand traversal |
structure |
TypesService, SpacesService, PropertiesService, PropertiesInTypeService, StatisticsService, internal/StructureService, internal/SummaryTablesReconciliationService |
Types, properties, spaces, statistics |
validation |
ValidationSchemaService, InstanceValidationService, ComplianceScore, SchemaReferences |
JSON-Schema validation |
invitation |
InvitationService, PendingInvitationService, InvitationLookupService, internal/InvitationsInternal |
Invitations for known users and invitation links |
comment, favorite |
CommentService, FavoriteService |
Personal and review data about instances |
tool |
ToolService |
Tools built on top of the graph and their categories (ADR-063) |
apiExample |
ApiExampleService, internal/ApiExampleOverridesInternal |
Examples of the OpenAPI specification, per tenant (ADR-068) |
authorization |
PermissionService, AuthContext, AuthorizationService, UserWithRoles, ClaimPatterns, functionalities/*, internal/* |
Permission model, role definitions and checks |
authentication |
AuthenticationService, internal/KeycloakInternal |
Keycloak integration, JWT verification |
graph |
GraphIndexingListener, GraphReindexService, ReindexLock, ManipulationThrottle, internal/GraphSourceInternal |
Graph synchronization and write coordination |
jsonld |
JsonLdService, JsonAdapter |
Normalization of payloads |
tenant |
TenantService, internal/TenantInternal |
Tenant definitions and themes |
| (root) | CachingService, UserService |
Cache management, the current user |
Instance services¶
classDiagram
class InstanceService {
createNewInstance(payload, id, space, updateIfExists, skipIfUnchanged, validate) UUID
contributeToInstance(payload, id, skipIfUnchanged, fullReplacement, validate)
previewNewInstance(payload, space) NormalizedJsonLd
previewContribution(payload, id, fullReplacement) NormalizedJsonLd
getInstance(id, stage, config) NormalizedJsonLd
getInstancesById(stage, ids, config)
getInstancesByIdentifiers(stage, identifiers, config)
listInstances(stage, types, spaces, search, ..., sorting, config, page) Paginated
getGroupedIncomingLinks(id, stage, property, type, page)
getNeighborhood(id, stage) GraphEntity
releaseInstance(id)
unreleaseInstance(id)
getReleaseStatus(id, releaseTreeScope, scope) ReleaseStatus
moveInstance(id, space, config)
removeInstance(id, forceUnrelease)
reconcileInstances(space, force) InferenceStatus
validateInstances(space) BulkValidationStatus
getValidationStatus() BulkValidationStatus
}
class InstanceProcessorInternal {
reconcileInstances(batch, force) List~ReconciliationResult~
processInstances(changed)
resolveRelations()
release(currentInstance)
unrelease(instance)
removeCurrent(instance)
}
class InstanceQueries {
listInstances(...)
countInstances(...)
nextMarker(last, sorting)
}
class JsonLdService {
normalizePayload(doc, requiresType)
}
class PermissionService
class AuthContext
class SpacesService {
getOrCreateSpace(name)
}
class ScopeService {
getReleaseStatusOfScope(id, name, restricted)
}
class InstanceValidationService {
validateAndStore(instance, payload)
removeResults(instance)
}
class ApplicationEventPublisher {
<<Spring>>
}
InstanceService --> PermissionService
InstanceService --> AuthContext
InstanceService --> JsonLdService
InstanceService --> SpacesService
InstanceService --> ScopeService
InstanceService --> InstanceProcessorInternal
InstanceService --> InstanceQueries
InstanceService --> InstanceValidationService
InstanceService --> ApplicationEventPublisher : InstanceRemovedEvent
InstanceProcessorInternal --> ApplicationEventPublisher : InstancesChangedEvent
Query, scope and graph services¶
classDiagram
class QueryService {
listQueries(rootType, search, page)
getQuery(id) StoredQuerySpecification
saveQuery(query, id, space)
moveQuery(id, space)
removeQuery(id)
executeStoredQuery(id, stage, params) PaginatedStream
runDynamicQuery(query, stage, params) PaginatedStream
}
class ScopeService {
getScopes(type)
specifyScope(type, name, spec)
removeScope(type, name)
getScopeForInstance(id, name, stage, ...) ScopeElement
getReleaseStatusOfScope(id, name, restricted) ReleaseStatus
}
class ScopeEvaluationService {
evaluate(id, name, stage) ScopeElement
evaluateAll(id, stage) ScopeElement
evaluateIds(id, names) Set~UUID~
}
class GraphDB {
<<interface>>
delete(id, space, stage)
upsert(stage, instance, linkingInstances)
reindex(stage, source) ReindexResult
executeQuery(query, stage, params, page, accessFilter, instanceId) GraphQueryResult
}
class GraphIndexingListener {
<<profile !nograph>>
onInstancesChanged(event)
onInstanceRemoved(event)
}
class GraphReindexService {
reindex(stages)
getStatus() ReindexStatus
}
class GraphSourceInternal {
readBatch(stage, afterId)
readInstances(stage, ids)
readInstancesLinkingTo(stage, id)
}
class ReindexLock {
<<aspect>>
}
class ManipulationThrottle {
<<aspect>>
}
QueryService --> GraphDB : executeQuery
QueryService --> AuthContext : access filter
ScopeService --> ScopeEvaluationService
GraphIndexingListener --> GraphSourceInternal
GraphIndexingListener --> GraphDB : upsert / delete
GraphReindexService --> ReindexLock : write lock
GraphReindexService --> GraphSourceInternal
GraphReindexService --> GraphDB : reindex
Scopes are evaluated with SQL on the relation tables, not in the graph, so they behave the same with every graph engine.
Structure services¶
classDiagram
class TypesService {
getTypes(stage, space, withProperties, withIncomingLinks, withCounts, types, page) Paginated~TypeInformation~
getTypeSpecification(type)
specifyType(type, spec)
removeType(type)
}
class SpacesService {
listSpaceInformation(page, permissions)
getOrCreateSpace(name)
specifySpace(space, autoRelease, ...)
removeSpaceSpecification(space)
specifyTypeInSpace(space, type)
}
class PropertiesService
class PropertiesInTypeService
class StatisticsService {
getStatistics() GraphStatistics
}
class StructureService {
<<internal>>
getTypesWithCount(typeIds)
getPropertiesForTypes(typeIds)
getTargetTypes(typeIds)
getIncomingLinks(typeIds)
}
class SummaryTablesReconciliationService {
<<internal, scheduled>>
reconcileSummaryTables()
}
class SummaryTables {
<<PostgreSQL, trigger-maintained>>
current_type_summary
current_property_occurrence_summary
current_target_type_summary
current_incoming_link_summary
current_embedded_type_summary
}
TypesService --> StructureService
StructureService --> SummaryTables : reads
StatisticsService --> SummaryTables : reads (in progress stage)
SummaryTablesReconciliationService --> SummaryTables : nightly recompute
graph¶
See Graph engines.
| Location | Content |
|---|---|
GraphDB |
The interface: delete, upsert, reindex, executeQuery |
neo4j, nograph |
The adapters, activated by Spring profile (@Neo4JProfile, @NoGraphProfile) |
neo4j/internal, nograph/internal |
The implementation of the adapters |
vocabulary/GraphVocabulary |
Compaction of IRIs for graph databases |
models |
Models exchanged with the adapters: IndexableInstance, GraphQueryPage, GraphQueryResult, ReindexResult |
models/query |
The internal query model (Specification, SpecProperty, SpecTraverse, field filters) |
persistence¶
| Location | Content |
|---|---|
entities/* |
JPA entities, one package per concept; see Data model |
repositories/* |
Spring Data repositories, native queries, and InstanceQueries with the criteria queries of the instance listing |
converters/* |
JPA converters, including gzip compression of JSON columns |
models |
Projections and helper types, such as PropertyUpdates and OffsetPageable |
common¶
| Location | Content |
|---|---|
jsonld |
JsonLdDoc (incoming), NormalizedJsonLd (normalized), DynamicJson, JsonLdId, InstanceId |
model |
DataStage, SpaceName, ReleaseStatus, response configuration, pagination (PaginationParam, Paginated, PaginatedStream) and the response wrappers |
model/query |
QuerySpecification, the model of a query |
model/scope |
ScopeSpecification |
model/validation |
Validation errors and status |
params |
Enumerations of request parameters, such as ReleaseTreeScope |
exceptions |
Domain exceptions, mapped to HTTP status codes by RestControllerAdvice |
constants |
Vocabularies and the names of the properties added to responses (InstanceResponseProperties, OutgoingLinkSummary) |
serializer, utils |
Jackson support and id helpers |
utils¶
MarkerUtils serializes the markers of the marker pagination, HashUtils computes payload hashes, and
TriggerOrchestrator re-enables the database triggers after bulk updates.
setup¶
Config holds the namespaces, AuthSetup the admin group, AsyncConfig the configuration for background work,
CommitInfo the git information of the build, and RuntimeMetricsAspect optional timing of service calls.
Legacy code¶
Some parts of the code predate the rewrite and aren't on any active path:
- Some models and exceptions in
commonrelate to removed features, such as terms of use (TermsOfUse,NotAcceptedTermsOfUseException). Functionalitystill lists values without an implementation, such as the client management.