# yuzd/hangfire.httpjob architecture

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

- Interactive diagram: https://gitdiagram.com/yuzd/hangfire.httpjob
- Repository: https://github.com/yuzd/hangfire.httpjob

## Overview

##### Main Components
- Server Component (Hangfire.HttpJob):
– Contains the primary Hangfire integration with HTTP job scheduling.
– Hosts the dashboard and API endpoints (for adding background and recurring jobs via HTTP POST requests).
– Manages the HTTP job dispatch, configuration (including authentication using basic auth), and job processing logic.
– Includes UI elements (JavaScript and CSS) for the dashboard and visual reports.
- Agent Component (Hangfire.HttpJob.Agent):
– Offers extensions to quickly develop and execute job programs.
– Contains multiple submodules for different storage backends (MSSQL, MySQL, PostgreSQL, Redis). Each “console” project is tailored to a specific backend.
– Provides support for different job lifecycles (singleton, transient, and “hang until stop,” which is reflected in the custom attributes).
– Implements logging, heartbeat monitoring, and agent-specific utilities to help integrate the job processes with Hangfire.
- Client Component (Hangfire.HttpJob.Client):
– Provides a library for external consumers to submit jobs via code.
– Contains methods for constructing and sending background job payloads, recurring job payloads, and handling responses.

##### Interaction and Relationships
- External Consumers/Application Layer:
– Uses the Client to interact with the Hangfire server, calling methods to add or remove jobs.
– Can interact directly via RESTful API endpoints on the server as described in the README.
- Server and Dashboard:
– The server hosts the HTTP API endpoints and a dashboard (with dynamic CSS/JS for real-time updates, logging, cron generation, etc.).
– It manages job scheduling, processing, and dispatching on behalf of client requests.
– It communicates with and receives job execution requests from the Agent modules.
- Agent and Server Communication:
– Agent components plug into the Hangfire pipeline to execute jobs using different storage mechanics.
– They read configurations (from appsettings or job attributes) to decide how the job runs.
– Heartbeat and monitoring functionality is implemented in both Server and Agent, ensuring job status and health are visible on the dashboard.

##### Architectural Patterns and Technologies
- The system employs a modular, layered approach:
– Separating core processing (Server), specialized execution (Agent), and client interaction (Client) into distinct modules.
- It makes use of dependency injection (via .NET Core’s IServiceCollection) and configuration extension methods.
- The project uses Hangfire storage providers (e.g., MySQL, SQL Server, PostgreSQL, Redis) and offers flexibility to choose the appropriate database/storage.
- There’s a clear separation of concerns:
– The Server handles scheduling and dashboard UI.
– Agents are designed to support various back-end stores and provide extensible job execution.
– The Client abstracts the REST API calls, making integration simple for developers.
- The design emphasizes error handling, logging, and built-in support for notifying via email upon job execution completion.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Consumer
    EC("External Consumer"):::external

    %% Hangfire.HttpJob Client Subgraph
    subgraph "Hangfire.HttpJob Client"
        CL("Hangfire.HttpJob Client"):::client
        C1("Background Job Submission"):::client
        C2("Recurring Job Submission"):::client
        C3("HTTP Job Client Factory"):::client
        CL --> C1
        CL --> C2
        CL --> C3
    end

    %% Hangfire.HttpJob Server Subgraph
    subgraph "Hangfire.HttpJob Server"
        S("Hangfire.HttpJob Server"):::server
        API("API Endpoints(HTTP_POST)"):::core
        D("Dashboard UI"):::ui
        JD("Job Dispatcher"):::core
        CA("Configuration/Auth"):::core
        S --> API
        S --> D
        S --> JD
        S --> CA
    end

    %% Hangfire.HttpJob Agent Subgraph
    subgraph "Hangfire.HttpJob Agent"
        A("Hangfire.HttpJob Agent"):::agent
        MSSQL("Storage:MSSQL"):::storage
        MySQL("Storage:MySQL"):::storage
        Postgres("Storage:PostgreSQL"):::storage
        Redis("Storage:Redis"):::storage
        JL("Job Lifecycle Management"):::lifecycle
        LH("Logging/Heartbeat"):::core
        A --> MSSQL
        A --> MySQL
        A --> Postgres
        A --> Redis
        A --> JL
        A --> LH
    end

    %% Connections between components
    EC -->|"submitsJob"| CL
    EC -->|"RESTCall"| API
    CL -->|"callsAPI"| API
    S -->|"dispatchJob"| A
    A -->|"statusUpdate"| D

    %% Click Events for Component Mapping
    click S "https://github.com/yuzd/hangfire.httpjob/blob/master/Server/Hangfire.HttpJob"
    click A "https://github.com/yuzd/hangfire.httpjob/blob/master/Agent/Hangfire.HttpJob.Agent"
    click CL "https://github.com/yuzd/hangfire.httpjob/blob/master/Client/Hangfire.HttpJob.Client"

    %% Style Definitions
    classDef external fill:#ffe0b2,stroke:#f57c00,stroke-width:2px;
    classDef server fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef agent fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef client fill:#ffccbc,stroke:#bf360c,stroke-width:2px;
    classDef core fill:#d1c4e9,stroke:#512da8,stroke-width:2px;
    classDef ui fill:#f8bbd0,stroke:#c2185b,stroke-width:2px;
    classDef storage fill:#fff9c4,stroke:#fbc02d,stroke-width:2px;
    classDef lifecycle fill:#c5e1a5,stroke:#7cb342,stroke-width:2px;
```
