# zeromq/azmq architecture

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

- Interactive diagram: https://gitdiagram.com/zeromq/azmq
- Repository: https://github.com/zeromq/azmq

## Overview

##### Main Components

a) Core Library Components:
- Context Management Layer
- Socket Abstraction Layer
- Error Handling System
- Message Handling System
- Actor System
- Signal Handling System

b) External Dependencies:
- Boost.Asio
- ZeroMQ (libzmq)
- Boost Libraries

**┌─ Application Layer ─────────────────────┐**
- (User Code)                            │
- ┬────────────────────┘
- ↓
**┌─ AZMQ Public API ─────────────────────────────────────────┐**
- ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────┐ │
- Socket  │ │ Actor   │ │ Signal  │ │ Message │ │Error│ │
- ┬────┘ └────┬────┘ └────┬────┘ └────┬────┘ └──┬──┘ │
- ┼──────────┼──────────┼──────────┼───────────┼────┘
- ↓          ↓          ↓          ↓           ↓
**┌─ Implementation Layer ──────────────────────────────────┐**
- ┌─────────────┐ ┌──────────────┐ ┌─────────────────┐  │
- Socket Service│ │Actor Service │ │Reactor Services │  │
- ┬──────┘ └───────┬──────┘ └────────┬────────┘  │

- ┌──────┴──────┐ ┌──────┴──────┐  ┌───────┴────────┐  │
- Socket Ops  │ │Context Ops  │  │Operation Handlers│  │
- ┬──────┘ └──────┬──────┘  └───────┬────────┘  │
- ┼─────────────┼────────────────────┼───────────┘
- ↓             ↓                     ↓
**┌─ Integration Layer ─────────────────────────────────────┐**
- ┌─────────────┐    ┌─────────────┐                     │
- Boost.Asio  │←→  │    AZMQ     │                     │
- ┘    └──────┬──────┘                     │
- ↓                             │
- ┌─────────────┐                     │
- ZeroMQ    │                     │
- ┘                     │
- ┘

##### Key Elements to Highlight

a) Socket Architecture:
- How azmq::socket integrates with Asio's io_service
- Reactor pattern implementation
- Connection to ZeroMQ's socket interface

b) Service Layer:
- Demonstrate how socket_service, actor_service, and other services interact
- Relationship with Asio's service architecture

c) Operation Flow:
- Send_op and receive_op components
- How reactor_op integrates with the async operations

##### Implementation Details

- How the detail/ directory components interact
- Util/ directory supporting functions
- Relationship between public headers and implementation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Application Layer"
        APP[User Application]
    end

    subgraph "AZMQ Public API"
        direction TB
        SOCKET["Socket API"]:::api
        ACTOR["Actor API"]:::api
        SIGNAL["Signal API"]:::api
        MSG["Message API"]:::api
        ERR["Error API"]:::api
        CTX["Context API"]:::api
    end

    subgraph "Implementation Layer"
        direction TB
        SOCK_SVC["Socket Service"]:::impl
        ACTOR_SVC["Actor Service"]:::impl
        REACT_SVC["Reactor Services"]:::impl
        
        SOCK_OPS["Socket Operations"]:::impl
        CTX_OPS["Context Operations"]:::impl
        OP_HANDLERS["Operation Handlers"]:::impl
        
        CONFIG["Configuration System"]:::impl
        
        subgraph "Utility Components"
            EXPECTED["Expected Utility"]:::util
            SCOPE["Scope Guard"]:::util
        end
    end

    subgraph "Integration Layer"
        direction TB
        ASIO["Boost.Asio"]:::external
        AZMQ_CORE["AZMQ Core"]:::core
        ZMQ["ZeroMQ"]:::external
    end

    %% Connections
    APP --> SOCKET & ACTOR & SIGNAL & MSG & ERR & CTX
    
    SOCKET --> SOCK_SVC
    ACTOR --> ACTOR_SVC
    MSG --> OP_HANDLERS
    CTX --> CTX_OPS
    
    SOCK_SVC --> SOCK_OPS
    SOCK_SVC --> REACT_SVC
    ACTOR_SVC --> CTX_OPS
    
    SOCK_OPS & CTX_OPS & OP_HANDLERS --> AZMQ_CORE
    
    CONFIG --> AZMQ_CORE
    EXPECTED & SCOPE --> AZMQ_CORE
    
    AZMQ_CORE <--> ASIO
    AZMQ_CORE --> ZMQ

    %% Click Events
    click SOCKET "https://github.com/zeromq/azmq/blob/master/azmq/socket.hpp"
    click ACTOR "https://github.com/zeromq/azmq/blob/master/azmq/actor.hpp"
    click SIGNAL "https://github.com/zeromq/azmq/blob/master/azmq/signal.hpp"
    click MSG "https://github.com/zeromq/azmq/blob/master/azmq/message.hpp"
    click ERR "https://github.com/zeromq/azmq/blob/master/azmq/error.hpp"
    click CTX "https://github.com/zeromq/azmq/blob/master/azmq/context.hpp"
    
    click SOCK_SVC "https://github.com/zeromq/azmq/blob/master/azmq/detail/socket_service.hpp"
    click ACTOR_SVC "https://github.com/zeromq/azmq/blob/master/azmq/detail/actor_service.hpp"
    click SOCK_OPS "https://github.com/zeromq/azmq/blob/master/azmq/detail/socket_ops.hpp"
    click CTX_OPS "https://github.com/zeromq/azmq/blob/master/azmq/detail/context_ops.hpp"
    click CONFIG "https://github.com/zeromq/azmq/tree/master/azmq/detail/config"
    
    click EXPECTED "https://github.com/zeromq/azmq/blob/master/azmq/util/expected.hpp"
    click SCOPE "https://github.com/zeromq/azmq/blob/master/azmq/util/scope_guard.hpp"

    %% Styles
    classDef api fill:#2196F3,stroke:#1565C0,color:white
    classDef impl fill:#4CAF50,stroke:#2E7D32,color:white
    classDef external fill:#FF9800,stroke:#F57C00,color:white
    classDef core fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef util fill:#00BCD4,stroke:#0097A7,color:white

    %% Legend
    subgraph Legend
        L1["Public API"]:::api
        L2["Implementation"]:::impl
        L3["External Dependency"]:::external
        L4["Core Component"]:::core
        L5["Utility"]:::util
    end
```
