# eltonriva1/curso-udemy-comunicacao-microsservicos architecture

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

- Interactive diagram: https://gitdiagram.com/eltonriva1/curso-udemy-comunicacao-microsservicos
- Repository: https://github.com/eltonriva1/curso-udemy-comunicacao-microsservicos

## Overview

##### Project Type and Purpose
- This is a microservices-based system composed of three services—Auth-API, Product-API, and Sales-API—containerized with Docker and orchestrated via Docker Compose.
- Purpose: demonstrate synchronous communication (HTTP/Feign), asynchronous messaging (RabbitMQ), JWT-based security, and containerized deployment.

##### High-Level File-Structure Analysis
- Top-level:
- README.md and docker-compose.yml
- auth-api (Node.js/Express)
- product-api (Java/Spring Boot)
- sales-api (Node.js/Express)
- Each service folder contains source code (controllers, services, repositories), configuration (DB, auth, RabbitMQ), and Docker files.
- product-api uses Spring Boot modules (controllers, services, repositories, Feign client, RabbitMQ listener), auth-api and sales-api use Express middleware for JWT and RabbitMQ setup.

##### Key Architectural Insights from README
- Three microservices with dedicated data stores:
- Auth-API → PostgreSQL
- Product-API → PostgreSQL
- Sales-API → MongoDB
- Shared RabbitMQ broker for asynchronous events (order placements, stock updates).
- Synchronous calls via HTTP/Feign for inter-service requests (e.g., Sales→Product, Product→Sales).
- JWT authentication enforced by Auth-API; checked by middleware/interceptor in Product and Sales services.

##### Components
a. Service Containers (rectangles):
- Auth-API (Node.js)
- Product-API (Spring Boot)
- Sales-API (Node.js)
- PostgreSQL instance for Auth & Product
- MongoDB instance for Sales
- RabbitMQ

##### Relationships and Data Flows
- Client → HTTP → Auth-API (login/register) → JWT issued
- Client → HTTP (with JWT) → Product-API / Sales-API
- Product-API and Sales-API → HTTP (Feign) → Auth-API for token verification
- Sales-API (OrderController) → HTTP (Feign) → Product-API (e.g., check stock)
- Sales-API → publish “order placed” event → RabbitMQ exchange/queue
- Product-API → subscribe to stock-update queue → update inventory
- Product-API → when appropriate, publish “stock changed” event → RabbitMQ
- Sales-API → subscribe to “sales confirmation” queue → update order status

##### Architectural Patterns & Design Principles
- Microservices—each service independently deployable, own database
- Layered architecture within each service: Controllers → Services → Repositories
- API security via JWT, enforced by middleware/interceptors
- Synchronous RPC-like calls via Feign (Spring) and HTTP clients (Node.js)
- Event–driven asynchronous communication via RabbitMQ
- Containerization for environment consistency

## Diagram (Mermaid)

```mermaid
flowchart TD
    client((Client)):::client

    subgraph "Docker Compose"
        direction TB
        auth["Auth-API\n(Node.js/Express)"]:::service
        product["Product-API\n(Java/Spring Boot)"]:::service
        sales["Sales-API\n(Node.js/Express)"]:::service
        rabbit[(RabbitMQ)]:::broker
        pg[(PostgreSQL)]:::db
        mongo[(MongoDB)]:::db
    end

    client -->|"HTTP /login, /register"| auth
    auth -->|"JWT token"| client
    client -->|"HTTP with JWT"| product
    client -->|"HTTP with JWT"| sales
    product -->|"FEIGN checkToken"| auth
    sales -->|"HTTP checkToken"| auth
    sales -->|"FEIGN /check-stock"| product

    sales -->|"publish orderPlaced"| rabbit
    rabbit -->|"consume orderPlaced"| product
    product -->|"publish stockChanged"| rabbit
    rabbit -->|"consume stockChanged"| sales

    auth -->|"reads/writes"| pg
    product -->|"reads/writes"| pg
    sales -->|"reads/writes"| mongo

    classDef service fill:#E8F1FF,stroke:#0366d6,color:#0366d6;
    classDef db fill:#E6F4EA,stroke:#28A745,color:#28A745;
    classDef broker fill:#FFF4E5,stroke:#FF8800,color:#FF8800;
    classDef client fill:#F0F8FF,stroke:#1E90FF,color:#1E90FF;

    %% Link Styles: HTTP Blue, Messaging Orange dashed, DB Green
    linkStyle 0,1,2,3,4,5,6 stroke:#1E90FF,stroke-width:2px
    linkStyle 7,8,9,10 stroke:#FF8800,stroke-width:2px,stroke-dasharray:5 5
    linkStyle 11,12,13 stroke:#28A745,stroke-width:2px

    %% Click Events
    click auth "https://github.com/eltonriva1/curso-udemy-comunicacao-microsservicos/tree/master/auth-api/"
    click product "https://github.com/eltonriva1/curso-udemy-comunicacao-microsservicos/tree/master/product-api/"
    click sales "https://github.com/eltonriva1/curso-udemy-comunicacao-microsservicos/tree/master/sales-api/"
    click rabbit "https://github.com/eltonriva1/curso-udemy-comunicacao-microsservicos/blob/master/docker-compose.yml"
    click pg "https://github.com/eltonriva1/curso-udemy-comunicacao-microsservicos/blob/master/auth-api/src/config/db/dbConfig.js"
    click mongo "https://github.com/eltonriva1/curso-udemy-comunicacao-microsservicos/blob/master/sales-api/src/config/db/mongoDbConfig.js"
```
