# golang-queue/queue architecture

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

- Interactive diagram: https://gitdiagram.com/golang-queue/queue
- Repository: https://github.com/golang-queue/queue

## Overview

##### Main Components

a) Core Queue System:
- Queue Pool Manager
- Worker Pool
- Task Handler
- Message Interface
- Recovery Handler
- Metrics Collector

b) Backend Implementations:
- Buffered Channel (Default)
- NSQ
- NATS
- Redis Pub/Sub
- Redis Streams
- RabbitMQ

**Top Layer: Client Applications**
**Middle Layer: Queue Library Core**
**Bottom Layer: Backend Services**

##### Specific Elements

a) Core Components (use rectangles):
- QueuePool: Central management component
- Worker: Goroutine execution units
- TaskMessage: Message interface
- ErrorHandler: Recovery mechanism
- MetricsCollector: Performance monitoring

b) Interfaces (use diamonds):
- Worker Interface
- Message Interface
- Queue Interface

- Channel Backend
- NSQ Connector
- NATS Connector
- Redis Connector
- RabbitMQ Connector

##### Flow Representation

- Task submission flow
- Worker allocation
- Message processing
- Error handling paths
- Backend communication

##### Important Details to Highlight

a) Concurrent Processing:
- How multiple workers operate simultaneously
- Worker pool size management
- Demonstrate task distribution

b) Backend Flexibility:
- Plug-and-play backend system
- Configuration options
- Message flow variations

##### Implementation Notes

- Goroutine pool management
- Message passing mechanisms
- Backend service integration
- Error recovery paths
- Metric collection points

##### Specific Project Elements

- Ring buffer implementation (ring.go)
- Worker pool management (pool.go)
- Job handling (job/job.go)
- Recovery mechanisms (recovery.go)
- Metric collection (metric.go)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef core fill:#2374f7,stroke:#000,stroke-width:2px,color:white
    classDef worker fill:#4CAF50,stroke:#000,stroke-width:2px,color:white
    classDef interface fill:#FFC107,stroke:#000,stroke-width:2px,color:black
    classDef backend fill:#9C27B0,stroke:#000,stroke-width:2px,color:white
    classDef error fill:#f44336,stroke:#000,stroke-width:2px,color:white
    classDef metrics fill:#00BCD4,stroke:#000,stroke-width:2px,color:white

    subgraph Client["Client Applications"]
        APP[Client Application]
    end

    subgraph Core["Core Queue System"]
        QP[Queue Pool Manager]:::core
        WP[Worker Pool]:::worker
        TH[Task Handler]:::core
        RH[Recovery Handler]:::error
        MC[Metrics Collector]:::metrics
        RB[Ring Buffer]:::core
        LOG[Logger System]:::core
        TM[Thread Management]:::core
    end

    subgraph Interfaces["Interface Layer"]
        WI[Worker Interface]:::interface
        MI[Message Interface]:::interface
        QI[Queue Interface]:::interface
    end

    subgraph Backends["Backend Services"]
        BC[(Buffered Channel)]:::backend
        NSQB[(NSQ)]:::backend
        NATSB[(NATS)]:::backend
        REDISB[(Redis)]:::backend
        RMQ[(RabbitMQ)]:::backend
    end

    %% Relationships
    APP --> QP
    QP --> WP
    WP --> TH
    TH --> RH
    TH --> MC
    WP --> RB
    QP --> LOG
    QP --> TM

    WP --> WI
    TH --> MI
    QP --> QI

    QI --> BC
    QI --> NSQB
    QI --> NATSB
    QI --> REDISB
    QI --> RMQ

    %% Click Events
    click QP "https://github.com/golang-queue/queue/blob/master/queue.go"
    click WP "https://github.com/golang-queue/queue/blob/master/pool.go"
    click TH "https://github.com/golang-queue/queue/blob/master/job/job.go"
    click RH "https://github.com/golang-queue/queue/blob/master/recovery.go"
    click MC "https://github.com/golang-queue/queue/blob/master/metric.go"
    click RB "https://github.com/golang-queue/queue/blob/master/ring.go"
    click LOG "https://github.com/golang-queue/queue/blob/master/logger.go"
    click TM "https://github.com/golang-queue/queue/blob/master/thread.go"
    click WI "https://github.com/golang-queue/queue/blob/master/mocks/mock_worker.go"
    click MI "https://github.com/golang-queue/queue/blob/master/mocks/mock_queued_message.go"

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Worker Components]:::worker
        L3[Interfaces]:::interface
        L4[Backend Services]:::backend
        L5[Error Handling]:::error
        L6[Metrics]:::metrics
    end
```
