# cero-t/spring-store-2022 architecture

> Architecture diagram of the GitHub repository cero-t/spring-store-2022, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cero-t/spring-store-2022
- Repository: https://github.com/cero-t/spring-store-2022

## Overview

This project is a Spring Boot–based microservices application, built as an example of a distributed, full-stack system using multiple bounded contexts. The README and file structure clearly indicate that it is organized into several services (BFF, Cart, Delivery, Item, Messaging, Order, Payment, and Stock) that interact with each other, following a microservices architecture. It also integrates monitoring (using Prometheus, Loki, Tempo and Grafana) as well as middleware (RabbitMQ for messaging) and deployment configurations for both Docker and Kubernetes.

##### Main Components
- BFF (Backend For Frontend): Acts as a gateway. It provides the Swagger UI for API interactions and communicates with other microservices.
- Microservices Domains:
- Cart Service: Includes its domain, client, and service implementations.
- Item Service: Contains client, domain, and service code for managing catalog items.
- Order Service: Handles processing orders and order-related operations.
- Payment Service: Processes payments via a client and service setup.
- Stock Service: Checks and maintains inventory levels.
- Delivery Service: Manages delivery operations.
- Messaging Service: Provides an abstraction layer for message handling and integration with RabbitMQ.
- Infrastructure and External Integrations:
- RabbitMQ for message queuing.
- Monitoring tools: Prometheus, Loki, Tempo for collecting metrics, logs, and traces, with Grafana as the visualization layer.
- Deployment components for Docker (docker-compose stack) and Kubernetes (YAML manifests and Helm charts).

##### Relationships and Interactions
- BFF → Item Service (for catalog viewing)
- BFF → Cart Service (for managing carts)
- BFF → Order Service (to place orders)
- Within services, illustrate additional interactions:
- Cart Service → Item Service (to fetch item details)
- Cart Service → Stock Service (to verify inventory)
- Order Service → Stock Service (for stock deductions)
- Order Service → Messaging Service (for asynchronous order processing and integration with payment and delivery)
- Messaging Service → Payment Service (to settle payments)
- Messaging Service → Delivery Service (to initiate delivery)
- Microservices to external middleware (show messaging with RabbitMQ as the underlying mechanism).

##### Architectural Patterns and Design Principles
- Emphasis on microservices and domain-driven design: Each service is encapsulated (with its own client, domain, and service layers).
- Clear separation of concerns: The BFF is separated from the core business logic that lives in individual services.
- Use of asynchronous messaging: The Messaging service and RabbitMQ ensure reliable event-driven communication.
- Observable design: Integration with Prometheus, Loki, Tempo, and Grafana emphasizes monitoring from the start.
- Deployment readiness: Support for containerization (via Docker) and orchestrated deployment (via Kubernetes) is evidenced by the provided configurations.

##### Relevant Technologies and Tools
- Spring Boot 3.0 and Spring Cloud Stream for developing microservices.
- Maven for build and dependency management.
- Docker and Kubernetes (with Helm charts) as deployment platforms.
- RabbitMQ for messaging infrastructure.
- Monitoring components: Prometheus, Loki, Tempo, Grafana.

##### Essential Elements
- Annotations to briefly explain roles where necessary (e.g., “Messaging Service: Provides asynchronous communication via RabbitMQ”).

## Diagram (Mermaid)

```mermaid
graph TD
    %% API Gateway
    subgraph "API Gateway"
        BFF["BFF (Backend For Frontend)"]:::gateway
    end

    %% Microservices Cluster
    subgraph "Microservices"
        Cart["Cart Service"]:::service
        Item["Item Service"]:::service
        Order["Order Service"]:::service
        Payment["Payment Service"]:::service
        Stock["Stock Service"]:::service
        Delivery["Delivery Service"]:::service
        Messaging["Messaging Service"]:::service
    end

    %% Messaging Infrastructure
    subgraph "Messaging Infrastructure"
        RabbitMQ["RabbitMQ"]:::infra
    end

    %% Monitoring & Observability Cluster
    subgraph "Monitoring & Observability"
        Prometheus["Prometheus"]:::monitoring
        Loki["Loki"]:::monitoring
        Tempo["Tempo"]:::monitoring
        Grafana["Grafana"]:::monitoring
    end

    %% Deployment Platforms Cluster
    subgraph "Deployment Platforms"
        Docker["Docker Deployment"]:::deployment
        Kubernetes["Kubernetes Deployment"]:::deployment
    end

    %% Inter-component Communication
    BFF -->|"calls"| Item
    BFF -->|"calls"| Cart
    BFF -->|"calls"| Order

    Cart -->|"fetches"| Item
    Cart -->|"verifies"| Stock

    Order -->|"deducts"| Stock
    Order -->|"initiates"| Messaging

    Messaging -->|"settles"| Payment
    Messaging -->|"initiates"| Delivery
    Messaging -->|"queues-on"| RabbitMQ

    %% Deployment to Monitoring Integration
    Docker -->|"observability"| Prometheus
    Docker -->|"observability"| Loki
    Docker -->|"observability"| Tempo
    Docker -->|"observability"| Grafana

    Kubernetes -->|"observability"| Prometheus
    Kubernetes -->|"observability"| Loki
    Kubernetes -->|"observability"| Tempo
    Kubernetes -->|"observability"| Grafana

    %% Styles
    classDef gateway fill:#f9c,stroke:#333,stroke-width:2px;
    classDef service fill:#ccf,stroke:#333,stroke-width:2px;
    classDef infra fill:#fc9,stroke:#333,stroke-width:2px;
    classDef monitoring fill:#9fc,stroke:#333,stroke-width:2px;
    classDef deployment fill:#cff,stroke:#333,stroke-width:2px;

    %% Click Events
    click BFF "https://github.com/cero-t/spring-store-2022/tree/main/services/bff"
    click Cart "https://github.com/cero-t/spring-store-2022/tree/main/services/cart"
    click Item "https://github.com/cero-t/spring-store-2022/tree/main/services/item"
    click Order "https://github.com/cero-t/spring-store-2022/tree/main/services/order"
    click Payment "https://github.com/cero-t/spring-store-2022/tree/main/services/payment"
    click Stock "https://github.com/cero-t/spring-store-2022/tree/main/services/stock"
    click Delivery "https://github.com/cero-t/spring-store-2022/tree/main/services/delivery/delivery-service"
    click Messaging "https://github.com/cero-t/spring-store-2022/tree/main/services/messaging"
    click RabbitMQ "https://github.com/cero-t/spring-store-2022/blob/main/k8s/deploy/rabbitmq.yml"
    click Prometheus "https://github.com/cero-t/spring-store-2022/blob/main/docker/config/prometheus.yml"
    click Loki "https://github.com/cero-t/spring-store-2022/tree/main/docker/config/grafana"
    click Tempo "https://github.com/cero-t/spring-store-2022/blob/main/docker/config/tempo-local.yaml"
    click Grafana "https://github.com/cero-t/spring-store-2022/tree/main/docker/config/grafana"
    click Docker "https://github.com/cero-t/spring-store-2022/blob/main/docker/docker-compose.yml"
    click Kubernetes "https://github.com/cero-t/spring-store-2022/tree/main/k8s/deploy"
```
