# haredis/haredis-py architecture

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

- Interactive diagram: https://gitdiagram.com/haredis/haredis-py
- Repository: https://github.com/haredis/haredis-py

## Overview

##### Main Components Identification

The system should be represented with these key components:

a) Core Components:
- Haredis Client Layer
- Lock Release Manager Layer
- Redis Integration Layer
- Async Support Layer

b) Supporting Components:
- Utility Services
- Exception Handling System
- Logging System

**┌─ Application Integration Layer ─┐**
- FastAPI Integration          │
- Sync/Async API Endpoints     │
- ┘

**┌─ Lock Release Management ──────┐    ┌─ Client Management ──────────┐**
- LockReleaseManager          │    │ - HaredisClientBuilder       │
- AioLockReleaseManager       │◄───►│ - AioHaredisClientBuilder   │
- ┘    └────────────────────────────┘

**┌─ Redis Connection Layer ───────┐**
- Sync Redis Client           │
- Async Redis Client          │
- ┘

##### Component Relationships

**┌─ Lock Management ─────────────┐**
- Stream-based locking       │
- Lock time extension        │
- High Availability support  │
- ┘

**┌─ Async Operations ────────────┐**
- Async client operations    │
- Async lock management      │
- Concurrent request handling│
- ┘

##### Implementation Details

Following key features:
- Lock-Release patterns (Streams/PubSub)
- High Availability mechanisms
- Error handling strategies
- Configuration options

- Separation between sync and async implementations
- Extensibility points for different Redis configurations
- Error handling and recovery paths
- Configuration parameters as notes

Remember to include version compatibility notes and any critical dependencies in supplementary documentation.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Application Integration Layer"
        API[FastAPI Integration]
        SyncEndpoints[Sync API Endpoints]
        AsyncEndpoints[Async API Endpoints]
    end

    subgraph "Core Service Layer"
        direction TB
        subgraph "Lock Release Management"
            LRM[Lock Release Manager]:::sync
            ALRM[Async Lock Release Manager]:::async
        end

        subgraph "Client Management"
            HCB[Haredis Client Builder]:::sync
            AHCB[Async Haredis Client Builder]:::async
        end
    end

    subgraph "Implementation Layer"
        direction TB
        subgraph "Lock Management"
            StreamLock[Stream-based Locking]
            LockExt[Lock Time Extension]
            HA[High Availability Support]
        end

        subgraph "Support Services"
            Logging[Logging System]:::logging
            Utils[Utility Services]:::utils
            Exceptions[Exception Handler]:::exceptions
        end
    end

    subgraph "Redis Integration Layer"
        SyncRedis[Sync Redis Client]:::redis
        AsyncRedis[Async Redis Client]:::redis
    end

    %% Relationships
    API --> SyncEndpoints & AsyncEndpoints
    SyncEndpoints --> LRM
    AsyncEndpoints --> ALRM
    
    LRM --> HCB
    ALRM --> AHCB
    
    HCB --> SyncRedis
    AHCB --> AsyncRedis
    
    LRM & ALRM --> StreamLock
    StreamLock --> LockExt
    LockExt --> HA
    
    LRM & ALRM --> Exceptions
    HCB & AHCB --> Utils
    Utils --> Logging

    %% Styling
    classDef sync fill:#2374ab
    classDef async fill:#2374ab,stroke-dasharray: 5 5
    classDef redis fill:#47a025
    classDef utils fill:#ffcd3c
    classDef logging fill:#ffcd3c
    classDef exceptions fill:#ffcd3c

    %% Click Events
    click LRM "https://github.com/haredis/haredis-py/blob/main/haredis/_manager/_manager.py"
    click ALRM "https://github.com/haredis/haredis-py/blob/main/haredis/_aio_manager/_aiomanager.py"
    click HCB "https://github.com/haredis/haredis-py/blob/main/haredis/_client/_builder.py"
    click AHCB "https://github.com/haredis/haredis-py/blob/main/haredis/_aioclient/_builder.py"
    click Exceptions "https://github.com/haredis/haredis-py/blob/main/haredis/_common/_exceptions.py"
    click Utils "https://github.com/haredis/haredis-py/blob/main/haredis/_utils/_util.py"
    click Logging "https://github.com/haredis/haredis-py/blob/main/haredis/_utils/_set_up_logging.py"

    %% Legend
    subgraph Legend
        L1[Sync Components]:::sync
        L2[Async Components]:::async
        L3[Redis Integration]:::redis
        L4[Support Services]:::utils
    end
```
