# enerbit/redsumer-rs architecture

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

- Interactive diagram: https://gitdiagram.com/enerbit/redsumer-rs
- Repository: https://github.com/enerbit/redsumer-rs

## Overview

##### Main Components
- Core Library: The central logic is defined inside the "redsumer-rs" directory. The project is organized into modules:
- The "core" module, which includes the generic client functionalities (client.rs, result.rs) and the streams submodule (producer, consumer, types).
- The "redsumer" submodule contains specific implementations of producer and consumer logic built on top of the core functionalities.
- Client & Configuration: The ClientArgs and configuration objects (ProducerConfig, ConsumerConfig) are used to abstract the connection details to the Redis server.
- External Dependencies: Although the Redis server is not part of the codebase, its role is crucial in the system. The code interacts with it for both producing and consuming messages.

##### Understand the Interactions
- Producers: A producer uses the client configurations to connect to Redis and sends messages to a designated stream. It allows for multiple ways of sending data (from BTreeMap, Vec of items, etc.).
- Consumers: A consumer initializes using similar connection details and then repeatedly polls Redis for new messages or pending messages. After processing a message, it acknowledges the message, ensuring that it is not reprocessed by other consumers.
- Redis Server (External): Acts as the data store for the Redis Streams. Both producing and consuming actions rely on the Redis commands and its stream semantics.

##### Architectural Patterns and Design Principles
- Modularity: The design shows a clear separation of concerns between the core functionalities (client, generic stream operations) and the higher-level abstractions (dedicated producer and consumer modules).
- Abstraction of Redis Operations: The project encapsulates the details on how messages are created, sent, and acknowledged. Using traits (e.g., ToRedisArgs) allows flexibility for data types.
- Resilience and Error Handling: Methods on producers and consumers clearly return a result that needs to be handled in case of errors, which is a good example of robust error management.

- Since this is a specialized Rust library targeting Redis Streams, emphasize the logical separation between the abstract “stream” operations and the actual network communication with Redis.
- How data flows from the producer through the client configuration to Redis and how the consumer continuously polls and acknowledges messages.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client & Config Layer"
        A["Client & Configuration (ClientArgs, ProducerConfig, ConsumerConfig)"]:::internal
    end

    subgraph "Core Library"
        B["Core: Client (client.rs)"]:::internal
        C["Core: Result Handling (result.rs)"]:::internal
        subgraph "Streams Submodule"
            D["Core Streams Producer Methods (producer.rs)"]:::internal
            E["Core Streams Consumer Methods (consumer.rs)"]:::internal
            F["Core Streams Types Definitions (types.rs)"]:::internal
        end
    end

    subgraph "Redsumer Modules"
        G["Redsumer Producer Implementation (producer.rs)"]:::internal
        H["Redsumer Consumer Implementation (consumer.rs)"]:::internal
    end

    I(["Redis Server"]):::external

    %% Data Flow and Interactions
    A -->|"Configure"| B
    A -->|"PassConfiguration"| D
    A -->|"PassConfiguration"| E

    B -->|"CommandExec"| I

    D -->|"FormatProduce"| G
    G -->|"ProduceMessage"| I

    I -->|"ConsumeRead"| E
    E -->|"ProcessMessage"| H
    H -->|"AcknowledgeMessage"| I

    %% Error Handling Paths
    B -- "ErrorHandling" --> C
    D -- "ErrorHandling" --> C
    E -- "ErrorHandling" --> C
    G -- "ErrorHandling" --> C
    H -- "ErrorHandling" --> C

    %% Styles
    classDef internal fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef external fill:#d4edda,stroke:#155724,stroke-width:2px,stroke-dasharray:5,5;

    %% Click Events
    click B "https://github.com/enerbit/redsumer-rs/blob/main/redsumer-rs/src/core/client.rs"
    click C "https://github.com/enerbit/redsumer-rs/blob/main/redsumer-rs/src/core/result.rs"
    click D "https://github.com/enerbit/redsumer-rs/blob/main/redsumer-rs/src/core/streams/producer.rs"
    click E "https://github.com/enerbit/redsumer-rs/blob/main/redsumer-rs/src/core/streams/consumer.rs"
    click F "https://github.com/enerbit/redsumer-rs/blob/main/redsumer-rs/src/core/streams/types.rs"
    click G "https://github.com/enerbit/redsumer-rs/blob/main/redsumer-rs/src/redsumer/producer.rs"
    click H "https://github.com/enerbit/redsumer-rs/blob/main/redsumer-rs/src/redsumer/consumer.rs"
```
