# folio-org/mod-bulk-operations architecture

> Architecture diagram of the GitHub repository folio-org/mod-bulk-operations, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/folio-org/mod-bulk-operations
- Repository: https://github.com/folio-org/mod-bulk-operations

## Overview

##### Main Architectural Components
- Frontline API/Controller Layer: Represented by classes like BulkOperationController which handle incoming HTTP requests.
- Service Layer: Includes BulkOperationService, ConsortiaService, DataExportJobUpdateService, and many other specialized services that encapsulate the business logic.
- Client/Integration Layer: Contains numerous client classes (e.g., OkapiClient, DataImportClient, etc.) used for calling external services such as Okapi, retrieving configuration, and interfacing with S3 storage as well as delegating responsibilities to other FOLIO modules.
- Domain Model & Data Layer: The “domain” package with its many entity and bean classes (and converters) model the data. Persistence is managed by the repository layer that interacts with a relational database (as defined by the changelog scripts under the resources).
- Messaging Component: Kafka integration is clear from the “configs/kafka”, “processor” subpackages, and related DTOs. These components govern how bulk operation events and job updates are handled asynchronously.
- External Systems & Infrastructure:
- Database: Represent with a component showing the persistence/database engine receiving DML operations.
- File Storage: S3/MinIO as the file store for bulk file uploads and downloads.
- Message Broker: Kafka is used for event-driven messaging.
- CI/CD & Deployment: Dockerfile, Jenkinsfile, and other pipeline configuration files suggest containerized deployment and integration.
- Configuration & Monitoring: The existence of configuration files (application.yml, prometheus-jmx-config.yaml) indicate operational monitoring and service configuration management.

##### Relationships and Interactions
- Incoming REST requests enter through the API controller, which then routes to the service layer.
- The service layer coordinates with the repository layer for data persistence and with client components for:
- Communicating with Okapi or other FOLIO modules (using Feign clients with custom configuration).
- Initiating and consuming Kafka events (through KafkaConfiguration, KafkaService, and producer/consumer interceptors).
- Handling file operations via S3/MinIO storage.
- Data flows from the controller to services then to repositories and external clients, with responses flowing back in the reverse order.
- The use of domain converters and mappers suggests data transformation layers between external API formats (e.g., CSV for bulk upload files) and internal entities.

##### Important Architectural Patterns and Design Principles
- Layered (n-tier) architecture – clear separation between presentation (controllers), business logic (services), and data access (repositories).
- Client-Server Communication – use of RESTful endpoints and Feign clients to interact with other FOLIO modules.
- Event-driven processing – integration with Kafka for asynchronous updates and processing pipelines.
- Modular design – distinct package groups for “client,” “configs,” “domain,” “processor,” etc. ensure that each component’s responsibilities are separated and maintainable.
- Use of external configuration – environment variables and configuration files (such as application.yml) ensure that the module can work in multiple deployment setups (Docker, Kubernetes, etc.).

