# a4z/zq architecture

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

- Interactive diagram: https://gitdiagram.com/a4z/zq
- Repository: https://github.com/a4z/zq

## Overview

##### Core Components Layer
- Context Management (from context.hpp)
- Socket Handling (from socket.hpp)
- Error Handling (from error.hpp, error_fmt.hpp)
- Message Processing (from message.hpp)
- Configuration (from config.hpp)

##### Message Type System
- Basic Types Handler
- String Message Handler
- Protobuf Message Handler (connected to proto/pingpong.proto)
- Custom Type Extensions

##### Communication Patterns
- Supported ZeroMQ patterns:
- PUB/SUB Pattern
- Request/Reply Pattern
- Multi-part Message Handling

##### External Dependencies
- Integration with:
- ZeroMQ Library
- Protocol Buffers
- Standard C++ Library

##### Use a Layered Architecture Approach
- [Client Applications]
- ↕
- [ZQ Interface Layer (zq.hpp)]
- ↕
- [Type System Layer]
- ↕
- [Core Components]
- ↕
- [ZeroMQ Library]

##### Testing Infrastructure
- A separate section showing test categories:
- Base Tests
- Communication Tests
- Context Tests
- Protocol Buffer Tests
- Extension Tests

Implementation Details to Note:

##### Build System Integration
- CMake configuration
- VCPKG dependency management
- Compiler requirements (C++20)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Applications"
        Client["Client Applications"]:::client
        click Client "https://github.com/a4z/zq/blob/main/src/example_c_client.cpp"
        Server["Server Applications"]:::client
        click Server "https://github.com/a4z/zq/blob/main/src/example_c_server.cpp"
    end

    subgraph "ZQ Interface Layer"
        ZQInterface["ZQ Main Interface"]:::interface
        click ZQInterface "https://github.com/a4z/zq/blob/main/include/zq/zq.hpp"
    end

    subgraph "Type System Layer"
        BasicMsg["Basic Message Handler"]:::type
        click BasicMsg "https://github.com/a4z/zq/blob/main/include/zq/message.hpp"
        ProtoMsg["Protobuf Message Handler"]:::type
        click ProtoMsg "https://github.com/a4z/zq/blob/main/include/zq/message_proto.hpp"
        SocketFlags["Socket Flags"]:::type
        click SocketFlags "https://github.com/a4z/zq/blob/main/include/zq/zflags.hpp"
    end

    subgraph "Core Components"
        Context["Context Management"]:::core
        click Context "https://github.com/a4z/zq/blob/main/include/zq/context.hpp"
        Socket["Socket Handling"]:::core
        click Socket "https://github.com/a4z/zq/blob/main/include/zq/socket.hpp"
        Error["Error Handling"]:::core
        click Error "https://github.com/a4z/zq/blob/main/include/zq/error.hpp"
        Message["Message Processing"]:::core
        click Message "https://github.com/a4z/zq/blob/main/include/zq/message.hpp"
        Config["Configuration"]:::core
        click Config "https://github.com/a4z/zq/blob/main/include/zq/config.hpp"
    end

    subgraph "Testing Framework"
        BaseTests["Base Tests"]:::test
        click BaseTests "https://github.com/a4z/zq/tree/main/tests/base"
        CommuTests["Communication Tests"]:::test
        click CommuTests "https://github.com/a4z/zq/tree/main/tests/commu"
        ContextTests["Context Tests"]:::test
        click ContextTests "https://github.com/a4z/zq/tree/main/tests/ctx0"
        ProtoTests["Protocol Buffer Tests"]:::test
        click ProtoTests "https://github.com/a4z/zq/tree/main/tests/proto"
        ExtTests["Extension Tests"]:::test
        click ExtTests "https://github.com/a4z/zq/tree/main/tests/xtend"
        XtraTests["Extra Tests"]:::test
        click XtraTests "https://github.com/a4z/zq/tree/main/tests/xtra"
    end

    subgraph "Communication Patterns"
        PubSub["PUB/SUB Pattern"]:::pattern
        click PubSub "https://github.com/a4z/zq/blob/main/tests/commu/pub_sub_test.cpp"
        BasicComm["Basic Communication"]:::pattern
        click BasicComm "https://github.com/a4z/zq/blob/main/tests/commu/hello_test.cpp"
        ProtoComm["Protobuf Communication"]:::pattern
        click ProtoComm "https://github.com/a4z/zq/blob/main/tests/commu/hello_proto_test.cpp"
        TypedMsg["Typed Messages"]:::pattern
        click TypedMsg "https://github.com/a4z/zq/blob/main/tests/commu/typedmessage_test.cpp"
    end

    subgraph "External Dependencies"
        ZMQ["ZeroMQ Library"]:::external
        Protobuf["Protocol Buffers"]:::external
        CPP["Standard C++ Library"]:::external
    end

    subgraph "Build System"
        CMake["CMake Configuration"]:::build
        click CMake "https://github.com/a4z/zq/blob/main/CMakeLists.txt"
        VCPKG["VCPKG Dependencies"]:::build
        click VCPKG "https://github.com/a4z/zq/blob/main/vcpkg.json"
    end

    %% Relationships
    Client & Server --> ZQInterface
    ZQInterface --> BasicMsg & ProtoMsg & SocketFlags
    BasicMsg & ProtoMsg --> Message
    Message --> Context & Socket
    Socket --> Error
    Context --> Config
    ProtoMsg --> Protobuf
    Socket --> ZMQ
    CommuTests --> PubSub & BasicComm & ProtoComm & TypedMsg

    %% Styles
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef type fill:#4CAF50,stroke:#388E3C,color:white
    classDef external fill:#FFC107,stroke:#FFA000,color:black
    classDef test fill:#9E9E9E,stroke:#616161,color:white
    classDef pattern fill:#673AB7,stroke:#512DA8,color:white
    classDef interface fill:#00BCD4,stroke:#0097A7,color:white
    classDef client fill:#FF5722,stroke:#E64A19,color:white
    classDef build fill:#795548,stroke:#5D4037,color:white
```
