# kubescape/synchronizer architecture

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

- Interactive diagram: https://gitdiagram.com/kubescape/synchronizer
- Repository: https://github.com/kubescape/synchronizer

## Overview

##### Main Components

a) Client-Side Components:
- Synchronizer Clients (Multiple instances)
- ETCD Clusters (Data source for each client)
- Client Adapters Layer
- In-cluster adapter (for kubernetes resources)
- HTTP endpoint adapter
- Backend adapter

b) Server-Side Components:
- Synchronizer Server
- Apache Pulsar (Message broker)
- Event Ingester
- Database
- Authentication Service

##### Key Architectural Patterns to Highlight

- Event-Driven Architecture
- Adapter Pattern (visible in the adapters/ directory)
- Publisher-Subscriber Pattern (using Pulsar)
- Domain-Driven Design (evident from the domain/ directory structure)

**Top Layer: Client Infrastructure (Multiple Clusters)**
**Middle Layer: Communication & Message Broker**
**Bottom Layer: Backend Infrastructure**

##### Data Flow Representation

- Bi-directional synchronization paths:
1. Cluster → Synchronizer Client → Server → Pulsar → Event Ingester → Database
2. Database → Event Ingester → Pulsar → Server → Synchronizer Client → Cluster

##### Additional Elements

- Configuration components (from config/ directory)
- Authentication flow (from cmd/server/authentication)
- Core domain objects (from domain/ directory)
- Messaging interfaces (from messaging/ directory)

##### Detailed Component Connections

**[ETCD Cluster] ←→ [Synchronizer Client]**
- ↕
**[Adapter Layer (In-cluster/HTTP/Backend)]**
- ↕
**[Synchronizer Server] ←→ [Authentication]**
- ↕
**[Pulsar Message Broker]**
- ↕
**[Event Ingester]**
- ↕
**[Database]**

##### Implementation Details to Note

- Version indicators for adapters (v1 as shown in the file structure)
- Different types of events supported (from domain/ directory)
- Configuration paths
- Monitoring/metrics points (visible in adapter metrics)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Infrastructure"
        direction TB
        C1["Synchronizer Client"]:::core
        click C1 "https://github.com/kubescape/synchronizer/blob/main/cmd/client/main.go"
        ETCD[(ETCD Cluster)]:::storage
        
        subgraph "Adapter Layer"
            direction TB
            ICA["In-cluster Adapter"]:::adapter
            click ICA "https://github.com/kubescape/synchronizer/blob/main/adapters/incluster/v1/adapter.go"
            HEA["HTTP Endpoint Adapter"]:::adapter
            click HEA "https://github.com/kubescape/synchronizer/blob/main/adapters/httpendpoint/v1/adapter.go"
            BA["Backend Adapter"]:::adapter
            click BA "https://github.com/kubescape/synchronizer/blob/main/adapters/backend/v1/adapter.go"
        end
        
        CC["Client Config"]:::config
        click CC "https://github.com/kubescape/synchronizer/blob/main/configuration/client/config.json"
    end

    subgraph "Server Infrastructure"
        direction TB
        SS["Synchronizer Server"]:::core
        click SS "https://github.com/kubescape/synchronizer/blob/main/cmd/server/main.go"
        AUTH["Authentication Service"]:::auth
        click AUTH "https://github.com/kubescape/synchronizer/blob/main/cmd/server/authentication/authentication.go"
        SC["Server Config"]:::config
        click SC "https://github.com/kubescape/synchronizer/blob/main/configuration/server/config.json"
    end

    subgraph "Message Broker Layer"
        direction TB
        PULSAR["Apache Pulsar"]:::broker
        click PULSAR "https://github.com/kubescape/synchronizer/blob/main/adapters/backend/v1/pulsar.go"
        MSG["Messaging Interface"]:::interface
        click MSG "https://github.com/kubescape/synchronizer/blob/main/messaging/interface.go"
    end

    subgraph "Event Processing Layer"
        direction TB
        EI["Event Ingester"]:::core
        IC["Ingester Config"]:::config
        click IC "https://github.com/kubescape/synchronizer/blob/main/configuration/ingester/config.json"
        
        subgraph "Domain Objects"
            direction TB
            ED["Event Definition"]:::domain
            click ED "https://github.com/kubescape/synchronizer/blob/main/domain/Event.go"
            BP["Batch Processing"]:::domain
            click BP "https://github.com/kubescape/synchronizer/blob/main/domain/Batch.go"
            OPS["Object Operations"]:::domain
            click OPS "https://github.com/kubescape/synchronizer/blob/main/domain/ObjectDeleted.go"
        end
    end

    subgraph "Storage Layer"
        DB[(Database)]:::storage
    end

    C1 <--> ETCD
    C1 <--> ICA
    C1 <--> HEA
    C1 <--> BA
    C1 --> CC
    
    BA <--> SS
    SS <--> AUTH
    SS --> SC
    
    SS <--> PULSAR
    PULSAR <--> MSG
    
    MSG <--> EI
    EI --> IC
    EI <--> ED
    EI <--> BP
    EI <--> OPS
    
    EI <--> DB

    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef storage fill:#2ecc71,stroke:#27ae60,color:white
    classDef adapter fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef broker fill:#f1c40f,stroke:#f39c12,color:white
    classDef auth fill:#e74c3c,stroke:#c0392b,color:white
    classDef config fill:#9b59b6,stroke:#8e44ad,color:white
    classDef interface fill:#1abc9c,stroke:#16a085,color:white
    classDef domain fill:#34495e,stroke:#2c3e50,color:white

    subgraph Legend
        L1["Core Components"]:::core
        L2[(Storage Components)]:::storage
        L3["Adapters"]:::adapter
        L4["Message Broker"]:::broker
        L5["Authentication"]:::auth
        L6["Configuration"]:::config
        L7["Interfaces"]:::interface
        L8["Domain Objects"]:::domain
    end
```
