# mher/node-celery architecture

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

- Interactive diagram: https://gitdiagram.com/mher/node-celery
- Repository: https://github.com/mher/node-celery

## Overview

##### Main Components

a. Client Application Layer:
- Node.js application using the node-celery client
- Main client interface (celery.createClient())
- Event handling system (error, connect events)

b. Message Broker Layer:
- Both supported message brokers:
- RabbitMQ (AMQP)
- Redis
- Broker configuration options
- SSL/Security configurations for RabbitMQ

c. Result Backend Layer:
- Both supported backends:
- AMQP (RabbitMQ)
- Redis
- Different result handling mechanisms:
- Polling (Redis)
- Event-based (AMQP)

d. Celery Worker Layer:
- Connection to actual Celery workers
- Task routing capabilities
- Queue management

##### Connection Flows

- Task Publication Flow:
- Client → Message Broker → Celery Workers
- Result Retrieval Flow:
- Celery Workers → Result Backend → Client
- Event Handling Flow:
- System Events (connect, error)
- Task Events (ready, result)

##### Special features

- Task Management:
- ETA scheduling
- Expiration handling
- Task routing
- Queue configuration

- Result Handling:
- Polling mechanism (Redis)
- Event-based results (AMQP)
- Task status tracking

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        APP[Node.js Application]
        CLI["Client Interface"]
        PROTO["Protocol Handler"]
        TM["Task Management"]
        EH["Event Handler"]
    end

    subgraph "Message Broker"
        AMQP["RabbitMQ (AMQP)"]
        REDIS["Redis Broker"]
    end

    subgraph "Result Backend"
        AMQP_BACK["AMQP Backend"]
        REDIS_BACK["Redis Backend"]
    end

    subgraph "Celery Workers"
        WORKER["Celery Worker Processes"]
        QUEUE["Task Queues"]
    end

    %% Client Layer Connections
    APP --> CLI
    CLI --> PROTO
    CLI --> TM
    CLI --> EH

    %% Message Flow
    PROTO --> |Task Publication| AMQP
    PROTO --> |Task Publication| REDIS
    AMQP --> |Task Distribution| WORKER
    REDIS --> |Task Distribution| WORKER
    WORKER --> QUEUE
    WORKER --> |Results| AMQP_BACK
    WORKER --> |Results| REDIS_BACK
    AMQP_BACK --> |Event-based Results| PROTO
    REDIS_BACK --> |Polling Results| PROTO

    %% Click Events
    click CLI "https://github.com/mher/node-celery/blob/master/celery.js"
    click PROTO "https://github.com/mher/node-celery/blob/master/protocol.js"
    click REDIS_BACK "https://github.com/mher/node-celery/blob/master/examples/redis-backend.js"
    click TM "https://github.com/mher/node-celery/blob/master/examples/routing.js"

    classDef client fill:#a8d5e5
    classDef broker fill:#f9d5a7
    classDef backend fill:#d5a7f9
    classDef worker fill:#a7f9d5
    classDef component fill:#ffffff,stroke:#333,stroke-width:2px

    class APP,CLI,PROTO,TM,EH client
    class AMQP,REDIS broker
    class AMQP_BACK,REDIS_BACK backend
    class WORKER,QUEUE worker

    %% Legend
    subgraph Legend
        L1[Client Components]:::client
        L2[Message Brokers]:::broker
        L3[Result Backends]:::backend
        L4[Worker Components]:::worker
    end
```