##### Relevant Technologies, Frameworks, and Integration Points
- Java (with Maven using pom.xml) and likely Spring Boot as the framework for building the application.
- Feign for declarative REST client integration.
- Kafka for messaging and integration with Apache Kafka brokers.
- S3 or MinIO for file storage.
- Docker, Jenkins, and possibly Kubernetes for container orchestration and CI/CD.
- Database interaction via JPA repositories (with changelogs under src/main/resources/db/changelog ensuring schema evolution).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Interactions
    APIConsumer("API Consumer"):::external

    %% Controller Layer
    subgraph "Controller Layer"
        BOController("BulkOperationController"):::internal
        click BOController "https://github.com/folio-org/mod-bulk-operations/blob/master/src/main/java/org/folio/bulkops/controller/BulkOperationController.java"
    end

    %% Service Layer
    subgraph "Service Layer"
        BOService("BulkOperationService"):::internal
        click BOService "https://github.com/folio-org/mod-bulk-operations/blob/master/src/main/java/org/folio/bulkops/service/BulkOperationService.java"
        Consortia("ConsortiaService"):::internal
        click Consortia "https://github.com/folio-org/mod-bulk-operations/blob/master/src/main/java/org/folio/bulkops/service/ConsortiaService.java"
        DataExport("DataExportJobUpdateService"):::internal
        click DataExport "https://github.com/folio-org/mod-bulk-operations/blob/master/src/main/java/org/folio/bulkops/service/DataExportJobUpdateService.java"
    end

    %% Domain & Data Layer
    subgraph "Domain & Data Layer"
        Domain("Domain Model"):::internal
        click Domain "https://github.com/folio-org/mod-bulk-operations/tree/master/src/main/java/org/folio/bulkops/domain"
        Repository("Repository"):::internal
        click Repository "https://github.com/folio-org/mod-bulk-operations/tree/master/src/main/java/org/folio/bulkops/repository"
    end

    %% Client/Integration Layer
    subgraph "Client/Integration Layer"
        Okapi("OkapiClient"):::client
        click Okapi "https://github.com/folio-org/mod-bulk-operations/blob/master/src/main/java/org/folio/bulkops/client/OkapiClient.java"
        DataImport("DataImportClient"):::client
        click DataImport "https://github.com/folio-org/mod-bulk-operations/blob/master/src/main/java/org/folio/bulkops/client/DataImportClient.java"
        RemoteFS("RemoteFileSystemClient"):::client
        click RemoteFS "https://github.com/folio-org/mod-bulk-operations/blob/master/src/main/java/org/folio/bulkops/client/RemoteFileSystemClient.java"
        S3Client("DataImportRestS3UploadClient"):::client
        click S3Client "https://github.com/folio-org/mod-bulk-operations/blob/master/src/main/java/org/folio/bulkops/client/DataImportRestS3UploadClient.java"
    end

    %% Messaging Component
    subgraph "Messaging Component"
        KafkaConfig("Kafka Configuration"):::internal
        click KafkaConfig "https://github.com/folio-org/mod-bulk-operations/tree/master/src/main/java/org/folio/bulkops/configs/kafka"
        KafkaDTO("Kafka DTOs"):::internal
        click KafkaDTO "https://github.com/folio-org/mod-bulk-operations/tree/master/src/main/java/org/folio/bulkops/configs/kafka/dto"
    end

    %% External Systems & Infrastructure
    subgraph "External Systems & Infrastructure"
        DB("Database Changelogs"):::external
        click DB "https://github.com/folio-org/mod-bulk-operations/tree/master/src/main/resources/db/changelog"
        KafkaBroker("Kafka Broker"):::external
        S3Storage("S3/MinIO Storage"):::external
        OkapiExt("External FOLIO Module via Okapi"):::external
    end

    %% CI/CD & Deployment
    subgraph "CI/CD & Deployment"
        Dockerfile("Dockerfile"):::external
        Jenkinsfile("Jenkinsfile"):::external
    end

    %% Configuration & Monitoring
    subgraph "Configuration & Monitoring"
        AppConfig("application.yml"):::external
        click AppConfig "https://github.com/folio-org/mod-bulk-operations/blob/master/src/main/resources/application.yml"
        Prometheus("prometheus-jmx-config.yaml"):::external
        click Prometheus "https://github.com/folio-org/mod-bulk-operations/blob/master/prometheus-jmx-config.yaml"
    end

    %% Connections
    APIConsumer -->|"calls"| BOController
    BOController -->|"delegates to"| BOService
    BOService -->|"orchestrates"| Consortia
    BOService -->|"orchestrates"| DataExport
    BOService -->|"uses"| Repository
    BOService -->|"transforms with"| Domain
    BOService -->|"calls"| Okapi
    BOService -->|"calls"| DataImport
    BOService -->|"calls"| RemoteFS
    BOService -->|"calls"| S3Client
    BOService -->|"triggers"| KafkaConfig
    BOService -->|"triggers"| KafkaDTO

    Domain -->|"maps to"| Repository
    Okapi -->|"communicates with"| OkapiExt
    S3Client -->|"accesses"| S3Storage
    KafkaConfig -->|"publishes"| KafkaBroker
    KafkaBroker -->|"sends to"| KafkaDTO

    %% Configuration influences
    AppConfig -.-> BOService
    Prometheus -.-> BOService

    %% Deployment connections (dotted)
    Dockerfile -.-> BOController
    Jenkinsfile -.-> BOController

    %% Styles
    classDef internal fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef client fill:#D5F5E3,stroke:#145A32,stroke-width:2px;
```
