# apache/curator architecture

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

- Interactive diagram: https://gitdiagram.com/apache/curator
- Repository: https://github.com/apache/curator

## Overview

##### Key Relationships and Interactions

- Client requests flow from CuratorFramework through to ZooKeeper
- Retry policy interactions with connection management
- Event propagation paths
- Cache synchronization patterns

##### Component Details

For each major component, include:

a) Recipes Module:
- Leaders election components
- Distributed locks
- Barriers
- Caches (PathChildrenCache, NodeCache, TreeCache)
- Atomic operations

b) Discovery Module:
- ServiceDiscovery
- ServiceCache
- ServiceProvider
- Instance management

c) Framework Core:
- Connection state management
- Session management
- Background operation handling
- Namespace management

##### Data Flow Indicators

Show:
- Synchronous operation flows
- Asynchronous operation flows
- Event notification paths
- Cache update mechanisms

##### Integration Points

Highlight:
- ZooKeeper server connection points
- Client application integration points
- Extension interfaces
- Plugin points

##### The connection management and retry mechanisms

Use a hierarchical layout with:
- Client applications at the top
- Curator framework in the middle layers
- ZooKeeper servers at the bottom
- Clear separation between sync and async paths
- Distinct boundaries between core functionality and recipes

This will provide a clear visualization of how Curator manages ZooKeeper interactions while providing high-level abstractions and reliable distributed coordination primitives.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Interface Layer"]
        CF["CuratorFramework"]:::core
        ACF["AsyncCuratorFramework"]:::async
        MF["ModeledFramework"]:::async
    end

    subgraph Features["Feature Modules Layer"]
        subgraph Recipes["Recipes Module"]
            LE["Leader Election"]:::recipe
            DL["Distributed Locks"]:::recipe
            BA["Barriers"]:::recipe
            CA["Caches"]:::recipe
            AO["Atomic Operations"]:::recipe
        end

        subgraph Discovery["Discovery Module"]
            SD["ServiceDiscovery"]:::discovery
            SC["ServiceCache"]:::discovery
            SP["ServiceProvider"]:::discovery
            IM["Instance Management"]:::discovery
        end

        subgraph DiscoveryServer["Discovery Server Module"]
            REST["REST Interface"]:::discovery
            DS["Discovery Server"]:::discovery
        end

        subgraph Async["Async Module"]
            AOP["Async Operations"]:::async
            EventH["Event Handlers"]:::async
        end
    end

    subgraph Core["Core Implementation Layer"]
        CM["Connection Management"]:::core
        SH["Session Handling"]:::core
        RM["Retry Mechanisms"]:::core
        SM["State Management"]:::core
    end

    ZK["Apache ZooKeeper"]:::external

    %% Connections
    CF --> CM
    CF --> SH
    CF --> SM
    ACF --> AOP
    MF --> AOP
    AOP --> CM
    CM --> ZK
    SH --> ZK
    RM --> CM
    SM --> CM

    %% Feature connections
    CF --> Recipes
    CF --> Discovery
    ACF --> Recipes
    ACF --> Discovery
    Discovery --> DiscoveryServer
    
    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef recipe fill:#4CAF50,stroke:#2E7D32,color:white
    classDef discovery fill:#FF9800,stroke:#EF6C00,color:white
    classDef async fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef external fill:#9E9E9E,stroke:#424242,color:white

    %% Click events
    click CF "https://github.com/apache/curator/blob/master/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java"
    click ACF "https://github.com/apache/curator/blob/master/curator-x-async/src/main/java/org/apache/curator/x/async/AsyncCuratorFramework.java"
    click MF "https://github.com/apache/curator/blob/master/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledFramework.java"
    click Recipes "https://github.com/apache/curator/tree/master/curator-recipes/src/main/java/org/apache/curator/framework/recipes/"
    click Discovery "https://github.com/apache/curator/tree/master/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/"
    click DiscoveryServer "https://github.com/apache/curator/tree/master/curator-x-discovery-server/src/main/java/org/apache/curator/x/discovery/server/"
    click CM "https://github.com/apache/curator/blob/master/curator-client/src/main/java/org/apache/curator/CuratorZookeeperClient.java"
    click SM "https://github.com/apache/curator/blob/master/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java"
    click RM "https://github.com/apache/curator/tree/master/curator-client/src/main/java/org/apache/curator/retry/"
    click SH "https://github.com/apache/curator/blob/master/curator-client/src/main/java/org/apache/curator/SessionFailRetryLoop.java"
    click Core "https://github.com/apache/curator/tree/master/curator-client/src/main/java/org/apache/curator/"
    click CA "https://github.com/apache/curator/tree/master/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/"
    click DL "https://github.com/apache/curator/tree/master/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/"
    click LE "https://github.com/apache/curator/tree/master/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader"
```
