# grishy/any-sync-bundle architecture

> Architecture diagram of the GitHub repository grishy/any-sync-bundle, 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/grishy/any-sync-bundle
- Repository: https://github.com/grishy/any-sync-bundle

## Overview

##### Main Components
- Command/Entry Point: The “cmd” package (with files like config.go, mongo.go, start.go, etc.) is clearly the starting point that wires up the application.
- Configuration Layer: Both the “config” directory and “lightcmp/lightconfig” contain configuration routines for the bundle.
- Core Business Modules:
– “lightcmp” package is subdivided into various modules:
- lightconsensusdb: Manages consensus-related data storage including schema (.sql);
- lightconsensusrpc: Exposes RPC handlers related to consensus functionalities;
- lightfilenodeindex & its “indexpb” subpackage: Handles indexing of file nodes, including protobuf definitions and tests;
- lightfilenoderpc: Manages RPC endpoints for file node operations, with associated tests;
- lightfilenodestore: Implements storage logic for file nodes using BadgerDB (plus mocks/tests);
- lightnodeconf: Provides node configuration management.
- Node and Synchronization Functionality: The “lightnode” folder contains components for consensus (core algorithm in consensus/consensus.go), node coordination (coordinator.go), file node handling (filenode/filenode.go), and overall node management and syncing (node.go and sync.go).
- Testing and Utility: Although you may not need to include test utilities in a high-level design, the “testutil” package shows there is support for block simulation etc.

##### Relationships and Interactions
- The entry point (cmd package) initializes the configuration, sets up the necessary modules, and starts the server.
- The configuration layer feeds into all modules to determine runtime settings (e.g., embedded vs external services).
- The “lightcmp” modules provide the core services:
– lightconfig, lightconsensusdb, and lightconsensusrpc work together to establish and expose consensus behavior.
– lightfilenodeindex and lightfilenoderpc handle file storage operations and their indexing services.
– lightfilenodestore acts as the underlying local storage mechanism, especially in the “light” version.
- The “lightnode” components build on top of these lower-level functionalities to provide distributed aspects (such as consensus and synchronization). The coordinator and consensus engines communicate internally via RPC (using the protocols defined in the light*-rpc packages) and likely manage interactions between nodes.
- Optionally, in the all-in-one bundle version, external components like MongoDB, Redis, and MinIO might be integrated (as seen via Docker configurations and environment variables) to extend the storage and caching layers.

##### Architectural Patterns and Design Principles
- Modularity in a Bundled Binary: Although multiple services exist logically, they are merged into one binary to simplify deployment. This means the system can be represented as a modular monolith with clearly decoupled components communicating through internal interfaces/RPC.
- RPC Communication: Several modules expose RPC interfaces, so emphasize the request/response flow between clients and services and among internal modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Internal Modules
    subgraph "Any-Sync-Bundle"
        subgraph "Startup & Config"
            A["CLI/Startup (cmd)"]:::internal
            B["Configuration/Settings"]:::internal
        end

        subgraph "Consensus Module"
            C["Data Storage & Schema"]:::internal
            D["RPC Handlers"]:::internal
        end

        subgraph "File Node Management"
            E["Indexing Service"]:::internal
            F["File Node RPC"]:::internal
            G["File Node Storage"]:::internal
        end

        subgraph "Node & Sync Engine"
            H["Node & Sync Engine"]:::internal
        end

        subgraph "Testing & Utilities"
            J["Testing and Utilities"]:::internal
        end
    end

    %% External Dependencies
    subgraph "External Dependencies"
        K["MongoDB"]:::external
        L["Redis"]:::external
        M["MinIO"]:::external
    end

    %% Connections between internal modules
    A -->|"initializes"| B
    B -->|"configures"| C
    B -->|"configures"| E
    D -->|"RPCcalls"| H
    F -->|"RPCcalls"| H

    %% External dependencies connections
    K -->|"stores"| C
    L -->|"supports"| D
    M -->|"provides"| G
    B -->|"bundleMode"| K
    B -->|"bundleMode"| L
    B -->|"bundleMode"| M

    %% Optional connection for testing utilities
    A -->|"triggers_tests"| J

    %% Click Events
    click A "https://github.com/grishy/any-sync-bundle/tree/main/cmd/"
    click B "https://github.com/grishy/any-sync-bundle/tree/main/config/"
    click C "https://github.com/grishy/any-sync-bundle/tree/main/lightcmp/lightconsensusdb"
    click D "https://github.com/grishy/any-sync-bundle/tree/main/lightcmp/lightconsensusrpc"
    click E "https://github.com/grishy/any-sync-bundle/tree/main/lightcmp/lightfilenodeindex"
    click F "https://github.com/grishy/any-sync-bundle/tree/main/lightcmp/lightfilenoderpc"
    click G "https://github.com/grishy/any-sync-bundle/tree/main/lightcmp/lightfilenodestore"
    click H "https://github.com/grishy/any-sync-bundle/tree/main/lightnode/"
    click J "https://github.com/grishy/any-sync-bundle/tree/main/testutil/"

    %% Styles
    classDef internal fill:#cce5ff,stroke:#1a75ff,stroke-width:2px;
    classDef external fill:#ffe0b3,stroke:#ff9933,stroke-width:2px;
```
