# ali-sattari/flyio-dist-sys architecture

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

- Interactive diagram: https://gitdiagram.com/ali-sattari/flyio-dist-sys
- Repository: https://github.com/ali-sattari/flyio-dist-sys

## Overview

##### Main Components Organization
- Broadcast System
- Echo Service
- G-Counter
- Kafka Implementation
- Unique IDs Generator (Snowflake)

##### Detailed Component Breakdown

A. Broadcast System
- Core Broadcast Component (broadcast.go)
- Gossip Protocol Implementation (gossip.go)
- Topology Manager (topology.go)
- A Read Handler (read.go)

B. Kafka Implementation
- Application Core (app.go)
- Gossip Protocol (gossip.go)
- Log Store (log_store.go)
- Use interfaces.go as connection points between components

C. Unique IDs (Snowflake)
- Snowflaker component
- Internal structure for ID generation
- Test components

##### Component Relationships and Interactions

Use the following visual elements:
- Blue: Core services
- Green: Protocol implementations
- Yellow: Storage components
- Gray: Utility functions

##### Specific Details

For each major component, show:
- Entry points (main.go files)
- Core business logic (pkg directories)
- Test coverage (all *_test.go files)
- Dependencies (represented by go.mod files)

##### Architecture Patterns to Highlight

- Gossip protocol patterns in both Broadcast and Kafka implementations
- Distributed counter pattern in G-Counter
- Snowflake ID generation pattern
- Echo service pattern

##### Layer Organization

- Application Layer (main.go files)
- Service Layer (pkg directories)
- Protocol Layer (gossip, broadcast implementations)
- Storage Layer (log store)
- Utility Layer (utils.go files)

##### Additional Elements

Include:
- Error handling flows
- Test coverage paths
- Interface boundaries
- Module dependencies

- Red: Critical paths
- Blue: Core services
- Green: Successful operations
- Yellow: Warning/Edge cases
- Gray: Utility functions

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        A[Service Component]:::service
        B[(Storage Component)]:::storage
        C{Interface}:::interface
        D[/Protocol/]:::protocol
        E[[Utility]]:::utility
    end

    subgraph "Application Layer"
        BM["Broadcast Main"]:::service
        KM["Kafka Main"]:::service
        GCM["G-Counter Main"]:::service
        EM["Echo Main"]:::service
        UIM["Unique IDs Main"]:::service
    end

    subgraph "Broadcast System"
        BC["Broadcast Core"]:::service
        GP[/"Gossip Protocol"/]:::protocol
        TM["Topology Manager"]:::service
        RH["Read Handler"]:::service
        BU[[Broadcast Utils]]:::utility
    end

    subgraph "Kafka Implementation"
        KA["Application Core"]:::service
        KG[/"Gossip Protocol"/]:::protocol
        LS[(Log Store)]:::storage
        KI{Interfaces}:::interface
        KU[[Kafka Utils]]:::utility
    end

    subgraph "G-Counter"
        GC["Counter Logic"]:::service
    end

    subgraph "Echo Service"
        ES["Echo Server"]:::service
    end

    subgraph "Unique IDs"
        SF["Snowflaker"]:::service
    end

    %% Relationships
    BM --> BC
    BC <--> GP
    BC <--> TM
    BC --> RH
    BC --> BU

    KM --> KA
    KA <--> KG
    KA <--> LS
    KA --> KI
    KA --> KU

    GCM --> GC
    EM --> ES
    UIM --> SF

    %% Styles
    classDef service fill:#2374f7,stroke:#000,stroke-width:2px
    classDef storage fill:#ffd700,stroke:#000,stroke-width:2px
    classDef interface fill:#95d475,stroke:#000,stroke-width:2px
    classDef protocol fill:#ff7675,stroke:#000,stroke-width:2px
    classDef utility fill:#a8a8a8,stroke:#000,stroke-width:2px

    %% Click events
    click BM "https://github.com/ali-sattari/flyio-dist-sys/blob/main/broadcast/main.go"
    click BC "https://github.com/ali-sattari/flyio-dist-sys/blob/main/broadcast/pkg/broadcast/broadcast.go"
    click GP "https://github.com/ali-sattari/flyio-dist-sys/blob/main/broadcast/pkg/broadcast/gossip.go"
    click TM "https://github.com/ali-sattari/flyio-dist-sys/blob/main/broadcast/pkg/broadcast/topology.go"
    click RH "https://github.com/ali-sattari/flyio-dist-sys/blob/main/broadcast/pkg/broadcast/read.go"
    click BU "https://github.com/ali-sattari/flyio-dist-sys/blob/main/broadcast/pkg/broadcast/utils.go"
    
    click KM "https://github.com/ali-sattari/flyio-dist-sys/blob/main/kafka/main.go"
    click KA "https://github.com/ali-sattari/flyio-dist-sys/blob/main/kafka/pkg/kafka/app.go"
    click KG "https://github.com/ali-sattari/flyio-dist-sys/blob/main/kafka/pkg/kafka/gossip.go"
    click LS "https://github.com/ali-sattari/flyio-dist-sys/blob/main/kafka/pkg/kafka/log_store.go"
    click KI "https://github.com/ali-sattari/flyio-dist-sys/blob/main/kafka/pkg/kafka/interfaces.go"
    click KU "https://github.com/ali-sattari/flyio-dist-sys/blob/main/kafka/pkg/kafka/utils.go"
    
    click GCM "https://github.com/ali-sattari/flyio-dist-sys/blob/main/g-counter/main.go"
    click GC "https://github.com/ali-sattari/flyio-dist-sys/blob/main/g-counter/app.go"
    
    click EM "https://github.com/ali-sattari/flyio-dist-sys/blob/main/echo/main.go"
    
    click UIM "https://github.com/ali-sattari/flyio-dist-sys/blob/main/unique-ids/main.go"
    click SF "https://github.com/ali-sattari/flyio-dist-sys/blob/main/unique-ids/pkg/snowflaker/snowflaker.go"
```
