# waydotnet/celery-pubsub architecture

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

- Interactive diagram: https://gitdiagram.com/waydotnet/celery-pubsub
- Repository: https://github.com/waydotnet/celery-pubsub

## Overview

##### Main Components

a) Publisher Component
- Represents the publishing interface
- Handles both synchronous (publish_now) and asynchronous (publish) operations
- Manages topic routing logic

b) Subscriber Component
- Manages subscription registration
- Handles topic pattern matching (*, #)
- Stores subscriber task references

c) Celery Integration Layer
- Shows integration with Celery's task system
- Represents task execution flow

d) Message Broker (External)
- Underlying message broker that Celery uses
- Typically RabbitMQ or Redis

**→ : Data flow**
**⟷ : Integration point**
**🔷 : Core component**
**⬚ : External system**

- ┌──────────────────────────────────────┐
- celery-pubsub Library         │
**┌──────────────┐                   │  ┌──────────────┐   ┌──────────────┐ │**
- Client     │                   │  │   Publisher   │   │  Subscriber  │ │
- Application │ ─publish/sub─────→│  │   Component   │⟷│   Component   │ │
- ┘                   │  └──────────────┘   └──────────────┘ │
- ↓                  ↑         │
- ┌──────────────────────────┐        │
- Celery Integration    │        │
- ┴──────────────┬───────────┴────────┘
- ↓
- ┌────────────────────────────┐
- Message Broker        │
- (RabbitMQ/Redis)       │
- ┘

##### Key Elements to Highlight

a) Topic-based Routing:
- How topics are matched using wildcards (* and #)
- Topic routing flow from publishers to subscribers

b) Task Execution:
- Demonstrate how tasks are executed through Celery
- Both synchronous and asynchronous paths

c) Integration Points:
- Clear boundaries between the library and Celery
- External dependencies

##### Implementation Details

- Decorator-based subscription mechanism (@subscribe_to)
- Task registration system
- Demonstrate the topic pattern matching system
- Task execution flow

##### Additional Notes

- A note about version compatibility (Python 3.7+ and Celery 4/5)
- Distinction between sync and async operations
- Where task results can be optionally retrieved

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#dbeafe,stroke:#2563eb,stroke-width:2px
    classDef external fill:#dcfce7,stroke:#16a34a,stroke-width:2px
    classDef client fill:#ffedd5,stroke:#ea580c,stroke-width:2px
    classDef integration fill:#f3f4f6,stroke:#4b5563,stroke-width:2px

    %% Client Application
    Client["Client Application"]:::client

    %% Main Library Container
    subgraph Library["celery-pubsub Library"]
        %% Core Components
        Publisher["Publisher Component"]:::core
        Subscriber["Subscriber Component"]:::core
        CeleryIntegration["Celery Integration Layer"]:::core
        Interface["Package Interface"]:::core

        %% Component Relationships
        Publisher <--> Subscriber
        Publisher --> CeleryIntegration
        Subscriber --> CeleryIntegration
        Interface --> Publisher
        Interface --> Subscriber
    end

    %% External Components
    MessageBroker["Message Broker<br/>(RabbitMQ/Redis)"]:::external

    %% Connections
    Client --> Interface
    CeleryIntegration --> MessageBroker

    %% Click Events
    click Publisher "https://github.com/WaYdotNET/celery-pubsub/blob/master/celery_pubsub/pubsub.py"
    click Subscriber "https://github.com/WaYdotNET/celery-pubsub/blob/master/celery_pubsub/pubsub.py"
    click CeleryIntegration "https://github.com/WaYdotNET/celery-pubsub/blob/master/celery_pubsub/pubsub.py"
    click Interface "https://github.com/WaYdotNET/celery-pubsub/blob/master/celery_pubsub/__init__.py"

    %% Legend
    subgraph Legend
        L1["Core Component"]:::core
        L2["External System"]:::external
        L3["Client Integration"]:::client
        L4["Communication Path"]:::integration
    end
```
