# densumesh/broccoli architecture

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

- Interactive diagram: https://gitdiagram.com/densumesh/broccoli
- Repository: https://github.com/densumesh/broccoli

## Overview

##### Main Components

a) Core Components:
- Message Queue Interface Layer
- Broker Abstraction Layer
- Redis Implementation Layer
- Connection Pool Management
- Message Processing System
- Error Handling System

b) External Components:
- Redis Server
- Client Applications (Publishers)
- Worker Applications (Consumers)

##### Component Relationships

- Publishers → BroccoliQueue → Broker Interface → Redis Implementation → Redis Server
- Consumers → BroccoliQueue → Broker Interface → Redis Implementation → Redis Server

##### Specific Implementation Details

Key architectural elements:
**┌─────────────────────────────────────────────────────────┐**
- Client Applications                     │
- (Publishers)                     (Consumers)         │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Broccoli Queue                       │
- ┌─────────────────────────────────────────────────┐   │
- Queue Interface Layer              │   │
- (queue.rs)                     │   │
- ┘   │
- ┌─────────────────────────────────────────────────┐   │
- Broker Abstraction Layer              │   │
- (broker.rs, connect.rs, error.rs)         │   │
- ┘   │
- ┌─────────────────────────────────────────────────┐   │
- Redis Implementation                 │   │
- (redis/broker.rs, redis/utils.rs)           │   │
- ┘   │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Redis Server                         │
- ┘

##### Additional Elements

- Connection Pool: Show how multiple connections are managed
- Message Flow: Indicate message serialization/deserialization points
- Error Handling: Show where errors are caught and handled

##### Important Notes

- Version information
- Configuration points
- Where retry strategies are implemented
- Extension points for future broker implementations

##### Technical Details to Highlight

- Async processing capabilities
- Type-safe message handling
- Connection pooling mechanism
- Retry strategy implementation points
- Serialization/deserialization boundaries

Remember to maintain a balance between showing the current Redis implementation while indicating the system's design allows for easy addition of other message brokers in the future.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef interface fill:#a8d1ff,stroke:#2270c1
    classDef core fill:#ffb3b3,stroke:#ff0000
    classDef broker fill:#b3ffb3,stroke:#00ff00
    classDef external fill:#e6e6e6,stroke:#666666
    classDef implementation fill:#ffd9b3,stroke:#ff9933
    classDef error fill:#ffccff,stroke:#ff00ff
    classDef planned fill:#f2f2f2,stroke:#666666,stroke-dasharray: 5 5
    
    subgraph Client_Layer
        Publisher["Publisher Interface"]:::interface
        Consumer["Consumer Interface"]:::interface
        LibInterface["Main Library Interface"]:::interface
    end

    subgraph Queue_Layer
        QueueInterface["Message Queue Interface"]:::core
        QueueBuilder["Queue Builder"]:::core
    end

    subgraph Core_Processing
        MessageProcessor["Message Processing System"]:::core
        ConnPool["Connection Pool Manager"]:::core
        RetryHandler["Retry Strategy Handler"]:::core
    end

    subgraph Broker_Layer
        BrokerTrait["Broker Trait Interface"]:::broker
        MessageTypes["Message Type Definitions"]:::broker
    end

    subgraph Implementation_Layer
        RedisBroker["Redis Broker Implementation"]:::implementation
        RedisUtils["Redis Utilities"]:::implementation
        RabbitMQ["RabbitMQ Implementation"]:::planned
        Kafka["Kafka Implementation"]:::planned
    end

    subgraph Error_Handling
        ErrorSystem["Error Handling System"]:::error
    end

    subgraph External_Systems
        Redis[(Redis Server)]:::external
        RMQServer[(RabbitMQ Server)]:::planned
        KafkaServer[(Kafka Server)]:::planned
    end

    %% Relationships
    Publisher --> LibInterface
    Consumer --> LibInterface
    LibInterface --> QueueInterface
    QueueInterface --> QueueBuilder
    QueueBuilder --> BrokerTrait
    BrokerTrait --> MessageTypes
    BrokerTrait --> RedisBroker
    BrokerTrait -.-> RabbitMQ
    BrokerTrait -.-> Kafka
    RedisBroker --> RedisUtils
    RedisBroker --> ConnPool
    RedisBroker --> Redis
    RabbitMQ -.-> RMQServer
    Kafka -.-> KafkaServer
    MessageProcessor --> RetryHandler
    ErrorSystem --> QueueInterface
    ErrorSystem --> BrokerTrait
    ErrorSystem --> MessageProcessor

    %% Click Events
    click QueueInterface "https://github.com/densumesh/broccoli/blob/main/src/queue.rs"
    click BrokerTrait "https://github.com/densumesh/broccoli/blob/main/src/brokers/broker.rs"
    click RedisBroker "https://github.com/densumesh/broccoli/blob/main/src/brokers/redis/broker.rs"
    click ConnPool "https://github.com/densumesh/broccoli/blob/main/src/brokers/connect.rs"
    click ErrorSystem "https://github.com/densumesh/broccoli/blob/main/src/error.rs"
    click RedisUtils "https://github.com/densumesh/broccoli/blob/main/src/brokers/redis/utils.rs"
    click Publisher "https://github.com/densumesh/broccoli/blob/main/examples/publisher.rs"
    click Consumer "https://github.com/densumesh/broccoli/blob/main/examples/consumer.rs"
    click LibInterface "https://github.com/densumesh/broccoli/blob/main/src/lib.rs"

    %% Legend
    subgraph Legend
        L1["Interface Components"]:::interface
        L2["Core Components"]:::core
        L3["Broker Components"]:::broker
        L4["Implementation Components"]:::implementation
        L5["Error Handling"]:::error
        L6["External Systems"]:::external
        L7["Planned Features"]:::planned
    end
```
