# mohamed-taman/springy-store-microservices architecture

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

- Interactive diagram: https://gitdiagram.com/mohamed-taman/springy-store-microservices
- Repository: https://github.com/mohamed-taman/springy-store-microservices

## Overview

##### Identify the Project Type and Purpose

**Project Type:**
Springy Store μServices is a **Spring Boot-based Microservices** architecture designed to implement cloud-native, reactive programming, and event-driven design patterns. It adheres to **CloudNative** recommendations and the **Twelve-Factor App** methodology, focusing on building scalable and maintainable software-as-a-service applications.

**Purpose:**
The project aims to demonstrate best practices in developing and deploying microservices using modern technologies like Docker, Kubernetes (planned for future milestones), Elasticsearch, MySQL, MongoDB, and messaging systems like RabbitMQ and Kafka. It emphasizes test-driven development (TDD), integration, and performance testing.

##### Analyze the File Structure

- **Top-Level Directories:**
- `config`: Contains all system configuration files, including keystores and various service configurations (e.g., Eureka, Gateway).
- `store-base`: Houses parent POMs and common build configurations (`store-build-chassis`, `store-cloud-chassis`, `store-service-chassis`).
- `store-cloud-infra`: Infrastructure services such as `authorization-server`, `edge-server` (API Gateway), `eureka-server` (Service Discovery), and `config-server` (Centralized Configuration).
- `store-common`: Shared components like `store-api` (API Endpoints) and `store-utils` (Common Utilities).
- `store-services`: Individual microservices including `product-service`, `recommendation-service`, `review-service`, and `store-service`.
- `docker-compose` files: Define different deployment scenarios using RabbitMQ and Kafka.
- Scripts: `run-em-all.sh`, `setup.sh`, `stop-em-all.sh`, `test-em-all.sh` for managing the lifecycle of services.

- **Patterns and Architectural Choices:**
- **Microservices Architecture:** Clearly separated services for product, recommendation, review, and store functionalities.
- **Infrastructure Services:** Centralized services for configuration, discovery, authorization, and API Gateway.
- **Shared Libraries:** Common APIs and utilities to promote code reuse and consistency across microservices.
- **Containerization:** Use of Docker Compose for deploying services, indicating a move towards container orchestration (future Kubernetes integration).

##### Examine the README for Additional Insights

- **Technologies Used:**
- **Backend:** Spring Boot, Java SE 15
- **Databases:** MySQL, MongoDB
- **Messaging:** RabbitMQ, Kafka
- **Containerization:** Docker, Docker Compose (with plans for Kubernetes)
- **Monitoring & Logging:** Elasticsearch Stack, Zipkin
- **Build Tools:** Maven
- **Version Control:** Git

- **Design Principles:**
- **Cloud-Native:** Designed for scalability and resilience in cloud environments.
- **Reactive Programming:** Ensures non-blocking, asynchronous communication between services.
- **Event-Driven:** Utilizes messaging systems for inter-service communication.
- **TDD:** Emphasizes test-driven development with comprehensive testing suites.

- **Deployment Scenarios:**
- Different Docker Compose files cater to varied deployment needs, such as using RabbitMQ with or without partitions and integrating Kafka with Zookeeper.

**a. Identify Main Components:**
- **Infrastructure Services:**
- **Config Server:** Centralized configuration management.
- **Eureka Server:** Service discovery mechanism.
- **Authorization Server:** Handles authentication and authorization.
- **Edge Server (API Gateway):** Manages API routing and acts as a single entry point.

- **Microservices:**
- **Product Service:** Manages product-related operations.
- **Recommendation Service:** Provides product recommendations.
- **Review Service:** Handles customer reviews.
- **Store Service:** Core store functionalities.

- **Shared Components:**
- **Store API:** Defines API endpoints for all services.
- **Store Utils:** Common utilities and helper functions.

- **Databases:**
- **MySQL:** Likely used by services requiring relational data storage.
- **MongoDB:** Used for services that benefit from NoSQL storage.

- **Messaging Systems:**
- **RabbitMQ:** Facilitates event-driven communication.
- **Kafka:** Alternative messaging system for handling high-throughput messaging.

- **Monitoring & Logging:**
- **Elasticsearch Stack:** For logging and monitoring.
- **Zipkin:** Distributed tracing of service interactions.

