# jobrunr/jobrunr architecture

> Architecture diagram of the GitHub repository jobrunr/jobrunr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jobrunr/jobrunr
- Repository: https://github.com/jobrunr/jobrunr

## Overview

##### Core Components

a. Job Scheduling Layer
- Fire-and-forget jobs (BackgroundJob.enqueue)
- Delayed jobs (BackgroundJob.schedule)
- Recurring jobs (BackgroundJob.scheduleRecurrently)
- JobRunr API interface that accepts job submissions

b. Processing Layer
- Job execution engine
- Worker thread pools
- Job state management
- Retry mechanism with back-off policy

c. Storage Layer
- RDBMS (PostgreSQL, MySQL, Oracle, SQL Server, DB2)
- NoSQL (MongoDB, Redis, ElasticSearch)
- Storage tables/collections:
- Jobs table
- Recurring jobs table
- Background job servers table
- Job stats

d. Dashboard Component
- Web-based dashboard showing:
- Job monitoring interface
- Real-time statistics
- Server status
- Job management controls

##### Integration Points

a. Framework Support
- Integration with:
- Spring Boot
- Quarkus
- Micronaut
- Plain Java

b. Monitoring & Metrics
- Connections to:
- Health checks
- Metrics (MicroMeter)
- Logging system

##### Flow Patterns

- Job submission flow from applications to scheduler
- Job distribution to background servers
- State changes and persistence
- Dashboard data flow
- Health check and metrics reporting

##### Clustering & Distribution

Illustrate:
- Multiple background job servers
- Job distribution mechanism
- Cluster coordination
- Load balancing

##### Important Notes

Callouts highlighting:
- Distributed nature of the system
- Fault tolerance capabilities
- Persistent storage backing
- Horizontal scaling ability
- Smart retry mechanism

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        API[Client Applications]
    end

    subgraph JobScheduler[Job Scheduling Layer]
        direction TB
        BackgroundJob["BackgroundJob API"]:::api
        JobBuilder["Job Builder"]:::core
        RecurringJobs["Recurring Jobs"]:::core
    end

    subgraph Processing[Processing Layer]
        direction TB
        BGServer["Background Job Server"]:::core
        JobPerformer["Job Performer"]:::core
        ThreadPool["Thread Pool"]:::core
    end

    subgraph Storage[Storage Layer]
        direction TB
        StorageProvider["Storage Provider Interface"]:::core
        subgraph SQL[SQL Storage]
            RDBMS[("RDBMS\n(PostgreSQL, MySQL,\nOracle, DB2)")]:::db
        end
        subgraph NoSQL[NoSQL Storage]
            NoSQLDB[("NoSQL\n(MongoDB, Redis,\nElasticSearch)")]:::db
        end
    end

    subgraph Dashboard[Dashboard Component]
        direction TB
        WebServer["Web Server"]:::ui
        APIHandler["API Handler"]:::api
        Frontend["Frontend UI"]:::ui
    end

    subgraph Frameworks[Framework Integration]
        direction TB
        Spring["Spring Boot"]:::framework
        Quarkus["Quarkus"]:::framework
        Micronaut["Micronaut"]:::framework
    end

    subgraph Monitoring[Monitoring & Metrics]
        direction TB
        Health["Health Checks"]:::monitor
        Metrics["Metrics"]:::monitor
    end

    API --> BackgroundJob
    BackgroundJob --> JobBuilder
    BackgroundJob --> RecurringJobs
    JobBuilder --> BGServer
    RecurringJobs --> BGServer
    BGServer --> JobPerformer
    BGServer --> ThreadPool
    JobPerformer --> StorageProvider
    StorageProvider --> RDBMS
    StorageProvider --> NoSQLDB
    BGServer --> APIHandler
    APIHandler --> WebServer
    WebServer --> Frontend
    BGServer --> Health
    BGServer --> Metrics
    Frameworks --> BackgroundJob

    %% Click Events
    click BackgroundJob "https://github.com/jobrunr/jobrunr/blob/master/core/src/main/java/org/jobrunr/scheduling/BackgroundJob.java"
    click JobBuilder "https://github.com/jobrunr/jobrunr/blob/master/core/src/main/java/org/jobrunr/scheduling/JobBuilder.java"
    click RecurringJobs "https://github.com/jobrunr/jobrunr/blob/master/core/src/main/java/org/jobrunr/scheduling/RecurringJobBuilder.java"
    click BGServer "https://github.com/jobrunr/jobrunr/blob/master/core/src/main/java/org/jobrunr/server/BackgroundJobServer.java"
    click JobPerformer "https://github.com/jobrunr/jobrunr/blob/master/core/src/main/java/org/jobrunr/server/BackgroundJobPerformer.java"
    click ThreadPool "https://github.com/jobrunr/jobrunr/tree/master/core/src/main/java/org/jobrunr/server/threadpool/"
    click StorageProvider "https://github.com/jobrunr/jobrunr/blob/master/core/src/main/java/org/jobrunr/storage/StorageProvider.java"
    click SQL "https://github.com/jobrunr/jobrunr/tree/master/core/src/main/java/org/jobrunr/storage/sql/"
    click NoSQL "https://github.com/jobrunr/jobrunr/tree/master/core/src/main/java/org/jobrunr/storage/nosql/"
    click WebServer "https://github.com/jobrunr/jobrunr/blob/master/core/src/main/java/org/jobrunr/dashboard/JobRunrDashboardWebServer.java"
    click APIHandler "https://github.com/jobrunr/jobrunr/blob/master/core/src/main/java/org/jobrunr/dashboard/JobRunrApiHandler.java"
    click Frontend "https://github.com/jobrunr/jobrunr/tree/master/core/src/main/resources/org/jobrunr/dashboard/frontend/"
    click Spring "https://github.com/jobrunr/jobrunr/tree/master/framework-support/jobrunr-spring-boot-2-starter/"
    click Quarkus "https://github.com/jobrunr/jobrunr/tree/master/framework-support/jobrunr-quarkus-extension/"
    click Micronaut "https://github.com/jobrunr/jobrunr/tree/master/framework-support/jobrunr-micronaut-feature/"
    click Health "https://github.com/jobrunr/jobrunr/tree/master/core/src/main/java/org/jobrunr/dashboard/ui/model/problems/"
    click Metrics "https://github.com/jobrunr/jobrunr/tree/master/core/src/main/java/org/jobrunr/server/metrics/"

    %% Styling
    classDef core fill:#2374ab
    classDef api fill:#ff7f50
    classDef db fill:#2a9d8f
    classDef ui fill:#f4a261
    classDef framework fill:#e76f51
    classDef monitor fill:#9b5de5

    %% Legend
    subgraph Legend
        direction TB
        L1[Core Components]:::core
        L2[APIs]:::api
        L3[Databases]:::db
        L4[UI Components]:::ui
        L5[Framework Integration]:::framework
        L6[Monitoring]:::monitor
    end
```
