# kalbhor/tasqueue architecture

> Architecture diagram of the GitHub repository kalbhor/tasqueue, 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/kalbhor/tasqueue
- Repository: https://github.com/kalbhor/tasqueue

## Overview

##### Main Components

a) Core Components:
- Task Queue Server
- Broker Interface (with implementations)
- Results Interface (with implementations)
- Job Processor
- Task Registry

b) Supporting Components:
- Job Types (Single Jobs, Groups, Chains)
- Results Store
- Message Queue

**Top Layer: Client Interface**
**Middle Layer: Task Queue Server Components**
**Bottom Layer: Storage & Message Queue Infrastructure**

##### Component Relationships

a) Client Layer:
- How clients can create and enqueue Jobs, Groups, and Chains
- Result retrieval flow

b) Server Layer:
- Task Registry connection to Job Processor
- Job Processor interaction with Broker Interface
- Results Interface interaction with Results Store

##### Implementation Details

- Blue rectangles: Core interfaces (Broker, Results)
- Green rectangles: Concrete implementations (Redis, NATS-JS)
- Yellow diamonds: Job processing components
- Purple rectangles: Job types (Single, Group, Chain)

##### Specific Elements

a) Broker Interface (show all implementations):
- In-Memory Broker
- Redis Broker
- NATS-JS Broker

b) Results Interface (show all implementations):
- In-Memory Results
- Redis Results
- NATS-JS Results

c) Job Processing Flow:
- Job Creation
- Task Registration
- Job Processing
- Result Storage

##### Key Workflows to Illustrate

a) Job Processing Pipeline:
**Client → Server → Broker → Processor → Results Store**

b) Chain Processing:
**Job1 → Result1 → Job2 → Result2 → Job3**

c) Processing:
- Job1 →
**Job2 → Results Store**
- Job3 →

##### Important Details to Note

- Queue names and concurrency settings
- Error handling and retry flows
- Where atomic operations are guaranteed

##### Technical Specifications

- Queue names (default: "tasqueue:tasks")
- Concurrency settings
- Supported broker types
- Result storage options

##### The result storage and retrieval mechanism

- Flow direction indicators

This system design should capture both the high-level architecture and the important implementation details while maintaining clarity and readability.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Client
        CL[Client Application]
        JT[Job Types]:::jobtype
        click JT "https://github.com/kalbhor/tasqueue/blob/main/jobs.go"
        GR[Groups]:::jobtype
        click GR "https://github.com/kalbhor/tasqueue/blob/main/groups.go"
        CH[Chains]:::jobtype
        click CH "https://github.com/kalbhor/tasqueue/blob/main/chains.go"
    end

    %% Server Layer
    subgraph Server
        TQS[Task Queue Server]:::core
        click TQS "https://github.com/kalbhor/tasqueue/blob/main/server.go"
        TR[Task Registry]:::core
        click TR "https://github.com/kalbhor/tasqueue/blob/main/examples/tasks/tasks.go"
        JP[Job Processor]:::core
    end

    %% Interfaces Layer
    subgraph Interfaces
        BI[Broker Interface]:::interface
        click BI "https://github.com/kalbhor/tasqueue/blob/main/interfaces.go"
        RI[Results Interface]:::interface
        click RI "https://github.com/kalbhor/tasqueue/blob/main/interfaces.go"
    end

    %% Broker Implementations
    subgraph "Broker Implementations"
        IMB[In-Memory Broker]:::implementation
        click IMB "https://github.com/kalbhor/tasqueue/blob/main/brokers/in-memory/broker.go"
        RB[Redis Broker]:::implementation
        click RB "https://github.com/kalbhor/tasqueue/blob/main/brokers/redis/broker.go"
        NB["NATS-JS Broker"]:::implementation
        click NB "https://github.com/kalbhor/tasqueue/blob/main/brokers/nats-js/broker.go"
    end

    %% Results Implementations
    subgraph "Results Implementations"
        IMR[In-Memory Results]:::implementation
        click IMR "https://github.com/kalbhor/tasqueue/blob/main/results/in-memory/results.go"
        RR[Redis Results]:::implementation
        click RR "https://github.com/kalbhor/tasqueue/blob/main/results/redis/results.go"
        NR["NATS-JS Results"]:::implementation
        click NR "https://github.com/kalbhor/tasqueue/blob/main/results/nats-js/results.go"
    end

    %% Example Implementations
    subgraph Examples
        IME[In-Memory Example]:::example
        click IME "https://github.com/kalbhor/tasqueue/blob/main/examples/in-memory/main.go"
        RE[Redis Example]:::example
        click RE "https://github.com/kalbhor/tasqueue/blob/main/examples/redis/main.go"
        NE["NATS-JS Example"]:::example
        click NE "https://github.com/kalbhor/tasqueue/blob/main/examples/nats-js/main.go"
    end

    %% Connections
    CL --> JT & GR & CH
    JT & GR & CH --> TQS
    TQS --> TR
    TQS --> JP
    JP --> BI
    JP --> RI
    
    BI --> IMB & RB & NB
    RI --> IMR & RR & NR
    
    IMB & RB & NB --> IME & RE & NE
    IMR & RR & NR --> IME & RE & NE

    %% Styles
    classDef core fill:#f9f,stroke:#333,stroke-width:2px
    classDef interface fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef implementation fill:#90EE90,stroke:#333,stroke-width:2px
    classDef jobtype fill:#FFD700,stroke:#333,stroke-width:2px
    classDef example fill:#DEB887,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Interfaces]:::interface
        L3[Implementations]:::implementation
        L4[Job Types]:::jobtype
        L5[Examples]:::example
    end
```