**b. Determine Relationships and Interactions:**
- **Service Discovery:** Microservices register with Eureka Server; services discover each other through Eureka.
- **API Gateway:** All external requests pass through the Edge Server, which routes them to the appropriate microservice.
- **Configuration Management:** All services fetch their configurations from the Config Server.
- **Authentication:** Authorization Server manages security, ensuring that only authenticated requests reach the microservices.
- **Inter-Service Communication:** Services communicate asynchronously via RabbitMQ or Kafka, enabling event-driven interactions.
- **Data Flow:** Each microservice interacts with its respective database (MySQL or MongoDB) for data persistence.
- **Monitoring:** Zipkin traces requests across services, while Elasticsearch aggregates logs for analysis.

**c. Highlight Architectural Patterns and Design Principles:**
- **Microservices Architecture:** Decoupled services focusing on specific business capabilities.
- **API Gateway Pattern:** Centralized entry point managing routing, security, and composition.
- **Service Discovery Pattern:** Dynamic discovery of service instances.
- **Centralized Configuration:** Externalized configuration management for consistency and flexibility.
- **Event-Driven Architecture:** Asynchronous communication through messaging systems.
- **Reactive Programming:** Ensures responsive and resilient interactions.

**d. Include Relevant Technologies, Frameworks, or Libraries:**
- **Spring Boot:** Framework for building microservices.
- **Maven:** Build and dependency management.
- **Docker:** Containerization of services.
- **RabbitMQ/Kafka:** Messaging systems for inter-service communication.
- **Elasticsearch, Zipkin:** Tools for monitoring and logging.
- **MySQL, MongoDB:** Data storage solutions.

##### Elements

