Skip to content

[FEAT] Introduce RESTHeart Repository Connector (oc-restheart-repository-connector) for MongoDB & Document REST APIs #82

Description

@OpenPj

📄 Summary

We propose introducing a dedicated RESTHeart Repository Connector (oc-restheart-repository-connector) module to support RESTHeart the open-source Web API server for MongoDB and HTTP microservices as a native enterprise data source for OpenCrawling.

Adding native support for RESTHeart allows organizations using RESTHeart to expose MongoDB collections, document databases, GridFS binary files, and microservice APIs to seamlessly crawl, index, vector-embed, and secure JSON documents and attachments into downstream Vector Search, RAG pipelines, and Model Context Protocol (MCP) AI Agents.


🎯 Motivation & Enterprise Use Case

RESTHeart by SoftInstigate is a widely adopted open-source framework that instantly turns MongoDB databases and microservices into secure REST, GraphQL, and WebSocket APIs.

Enterprises rely on RESTHeart for:

  1. JSON Document Storage & Microservices: Storing multi-structured domain entities, customer records, audit logs, and catalog items in MongoDB collections exposed over HTTP REST APIs.
  2. GridFS Binary Attachments: Serving large files, PDF reports, images, and media blobs stored in MongoDB GridFS buckets via RESTHeart's RESTful file endpoints.
  3. Built-in Security & RBAC: Enforcing fine-grained Access Control Lists (ACLs), Role-Based Access Control (RBAC), and JWT / Basic / API-Key authentication at the database and collection levels.
  4. Change Streams & Real-time WebSockets: Emitting real-time document mutation events whenever documents are inserted, updated, or deleted.

However, when enterprise AI applications deploy Retrieval-Augmented Generation (RAG), documents stored within RESTHeart/MongoDB collections often remain isolated. By introducing oc-restheart-repository-connector, OpenCrawling can incrementally scan RESTHeart collections, extract raw JSON payloads and GridFS attachments, map native RESTHeart ACL security rules into Open Ingestion Standard (OIS) headers, and stream vector embeddings to vector databases with zero-trust identity security.


💡 Proposed Architecture & Data Pipeline

graph TD
    subgraph RESTHeart API & MongoDB Store
        RH[RESTHeart Web API Server]
        MongoDB[(MongoDB Collections / GridFS Buckets)]
        Sec[RESTHeart Security Engine - RBAC / ACLs]
        RH --> MongoDB
        RH --> Sec
    end

    subgraph OpenCrawling Ingestion Pipeline
        Connector[oc-restheart-repository-connector]
        Connector -->|1. Authenticate & Page REST Collections / GridFS| RH
        Connector -->|2. Fetch Document JSON & Binary Streams| RH
        Connector -->|3. Extract Roles & User ACLs| Sec
        
        Core[oc-core Pipeline - Tika & TokenTextSplitter]
        Kafka[Apache Kafka - Topic: raw-documents]
        
        Connector -->|4. Emit OIS RepositoryDocuments + ACL Metadata| Core
        Core -->|5. Publish Document Chunks| Kafka
    end

    subgraph Embedding & Vector Target
        Embed[Spring AI / EmbeddingModel - Ollama / OpenAI]
        VectorStore[(Vector Store - pgvector / Qdrant / ES)]
        Kafka --> Embed
        Embed -->|6. Store Embeddings + ACL Metadata| VectorStore
    end

    subgraph AI Retrieval / RAG
        MCP[OpenCrawling Secure MCP Server]
        LLM[LLM Agent / RAG Pipeline]
        LLM -->|7. Query MCP with User Identity| MCP
        MCP -->|8. Filtered Vector Search via OIS ACLs| VectorStore
    end
Loading

🏛️ Implementation Details & Specifications

1. Maven Module (oc-restheart-repository-connector)

Create a new Maven sub-module oc-restheart-repository-connector within the OpenCrawling project structure:

<dependency>
    <groupId>org.opencrawling</groupId>
    <artifactId>oc-core</artifactId>
    <version>${project.version}</version>
</dependency>

<!-- Reactive WebClient / HTTP Client for RESTHeart REST APIs -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
</dependency>

2. Core Repository Connector Implementation (RestheartRepositoryConnector.java)

  • Implement RepositoryConnector interface from oc-core.
  • Annotate with @Component and @ConditionalOnProperty(name = "opencrawling.connector.restheart.enabled", havingValue = "true").
  • Execute collection scans leveraging Java 25 Virtual Threads and StructuredTaskScope for concurrent batch fetching across databases, collections, and GridFS buckets.

Key Crawling Strategies:

  1. Full Collection Scan: Pages through collections using RESTHeart pagination headers and query parameters (GET /{db}/{coll}?page=1&pagesize=100&sort={"_etag":1}).
  2. Incremental Crawling via _etag / _lastModified: Filters updated documents using RESTHeart filter syntax (GET /{db}/{coll}?filter={"_etag":{"$gt":{"$oid":"..."}}}).
  3. GridFS File Ingestion: Detects GridFS file collections (*.files) and fetches binary file contents via RESTHeart binary endpoints (GET /{db}/{bucket}/{file_id}) for Apache Tika text & metadata extraction.
  4. Change Stream Ingestion: Connects to RESTHeart WebSocket / Change Stream endpoints (GET /{db}/{coll}/_changes) for real-time document mutation streaming.

3. Security & ACL Mapping (RestheartAclExtractor.java)

RESTHeart provides role-based and permission-based security. The connector will automatically extract document and collection-level permission rules and translate them into Open Ingestion Standard (OIS) ACL headers:

// Maps RESTHeart security roles and allowed read principals to OIS ACL Headers
OisDocumentHeader oisHeader = OisDocumentHeader.builder()
    .uri("restheart://" + host + "/" + database + "/" + collection + "/" + documentId)
    .title(document.path("title").asText(documentId))
    .mimeType("application/json")
    .lastModified(Instant.ofEpochMilli(document.path("_etag").path("$timestamp").path("t").asLong()))
    .securityInheritanceEnabled(true)
    .allowedReadPrincipals(extractRestheartRoles(document)) // e.g. ["role:finance", "role:admin", "user:john.doe"]
    .deniedReadPrincipals(List.of())
    .build();

4. Configuration Schema (application.yml)

opencrawling:
  connector:
    restheart:
      enabled: true
      endpoint: "http://restheart-server:8080"
      authentication:
        type: "BASIC" # BASIC, BEARER_JWT, or API_KEY
        username: "${RESTHEART_ADMIN_USER}"
        password: "${RESTHEART_ADMIN_PASSWORD}"
        api-key: "${RESTHEART_API_KEY}"
      target-databases:
        - name: "enterprise_db"
          collections: ["contracts", "reports", "customer_files.files"]
          exclude-collections: ["system.indexes", "_users"]
      scan-gridfs: true
      batch-size: 100
      cron: "0 */15 * * * *" # Sync every 15 minutes

🧪 Acceptance Criteria

  • New Maven module oc-restheart-repository-connector added to parent pom.xml.
  • Implement RestheartRepositoryConnector supporting RESTHeart REST APIs (documents, collections, GridFS files).
  • Implement incremental scan mechanism based on _etag / _lastModified timestamps.
  • Implement RestheartAclExtractor to map RESTHeart roles and permissions to OIS ACL headers.
  • Add integration test suite using Testcontainers (softinstigate/restheart and mongo container images).
  • Add full documentation and usage guide to opencrawling.github.io.

📌 References

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions