# meshery/meshsync architecture

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

- Interactive diagram: https://gitdiagram.com/meshery/meshsync
- Repository: https://github.com/meshery/meshsync

## Overview

##### Project Type and Purpose
- MeshSync is a backend service written in Go that acts as a custom Kubernetes controller for Meshery.
- Its purpose is to continuously discover configuration and operational states in a Kubernetes environment and synchronize these states with the Meshery Server.

##### File Structure for Key Components
- Top-Level Files:
- main.go: Initializes and launches the MeshSync engine.
- Dockerfile, Makefile, and go.mod: Highlight that the project is containerized and uses Go for its business logic.
- .github Directory: Contains multiple workflows (CI, build, release, etc.) and templates which show a robust CI/CD and collaboration setup.
- Internal Packages:
- internal/config: Manages configuration settings and Kubernetes CRD configurations.
- internal/channels: Implements event channels (broker, generic, system) for communication and message passing within the system.
- internal/pipeline: Manages the processing pipeline, including sequencing handlers and processing steps.
- Domain and Utility Packages:
- meshsync (separate from internal): Implements discovery, event handling, log streaming, and execution of synchronization tasks.
- pkg/model and pkg/utils: Handle data models, conversion between different formats, pre-processing, and general utility functions.
- Helpers and Install Scripts: Provide additional support for configuration, installation, and tooling.

##### Defining Main Components
- External Environment:
- Kubernetes Cluster: As MeshSync is deployed as a Kubernetes custom controller.
- Meshery Operator/Meshery Server: The external system that receives synchronization updates.
- Core MeshSync Engine:
- Entry Point (main.go): The application’s starting point.
- Configuration Management:
- internal/config: Responsible for loading, validating, and managing configuration (including CRD configurations).
- Event Channels:
- internal/channels: Different channels (broker, generic, system) handle event distribution from Kubernetes or internal triggers.
- Processing Pipeline:
- internal/pipeline: Orchestrates the processing of events through the defined steps (handlers, error management).
- Discovery and Synchronization Logic:
- meshsync Package: Contains discovery mechanisms, event handlers, log streaming, and execution logic for synchronizing state.
- Domain Models and Utilities:
- pkg/model: Defines the models for representing configuration and execution status, along with converter and preprocessor functions.
- pkg/utils: Provides utility functions supporting the overall logic.
- CI/CD and DevOps Artifacts (Optional for System Overview):
- .github Workflows, Makefile, Dockerfile: Although these are not runtime components, they illustrate the project's deployment and release pipelines.

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Systems
    subgraph "External Systems"
        K["Kubernetes Cluster"]:::external
        M["Meshery Server/Operator"]:::external
    end

    %% MeshSync Engine
    subgraph "MeshSync Engine"
        A["Main Entry (main.go)"]:::core
        B["Config Manager\n(internal/config)"]:::core
        C["Event Channels\n(internal/channels)"]:::core
        D["Processing Pipeline\n(internal/pipeline)"]:::core
        E["Discovery & Sync Logic\n(meshsync)"]:::core
        F["Domain Models\n(pkg/model)"]:::core
        G["Utility Functions\n(pkg/utils)"]:::core
    end

    %% CI/CD and DevOps Artifacts
    subgraph "CI/CD and DevOps"
        H[".github Workflows & Artifacts\n(.github)"]:::devops
    end

    %% Relationships
    A -->|"Initialize"| B
    B -->|"ConfigSetup"| D
    B -->|"ConfigUpdate"| C
    K -->|"Events"| C
    C -->|"EventFlow"| D
    D -->|"ProcessData"| E
    E -->|"SyncUpdate"| M

    %% Supporting Dependencies (dashed arrows)
    F -.-> D
    F -.-> E
    G -.-> C
    G -.-> D
    G -.-> E

    %% Click Events
    click A "https://github.com/meshery/meshsync/blob/master/main.go"
    click B "https://github.com/meshery/meshsync/tree/master/internal/config"
    click C "https://github.com/meshery/meshsync/tree/master/internal/channels"
    click D "https://github.com/meshery/meshsync/tree/master/internal/pipeline"
    click E "https://github.com/meshery/meshsync/tree/master/meshsync"
    click F "https://github.com/meshery/meshsync/tree/master/pkg/model"
    click G "https://github.com/meshery/meshsync/tree/master/pkg/utils"
    click H "https://github.com/meshery/meshsync/blob/master/.github"

    %% Class Definitions for Styling
    classDef external fill:#ffcccb,stroke:#cc0000,stroke-width:2px;
    classDef core fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef devops fill:#d4edda,stroke:#155724,stroke-width:2px;
```
