# chitika/cberl architecture

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

- Interactive diagram: https://gitdiagram.com/chitika/cberl
- Repository: https://github.com/chitika/cberl

## Overview

##### Main Components

a) Core Components:
- Erlang Application Layer
- NIF Interface Layer
- libcouchbase Integration Layer
- Connection Pool Management
- Transcoder System

b) External Dependencies:
- Couchbase Server
- libcouchbase Library

- cberl.erl (Main API Module)
- cberl_app.erl (Application Behavior)
- cberl_sup.erl (Supervisor)

- cberl_worker.erl (Connection Pool Workers)
- cberl_transcoder.erl (Data Encoding/Decoding)

- cberl_nif.erl (Erlang NIF Interface)
- C Source Files (c_src/*.c and *.h files)

- libcouchbase
- Couchbase Server

##### Key Relationships to Highlight

- Application calls → Worker Pool
- Worker Pool → NIF Interface
- NIF Interface → libcouchbase
- libcouchbase → Couchbase Server
- Data flow through Transcoder

##### Specific Design Elements

- Rectangles: Erlang modules
- Hexagons: NIF components
- Rounded rectangles: External libraries

- Blue: Erlang components
- Green: C/NIF components
- Orange: External dependencies
- Purple: Data transformation components

##### Important Features to Emphasize

- Connection pooling mechanism
- Custom transcoder support
- Support for different operations (get/set/view/n1ql)
- NIF communication pathway

##### Implementation Details

- Pool of worker processes
- NIF callback system
- Data encoding/decoding flow
- Query execution path

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Application Layer"
        API[Main API Module]
        APP[Application Behavior]
        SUP[Supervisor]
        BENCH[Benchmark Driver]
        TESTS[Test Suite]
    end

    subgraph "Core Layer"
        WORKER[Connection Pool Worker]
        TRANS[Transcoder System]
        HEADER[Header Definitions]
    end

    subgraph "NIF Interface Layer"
        NIF_ERL[Erlang NIF Interface]
        NIF_C[C NIF Implementation]
        CALLBACK[Callback System]
        QUEUE[Queue Management]
        CORE_C[Core C Implementation]
    end

    subgraph "External Dependencies"
        LCB[libcouchbase]
        CBS[(Couchbase Server)]
    end

    %% Relationships
    API --> WORKER
    API --> TRANS
    APP --> SUP
    SUP --> WORKER
    WORKER --> NIF_ERL
    WORKER --> TRANS
    NIF_ERL --> NIF_C
    NIF_C --> CALLBACK
    NIF_C --> QUEUE
    NIF_C --> CORE_C
    CORE_C --> LCB
    LCB --> CBS
    BENCH --> API
    TESTS --> API

    %% Click Events
    click API "https://github.com/chitika/cberl/blob/master/src/cberl.erl"
    click APP "https://github.com/chitika/cberl/blob/master/src/cberl_app.erl"
    click SUP "https://github.com/chitika/cberl/blob/master/src/cberl_sup.erl"
    click WORKER "https://github.com/chitika/cberl/blob/master/src/cberl_worker.erl"
    click TRANS "https://github.com/chitika/cberl/blob/master/src/cberl_transcoder.erl"
    click NIF_ERL "https://github.com/chitika/cberl/blob/master/src/cberl_nif.erl"
    click NIF_C "https://github.com/chitika/cberl/blob/master/c_src/cberl_nif.c"
    click CALLBACK "https://github.com/chitika/cberl/blob/master/c_src/callbacks.c"
    click QUEUE "https://github.com/chitika/cberl/blob/master/c_src/queue.c"
    click CORE_C "https://github.com/chitika/cberl/blob/master/c_src/cb.c"
    click HEADER "https://github.com/chitika/cberl/blob/master/include/cberl.hrl"
    click BENCH "https://github.com/chitika/cberl/blob/master/bench/basho_bench_driver_cberl.erl"
    click TESTS "https://github.com/chitika/cberl/tree/master/test"

    %% Styling
    classDef erlang fill:#3498db,stroke:#2980b9,color:white
    classDef c fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#e67e22,stroke:#d35400,color:white
    classDef test fill:#9b59b6,stroke:#8e44ad,color:white
    classDef database fill:#e74c3c,stroke:#c0392b,color:white

    class API,APP,SUP,WORKER,TRANS,NIF_ERL erlang
    class NIF_C,CALLBACK,QUEUE,CORE_C,HEADER c
    class LCB external
    class CBS database
    class BENCH,TESTS test
```
