# felipecesargomes/rabbitmq-fanout-spring architecture

> Architecture diagram of the GitHub repository felipecesargomes/rabbitmq-fanout-spring, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/felipecesargomes/rabbitmq-fanout-spring
- Repository: https://github.com/felipecesargomes/rabbitmq-fanout-spring

## Overview

##### Project type and purpose
- This is a distributed, event-driven microservices system built with Spring Boot and RabbitMQ in a fanout pattern.
- It consists of three independent services (pedidos-api, notification, worker) that communicate via a RabbitMQ exchange.

##### Main components
a. pedidos-api Service (Producer)
- Spring Boot REST API
- Publishes order messages to a RabbitMQ fanout exchange.
b. RabbitMQ (Message Broker)
- A fanout Exchange
- Two Bound Queues (one for notification, one for worker)
c. notification Service (Consumer #1)
- Listens on its queue
- Processes orders by sending emails via MailHog
d. worker Service (Consumer #2)
- Listens on its queue
- Persists order data to a database (JPA repositories)
e. External Services/Tools
- MailHog (SMTP server for email testing)
- (Optional) Relational Database for the worker service

##### Relationships and Data Flows
- Client → HTTP POST /orders → pedidos-api
- pedidos-api → publish message to FanoutExchange
- FanoutExchange → broadcast message to both queues
- notification.queue → notification Service consumes → EmailService → MailHog
- worker.queue → worker Service consumes → JPA Repositories → Database

##### Architectural Patterns & Principles
- Microservices: each service is packaged separately (its own pom.xml, Docker config).
- Event-Driven: loose coupling via RabbitMQ; producer doesn’t know consumers.
- Fanout Exchange: one-to-many broadcast semantics.
- Spring AMQP: RabbitMQConfig classes in each module.
- Separation of Concerns:
- pedidos-api: API layer + messaging
- notification: messaging + email
- worker: messaging + persistence

##### Technologies & Frameworks
- Java 11+ / Spring Boot
- Spring AMQP (RabbitMQConfig)
- Maven (build tool)
- RabbitMQ (broker)
- MailHog (email)
- Spring Data JPA (worker persistence)
- Docker-Compose (defines RabbitMQ, MailHog, maybe database)

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client"]:::external
    subgraph "pedidos-api"
        API["pedidos-api Service"]:::service
    end
    subgraph "RabbitMQ Broker"
        EX["FanoutExchange (fanout)"]:::broker
        Q1["notification.queue"]:::broker
        Q2["worker.queue"]:::broker
    end
    subgraph "notification"
        NOTI["notification Service"]:::service
    end
    subgraph "worker"
        WORK["worker Service"]:::service
    end
    MH["MailHog (SMTP)"]:::external
    DB["Database (Optional/Configurable)"]:::datastore

    Client -->|"POST /orders"| API
    API -->|"OrderCreatedEvent"| EX
    EX -->|"broadcast"| Q1
    EX -->|"broadcast"| Q2
    Q1 -->|"consume"| NOTI
    NOTI -->|"send email"| MH
    Q2 -->|"consume"| WORK
    WORK -->|"persist order"| DB

    click API "https://github.com/felipecesargomes/rabbitmq-fanout-spring/tree/main/pedidos-api/"
    click NOTI "https://github.com/felipecesargomes/rabbitmq-fanout-spring/tree/main/notification/"
    click WORK "https://github.com/felipecesargomes/rabbitmq-fanout-spring/tree/main/worker/"
    click EX "https://github.com/felipecesargomes/rabbitmq-fanout-spring/blob/main/docker-compose.yml"

    classDef service fill:#D6EAF8,stroke:#3498DB;
    classDef broker fill:#FAD7A0,stroke:#E67E22;
    classDef datastore fill:#ABEBC6,stroke:#27AE60;
    classDef external fill:#ABEBC6,stroke:#27AE60;
```
