# adeshppp/shopit-a-microservices-based-online-shopping-platform architecture

> Architecture diagram of the GitHub repository adeshppp/shopit-a-microservices-based-online-shopping-platform, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adeshppp/shopit-a-microservices-based-online-shopping-platform
- Repository: https://github.com/adeshppp/shopit-a-microservices-based-online-shopping-platform

## Overview

##### Project Type and Purpose
- The project is an online shopping platform built using a microservices architecture.
- It includes several key functionalities such as user authentication/authorization (secured by Keycloak), product catalog management, shopping cart, order processing/tracking, and payment integration.
- The README mentions extensive use of synchronous/asynchronous communication patterns, circuit breakers (using Resilience4J), distributed tracing (via Spring Cloud Sleuth and Zipkin), and event-driven architecture with Apache Kafka.

##### File Structure
- The top-level directories each represent one microservice:
- api-gateway (single entry point using Spring Cloud Gateway)
- discovery-server (service registry using Netflix Eureka with basic authentication)
- inventory-service, order-service, product-service, and notification-service (each a Spring Boot project with their own controllers, services, models, repositories, and configurations).
- A docker-compose.yml file indicates container orchestration across the entire system.
- The presence of multiple Dockerfiles and Maven pom.xml files for each service reinforces the decoupled microservices paradigm.

##### Main Components to Capture
a. API Gateway:
- Acts as the single entry point for external consumers.
- Implements request filtering, load balancing, authentication (integrated with Keycloak), and SSL termination.
- Should be placed at the edge of the system.
b. Discovery Server:
- Uses Netflix Eureka to register service instances.
- Helps microservices to discover each other dynamically, and includes a local registry for failover if the discovery server itself fails.
c. Core Microservices:
- Inventory Service: Manages inventory database and product availability.
- Order Service: Processes orders and coordinates with other services.
- Product Service: Manages product catalog details.
- Notification Service: Sends notifications post order placement.
d. External Integrations and Supporting Components:
- Keycloak: Provides robust authentication and authorization.
- Databases: A mix of MySQL AWS RDS and NoSQL MongoDB.
- Kafka: Facilitates event-driven communication (asynchronously between Order and Notification services).
- Distributed Tracing: Implements Spring Cloud Sleuth and Zipkin to trace requests across services.
- Circuit Breaker: Implemented with Resilience4J to ensure resilient communication between Order Service and Inventory Service.
e. Docker & Deployment:
- Dockerfiles for containerization.
- A global docker-compose file to orchestrate service containers.

##### Relationships and Interactions
- The API Gateway then dispatches traffic to appropriate microservices based on REST API routes.
- The Discovery Server mediates lookup for service instances (key for handling multiple instances and dynamic IP addresses).
- Inter-service communications that also incorporate distributed tracing (show propagation of trace IDs/spans across API Gateway, Order, and Inventory Services) and circuit breaker flows.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Define styles
    classDef microservice fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef external fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef infra fill:#F0E68C,stroke:#000,stroke-width:2px;
    classDef deployment fill:#FFB6C1,stroke:#000,stroke-width:2px;

    %% Top Level: Client
    Client["Client"]:::external

    %% Entry Point Subgraph: API Gateway & Authentication
    subgraph "Entry Point"
        APIGateway["API Gateway"]:::infra
        Keycloak["Keycloak (Auth)"]:::external
    end

    %% Service Discovery Subgraph
    subgraph "Service Discovery"
        Discovery["Discovery Server"]:::infra
    end

    %% Microservices Subgraph (listed vertically)
    subgraph "Microservices"
        Product["Product Service"]:::microservice
        Order["Order Service"]:::microservice
        Inventory["Inventory Service"]:::microservice
        Notification["Notification Service"]:::microservice
    end

    %% External Systems Subgraph
    subgraph "External Systems"
        MySQL["MySQL AWS RDS"]:::external
        MongoDB["MongoDB"]:::external
        Kafka["Apache Kafka"]:::external
        Zipkin["Zipkin (Tracing)"]:::external
    end

    %% Deployment Subgraph
    subgraph "Deployment"
        Compose["docker-compose.yml"]:::deployment
    end

    %% Arrows and Relationships

    %% Client sends requests to API Gateway
    Client -->|"http-request"| APIGateway

    %% API Gateway authenticates using Keycloak
    APIGateway -->|"auth"| Keycloak

    %% API Gateway queries Service Discovery for dynamic routing
    APIGateway -->|"lookup"| Discovery

    %% API Gateway dispatches REST calls to Microservices
    APIGateway -->|"REST"| Product
    APIGateway -->|"REST"| Order
    APIGateway -->|"REST"| Inventory
    APIGateway -->|"REST"| Notification

    %% Microservices register themselves with Discovery Server
    Product -->|"register"| Discovery
    Order -->|"register"| Discovery
    Inventory -->|"register"| Discovery
    Notification -->|"register"| Discovery

    %% Order Service interactions
    %% Synchronous communication with Inventory Service with circuit breaker (Resilience4J)
    Order -->|"sync-call-CB"| Inventory

    %% Asynchronous communication via Kafka
    Order -.->|"publish-event"| Kafka
    Kafka -.->|"consume-event"| Notification

    %% Database interactions for persistence
    Inventory -->|"DB-access"| MySQL
    Product -->|"DB-access"| MongoDB

    %% Distributed tracing flows to Zipkin from core components
    APIGateway -->|"trace"| Zipkin
    Order -->|"trace"| Zipkin
    Inventory -->|"trace"| Zipkin

    %% Deployment: Containerized services orchestrated by docker-compose
    APIGateway -->|"container"| Compose
    Discovery -->|"container"| Compose
    Inventory -->|"container"| Compose
    Order -->|"container"| Compose
    Product -->|"container"| Compose
    Notification -->|"container"| Compose

    %% Click events for component mapping
    click APIGateway "https://github.com/adeshppp/shopit-a-microservices-based-online-shopping-platform/tree/main/api-gateway/"
    click Discovery "https://github.com/adeshppp/shopit-a-microservices-based-online-shopping-platform/tree/main/discovery-server/"
    click Inventory "https://github.com/adeshppp/shopit-a-microservices-based-online-shopping-platform/tree/main/inventory-service/"
    click Order "https://github.com/adeshppp/shopit-a-microservices-based-online-shopping-platform/tree/main/order-service/"
    click Product "https://github.com/adeshppp/shopit-a-microservices-based-online-shopping-platform/tree/main/product-service/"
    click Notification "https://github.com/adeshppp/shopit-a-microservices-based-online-shopping-platform/tree/main/notification-service/"
    click Compose "https://github.com/adeshppp/shopit-a-microservices-based-online-shopping-platform/blob/main/docker-compose.yml"
```
