# bamzi/jobrunner architecture

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

- Interactive diagram: https://gitdiagram.com/bamzi/jobrunner
- Repository: https://github.com/bamzi/jobrunner

## Overview

##### Main Components

a) Core Components:
- Job Scheduler (Central Controller)
- Job Queue Manager
- Job Executor
- Status Monitor
- Web Interface Components

b) External Interfaces:
- HTTP Endpoints (for monitoring)
- Integration Points with Host Application

**┌─────────────────────────────────────────────┐**
- Host Application              │
- ┬─────────────────────────┘

**┌───────────────────▼─────────────────────────┐**
- JobRunner Core                  │
- ┬─────────────┬─────────────────┤
- Scheduler  │   Queue     │    Executor     │
- Manager    │                 │
- ┴─────────────┴─────────────────┘

- ┴────┬──────┘
- ▼
**┌─────────────────────────────────────────────┐**
- Status Monitor                  │
- ┬────────────────────────┤
- JSON API       │      HTML View         │
- ┴────────────────────────┘

##### Important Elements to Highlight

a) Job Lifecycle Flow:
- How jobs are scheduled (cron expressions)
- Job states (pending, running, completed)
- Monitoring feedback loop

b) Integration Points:
- How JobRunner integrates with the host application
- Monitoring endpoint connections

##### Technical Details

- Cron scheduling support
- Job types (Now, In, Every, Schedule)
- Status reporting formats (JSON/HTML)
- Connection to host application's HTTP router

##### Implementation Notes

- Asynchronous execution nature
- Framework-agnostic design
- Built-in monitoring capabilities
- Job scheduling patterns

##### Scale and Detail Level

- Main components and their interactions
- Job scheduling and execution flow
- Monitoring system integration
- Host application integration points

This system design should effectively communicate JobRunner's architecture as a lightweight, embedded job processing framework that operates asynchronously within a host application while providing monitoring capabilities.

Remember to emphasize the project's key feature of processing jobs outside the request flow, which is crucial for understanding its architecture and purpose.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Host["Host Application"]
        HA[Application Code]
    end

    subgraph Core["JobRunner Core"]
        direction TB
        JS["Job Scheduler"]:::core
        QM["Queue Manager"]:::core
        JE["Job Executor"]:::core
        JC["Job Control"]:::core
        Init["System Initializer"]:::core
    end

    subgraph Monitor["Monitoring Layer"]
        direction TB
        SM["Status Monitor"]:::monitor
        subgraph Interface["Interface Layer"]
            direction TB
            API["JSON API"]:::interface
            WEB["HTML View"]:::interface
        end
    end

    %% Connections
    HA --> JS
    JS --> QM
    QM --> JE
    JE --> JC
    JE --> SM
    SM --> API
    SM --> WEB
    Init --> JS
    Init --> QM
    Init --> SM

    %% Job Flow
    JOB[("Job Types")]:::jobtype
    JOB --> |Now/In/Every/Schedule| JS

    %% Styles
    classDef core fill:#a8d1f0,stroke:#333,stroke-width:1px
    classDef monitor fill:#90EE90,stroke:#333,stroke-width:1px
    classDef interface fill:#FFB6C1,stroke:#333,stroke-width:1px
    classDef jobtype fill:#FFE4B5,stroke:#333,stroke-width:1px

    %% Legend
    subgraph Legend
        L1["Core Component"]:::core
        L2["Monitor Component"]:::monitor
        L3["Interface Component"]:::interface
        L4[("Job Type")]:::jobtype
    end

    %% Click Events
    click JS "https://github.com/bamzi/jobrunner/blob/master/jobrunner.go"
    click JE "https://github.com/bamzi/jobrunner/blob/master/runjob.go"
    click SM "https://github.com/bamzi/jobrunner/blob/master/status.go"
    click JC "https://github.com/bamzi/jobrunner/blob/master/stopjob.go"
    click WEB "https://github.com/bamzi/jobrunner/blob/master/views/Status.html"
    click Init "https://github.com/bamzi/jobrunner/blob/master/init.go"
```
