# lovelaze/nebula-sync architecture

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

- Interactive diagram: https://gitdiagram.com/lovelaze/nebula-sync
- Repository: https://github.com/lovelaze/nebula-sync

## Overview

##### Project Type and Purpose
- This is a Go-based CLI tool (that can also run in a Docker container) designed to synchronize the configuration of a primary Pi-hole instance with one or more replica instances.
- The README highlights two main synchronization modes ("Full sync" via Teleporter and "Selective sync"). It also shows that the tool can be scheduled via cron and run in containerized environments.

##### File Structure
- Top-Level Directories/Files:
- cmd: Contains the main entry points (root.go, run.go) where command-line parsing and the program startup happen.
- internal: Holds the core business logic:
▪ config: Reads and validates environment variables and configuration settings.
▪ log: Handles logging across the application.
▪ pihole: Encapsulates interactions with Pi-hole’s API including data model definitions.
▪ service: Likely acts as an orchestrator for the overall synchronization logic.
▪ sync: Contains modules for the synchronization process with subdivisions for “full”, “selective”, “retry” and filtering logic.
▪ mocks: Contains mocks for Pi-hole and sync components for testing purposes.
- e2e, testdata: For end-to-end and other tests.
- version: Provides versioning information.
- Others: GitHub workflows, Dockerfile, and related build/release configurations.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Application"
        A["CLI (cmd)"]:::cli
        B["Configuration Manager (internal/config)"]:::config
        C["Logging Module (internal/log)"]:::log
        D["Sync Service (internal/service)"]:::service

        subgraph "Synchronization Modules"
            E["Full Sync Module (internal/sync/full)"]:::sync
            F["Selective Sync Module (internal/sync/selective)"]:::sync
            G["Retry/Resilience Module (internal/sync/retry)"]:::sync
            H["Filter Module (internal/sync/filter)"]:::sync
        end

        I["Pi-hole API Client (internal/pihole)"]:::pihole
    end

    J["Primary Pi-hole"]:::external
    K["Replica Pi-hole(s)"]:::external
    L["Docker Container (optional)"]:::docker
    M["Cron Scheduler (optional)"]:::cron

    A -->|"initialize"| B
    A -->|"initialize"| C
    B -->|"config_data"| D
    C -->|"logging_info"| D
    D -->|"sync_command"| E
    D -->|"sync_command"| F
    D -->|"sync_command"| G
    D -->|"sync_command"| H
    D -->|"API_call"| I
    I -->|"export"| J
    I -->|"import"| K
    J -->|"response"| I
    K -->|"response"| I
    M -->|"scheduled_trigger"| A
    L -->|"containerized"| A

    click A "https://github.com/lovelaze/nebula-sync/blob/main/cmd/root.go"
    click B "https://github.com/lovelaze/nebula-sync/tree/main/internal/config"
    click C "https://github.com/lovelaze/nebula-sync/blob/main/internal/log/log.go"
    click D "https://github.com/lovelaze/nebula-sync/blob/main/internal/service/service.go"
    click E "https://github.com/lovelaze/nebula-sync/blob/main/internal/sync/full.go"
    click F "https://github.com/lovelaze/nebula-sync/blob/main/internal/sync/selective.go"
    click G "https://github.com/lovelaze/nebula-sync/blob/main/internal/sync/retry/retry.go"
    click H "https://github.com/lovelaze/nebula-sync/blob/main/internal/sync/filter/filter.go"
    click I "https://github.com/lovelaze/nebula-sync/tree/main/internal/pihole"

    classDef cli fill:#f9c74f,stroke:#000,stroke-width:1px;
    classDef config fill:#90be6d,stroke:#000,stroke-width:1px;
    classDef log fill:#f94144,stroke:#000,stroke-width:1px;
    classDef service fill:#577590,stroke:#000,stroke-width:1px;
    classDef sync fill:#43aa8b,stroke:#000,stroke-width:1px;
    classDef pihole fill:#277da1,stroke:#000,stroke-width:1px;
    classDef external fill:#f3722c,stroke:#000,stroke-width:1px;
    classDef docker fill:#8ecae6,stroke:#000,stroke-width:1px;
    classDef cron fill:#ffb703,stroke:#000,stroke-width:1px;
```
