# hangfireio/hangfire architecture

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

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

## Overview

##### Main Components

a. Core Components:
- Job Storage System (with multiple provider support)
- Background Job Server
- Background Job Client
- Dashboard UI
- Job Processing Pipeline

b. Integration Components:
- ASP.NET Core Integration
- OWIN Integration
- Storage Providers (SQL Server, MSMQ)

##### Key Relationships to Highlight

a. Client-Server Flow:
**Client -> Job Storage <- Background Server**

b. Job Processing Pipeline:
**Job Creation -> Queue -> Processing -> State Changes -> Completion**

##### Detailed Component Breakdown

a. Storage Layer:
- Concrete implementations (SqlServerStorage, MsmqStorage)
- Monitoring API connection

b. Server Components:
- BackgroundJobServer
- Worker Pools
- Job Filters
- State Machine
- Recurring Job Scheduler
- Delayed Job Scheduler

c. Client Components:
- BackgroundJobClient
- Job Creation Pipeline
- Continuation Management
- Recurring Job Manager

##### Specific Implementation Details

**[Dashboard UI] -----> [ASP.NET Core/OWIN Middleware]**

**[Client API] -----> [Storage Abstraction Layer]**

- [Storage Providers]
- /          \
- [SQL Server]     [MSMQ]

**[Background Server] <--> [Processing Pipeline]**

- [Worker Pools]         [State Machine]

**[Job Execution] <----- [Job Filters/Attributes]**

##### Additional Elements

- Queues and their relationships
- Retry mechanisms
- Continuation flows
- Demonstrate recurring job scheduling
- Monitoring and metrics flow

##### Important Architectural Patterns

- Publisher-subscriber pattern for job processing
- State machine pattern for job states
- Demonstrate the pipeline pattern for job filters
- Storage abstraction pattern

**→ Data Flow**
**⇢ Event Flow**
**↔ Two-way Communication**
**□ Core Component**
**○ Integration Point**
**◇ Storage Provider**

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        BJC[Background Job Client]
        JCP[Job Creation Pipeline]
        RJM[Recurring Job Manager]
        CONT[Continuation Management]
    end

    subgraph Integration
        ASPNET[ASP.NET Core Integration]
        OWIN[OWIN Integration]
    end

    subgraph Dashboard
        DUI[Dashboard UI]
        MON[Monitoring API]
    end

    subgraph Storage
        SAL[Storage Abstraction Layer]
        subgraph Providers
            SQL[SQL Server Storage]
            MSMQ[MSMQ Storage]
        end
    end

    subgraph Server
        BJS[Background Job Server]
        WP[Worker Pools]
        PP[Processing Pipeline]
        SM[State Machine]
        JF[Job Filters]
        RJS[Recurring Job Scheduler]
        DJS[Delayed Job Scheduler]
    end

    BJC --> SAL
    JCP --> SAL
    RJM --> SAL
    CONT --> SAL

    DUI --> ASPNET
    DUI --> OWIN
    DUI --> MON
    MON --> SAL

    SAL --> SQL
    SAL --> MSMQ

    BJS --> SAL
    BJS --> WP
    BJS --> PP
    PP --> SM
    PP --> JF
    BJS --> RJS
    BJS --> DJS

    classDef core fill:#2374ab
    classDef storage fill:#2a9d8f
    classDef processing fill:#e9c46a
    classDef integration fill:#8338ec
    classDef external fill:#grey

    class BJC,JCP,RJM,CONT core
    class SAL,SQL,MSMQ storage
    class BJS,WP,PP,SM,JF,RJS,DJS processing
    class ASPNET,OWIN integration
    class DUI,MON external

    click BJC "https://github.com/HangfireIO/Hangfire/blob/main/src/Hangfire.Core/BackgroundJobClient.cs"
    click BJS "https://github.com/HangfireIO/Hangfire/blob/main/src/Hangfire.Core/BackgroundJobServer.cs"
    click DUI "https://github.com/HangfireIO/Hangfire/tree/main/src/Hangfire.Core/Dashboard/"
    click PP "https://github.com/HangfireIO/Hangfire/tree/main/src/Hangfire.Core/Processing/"
    click ASPNET "https://github.com/HangfireIO/Hangfire/tree/main/src/Hangfire.AspNetCore/"
    click OWIN "https://github.com/HangfireIO/Hangfire/tree/main/src/Hangfire.Core/Dashboard/Owin/"
    click SQL "https://github.com/HangfireIO/Hangfire/tree/main/src/Hangfire.SqlServer/"
    click MSMQ "https://github.com/HangfireIO/Hangfire/tree/main/src/Hangfire.SqlServer.Msmq/"
    click SM "https://github.com/HangfireIO/Hangfire/tree/main/src/Hangfire.Core/States/"
    click JF "https://github.com/HangfireIO/Hangfire/blob/main/src/Hangfire.Core/Common/JobFilter.cs"
    click RJM "https://github.com/HangfireIO/Hangfire/blob/main/src/Hangfire.Core/RecurringJobManager.cs"
    click SAL "https://github.com/HangfireIO/Hangfire/tree/main/src/Hangfire.Core/Storage/"
```
