# aniruddha96/toymb architecture

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

- Interactive diagram: https://gitdiagram.com/aniruddha96/toymb
- Repository: https://github.com/aniruddha96/toymb

## Overview

##### Main Components

a) Client Layer:
- Java Driver component (ToyMB-client)
- Two client interfaces:
- Publisher (ToyMBTemplate)
- Subscriber (with @Subscribe annotation)

b) Broker Cluster:
- Multiple ToyMB nodes
- Rendezvous routing mechanism
- Topic ownership distribution
- Partition management

c) Storage Layer:
- SQL Database (supports MySQL, H2)
- Key entities (Topics, Groups, Messages, Subscribers, Nodes)

d) Message Processing Pipeline:
- Message enrichment system
- Partition assignment
- Message routing

##### Relationships and Interactions

- Publisher → Broker → Subscribers
- Topic creation flow
- Subscriber registration flow
- Inter-node communication
- Enrichment pipeline

##### Specific Elements

a) Node Components:
**┌─ ToyMB Node ─────────────────┐**
- ┌─ Controllers ─┐ ┌─ Workers ┐│
- Message     │ │- Message ││
- Subscriber  │ │ Notifier ││
- Topic      │ └─────────┘││
- ┘            ││
- ┌─ Enrichment ┐            ││
- Enrichers  │            ││
- Topics     │            ││
- ┘            ││
- ┘

b) Client Integration:
**┌─ Client Application ──────┐**
- ┌─ ToyMB Client ────────┐ │
- @Subscribe          │ │
- ToyMBTemplate      │ │
- Message Handlers    │ │
- ┘ │
- ┘

##### Important Architectural Patterns to Highlight

a) Publisher-Subscriber Pattern:
- Topic partitioning
- -based subscription
- Push/Pull interfaces

b) Distributed System Patterns:
- Rendezvous routing
- Partition distribution
- Cluster communication

##### Technical Details

a) Protocol Information:
- HTTP-based communication
- REST endpoints

b) Storage Details:
- Entity relationships
- Partition management

c) Configuration Elements:
- Node properties
- Topic configurations
- Cluster setup

##### The storage and persistence model

Remember to maintain clarity while showing the complexity of the system, using appropriate abstraction levels for different components while ensuring that critical architectural decisions are visible.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        Publisher["Publisher (ToyMBTemplate)"]:::client
        Subscriber["Subscriber (@Subscribe)"]:::client
        ClientImpl["Client Implementation"]:::client
    end

    subgraph Broker["Broker Cluster"]
        subgraph Node1["ToyMB Node 1"]
            Controllers1["Controllers"]:::broker
            Workers1["Message Workers"]:::broker
            Enrichment1["Enrichment System"]:::broker
        end

        subgraph Node2["ToyMB Node 2"]
            Controllers2["Controllers"]:::broker
            Workers2["Message Workers"]:::broker
            Enrichment2["Enrichment System"]:::broker
        end
    end

    subgraph Storage["Storage Layer"]
        DB[(SQL Database)]:::storage
        subgraph Entities["Database Entities"]
            Topics["Topics"]:::entity
            Groups["Groups"]:::entity
            Messages["Messages"]:::entity
            Subscribers["Subscribers"]:::entity
            Nodes["Nodes"]:::entity
        end
    end

    Publisher --> Controllers1
    Publisher --> Controllers2
    Controllers1 --> Workers1
    Controllers2 --> Workers2
    Workers1 --> Subscriber
    Workers2 --> Subscriber
    Controllers1 --> Enrichment1
    Controllers2 --> Enrichment2
    Controllers1 <--> DB
    Controllers2 <--> DB
    Node1 <--> Node2

    %% Component Mappings
    click Publisher "https://github.com/aniruddha96/ToyMB/blob/main/java-driver/ToyMB-client/src/main/java/com/toymb/client/ToyMBTemplate.java"
    click Subscriber "https://github.com/aniruddha96/ToyMB/blob/main/java-driver/ToyMB-client/src/main/java/com/toymb/annotations/Subscribe.java"
    click ClientImpl "https://github.com/aniruddha96/ToyMB/blob/main/java-driver/ToyMB-client/src/main/java/com/toymb/client/ToyMBTemplateImpl.java"
    click Controllers1 "https://github.com/aniruddha96/ToyMB/tree/main/src/main/java/com/toymb/controllers"
    click Workers1 "https://github.com/aniruddha96/ToyMB/blob/main/src/main/java/com/toymb/workers/MessageNotifier.java"
    click Enrichment1 "https://github.com/aniruddha96/ToyMB/blob/main/src/main/java/com/toymb/common/TopicEnricher.java"
    click Topics "https://github.com/aniruddha96/ToyMB/blob/main/src/main/java/com/toymb/entities/TopicEntity.java"
    click Groups "https://github.com/aniruddha96/ToyMB/blob/main/src/main/java/com/toymb/entities/GroupEntity.java"
    click Messages "https://github.com/aniruddha96/ToyMB/blob/main/src/main/java/com/toymb/entities/MessageEntity.java"
    click Subscribers "https://github.com/aniruddha96/ToyMB/blob/main/src/main/java/com/toymb/entities/SubscriberEntity.java"
    click Nodes "https://github.com/aniruddha96/ToyMB/blob/main/src/main/java/com/toymb/entities/NodeEntity.java"
    click DB "https://github.com/aniruddha96/ToyMB/blob/main/src/main/java/com/toymb/database/Database.java"

    classDef client fill:#2374ab
    classDef broker fill:#57a773
    classDef storage fill:#ffc857
    classDef entity fill:#ddd
    
    %% Legend
    subgraph Legend
        Client_Component["Client Component"]:::client
        Broker_Component["Broker Component"]:::broker
        Storage_Component["Storage Component"]:::storage
        Entity_Component["Entity"]:::entity
    end
```
