# abinash4567/pub-sub architecture

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

- Interactive diagram: https://gitdiagram.com/abinash4567/pub-sub
- Repository: https://github.com/abinash4567/pub-sub

## Overview

##### Main components
- Server Component (server.go): This is the central hub that handles incoming websocket connections. It listens on the /sender endpoint for the sender connection and on the /receiver endpoint for multiple receiver connections.
- Sender Component (sender_go directory): Contains the sender code (sender.go) which connects to the server’s /sender endpoint to broadcast messages.
- Receiver Component (client_go directory): Contains the receiver code (client.go) which connects to the server’s /receiver endpoint in order to receive broadcast messages.

##### Understand the relationships and interactions
- The sender establishes a websocket connection at "ws://localhost:8000/sender". Once connected, it sends messages to the server.
- The server receives these messages and, leveraging Go’s concurrency and epoll features, efficiently forwards the messages to all connected receivers.
- Multiple receivers connect to "ws://localhost:8000/receiver" and get the broadcasted messages in real time.

##### Architectural patterns and design principles
- Microservice Architecture: The project is built as a small, focused microservice for message broadcasting.
- Pub-Sub Pattern: The design follows a publish–subscribe model where a single sender’s messages are broadcast to many receivers.
- Concurrency and Efficiency: The system leverages Go’s built-in concurrency and optimized event handling (via epoll) to serve potentially millions of receivers with minimal resources.

##### Relevant technologies
- Programming Language: Go
- WebSocket Library: ws (as referenced in the README)
- System Calls: sysCall (golang.org/x/sys/unix), which is used for efficient OS level event handling.

##### Instructing the principal software engineer on key elements
- Optionally, include annotations to note that the Server uses efficient concurrency (via Go’s routines and epoll) and is designed for high scalability with minimal resource usage.

- At the center is the Server (server.go) acting as a hub.
- On one side, a Sender from the sender_go directory sends messages to the Server.
- On the opposite side, multiple Receiver Clients from the client_go directory connect to the Server.
- Communication flow: Sender → Server → Broad Collection of Receivers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Sender["Sender<br>(/sender endpoint)"]:::sender
    Server["Broadcast Server<br>(server.go)<br>Listens: /sender & /receiver<br>Utilizes Go concurrency & epoll"]:::server
    Receiver["Receiver Clients<br>(/receiver endpoint)"]:::receiver

    Sender -->|"BroadcastMessage"| Server
    Server -->|"DistributeMessage"| Receiver

    click Sender "https://github.com/abinash4567/pub-sub/blob/main/sender_go/sender.go"
    click Server "https://github.com/abinash4567/pub-sub/blob/main/server.go"
    click Receiver "https://github.com/abinash4567/pub-sub/blob/main/client_go/client.go"

    classDef sender fill:#a0e1f5,stroke:#333,stroke-width:2px;
    classDef server fill:#f8d6a8,stroke:#333,stroke-width:2px;
    classDef receiver fill:#c3f5a1,stroke:#333,stroke-width:2px;
```
