https://github.com/rafaelfgx/microservices
Clean Architecture, Event-Driven Architecture, Clean Code, SOLID Principles, Resilience, Idempotency, Folder-by-Feature, Patterns (Mediator, Result, Strategy, Outbox, Retry, Circuit Breaker), Java, Spring Boot, Kong, Keycloak, Kafka, MongoDB, Redis, Elastic, Kibana, Swagger, Docker.
https://github.com/rafaelfgx/microservices
circuit-breaker-pattern clean-architecture clean-code elasticsearch event-driven-architecture java kafka keycloak kong mediator-pattern mongodb outbox-pattern redis retry-pattern solid spring-boot strategy-pattern
Last synced: about 1 month ago
JSON representation
Clean Architecture, Event-Driven Architecture, Clean Code, SOLID Principles, Resilience, Idempotency, Folder-by-Feature, Patterns (Mediator, Result, Strategy, Outbox, Retry, Circuit Breaker), Java, Spring Boot, Kong, Keycloak, Kafka, MongoDB, Redis, Elastic, Kibana, Swagger, Docker.
- Host: GitHub
- URL: https://github.com/rafaelfgx/microservices
- Owner: rafaelfgx
- License: mit
- Created: 2025-05-16T12:19:34.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-09T11:56:43.000Z (about 1 year ago)
- Last Synced: 2025-06-09T12:46:09.316Z (about 1 year ago)
- Topics: circuit-breaker-pattern, clean-architecture, clean-code, elasticsearch, event-driven-architecture, java, kafka, keycloak, kong, mediator-pattern, mongodb, outbox-pattern, redis, retry-pattern, solid, spring-boot, strategy-pattern
- Language: Java
- Homepage:
- Size: 1.3 MB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# Microservices


