# trendyol/go-dcp architecture

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

- Interactive diagram: https://gitdiagram.com/trendyol/go-dcp
- Repository: https://github.com/trendyol/go-dcp

## Overview

##### Main Components
- DCP Client Core: Represent the core module that manages Couchbase data streams and event delivery. This includes files like api/api.go, dcp.go, and dcp_test.go.
- Couchbase Integration Module: Emphasize the components specific to interacting with Couchbase (found under the “couchbase” directory) for handling asynchronous operations, document operations, versioning, healthchecks, and membership.
- Membership & Leader Election: Separate out the membership-related logic (in directories like membership, leaderelector, and the Kubernetes specific implementations) to show the dynamic membership, static membership, or leader election (especially for Kubernetes implementations using HA leader election or StatefulSet membership).
- Configuration & Metadata Management: Include the configuration management modules (under config) and metadata handling (found under metadata) which, together, are critical for bootstrapping the client with Couchbase and membership settings.
- Utility and Helper Modules: Identify helper packages (under helpers, logger, and metric) used for logging, constants, and metrics registration, which are essential for debugging and performance monitoring.
- External Integration & Deployment: Although not part of the core library, include examples and deployment templates (in the example and kubernetes directories) to highlight how the DCP client is containerized (Dockerfiles) and deployed in real-world environments.

##### Relationships and Data Flow
- Use connectors from the core DCP component to the Couchbase integration module; illustrate that event data (mutations, deletions, expirations) are processed here.
- How configuration settings and metadata are loaded (from config files and environment variables) into the core and auxiliary modules.

##### Architectural Patterns and Principles
- Modular Design: Emphasize the separation of concerns between core DCP functionality, Couchbase-specific operations, membership handling, and external APIs.
- Configurability and Extensibility: Mark how configuration and environment variable overrides allow tailored deployment and how membership modes (static vs. dynamic) enable integration with different orchestration systems.
- Observability: Note the inclusion of detailed logging and metrics (with dedicated packages, e.g., logger and metric) and the API endpoints that expose system health.
- Resilience: Indicate the presence of healthchecking, rollback mitigation, and checkpointing mechanisms to ensure robust and stateful processing.

- Branch out to modules like “Couchbase Integration”, “Membership & Leader Election”, “Metadata & Configuration”, and “Utilities (logger/metrics)”.
- Annotations, such as key configurations (e.g., dcp configurations) and important interactions (like member rebalances, event acknowledgments) for clarity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    CB["Couchbase Database"]:::external
    PROM["Prometheus"]:::external
    GRAF["Grafana"]:::external

    %% DCP Client Core Subgraph
    subgraph "DCP Client Core"
        DCP_Go["dcp.go"]:::core
        DCP_Test["dcp_test.go"]:::core
        API_Core["api/api.go"]:::core
    end

    %% Couchbase Integration Module
    CIC["Couchbase Integration"]:::integration

    %% Membership & Leader Election Subgraph
    subgraph "Membership & Leader Election"
        Membership["membership/"]:::membership
        LeaderElector["leaderelector/leader_elector.go"]:::membership
        KubernetesMembership["kubernetes/"]:::membership
    end

    %% Configuration & Metadata Management Subgraph
    subgraph "Configuration & Metadata Management"
        Configuration["config/"]:::config
        Metadata["metadata/"]:::config
    end

    %% Utility and Helper Modules Subgraph
    subgraph "Utility and Helper Modules"
        Helpers["helpers/"]:::utility
        Logger["logger/logger.go"]:::utility
        MetricsUtil["metric/"]:::utility
    end

    %% API & Monitoring Endpoints Subgraph
    subgraph "API & Monitoring Endpoints"
        REST_API["api/api.go"]:::api
        MetricsEndpoint["metric/"]:::api
    end

    %% External Integration & Deployment Subgraph
    subgraph "External Integration & Deployment"
        Examples["example/"]:::deployment
        KubernetesDeployment["example/kubernetes/"]:::deployment
        GrafanaExample["example/grafana/"]:::deployment
    end

    %% Data Flow Connections
    CB -- "streams" --> DCP_Go
    DCP_Go -- "processes" --> CIC
    DCP_Go -- "coordinates" --> Membership
    DCP_Go -- "loads" --> Configuration
    DCP_Go -- "utilizes" --> Helpers
    DCP_Go -- "exposes" --> REST_API
    REST_API -- "reports to" --> PROM
    REST_API -- "visualizes" --> GRAF
    MetricsEndpoint -- "feeds" --> Examples

    %% Additional connections from core subgraph internal nodes (vertical grouping)
    DCP_Go --> DCP_Test
    DCP_Test --> API_Core

    %% Class Definitions with Colors
    classDef external fill:#b3e5fc,stroke:#01579b,stroke-width:2px;
    classDef core fill:#ffe082,stroke:#f57f17,stroke-width:2px;
    classDef integration fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef membership fill:#d1c4e9,stroke:#512da8,stroke-width:2px;
    classDef config fill:#ffccbc,stroke:#d84315,stroke-width:2px;
    classDef utility fill:#d7ccc8,stroke:#5d4037,stroke-width:2px;
    classDef api fill:#b2dfdb,stroke:#00796b,stroke-width:2px;
    classDef deployment fill:#f8bbd0,stroke:#ad1457,stroke-width:2px;

    %% Click Events for DCP Client Core Files
    click DCP_Go "https://github.com/trendyol/go-dcp/blob/master/dcp.go"
    click DCP_Test "https://github.com/trendyol/go-dcp/blob/master/dcp_test.go"
    click API_Core "https://github.com/trendyol/go-dcp/blob/master/api/api.go"

    %% Click Event for Couchbase Integration Module
    click CIC "https://github.com/trendyol/go-dcp/tree/master/couchbase/"

    %% Click Events for Membership & Leader Election Modules
    click Membership "https://github.com/trendyol/go-dcp/tree/master/membership/"
    click LeaderElector "https://github.com/trendyol/go-dcp/blob/master/leaderelector/leader_elector.go"
    click KubernetesMembership "https://github.com/trendyol/go-dcp/tree/master/kubernetes/"

    %% Click Events for Configuration & Metadata Management
    click Configuration "https://github.com/trendyol/go-dcp/tree/master/config/"
    click Metadata "https://github.com/trendyol/go-dcp/tree/master/metadata/"

    %% Click Events for Utility and Helper Modules
    click Helpers "https://github.com/trendyol/go-dcp/tree/master/helpers/"
    click Logger "https://github.com/trendyol/go-dcp/blob/master/logger/logger.go"
    click MetricsUtil "https://github.com/trendyol/go-dcp/tree/master/metric/"

    %% Click Events for API & Monitoring Endpoints
    click REST_API "https://github.com/trendyol/go-dcp/blob/master/api/api.go"
    click MetricsEndpoint "https://github.com/trendyol/go-dcp/tree/master/metric/"

    %% Click Events for External Integration & Deployment
    click Examples "https://github.com/trendyol/go-dcp/tree/master/example/"
    click KubernetesDeployment "https://github.com/trendyol/go-dcp/tree/master/example/kubernetes/"
    click GrafanaExample "https://github.com/trendyol/go-dcp/tree/master/example/grafana/"
```
