# subramanyabengaluru/e-commerce-microservices architecture

> Architecture diagram of the GitHub repository subramanyabengaluru/e-commerce-microservices, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/subramanyabengaluru/e-commerce-microservices
- Repository: https://github.com/subramanyabengaluru/e-commerce-microservices

## Overview

#### Purpose and topology
A Maven multi-module Java 21/Spring Boot 3.5 e-commerce backend. The active architecture is independently deployable Spring Cloud services; `monolith/` is a retained reference implementation. Primary client entry point is the gateway (`:8080`); service bootstrap entry points are each `*Application.java`, e.g. `api-gateway/src/main/java/com/ecommerce/gateway/ApiGatewayApplication.java` and `order-service/src/main/java/com/ecommerce/orderservice/OrderServiceApplication.java`.

#### Edge security and routing
The reactive API gateway validates bearer JWTs, applies security policy, injects trusted user identity headers, and routes to discovered services. Downstream services therefore rely on propagated identity rather than independently authenticating requests.
- `api-gateway/src/main/java/com/ecommerce/gateway/config/RouteConfig.java`
- `api-gateway/src/main/java/com/ecommerce/gateway/security/GatewaySecurityConfig.java`
- `api-gateway/src/main/java/com/ecommerce/gateway/security/JwtAuthenticationFilter.java`

#### Platform control plane and shared contracts
Config Server serves common and per-service external configuration from the repository-local config set; Eureka supplies registration and discovery. `platform-common` defines cross-service event, exception, paging, roles, and gateway-header contracts, preventing direct sharing of domain models.
- `config-server/src/main/java/com/ecommerce/configserver/ConfigServerApplication.java`
- `discovery-server/src/main/java/com/ecommerce/discovery/DiscoveryServerApplication.java`
- `config-repo/application.yml`
- `platform-common/src/main/java/com/ecommerce/common/event/OrderEvent.java`
- `platform-common/src/main/java/com/ecommerce/common/web/GatewayHeaders.java`

#### Identity, catalog, and stock ownership
User Service owns registration/login and JWT issuance. Product Service owns catalog writes and cached catalog reads, enriching product information through Inventory Service. Inventory Service exclusively owns stock mutation and exposes internal-facing operations for initialization and checkout adjustments. Service-to-service calls use OpenFeign/load balancing with Resilience4j boundaries; product reads may degrade when inventory is unavailable.
- `user-service/src/main/java/com/ecommerce/userservice/user/AuthService.java`
- `product-service/src/main/java/com/ecommerce/productservice/product/ProductService.java`
- `product-service/src/main/java/com/ecommerce/productservice/product/ProductCacheService.java`
- `inventory-service/src/main/java/com/ecommerce/inventoryservice/inventory/InventoryService.java`

#### Cart and transactional order workflow
Cart Service owns per-user carts and validates product references through Product Service. Order Service orchestrates checkout: retrieve cart lines, obtain product data, decrement inventory, persist order/item snapshots, clear the cart, and publish an order event. Cancellation reverses stock. These synchronous dependencies are correctness-critical and should fail rather than silently degrade.
- `cart-service/src/main/java/com/ecommerce/cartservice/cart/CartService.java`
- `order-service/src/main/java/com/ecommerce/orderservice/order/OrderService.java`
- `order-service/src/main/java/com/ecommerce/orderservice/client/CartClient.java`
- `order-service/src/main/java/com/ecommerce/orderservice/client/InventoryClient.java`

#### Event projections and side effects
Product Service publishes catalog-change events; Search Service consumes them to maintain an Elasticsearch `ProductDocument` read model, with a catalog backfill path for reconstruction. Order Service publishes order events consumed by Notification Service. Kafka is the asynchronous boundary: search and notifications are eventually consistent and decoupled from write requests.
- `product-service/src/main/java/com/ecommerce/productservice/event/ProductEventPublisher.java`
- `search-service/src/main/java/com/ecommerce/searchservice/event/ProductEventListener.java`
- `search-service/src/main/java/com/ecommerce/searchservice/search/ProductDocument.java`
- `order-service/src/main/java/com/ecommerce/orderservice/event/OrderEventPublisher.java`
- `notification-service/src/main/java/com/ecommerce/notificationservice/event/OrderEventListener.java`

