# saostad/sync-engine architecture

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

- Interactive diagram: https://gitdiagram.com/saostad/sync-engine
- Repository: https://github.com/saostad/sync-engine

## Overview

Key Components to Include:

##### Core Engine Component
- Main configuration interfaces (mappings and syncFns)

##### Data Flow Components
- Source Data Store (Input)
- Destination Data Store (Output)
- Transformation Pipeline
- Change Detection System
- Synchronization Executor

##### Middle Level (Core Processing)
a. Field Mapper
- Shows the transformation of source fields to destination format
- Mapping configuration interface

b. Change Detector
- Represents the comparison logic
- Three outputs: Inserted, Updated, and Deleted records

c. Sync Executor
- Shows the execution of sync functions
- Three sync function types (insertFn, updateFn, deleteFn)

##### Important Details
- Async operation indicators (since many operations are asynchronous)
- Configuration interfaces showing the structure of mapping definitions
- Key comparison logic representation
- Field transformation pipeline

Specific Implementation Guidelines:

- Source Data  |    Dest Data  |

- Sync Engine             |

- Field Mapper       |     |

- Change Detector     |     |

- Sync Executor       |     |

##### A configuration section on the side

- Configuration  |
- Mappings    |
- Sync Fns    |

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Data_Stores
        direction TB
        Source[("Source Data Store")]:::source
        Dest[("Destination Data Store")]:::destination
    end

    subgraph Core_Engine
        direction TB
        SyncEngine[("Sync Engine")]:::core
        click SyncEngine "https://github.com/saostad/sync-engine/blob/main/mod.ts"

        subgraph Processing_Pipeline
            direction TB
            FieldMapper["Field Mapper"]:::processor
            ChangeDetector["Change Detector"]:::processor
            SyncExecutor["Sync Executor"]:::processor
        end

        SyncEngine --> FieldMapper
        FieldMapper --> ChangeDetector
        ChangeDetector --> SyncExecutor
    end

    subgraph Configuration
        direction TB
        Config["Runtime Config"]:::config
        click Config "https://github.com/saostad/sync-engine/blob/main/deno.json"
        TestImpl["Test Implementation"]:::test
        click TestImpl "https://github.com/saostad/sync-engine/blob/main/tests/mod.test.ts"
        SampleData["Sample Data"]:::data
        click SampleData "https://github.com/saostad/sync-engine/blob/main/tests/sample-data.json"
        Pipeline["Build Pipeline"]:::pipeline
        click Pipeline "https://github.com/saostad/sync-engine/blob/main/.github/workflows/publish.yml"
    end

    subgraph Operations
        direction TB
        Insert["Insert Operations"]:::insert
        Update["Update Operations"]:::update
        Delete["Delete Operations"]:::delete
    end

    Source --> SyncEngine
    SyncEngine --> Dest

    ChangeDetector --> Insert
    ChangeDetector --> Update
    ChangeDetector --> Delete

    Insert --> SyncExecutor
    Update --> SyncExecutor
    Delete --> SyncExecutor

    Config -.-> SyncEngine
    TestImpl -.-> SyncEngine
    SampleData -.-> TestImpl

    classDef source fill:#3498db,stroke:#2980b9,color:white
    classDef destination fill:#2ecc71,stroke:#27ae60,color:white
    classDef core fill:#9b59b6,stroke:#8e44ad,color:white
    classDef processor fill:#f1c40f,stroke:#f39c12,color:black
    classDef config fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef test fill:#e74c3c,stroke:#c0392b,color:white
    classDef data fill:#1abc9c,stroke:#16a085,color:white
    classDef pipeline fill:#34495e,stroke:#2c3e50,color:white
    classDef insert fill:#27ae60,stroke:#219a52,color:white
    classDef update fill:#f39c12,stroke:#d68910,color:white
    classDef delete fill:#c0392b,stroke:#a93226,color:white

    %% Legend
    subgraph Legend
        direction TB
        L1["🔄 Async Operation"]
        L2["➡️ Data Flow"]
        L3["🔑 Key Field"]
        L4["🔄 Transform Function"]
    end
```
