# srttk/queue architecture

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

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

## Overview

##### Main Components Identification

a. Core Components:
- Queue Manager (Central Controller)
- Queue Processors
- Workers
- Redis Database (External Dependency)
- Job Processing Pipeline

**┌─────────────────────────────────────────┐**
- Queue Manager                 │
- ┌─────────┐ ┌─────────┐ ┌─────────┐    │
- Queues  │ │ Workers │ │ Events  │    │
- ┘ └─────────┘ └─────────┘    │
- ┘

**┌─────────────────────┐  ┌─────────────────────┐**
- Queue Process    │──│    Job Lifecycle    │
- Implementation   │  │      Management     │
- ┘  └─────────────────────┘

##### Detailed Elements

a. Queue Manager Section:
**┌─────────────────────────────────┐**
- Queue Manager           │
- ┌─────────┐    ┌─────────────┐ │
- Queues  │←→  │   Workers   │ │
- ┘    └─────────────┘ │
- ↓              ↓          │
- ┌─────────┐    ┌─────────────┐ │
- Jobs   │←→  │   Events    │ │
- ┘    └─────────────┘ │
- ┘

b. Job Processing Flow:
**┌───────────┐  ┌──────────┐  ┌───────────┐**
- Queued   │→ │ Active   │→ │ Completed │
- ┘  └──────────┘  └───────────┘
- ↓             ↓             ↓
**┌───────────┐  ┌──────────┐  ┌───────────┐**
- Stalled  │  │ Failed   │  │ Progress  │
- ┘  └──────────┘  └───────────┘

##### Special Features to Highlight

a. Namespace Support:
**┌─────────────────────┐**
- Namespace       │
- ┌───────┐ ┌───────┐│
- App1  │ │ App2  ││
- ┘ └───────┘│
- ┘

b. Worker Groups:
**┌────────────────────┐**
- Worker Groups    │
- ┌────┐ ┌────┐ ┌───┐│
- App1│ │App2│ │Dev││
- ┘ └────┘ └───┘│
- ┘

##### Implementation Notes

- Notes for important configuration options
- Error handling paths and recovery flows
- Scaling points and bottlenecks

## Diagram (Mermaid)

```mermaid
%%{init: {
  'theme': 'base',
  'themeVariables': {
    'primaryColor': '#2b2b2b',
    'primaryTextColor': '#fff',
    'primaryBorderColor': '#7C0000',
    'lineColor': '#F8B229',
    'secondaryColor': '#006100',
    'tertiaryColor': '#0000ff'
  }
}}%%

flowchart TB
    subgraph Core["Core Infrastructure Layer"]
        QM["Queue Manager"]
        QP["Queue Processors"]
        WG["Worker Groups"]
        NS["Namespace Support"]
    end

    subgraph Processing["Processing Layer"]
        JL["Job Lifecycle Management"]
        QE["Queue Events System"]
        
        subgraph Queues["Queue Implementations"]
            BQ["Basic Queue"]
            SP["Slow Processing Queue"]
            HR["High-Risk Queue"]
        end
    end

    subgraph External["External Dependencies"]
        RD[(Redis Database)]
    end

    %% Relationships
    QM --> QP
    QM --> WG
    QM --> NS
    QP --> JL
    QP --> QE
    JL --> Queues
    QE --> Queues
    QM -.-> RD
    QP -.-> RD

    %% Click Events
    click QM "https://github.com/srttk/queue/blob/main/src/lib/queue-manager.ts"
    click QP "https://github.com/srttk/queue/blob/main/src/lib/queue-process.ts"
    click WG "https://github.com/srttk/queue/blob/main/src/example/queues/group-greet.queue.ts"
    click NS "https://github.com/srttk/queue/blob/main/src/example/app3-namespace.ts"
    click JL "https://github.com/srttk/queue/blob/main/src/example/app5.life-cycle-events.ts"
    click QE "https://github.com/srttk/queue/blob/main/src/example/queues/events.ts"
    click BQ "https://github.com/srttk/queue/blob/main/src/example/queues/greet.queue.ts"
    click SP "https://github.com/srttk/queue/blob/main/src/example/queues/slow-greet.ts"
    click HR "https://github.com/srttk/queue/blob/main/src/example/queues/danger.queue.ts"

    %% Styling
    classDef core fill:#2b2b2b,stroke:#333,stroke-width:2px,color:#fff
    classDef processing fill:#006100,stroke:#333,stroke-width:2px,color:#fff
    classDef external fill:#0000ff,stroke:#333,stroke-width:2px,color:#fff
    classDef queue fill:#F8B229,stroke:#333,stroke-width:2px,color:#000

    class QM,QP,WG,NS core
    class JL,QE processing
    class RD external
    class BQ,SP,HR queue

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Processing Components"]:::processing
        L3["External Dependencies"]:::external
        L4["Queue Types"]:::queue
    end
```