## Ebooks
## Flow
```mermaid
sequenceDiagram
participant Client
participant AuthService
participant CustomerService
participant ProductService
participant OrderService
participant PaymentService
participant Kafka
Client->>AuthService: POST /auth
AuthService-->>Client: JWT
Client->>CustomerService: POST /customers
CustomerService-->>Client: Customer Created
Client->>ProductService: POST /products
ProductService-->>Client: Product Created
Client->>OrderService: POST /orders
OrderService-->>Client: Order Created
OrderService->>Kafka: OrderEvent Published
Kafka-->>PaymentService: OrderEvent Consumed
Note right of PaymentService: Payment Created
Client->>PaymentService: PUT /payments/order/{orderId}/status/{status}
PaymentService-->>Client: Payment Status Updated
PaymentService->>Kafka: PaymentEvent Published
Kafka-->>OrderService: PaymentEvent Consumed
Note right of OrderService: Status Updated
```
## Architecture, Design and Principles
- [Screaming Architecture](https://blog.cleancoder.com/uncle-bob/2011/09/30/Screaming-Architecture.html)
- [Clean Architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html)
- [Event-Driven Architecture](https://martinfowler.com/articles/201701-event-driven.html)
- [Clean Code](https://www.oreilly.com/library/view/clean-code-a/9780136083238)
- [Domain-Driven Design](https://martinfowler.com/bliki/DomainDrivenDesign.html)
- [SOLID Principles](https://www.baeldung.com/solid-principles)
- [Separation of Concerns](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html)
- [Common Closure Principle](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html)
- [Common Reuse Principle](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html)
- [Test Pyramid](https://martinfowler.com/articles/practical-test-pyramid.html)
## Patterns
- [Ambassador Pattern](https://www.geeksforgeeks.org/system-design/ambassador-pattern-in-distributed-systems)
- [Circuit Breaker Pattern](https://www.geeksforgeeks.org/circuit-breaker-vs-retry-pattern)
- [Mediator Pattern](https://refactoring.guru/design-patterns/mediator)
- [Outbox Pattern](https://www.geeksforgeeks.org/outbox-pattern-for-reliable-messaging-system-design)
- [Result Pattern](https://www.codingexplorations.com/blog/mastering-the-result-pattern-in-software-development)
- [Retry Pattern](https://www.geeksforgeeks.org/circuit-breaker-vs-retry-pattern)
- [Strategy Pattern](https://refactoring.guru/design-patterns/strategy)
## Technologies and Tools
- [Java](https://www.oracle.com/java)
- [Spring Boot](https://spring.io/projects/spring-boot)
- [Kong](https://konghq.com)
- [Keycloak](https://www.keycloak.org)
- [OAuth2](https://oauth.net/2)
- [JWT](https://jwt.io)
- [Kafka](https://kafka.apache.org)
- [MongoDB](https://www.mongodb.com)
- [Debezium](https://debezium.io)
- [Redis](https://redis.io/)
- [Elastic](https://www.elastic.co)
- [Swagger](https://swagger.io)
- [Testcontainers](https://testcontainers.com)
- [Docker](https://www.docker.com)
- [Kubernetes](https://kubernetes.io)
## Docker
`docker compose up --detach --build --remove-orphans`
## Starter
Install Into Local Maven Repository: `mvn clean install`
## Tools
- **Kong:** `http://localhost:8002`
- **Keycloak:** `http://localhost:8005` **Username:** `admin` **Password:** `password`
- **Kafka:** `http://localhost:9000`
- **Mongo:** `http://localhost:27018`
- **Redis:** `http://localhost:6380`
- **Logs:** `http://localhost:5601/app/management/data/index_management/data_streams`
- **APM:** `http://localhost:5601/app/apm/services`
## Services
### AuthService
**Localhost:** `http://localhost:8010`
**Docker:** `http://localhost:9010`
**Kong:** `http://localhost:8000/authservice`
| Method | Endpoint | Description |
|:--------------------------------------------------:|-------------|-------------|
|  | /auth | Get |
|  | /auth | Auth |
|  | /users | Save |
|  | /users/{id} | Delete |
### ConfigurationService
**Localhost:** `http://localhost:8015`
**Docker:** `http://localhost:9015`
**Kong:** `http://localhost:8000/configurationservice`
| Method | Endpoint | Description |
|:---------------------------------------------------:|------------------------------------|---------------|
|  | /configurations | List |
|  | /configurations/{id} | Get |
|  | /configurations | Create |
|  | /configurations/{id} | Delete |
|  | /configurations/{id}/value/{value} | Update Value |
|  | /configurations/broadcast | Broadcast |
### CustomerService
**Localhost:** `http://localhost:8020`
**Docker:** `http://localhost:9020`
**Kong:** `http://localhost:8000/customerservice`
| Method | Endpoint | Description |
|:--------------------------------------------------:|-----------------|-------------|
|  | /customers | List |
|  | /customers/{id} | Get |
|  | /customers | Create |
|  | /customers/{id} | Update |
|  | /customers/{id} | Delete |
### ProductService
**Localhost:** `http://localhost:8025`
**Docker:** `http://localhost:9025`
**Kong:** `http://localhost:8000/productservice`
| Method | Endpoint | Description |
|:--------------------------------------------------:|----------------|-------------|
|  | /products | List |
|  | /products/{id} | Get |
|  | /products | Create |
|  | /products/{id} | Update |
|  | /products/{id} | Delete |
### OrderService
**Localhost:** `http://localhost:8030`
**Docker:** `http://localhost:9030`
**Kong:** `http://localhost:8000/orderservice`
| Method | Endpoint | Description |
|:-----------------------------------------------:|--------------|-------------|
|  | /orders | List |
|  | /orders/{id} | Get |
|  | /orders | Create |
### PaymentService
**Localhost:** `http://localhost:8035`
**Docker:** `http://localhost:9035`
**Kong:** `http://localhost:8000/paymentservice`
| Meth od | Endpoint | Description |
|-----------------------------------------------------|-------------------------------------------|-----------------|
|  | /payments | List |
|  | /payments/{id} | Get |
|  | /payments/order/{orderId} | Get By Order Id |
|  | /payments/order/{orderId}/status/{status} | Update Status |
## Examples
### Cache
```java
@Service
public class ProductService {
@Cacheable(value = "products")
public List get() {
return repository.findAll();
}
@Cacheable(value = "products", key = "#id")
public Optional get(final UUID id) {
return repository.findById(id);
}
@CachePut(value = "products", key = "#product.id")
public Product save(final Product product) {
return repository.save(product);
}
@CacheEvict(value = "products", key = "#id")
public void delete(final UUID id) {
repository.deleteById(id);
}
@CacheEvict(value = "products", allEntries = true)
public void delete() {
repository.deleteAll();
}
}
```
### Kafka
```bash
echo KEY:{"Key":"KEY"} | docker exec -i kafka /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:9094 --topic TOPIC --reader-property parse.key=true --reader-property key.separator=":"
```
```bash
docker exec -i kafka /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9094 --topic TOPIC --from-beginning --formatter-property print.key=true --formatter-property key.separator=:
```