Skip to content

Architecture

Core is a single-module Spring Boot 4 application on Java 24. Its packages are kept separate by convention rather than by the build (ADR-001, ADR-006).

Layers

flowchart TB
    subgraph api["api: REST controllers, no business logic"]
        v3b["v3beta"] --> v3["v3"] --> v4["v4"]
    end

    subgraph services["services: business logic and permission checks"]
        inst["instances"]
        struct["structure"]
        queries["queries"]
        scope["scope"]
        valid["validation"]
        invit["invitation / comment / favorite"]
        misc["tool / apiExample / tenant / jsonld"]
        authz["authorization / authentication"]
        sync["graph (synchronization)"]
    end

    subgraph data["data access"]
        persist["persistence<br/>JPA entities and repositories"]
        graphdb["graph<br/>GraphDB interface"]
    end

    common["common: models, exceptions, JSON-LD"]

    v4 --> services
    services --> persist
    services --> graphdb
    persist --> pg[("PostgreSQL")]
    graphdb --> neo[("Neo4j")]
    graphdb -- "nograph" --> pg
    services -.-> common
    api -.-> common

Package layout

Package (org.marmotgraph.core) Role
api Controllers per version, API models, OpenAPI configuration, authentication aspect and advices
services Business logic and authorization
graph The GraphDB abstraction, its adapters and vocabulary compaction
persistence JPA entities, Spring Data repositories and converters
common Models, exceptions and JSON-LD types shared across modules
setup Application configuration and startup
utils Technical helpers: pagination markers, hashing, database triggers

The Code base tour shows the content of each package and how they depend on each other.

Principles

Controllers don't contain business logic

Controllers bind parameters, call services and shape the response. They only declare whether authentication is needed.

Authorization lives in services

Every endpoint needs a valid token unless it's annotated with @AuthenticationAspect.None. Permission checks happen in the services through PermissionService (ADR-005). Nothing at the API level shows whether an endpoint checks permissions, which is why the security test suite tests it from the outside.

PostgreSQL is authoritative

All data lives in PostgreSQL. A graph database, if there is one, holds a copy used only to execute queries (ADR-002, ADR-003).

One implementation per feature

New behavior goes into v4. Older versions delegate and adapt the request and response (ADR-019 to ADR-021).

sequenceDiagram
    participant C as Client
    participant V3 as InstancesV3
    participant V4 as InstancesV4
    participant S as InstanceService

    C->>V3: GET /v3/instances/{id}
    V3->>V4: getInstanceById(...)
    V4->>S: getInstance(...)
    S-->>V4: NormalizedJsonLd
    V4-->>V3: result in v4 format
    V3-->>C: result in v3 format (InstanceFormatV3)

internal packages are private

Classes in an internal package are only meant for their own module. Services for other modules are in the module's root package (ADR-006).

Cross-cutting components

Concern Component
Authentication AuthenticationAspect intercepts public @RestController methods
Request context Request-scoped AuthContextInternal, used via AuthContext and UserWithRoles
Errors RestControllerAdvice maps exceptions to HTTP responses
v3 response format V3ResponseAdvice
Metrics and logging MetricsAspect, RequestLoggingFilter, optionally RuntimeMetricsAspect
Write coordination ReindexLock and ManipulationThrottle, activated by @ReindexLock.Manipulation
Caching Spring Cache, with keys in CachingService.Keys
Schema Flyway migrations in src/main/resources/db/migration

Virtual threads are enabled (spring.threads.virtual.enabled).

Authorization model

classDiagram
    class Functionality {
        <<enumeration>>
        READ_RELEASED
        READ
        RELEASE_STATUS
        COMMENT
        WRITE
        CREATE
        DELETE
        RELEASE
        UNRELEASE
        READ_CONTRIBUTORS
        INVITE_FOR_REVIEW
        MANAGE_SPACE
        DEFINE_TYPES_AND_PROPERTIES
        …
        allowedPermissionLevels
        stage
    }
    class RoleMapping {
        <<enumeration>>
        CONSUMER
        REVIEWER
        EDITOR
        OWNER
        ADMIN
        fromRole(role) Set~FunctionalityInstance~
    }
    class FunctionalityInstance {
        <<record>>
        functionality
        space
        instanceId
    }
    class UserWithRoles {
        user
        permissions
        getPrivateSpace()
    }
    class AuthContext {
        getUserWithRoles()
        getInvitations()
        resolveSpaceName(name)
        restrictToSpaces(stage)
    }
    class PermissionService {
        canReadInstance(space, id, stage)
        canCreateInstance(space)
        canWriteInstance(space)
        canReleaseInstance(space)
        hasPermission(functionality, space, id) boolean
        hasPermissionOrThrow(functionality, space, id)
    }
    class Invitation {
        <<entity>>
        user
        instance
        scopes
    }

    RoleMapping "1" o-- "*" Functionality : grants
    RoleMapping ..> FunctionalityInstance : creates
    UserWithRoles "1" *-- "*" FunctionalityInstance
    AuthContext --> UserWithRoles
    PermissionService --> AuthContext
    AuthContext ..> Invitation : invited instance ids (cached)
Role Adds to the role below
CONSUMER READ_RELEASED
REVIEWER READ, RELEASE_STATUS, COMMENT
EDITOR WRITE, CREATE, DELETE, READ_CONTRIBUTORS, INVITE_FOR_REVIEW
OWNER RELEASE, UNRELEASE, MANAGE_SPACE
ADMIN All functionalities

PermissionService.hasPermission grants a functionality if the user has it globally, for the space, for the instance, or through a wildcard space. Invitations additionally grant READ and COMMENT on the invited instances and the instances in the invited scopes, in progress only.

A role is represented as the string <space>:<role>, or :<role> for a global role. RoleMapping.fromRole expands it to the functionalities of the role and the roles below it. Each user is ADMIN of their private space, which UserWithRoles adds automatically (ADR-043).

Decision records

Significant design decisions are recorded as ADRs and available under Decision records.