# girish946/simple-pub-sub architecture

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

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

## Overview

##### Project Type and Purpose
- This is a message broker (pub/sub) system. Its goal is to allow clients to subscribe to topics, publish messages, and query topics via TCP or Unix socket connections.
- The README shows both CLI and API usage, and the file tree confirms the existence of core server and client modules within the source.

##### File Structure
- Top-Level Structure:
- The Cargo.toml, Cargo.lock, build.rs, and Rust source files indicate it’s a Rust project.
- Directories such as src, tests, examples indicate separation of concerns.
- In src:
- src/main.rs is the entry point for the executable.
- src/lib.rs exports the core library logic.
- The server folder (src/server) holds server-related code, e.g., client_handler.rs indicates handling connected clients.
- The client folder (src/client) holds client functionality; the CLI module (src/cli.rs) provides command-line interface logic.
- Other modules (e.g., src/message.rs, src/topics.rs, src/stream.rs) are likely responsible for managing the message framing (as described in the README) and streaming data.
- Additional Files:
- examples and tests directories illustrate how to use and validate the functionality over different socket types and TLS configurations.
- The client.py indicates a possible integration or sample client in Python.

##### Key Components
a. Main Components:
- CLI Interface & Command Parser: Represented by src/cli.rs.
- Client Module: Located in src/client – handles connection setup, subscription, publishing, and query actions.
- Server Module: Located in src/server – handles incoming connections, client management, and message dispatching.
- Core Library & Message Handling: Represented by src/lib.rs, src/message.rs, src/stream.rs, and src/topics.rs. This layer defines the message frame format and core logic.
- Network I/O: Represent TCP and Unix socket connections. Also note the optional TLS integration (certs folder, key/cert handling from README).
b. Relationships and Interactions:
- The CLI layer interacts with the Client Module to invoke commands (publish, subscribe, or query).
- Client Modules use TCP/Unix sockets to establish a connection with the Server Module.
- The Server Module receives incoming messages (following the defined message frame structure) and routes messages to the appropriate subscribers.
- The API usage example shows direct calls into the client’s Rust API to subscribe or publish messages.
- Optional external elements include TLS certificates used to secure connections.
c. Architectural Patterns or Design Principles:
- Modular separation between server and client functionalities, ensuring clear boundaries.
- Use of a pub/sub pattern where a message broker dispatches messages to multiple subscribers.
- Clean separation of concerns: CLI, networking, message framing, and business logic are divided into separate modules.
- Testing and example modules support extensibility and maintainability.
d. Technologies and Frameworks:
- Rust (with Cargo for package management) is the core language/platform.
- The use of asynchronous programming (as seen in the API examples using tokio) suggests that the project leverages async networking.
- TLS/SSL configuration is supported using certificates (likely via popular Rust TLS libraries).

- Individual components where relevant. For example, note that the message framing follows: “header|version|pkt type|topic length|message length|padding|topic|message” – this helps to understand how data is packaged.
- External dependency flows, such as certificate generation/usage for TLS connections.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        A["CLI & Command Parser"]:::cli
        B["Client Module"]:::client
    end

    %% Common and Networking Layer
    subgraph "Common & Networking"
        E["Core Logic & Message Framing"]:::core
        C["Networking Layer"]:::network
        F["TLS/SSL Layer"]:::tls
    end

    %% Server Side
    subgraph "Server Side"
        D["Server Module"]:::server
    end

    %% Testing and Examples
    subgraph "Test & Example Layer"
        G["Tests & Examples"]:::test
    end

    %% Relationships
    A -->|"invokes"| B
    B -->|"calls"| C
    B -->|"uses"| E
    C -->|"routes to"| D
    D -->|"utilizes"| E
    D -->|"responds via"| C
    C -->|"deliversResponse"| B
    C -->|"securedBy"| F
    G -->|"validates"| C

    %% Click Events
    click A "https://github.com/girish946/simple-pub-sub/blob/master/src/cli.rs"
    click B "https://github.com/girish946/simple-pub-sub/tree/master/src/client"
    click B "https://github.com/girish946/simple-pub-sub/blob/master/src/client/mod.rs"
    click D "https://github.com/girish946/simple-pub-sub/blob/master/src/server/mod.rs"
    click D "https://github.com/girish946/simple-pub-sub/blob/master/src/server/client_handler.rs"
    click E "https://github.com/girish946/simple-pub-sub/blob/master/src/lib.rs"
    click E "https://github.com/girish946/simple-pub-sub/blob/master/src/message.rs"
    click E "https://github.com/girish946/simple-pub-sub/blob/master/src/stream.rs"
    click E "https://github.com/girish946/simple-pub-sub/blob/master/src/topics.rs"
    click F "https://github.com/girish946/simple-pub-sub/tree/master/certs"
    click G "https://github.com/girish946/simple-pub-sub/blob/master/examples/publish_tcp.rs"
    click G "https://github.com/girish946/simple-pub-sub/blob/master/examples/subscribe_tcp.rs"
    click G "https://github.com/girish946/simple-pub-sub/blob/master/tests/tcp.rs"
    click G "https://github.com/girish946/simple-pub-sub/blob/master/tests/tls.rs"
    click G "https://github.com/girish946/simple-pub-sub/blob/master/tests/unix.rs"

    %% Styles
    classDef cli fill:#ffdddd,stroke:#a00,stroke-width:2px;
    classDef client fill:#ddffdd,stroke:#0a0,stroke-width:2px;
    classDef server fill:#ddddff,stroke:#00a,stroke-width:2px;
    classDef core fill:#ffffdd,stroke:#aa0,stroke-width:2px;
    classDef network fill:#ddffff,stroke:#0aa,stroke-width:2px;
    classDef tls fill:#ffeedd,stroke:#a60,stroke-width:2px;
    classDef test fill:#f0f0f0,stroke:#999,stroke-width:2px;
```
