# lonewolf38/registry architecture

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

- Interactive diagram: https://gitdiagram.com/lonewolf38/registry
- Repository: https://github.com/lonewolf38/registry

## Overview

##### Main Components

a) Server Components:
- TCP Server (Main Entry Point)
- HB Protocol Parser
- Registry Service
- Cache System
- (Future) Raft Consensus Layer

b) Client Components:
- TCP Client(s)
- Heartbeat Generator

**┌─ Protocol Layer ─────┐    ┌─ Service Layer ──┐    ┌─ Storage Layer ──┐**

- TCP Server    ─────────► │  Registry     ──────► │  Cache          │
- HB Protocol   ◄─────────┤  Service       │    │  Strategies      │

- ┘    └──────────────────┘    └──────────────────┘

##### Component Details

- Blue rectangles for network components (TCP Server)
- Green rectangles for processing components (Protocol Parser)
- Yellow rectangles for service components (Registry)
- Purple rectangles for storage components (Cache)

Following flows:
a) Client → TCP Server (Heartbeat packets)
b) TCP Server → Protocol Parser (Raw data)
c) Protocol Parser → Registry Service (Parsed heartbeats)
d) Registry Service → Cache (Host registration data)

##### Key Elements to Highlight

a) Protocol Layer:
- TCP connection handling (pkg/protocol/tcp.go)
- Heartbeat protocol parsing (pkg/protocol/beat.go)
- Connection management

b) Service Layer:
- Registry service (pkg/registry/registry.go)
- Host registration logic
- Health checking mechanism

c) Storage Layer:
- Cache implementation (pkg/cache/cache.go)
- Different caching strategies (planned)
- Future Raft consensus integration points

##### Implementation Notes

Use these visual elements:
- State transition indicators for host registration status

##### Scale and Distribution

How the system will scale by including:
- Multiple client connections
- Future Raft cluster nodes
- Cache distribution possibilities

Remember to indicate the project's evolution path by marking future implementations differently from current ones, as this will help in understanding both the current state and the intended architecture.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef network fill:#a8d1f0,stroke:#3182bd
    classDef processing fill:#a1d99b,stroke:#31a354
    classDef service fill:#fed976,stroke:#feb24c
    classDef storage fill:#bcbddc,stroke:#756bb1
    classDef future fill:#ffffff,stroke:#999999,stroke-dasharray: 5 5
    classDef client fill:#fdd0a2,stroke:#fd8d3c

    %% Client Layer
    subgraph Clients
        C1[Client 1]:::client
        C2[Client 2]:::client
        C3[Client N]:::client
        HBGen[Heartbeat Generator]:::client
    end

    %% Protocol Layer
    subgraph Protocol
        TCP[TCP Server]:::network
        Parser[HB Protocol Parser]:::processing
    end

    %% Service Layer
    subgraph Services
        Registry[Registry Service]:::service
    end

    %% Storage Layer
    subgraph Storage
        Cache[Cache System]:::storage
        CacheStrat1[Primary Cache Strategy]:::storage
        CacheStrat2[Backup Cache Strategy]:::future
        RaftConsensus[Raft Consensus Layer]:::future
    end

    %% Connections
    C1 --> TCP
    C2 --> TCP
    C3 --> TCP
    HBGen --> |Heartbeat Packets| TCP
    TCP --> |Raw Data| Parser
    Parser --> |Parsed Heartbeats| Registry
    Registry --> |Host Registration| Cache
    Cache --> CacheStrat1
    Cache -.-> CacheStrat2
    Cache -.-> RaftConsensus

    %% Click events
    click TCP "https://github.com/LoneWolf38/registry/blob/main/pkg/protocol/tcp.go"
    click Parser "https://github.com/LoneWolf38/registry/blob/main/pkg/protocol/beat.go"
    click Registry "https://github.com/LoneWolf38/registry/blob/main/pkg/registry/registry.go"
    click Cache "https://github.com/LoneWolf38/registry/blob/main/pkg/cache/cache.go"

    %% Legend
    subgraph Legend
        L1[Network Components]:::network
        L2[Processing Components]:::processing
        L3[Service Components]:::service
        L4[Storage Components]:::storage
        L5[Future Components]:::future
        L6[Client Components]:::client
    end
```
