# valdircezar/formacao-backend-expert architecture

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

- Interactive diagram: https://gitdiagram.com/valdircezar/formacao-backend-expert
- Repository: https://github.com/valdircezar/formacao-backend-expert

## Overview

##### Project Type and Purpose
- This is a backend-focused microservices system built with Spring Boot and Spring Cloud.
- Purpose: Provide a “Backend Expert” training platform demonstrating a full microservices ecosystem, including authentication, user/order management, messaging, centralized configuration, service discovery, and a BFF layer.

a. API Gateway
b. Helpdesk BFF
c. Service Discovery (Eureka)
d. Config Server
e. Auth Service API
f. User Service API
g. Order Service API
h. Email Service
i. Shared Commons Library (hd-commons-lib) – not a deployed component but note its usage in service code
j. RabbitMQ Broker
k. Databases – one per service (e.g., MongoDB Atlas or Amazon RDS instances)

##### Relationships and Interactions
- External client → API Gateway (routes requests)
- API Gateway → Helpdesk BFF for UI-oriented endpoints
- Helpdesk BFF → Auth/User/Order services via Feign clients (synchronous HTTP)
- Order Service → User Service (via Feign client) to enrich order data
- Auth Service issues JWT tokens; BFF and API Gateway apply JWTAuthorizationFilters
- Services register with Service Discovery; Gateway and BFF use Discovery to locate them
- Config Server serves configuration (bootstrap.yml/application.yml) to all services at startup
- Order Service publishes “order-created” messages to RabbitMQ
- Email Service listens on RabbitMQ queue, processes messages, and sends emails
- Each service interacts with its own database

##### Architectural Patterns and Principles
- Microservices with single responsibility per service
- API Gateway pattern for routing, authentication, load balancing
- Backend-for-Frontend (BFF) pattern to tailor APIs to clients
- Centralized Configuration (Spring Cloud Config)
- Service Discovery (Eureka)
- Synchronous inter-service calls via Feign + load balancing
- Asynchronous messaging via RabbitMQ for decoupling
- JWT-based stateless authentication
- Shared library for DTOs, enums, exceptions to ensure common contracts

##### Technologies/Frameworks to annotate
- Spring Boot, Spring Cloud Gateway (or Netflix Zuul) for API Gateway
- Spring Cloud Config Server
- Spring Cloud Netflix Eureka (Service Discovery)
- Spring Security + JWT
- Spring Cloud OpenFeign for HTTP clients
- RabbitMQ
- Databases (MongoDB Atlas or RDS)
- Docker & Docker-Compose for orchestration

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    EC["External Client"]:::external

    %% API Layer
    subgraph "API Layer"
        direction TB
        APIGW["API Gateway"]:::gateway
        BFF["Helpdesk BFF"]:::gateway
    end

    %% Backend Services
    subgraph "Microservices"
        direction TB
        AUTH["Auth Service API"]:::service
        USER["User Service API"]:::service
        ORDER["Order Service API"]:::service
        EMAIL["Email Service"]:::service
    end

    %% Infrastructure
    subgraph "Infrastructure"
        direction TB
        CONFIG["Config Server"]:::infra
        DISCOVERY["Service Discovery (Eureka)"]:::infra
        RABBIT["RabbitMQ Broker"]:::infra
    end

    %% Databases
    subgraph "Databases"
        direction TB
        AuthDB[(Auth DB)]:::db
        UserDB[(User DB)]:::db
        OrderDB[(Order DB)]:::db
    end

    %% Shared Library
    LIB["hd-commons-lib"]:::lib

    %% Connections
    EC -->|"REST"| APIGW
    APIGW -->|"Routes UI Calls"| BFF
    BFF -->|"Feign REST"| AUTH
    BFF -->|"Feign REST"| USER
    BFF -->|"Feign REST"| ORDER

    ORDER -->|"Feign Enrich"| USER

    %% Service Discovery & Config
    APIGW -->|"Discover/Register"| DISCOVERY
    BFF -->|"Discover/Register"| DISCOVERY
    AUTH -->|"Register"| DISCOVERY
    USER -->|"Register"| DISCOVERY
    ORDER -->|"Register"| DISCOVERY
    EMAIL -->|"Register"| DISCOVERY

    APIGW -->|"Config Fetch"| CONFIG
    BFF -->|"Config Fetch"| CONFIG
    AUTH -->|"Config Fetch"| CONFIG
    USER -->|"Config Fetch"| CONFIG
    ORDER -->|"Config Fetch"| CONFIG
    EMAIL -->|"Config Fetch"| CONFIG

    %% Async Messaging
    ORDER -->|"Publish Order Created"| RABBIT
    RABBIT -->|"Consume & Send Email"| EMAIL

    %% Databases Connections
    AUTH -->|"Reads/Writes"| AuthDB
    USER -->|"Reads/Writes"| UserDB
    ORDER -->|"Reads/Writes"| OrderDB

    %% Shared Library Usage
    AUTH -.-> LIB
    USER -.-> LIB
    ORDER -.-> LIB
    EMAIL -.-> LIB

    %% Click Events
    click APIGW "https://github.com/valdircezar/formacao-backend-expert/tree/master/api-gateway/"
    click BFF "https://github.com/valdircezar/formacao-backend-expert/tree/master/helpdesk-bff/"
    click DISCOVERY "https://github.com/valdircezar/formacao-backend-expert/tree/master/service-discovery/"
    click CONFIG "https://github.com/valdircezar/formacao-backend-expert/tree/master/config-server/"
    click AUTH "https://github.com/valdircezar/formacao-backend-expert/tree/master/auth-service-api/"
    click USER "https://github.com/valdircezar/formacao-backend-expert/tree/master/user-service-api/"
    click ORDER "https://github.com/valdircezar/formacao-backend-expert/tree/master/order-service-api/"
    click EMAIL "https://github.com/valdircezar/formacao-backend-expert/tree/master/email-service/"
    click LIB "https://github.com/valdircezar/formacao-backend-expert/tree/master/hd-commons-lib/"
    click RABBIT "https://github.com/valdircezar/formacao-backend-expert/blob/master/docker-compose.yml"
    click AuthDB "https://github.com/valdircezar/formacao-backend-expert/blob/master/docker-compose.yml"
    click UserDB "https://github.com/valdircezar/formacao-backend-expert/blob/master/docker-compose.yml"
    click OrderDB "https://github.com/valdircezar/formacao-backend-expert/blob/master/docker-compose.yml"

    %% Styles
    classDef gateway fill:#FFD580,stroke:#333,stroke-width:1px
    classDef service fill:#80C3FF,stroke:#333,stroke-width:1px
    classDef infra fill:#C8C8C8,stroke:#333,stroke-width:1px
    classDef db fill:#FFE680,stroke:#333,stroke-width:1px
    classDef lib fill:#D3B8AE,stroke:#333,stroke-width:1px
    classDef external fill:#B4E7B1,stroke:#333,stroke-width:1px
```
