# streadway/amqp architecture

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

- Interactive diagram: https://gitdiagram.com/streadway/amqp
- Repository: https://github.com/streadway/amqp

## Overview

##### Main Components

a. Core Components (Primary Layer):
- Connection Management (connection.go)
- Channel Management (channel.go)
- Message Delivery System (delivery.go)
- Authentication Handler (auth.go)
- Read/Write Operations (read.go, write.go)

b. Supporting Components (Secondary Layer):
- Type System (types.go)
- URI Handling (uri.go)
- Memory Management (allocator.go)
- Confirmation System (confirms.go)
- Consumer Management (consumers.go)

- Application    |  (Top Layer - External Usage)

- AMQP Client    |  (Middle Layer - Core Implementation)

- RabbitMQ      |  (Bottom Layer - External Server)

##### Key Interactions to Highlight

- Connection lifecycle management
- Channel multiplexing
- Message publishing flow
- Consumer subscription flow
- Confirmation handling
- Error handling and recovery paths

##### Implementation Details

- [Application Layer]
- ↕
- [Client Implementation]

- URI → Auth → Conn   |
- ↓                   |
- Channel Management     |
- ↓                   |
- Publishing/Consuming   |

- ↕
- [RabbitMQ Server]

##### Additional Elements

- Notes about important configuration options
- Version compatibility information
- Error handling paths
- Document reconnection boundaries (noting it's not auto-handled)

Remember to:
- Keep the focus on the client-side implementation
- Clear boundaries between the application, client library, and server
- Asynchronous nature of the protocol
- Important error paths and edge cases
- Document the multiplexing of channels over connections

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef external fill:#D3D3D3,stroke:#333
    classDef core fill:#B3E0FF,stroke:#333
    classDef messaging fill:#98FB98,stroke:#333
    classDef utility fill:#FFE5B4,stroke:#333
    classDef critical fill:#FFB6C1,stroke:#333
    classDef example fill:#E6E6FA,stroke:#333

    %% Application Layer
    subgraph Application
        APP[Client Application]
        EX1["Simple Producer"]:::example
        EX2["Simple Consumer"]:::example
        EX3["Publisher/Subscriber"]:::example
    end

    %% Core Implementation Layer
    subgraph ClientImplementation
        %% Core Components
        URI["URI Handler"]:::utility
        AUTH["Authentication"]:::critical
        CONN["Connection Manager"]:::core
        CHAN["Channel Manager"]:::core
        
        %% Supporting Components
        TYPES["Type System"]:::utility
        ALLOC["Memory Manager"]:::utility
        READ["Read Operations"]:::core
        WRITE["Write Operations"]:::core
        
        %% Message Handling
        DEL["Message Delivery"]:::messaging
        CONF["Confirmation System"]:::critical
        CONS["Consumer Management"]:::messaging
        RET["Return Handler"]:::messaging
        SPEC["Protocol Implementation"]:::core
    end

    %% RabbitMQ Server Layer
    RABBITMQ[RabbitMQ Server]:::external

    %% Relationships
    APP --> EX1 & EX2 & EX3
    EX1 & EX2 & EX3 --> URI
    URI --> AUTH
    AUTH --> CONN
    CONN --> CHAN
    CHAN --> DEL
    CHAN --> CONF
    CHAN --> CONS
    CHAN --> RET
    
    READ & WRITE --> CONN
    TYPES --> CHAN
    ALLOC --> CONN
    SPEC --> CONN
    
    DEL & CONF & CONS & RET --> RABBITMQ

    %% Click events for file mapping
    click CONN "https://github.com/streadway/amqp/blob/master/connection.go"
    click CHAN "https://github.com/streadway/amqp/blob/master/channel.go"
    click DEL "https://github.com/streadway/amqp/blob/master/delivery.go"
    click AUTH "https://github.com/streadway/amqp/blob/master/auth.go"
    click READ "https://github.com/streadway/amqp/blob/master/read.go"
    click WRITE "https://github.com/streadway/amqp/blob/master/write.go"
    click TYPES "https://github.com/streadway/amqp/blob/master/types.go"
    click URI "https://github.com/streadway/amqp/blob/master/uri.go"
    click ALLOC "https://github.com/streadway/amqp/blob/master/allocator.go"
    click CONF "https://github.com/streadway/amqp/blob/master/confirms.go"
    click CONS "https://github.com/streadway/amqp/blob/master/consumers.go"
    click SPEC "https://github.com/streadway/amqp/blob/master/spec091.go"
    click RET "https://github.com/streadway/amqp/blob/master/return.go"
    click EX1 "https://github.com/streadway/amqp/blob/master/_examples/simple-producer/producer.go"
    click EX2 "https://github.com/streadway/amqp/blob/master/_examples/simple-consumer/consumer.go"
    click EX3 "https://github.com/streadway/amqp/blob/master/_examples/pubsub/pubsub.go"

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Message Handling]:::messaging
        L3[Utility Components]:::utility
        L4[Critical Path]:::critical
        L5[External Systems]:::external
        L6[Examples]:::example
    end
```
