# nawinsharma/message-queue-architecture architecture

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

- Interactive diagram: https://gitdiagram.com/nawinsharma/message-queue-architecture
- Repository: https://github.com/nawinsharma/message-queue-architecture

## Overview

- Producer – responsible for enqueuing jobs (for instance, simulating email tasks)
- Worker – listens to the “email-queue” and processes the jobs (simulating sending an email)

##### Main components
- Producer Application: A Node.js module that adds tasks to the queue.
- Worker Application: Another Node.js module that listens for and processes tasks.
- Message Queue Infrastructure: The BullMQ queue, hosted on Redis.
- Redis: The in-memory data store acting as the backend for the queue.
- External dependencies/libraries: BullMQ (for managing jobs) and any logging or event-handling mechanisms that appear in the code.

##### Architectural Patterns and Design Principles
- Client-Server (or Producer-Consumer): Clearly showing separation between the role that produces the tasks and the role that consumes/processes them.
- Asynchronous Processing: Emphasize the decoupled nature of job creation and job processing.
- Resilience: The Worker handles job events such as “completed,” “failed,” and error events, along with graceful shutdown signals.

##### Relevant Technologies
- Node.js (for both producer and worker)
- BullMQ: Highlight this as the job queue management system within Node.js.
- Redis: Note that Redis is the backend technology managing queue state.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Producer Subgraph
    subgraph "Producer"
        PA("Producer (Job Enqueue)"):::app
        PD("External Dependencies"):::dep
        PA -->|"uses"| PD
    end

    %% Message Queue Infrastructure
    subgraph "Message Queue Infrastructure"
        MQ("BullMQ/Redis (Queue Manager)"):::infra
    end

    %% Worker Subgraph
    subgraph "Worker"
        WA("Worker (Job Processing)"):::app
        WD("External Dependencies"):::dep
        WA -->|"uses"| WD
    end

    %% Data Flow
    PA -->|"adds-job-to-email-queue"| MQ
    MQ -->|"processes-job"| WA

    %% Click Events
    click PA "https://github.com/nawinsharma/message-queue-architecture/blob/main/producer/src/index.ts"
    click PD "https://github.com/nawinsharma/message-queue-architecture/blob/main/producer/package.json"
    click WA "https://github.com/nawinsharma/message-queue-architecture/blob/main/worker/src/index.ts"
    click WD "https://github.com/nawinsharma/message-queue-architecture/blob/main/worker/package.json"

    %% Styles
    classDef app fill:#ffdd99,stroke:#d97706,stroke-width:2px;
    classDef dep fill:#c6e5ff,stroke:#1d4ed8,stroke-width:2px;
    classDef infra fill:#ddf1dd,stroke:#16a34a,stroke-width:2px,stroke-dasharray: 5 5;
```