- **Clear Labels:** Each component (e.g., Product Service, Eureka Server) should be distinctly labeled.
- **Monitoring Tools:** Unique identifiers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Subgraphs
    subgraph "Infrastructure Services"
        CS["Config Server"]:::infra
        ES["Eureka Server"]:::infra
        AS["Authorization Server"]:::infra
        EG["Edge Server (API Gateway)"]:::infra
    end
    subgraph "Microservices"
        PS["Product Service"]:::micro
        RS["Recommendation Service"]:::micro
        ReS["Review Service"]:::micro
        StS["Store Service"]:::micro
    end
    subgraph "Shared Components"
        API["Store API"]:::shared
        Utils["Store Utils"]:::shared
    end
    subgraph "Databases"
        MySQL["MySQL"]:::db
        MongoDB["MongoDB"]:::db
    end
    subgraph "Messaging Systems"
        RabbitMQ["RabbitMQ"]:::messaging
        Kafka["Kafka"]:::messaging
    end
    subgraph "Monitoring & Logging"
        ES_Log["Elasticsearch Stack"]:::monitor
        Zip["Zipkin"]:::monitor
    end
    subgraph "Build & Deployment"
        SBChassis["Store Build Chassis"]:::build
        SCChassis["Store Cloud Chassis"]:::build
        SSChassis["Store Service Chassis"]:::build
        DockerYML["docker-compose.yml"]:::build
        KafkaYML["docker-compose-kafka.yml"]:::build
        PartitionsYML["docker-compose-partitions.yml"]:::build
        RunEm["run-em-all.sh"]:::build
        Setup["setup.sh"]:::build
        StopEm["stop-em-all.sh"]:::build
        TestEm["test-em-all.sh"]:::build
    end
    %% Connections
    CS -->|"Provides config"| PS
    CS -->|"Provides config"| RS
    CS -->|"Provides config"| ReS
    CS -->|"Provides config"| StS
    ES -->|"Service Discovery"| PS
    ES -->|"Service Discovery"| RS
    ES -->|"Service Discovery"| ReS
    ES -->|"Service Discovery"| StS
    AS -->|"Auth"| EG
    EG -->|"Routes to"| PS
    EG -->|"Routes to"| RS
    EG -->|"Routes to"| ReS
    EG -->|"Routes to"| StS
    PS -->|"Uses"| MySQL
    RS -->|"Uses"| MongoDB
    ReS -->|"Uses"| MongoDB
    StS -->|"Uses"| MySQL
    PS -->|"Communicates via"| RabbitMQ
    RS -->|"Communicates via"| Kafka
    ReS -->|"Communicates via"| RabbitMQ
    StS -->|"Communicates via"| Kafka
    RabbitMQ -->|"Events"| PS
    Kafka -->|"Events"| RS
    %% Monitoring
    PS -->|"Traces"| Zip
    RS -->|"Traces"| Zip
    ReS -->|"Traces"| Zip
    StS -->|"Traces"| Zip
    PS -->|"Logs to"| ES_Log
    RS -->|"Logs to"| ES_Log
    ReS -->|"Logs to"| ES_Log
    StS -->|"Logs to"| ES_Log
    %% API and Utils
    PS --> API
    RS --> API
    ReS --> API
    StS --> API
    PS --> Utils
    RS --> Utils
    ReS --> Utils
    StS --> Utils
    %% Build & Deployment
    SBChassis -->|"Builds"| PS
    SBChassis -->|"Builds"| RS
    SBChassis -->|"Builds"| ReS
    SBChassis -->|"Builds"| StS
    SCChassis -->|"Configures"| CS
    SCChassis -->|"Configures"| ES
    SCChassis -->|"Configures"| AS
    SCChassis -->|"Configures"| EG
    SSChassis -->|"Configures"| PS
    SSChassis -->|"Configures"| RS
    SSChassis -->|"Configures"| ReS
    SSChassis -->|"Configures"| StS
    DockerYML --> SBChassis
    KafkaYML --> SCChassis
    PartitionsYML --> SSChassis
    RunEm --> SBChassis
    Setup --> SCChassis
    StopEm --> SSChassis
    TestEm --> SBChassis
    %% Click Events
    click CS "https://github.com/mohamed-taman/springy-store-microservices/tree/master/store-cloud-infra/config-server"
    click ES "https://github.com/mohamed-taman/springy-store-microservices/tree/master/store-cloud-infra/eureka-server"
    click AS "https://github.com/mohamed-taman/springy-store-microservices/tree/master/store-cloud-infra/authorization-server"
    click EG "https://github.com/mohamed-taman/springy-store-microservices/tree/master/store-cloud-infra/edge-server"
    click PS "https://github.com/mohamed-taman/springy-store-microservices/tree/master/store-services/product-service"
    click RS "https://github.com/mohamed-taman/springy-store-microservices/tree/master/store-services/recommendation-service"
    click ReS "https://github.com/mohamed-taman/springy-store-microservices/tree/master/store-services/review-service"
    click StS "https://github.com/mohamed-taman/springy-store-microservices/tree/master/store-services/store-service"
    click API "https://github.com/mohamed-taman/springy-store-microservices/tree/master/store-common/store-api"
    click Utils "https://github.com/mohamed-taman/springy-store-microservices/tree/master/store-common/store-utils"
    click SBChassis "https://github.com/mohamed-taman/springy-store-microservices/tree/master/store-base/store-build-chassis"
    click SCChassis "https://github.com/mohamed-taman/springy-store-microservices/tree/master/store-base/store-cloud-chassis"
    click SSChassis "https://github.com/mohamed-taman/springy-store-microservices/tree/master/store-base/store-service-chassis"
    click DockerYML "https://github.com/mohamed-taman/springy-store-microservices/blob/master/docker-compose.yml"
    click KafkaYML "https://github.com/mohamed-taman/springy-store-microservices/blob/master/docker-compose-kafka.yml"
    click PartitionsYML "https://github.com/mohamed-taman/springy-store-microservices/blob/master/docker-compose-partitions.yml"
    click RunEm "https://github.com/mohamed-taman/springy-store-microservices/blob/master/run-em-all.sh"
    click Setup "https://github.com/mohamed-taman/springy-store-microservices/blob/master/setup.sh"
    click StopEm "https://github.com/mohamed-taman/springy-store-microservices/blob/master/stop-em-all.sh"
    click TestEm "https://github.com/mohamed-taman/springy-store-microservices/blob/master/test-em-all.sh"
    %% Styles
    classDef infra fill:#add8e6,stroke:#000,stroke-width:1px
    classDef micro fill:#90ee90,stroke:#000,stroke-width:1px
    classDef shared fill:#ffffe0,stroke:#000,stroke-width:1px
    classDef db fill:#ffcc99,stroke:#000,stroke-width:1px
    classDef messaging fill:#dda0dd,stroke:#000,stroke-width:1px
    classDef monitor fill:#ffb6c1,stroke:#000,stroke-width:1px
    classDef build fill:#d3d3d3,stroke:#000,stroke-width:1px
    class CS,ES,AS,EG infra
    class PS,RS,ReS,StS micro
    class API,Utils shared
    class MySQL,MongoDB db
    class RabbitMQ,Kafka messaging
    class ES_Log,Zip monitor
    class SBChassis,SCChassis,SSChassis,DockerYML,KafkaYML,PartitionsYML,RunEm,Setup,StopEm,TestEm build
```