#### Runtime infrastructure and observability
Business services persist independently in PostgreSQL; Redis supports catalog/cart caching, Kafka carries domain events, and Elasticsearch serves search. Docker Compose provisions those dependencies plus Prometheus, Grafana, and Zipkin. Services export metrics and traces, including Feign/gateway request chains and resilience signals.
- `docker-compose.infra.yml`
- `docker/postgres/init-databases.sql`
- `docker/prometheus/prometheus.yml`
- `docker/grafana/provisioning/dashboards/ecommerce-overview.json`

Main entry points: [`product-service/src/main/java/com/ecommerce/productservice/product/ProductService.java`](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/product-service/src/main/java/com/ecommerce/productservice/product/ProductService.java) (Product Service), [`order-service/src/main/java/com/ecommerce/orderservice/order/OrderService.java`](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/order-service/src/main/java/com/ecommerce/orderservice/order/OrderService.java) (Order Service), [`api-gateway/src/main/java/com/ecommerce/gateway/config/RouteConfig.java`](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/api-gateway/src/main/java/com/ecommerce/gateway/config/RouteConfig.java) (API Gateway), [`config-server/src/main/java/com/ecommerce/configserver/ConfigServerApplication.java`](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/config-server/src/main/java/com/ecommerce/configserver/ConfigServerApplication.java) (Config Server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Platform control plane"]
  node_config["Config Server<br/>Spring Cloud service"]
  node_config_repo["Config set<br/>configuration source<br/>[application.yml]"]
  node_discovery{{"Eureka<br/>service discovery"}}
  node_contracts["Platform contracts<br/>shared library"]
end

subgraph group_edge["Edge and business services"]
  node_gateway["API Gateway<br/>reactive edge service<br/>[RouteConfig.java]"]
  node_user["User Service<br/>identity service<br/>[AuthService.java]"]
  node_product["Product Service<br/>catalog service"]
  node_product_cache["Catalog cache<br/>cache layer"]
  node_inventory["Inventory Service<br/>stock service"]
  node_cart["Cart Service<br/>[CartService.java]"]
  node_order["Order Service<br/>checkout orchestrator<br/>[OrderService.java]"]
end

subgraph group_async["Event projections"]
  node_search["Search Service<br/>search projection"]
  node_notification["Notification Service<br/>event consumer"]
end

subgraph group_infra["Runtime infrastructure"]
  node_postgres[("PostgreSQL<br/>service databases<br/>[init-databases.sql]")]
  node_redis[("Redis<br/>cache store")]
  node_kafka["Kafka<br/>event backbone"]
  node_elasticsearch[("Elasticsearch<br/>search store")]
  node_observability["Prometheus, Grafana &amp; Zipkin<br/>telemetry stack<br/>[prometheus.yml]"]
end

node_config_repo -->|"served as external config"| node_config
node_config -.->|"configuration"| node_gateway
node_config -.->|"configuration"| node_user
node_config -.->|"configuration"| node_product
node_discovery -.->|"route discovery"| node_gateway
node_discovery -.->|"registration"| node_user
node_discovery -.->|"registration"| node_product
node_contracts -.->|"trusted identity headers"| node_gateway
node_contracts -.->|"order event contract"| node_order
node_gateway -->|"authenticated requests"| node_user
node_gateway -->|"authenticated requests"| node_product
node_gateway -->|"authenticated requests"| node_cart
node_gateway -->|"authenticated requests"| node_order
node_product -->|"cached reads"| node_product_cache
node_product -->|"stock enrichment"| node_inventory
node_cart -->|"validate product references"| node_product
node_order -->|"retrieve and clear cart"| node_cart
node_order -->|"obtain product data"| node_product
node_order -->|"decrement or restore stock"| node_inventory
node_product -->|"catalog-change events"| node_kafka
node_kafka -->|"catalog events"| node_search
node_order -->|"order events"| node_kafka
node_kafka -->|"order events"| node_notification
node_search -->|"product documents"| node_elasticsearch
node_user -->|"identity data"| node_postgres
node_product -->|"catalog data"| node_postgres
node_inventory -->|"stock data"| node_postgres
node_cart -->|"cart cache"| node_redis
node_product_cache -->|"catalog cache"| node_redis
node_order -->|"orders and item snapshots"| node_postgres
node_gateway -.->|"metrics and traces"| node_observability
node_order -.->|"metrics and traces"| node_observability

click node_config "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/config-server/src/main/java/com/ecommerce/configserver/ConfigServerApplication.java"
click node_config_repo "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/config-repo/application.yml"
click node_discovery "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/discovery-server/src/main/java/com/ecommerce/discovery/DiscoveryServerApplication.java"
click node_contracts "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/platform-common/src/main/java/com/ecommerce/common/web/GatewayHeaders.java"
click node_gateway "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/api-gateway/src/main/java/com/ecommerce/gateway/config/RouteConfig.java"
click node_user "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/user-service/src/main/java/com/ecommerce/userservice/user/AuthService.java"
click node_product "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/product-service/src/main/java/com/ecommerce/productservice/product/ProductService.java"
click node_product_cache "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/product-service/src/main/java/com/ecommerce/productservice/product/ProductCacheService.java"
click node_inventory "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/inventory-service/src/main/java/com/ecommerce/inventoryservice/inventory/InventoryService.java"
click node_cart "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/cart-service/src/main/java/com/ecommerce/cartservice/cart/CartService.java"
click node_order "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/order-service/src/main/java/com/ecommerce/orderservice/order/OrderService.java"
click node_search "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/search-service/src/main/java/com/ecommerce/searchservice/event/ProductEventListener.java"
click node_notification "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/notification-service/src/main/java/com/ecommerce/notificationservice/event/OrderEventListener.java"
click node_postgres "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/docker/postgres/init-databases.sql"
click node_redis "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/docker-compose.infra.yml"
click node_kafka "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/docker-compose.infra.yml"
click node_elasticsearch "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/docker-compose.infra.yml"
click node_observability "https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/docker/prometheus/prometheus.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_config,node_config_repo,node_discovery,node_contracts toneBlue
class node_gateway,node_user,node_product,node_product_cache,node_inventory,node_cart,node_order toneAmber
class node_search,node_notification toneMint
class node_postgres,node_redis,node_kafka,node_elasticsearch,node_observability toneRose
```

## Components

### Platform control plane

- [Config Server](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/config-server/src/main/java/com/ecommerce/configserver/ConfigServerApplication.java): Spring Cloud service · Serves shared and per-service external configuration. · `config-server/src/main/java/com/ecommerce/configserver/ConfigServerApplication.java`
- [Config set](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/config-repo/application.yml): configuration source · `config-repo/application.yml`
- [Eureka](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/discovery-server/src/main/java/com/ecommerce/discovery/DiscoveryServerApplication.java): service discovery · `discovery-server/src/main/java/com/ecommerce/discovery/DiscoveryServerApplication.java`
- [Platform contracts](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/platform-common/src/main/java/com/ecommerce/common/web/GatewayHeaders.java): shared library · Events, errors, paging, roles, and trusted gateway headers. · `platform-common/src/main/java/com/ecommerce/common/web/GatewayHeaders.java`

### Edge and business services

- [API Gateway](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/api-gateway/src/main/java/com/ecommerce/gateway/config/RouteConfig.java): reactive edge service · Validates JWTs, injects identity headers, and routes requests. · `api-gateway/src/main/java/com/ecommerce/gateway/config/RouteConfig.java`
- [User Service](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/user-service/src/main/java/com/ecommerce/userservice/user/AuthService.java): identity service · Owns registration, login, and JWT issuance. · `user-service/src/main/java/com/ecommerce/userservice/user/AuthService.java`
- [Product Service](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/product-service/src/main/java/com/ecommerce/productservice/product/ProductService.java): catalog service · Owns catalog writes and enriches product reads with stock data. · `product-service/src/main/java/com/ecommerce/productservice/product/ProductService.java`
- [Catalog cache](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/product-service/src/main/java/com/ecommerce/productservice/product/ProductCacheService.java): cache layer · Cached catalog reads may degrade if inventory is unavailable. · `product-service/src/main/java/com/ecommerce/productservice/product/ProductCacheService.java`
- [Inventory Service](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/inventory-service/src/main/java/com/ecommerce/inventoryservice/inventory/InventoryService.java): stock service · Exclusively owns stock mutations and checkout adjustments. · `inventory-service/src/main/java/com/ecommerce/inventoryservice/inventory/InventoryService.java`
- [Cart Service](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/cart-service/src/main/java/com/ecommerce/cartservice/cart/CartService.java): cart service · Owns per-user carts and validates product references. · `cart-service/src/main/java/com/ecommerce/cartservice/cart/CartService.java`
- [Order Service](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/order-service/src/main/java/com/ecommerce/orderservice/order/OrderService.java): checkout orchestrator · Persists order snapshots and coordinates correctness-critical checkout calls. · `order-service/src/main/java/com/ecommerce/orderservice/order/OrderService.java`

### Event projections

- [Search Service](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/search-service/src/main/java/com/ecommerce/searchservice/event/ProductEventListener.java): search projection · Maintains the Elasticsearch product read model and supports backfill. · `search-service/src/main/java/com/ecommerce/searchservice/event/ProductEventListener.java`
- [Notification Service](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/notification-service/src/main/java/com/ecommerce/notificationservice/event/OrderEventListener.java): event consumer · Handles order-event side effects. · `notification-service/src/main/java/com/ecommerce/notificationservice/event/OrderEventListener.java`

### Runtime infrastructure

- [PostgreSQL](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/docker/postgres/init-databases.sql): service databases · Each business service persists independently. · `docker/postgres/init-databases.sql`
- [Redis](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/docker-compose.infra.yml): cache store · Supports catalog and cart caching. · `docker-compose.infra.yml`
- [Kafka](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/docker-compose.infra.yml): event backbone · Asynchronous boundary for catalog and order events. · `docker-compose.infra.yml`
- [Elasticsearch](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/docker-compose.infra.yml): search store · `docker-compose.infra.yml`
- [Prometheus, Grafana & Zipkin](https://github.com/subramanyabengaluru/e-commerce-microservices/blob/main/docker/prometheus/prometheus.yml): telemetry stack · Collects metrics, traces, and resilience signals. · `docker/prometheus/prometheus.yml`

## Connections

- Config set → Config Server: served as external config
- Config Server → API Gateway: configuration
- Config Server → User Service: configuration
- Config Server → Product Service: configuration
- Eureka → API Gateway: route discovery
- Eureka → User Service: registration
- Eureka → Product Service: registration
- Platform contracts → API Gateway: trusted identity headers
- Platform contracts → Order Service: order event contract
- API Gateway → User Service: authenticated requests
- API Gateway → Product Service: authenticated requests
- API Gateway → Cart Service: authenticated requests
- API Gateway → Order Service: authenticated requests
- Product Service → Catalog cache: cached reads
- Product Service → Inventory Service: stock enrichment
- Cart Service → Product Service: validate product references
- Order Service → Cart Service: retrieve and clear cart
- Order Service → Product Service: obtain product data
- Order Service → Inventory Service: decrement or restore stock
- Product Service → Kafka: catalog-change events
- Kafka → Search Service: catalog events
- Order Service → Kafka: order events
- Kafka → Notification Service: order events
- Search Service → Elasticsearch: product documents
- User Service → PostgreSQL: identity data
- Product Service → PostgreSQL: catalog data
- Inventory Service → PostgreSQL: stock data
- Cart Service → Redis: cart cache
- Catalog cache → Redis: catalog cache
- Order Service → PostgreSQL: orders and item snapshots
- API Gateway → Prometheus, Grafana & Zipkin: metrics and traces
- Order Service → Prometheus, Grafana & Zipkin: metrics and traces
