# mathesh04/ecommerce-microservices-platform architecture

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

- Interactive diagram: https://gitdiagram.com/mathesh04/ecommerce-microservices-platform
- Repository: https://github.com/mathesh04/ecommerce-microservices-platform

## Overview

#### Purpose and topology
A full-stack e-commerce platform organized as independently deployable Spring Boot microservices plus a Vite/React frontend. The backend uses Eureka for discovery, Spring Cloud Gateway for ingress, Kafka for order/inventory choreography, MongoDB for products, and MySQL for auth, orders, and inventory. Root orchestration/build boundaries are `pom.xml`, `docker-compose.yml`, and `docker/mysql/init.sql`.

#### Client and ingress
The browser client starts at `frontend/src/main.jsx` and composes application UI in `frontend/src/App.jsx`. Cross-cutting client state is separated into authentication and shopping-cart contexts at `frontend/src/context/AuthContext.jsx` and `frontend/src/context/CartContext.jsx`.

External requests enter the gateway application at `api-gateway/src/main/java/com/example/ecommerce/apigateway/ApiGatewayApplication.java`. `api-gateway/src/main/java/com/example/ecommerce/apigateway/filter/JwtAuthenticationFilter.java` validates JWTs, extracts identity/role claims, and forwards user metadata headers to downstream services. Gateway route, discovery, and runtime settings are at `api-gateway/src/main/resources/application.yml`.

#### Discovery and deployment runtime
`discovery-server/src/main/java/com/example/ecommerce/discoveryserver/DiscoveryServerApplication.java` is the Eureka registry; services register dynamically and gateway routing can resolve services without fixed host URLs. Its service configuration is `discovery-server/src/main/resources/application.yml`.

Each backend service has an independent Maven module and Docker image, e.g. `order-service/pom.xml`, `order-service/Dockerfile`, and `product-service/Dockerfile`. `docker-compose.yml` defines the local multi-service infrastructure boundary.

#### Identity and service-owned data
Auth owns users, roles, credentials, and JWT issuance. HTTP entry and security boundary are `auth-service/src/main/java/com/example/ecommerce/auth/controller/AuthController.java` and `auth-service/src/main/java/com/example/ecommerce/auth/config/SecurityConfig.java`; token and registration/login workflows reside in `auth-service/src/main/java/com/example/ecommerce/auth/service/AuthService.java` and `auth-service/src/main/java/com/example/ecommerce/auth/service/JwtService.java`. User persistence is represented by `auth-service/src/main/java/com/example/ecommerce/auth/model/User.java`.

Product catalog is independently owned by product-service, with API/service/repository layers at `product-service/src/main/java/com/example/ecommerce/product/controller/ProductController.java`, `product-service/src/main/java/com/example/ecommerce/product/service/ProductService.java`, and `product-service/src/main/java/com/example/ecommerce/product/repository/ProductRepository.java`. Its `Product` model supports the MongoDB-oriented catalog boundary.

#### Order-to-inventory saga
Order creation enters through `order-service/src/main/java/com/example/ecommerce/order/controller/OrderController.java`, persists an order with an initial lifecycle status, and publishes the order-placed event from `order-service/src/main/java/com/example/ecommerce/order/service/OrderService.java`. Event contracts include `order-service/src/main/java/com/example/ecommerce/order/event/OrderPlacedEvent.java`; order state is modeled by `order-service/src/main/java/com/example/ecommerce/order/model/Order.java` and `order-service/src/main/java/com/example/ecommerce/order/model/OrderStatus.java`.

Inventory consumes the placement event in `inventory-service/src/main/java/com/example/ecommerce/inventory/consumer/OrderPlacedEventConsumer.java`. `inventory-service/src/main/java/com/example/ecommerce/inventory/service/InventoryService.java` performs stock reservation against its own inventory store and emits reserved, low-stock, or reservation-failed Kafka outcomes. Relevant contracts are `inventory-service/src/main/java/com/example/ecommerce/inventory/event/InventoryReservedEvent.java` and `inventory-service/src/main/java/com/example/ecommerce/inventory/event/InventoryReservationFailedEvent.java`.

#### Asynchronous completion and notification
Order service consumes inventory outcomes via `order-service/src/main/java/com/example/ecommerce/order/consumer/InventoryReservedEventConsumer.java` and `order-service/src/main/java/com/example/ecommerce/order/consumer/InventoryReservationFailedEventConsumer.java`, transitioning orders to `CONFIRMED` or `FAILED`. This is a choreographed saga: no synchronous distributed transaction spans order and inventory databases.

Notification-service is an event-only downstream consumer: `notification-service/src/main/java/com/example/ecommerce/notification/consumer/NotificationConsumer.java` handles order/inventory event messages, while `notification-service/src/main/java/com/example/ecommerce/notification/service/NotificationService.java` encapsulates notification delivery. Kafka is therefore the durability and service-boundary mechanism for saga progression and low-inventory alerts.

Main entry points: [`api-gateway/src/main/java/com/example/ecommerce/apigateway/ApiGatewayApplication.java`](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/api-gateway/src/main/java/com/example/ecommerce/apigateway/ApiGatewayApplication.java) (API gateway), [`order-service/src/main/java/com/example/ecommerce/order/service/OrderService.java`](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/order-service/src/main/java/com/example/ecommerce/order/service/OrderService.java) (Order service), [`discovery-server/src/main/java/com/example/ecommerce/discoveryserver/DiscoveryServerApplication.java`](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/discovery-server/src/main/java/com/example/ecommerce/discoveryserver/DiscoveryServerApplication.java) (Eureka discovery), [`inventory-service/src/main/java/com/example/ecommerce/inventory/service/InventoryService.java`](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/inventory-service/src/main/java/com/example/ecommerce/inventory/service/InventoryService.java) (Inventory service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client &amp; ingress"]
  node_frontend["React storefront<br/>Vite/React app<br/>[App.jsx]"]
  node_client_state["Auth &amp; cart state<br/>React contexts<br/>[AuthContext.jsx]"]
  node_gateway{{"API gateway<br/>Spring Cloud Gateway"}}
  node_jwt_filter["JWT gateway filter"]
end

subgraph group_services["Business services"]
  node_auth["Auth service<br/>Spring Boot service<br/>[AuthService.java]"]
  node_products["Product service<br/>Spring Boot service"]
  node_orders["Order service<br/>Spring Boot service<br/>[OrderService.java]"]
  node_order_events["Order placed event<br/>Kafka contract"]
  node_inventory["Inventory service<br/>Spring Boot service"]
  node_inventory_events["Inventory outcomes<br/>Kafka contracts"]
  node_notifications["Notification service<br/>event consumer"]
end

subgraph group_runtime["Runtime &amp; data"]
  node_discovery{{"Eureka discovery<br/>service registry"}}
  node_kafka["Kafka<br/>event broker"]
  node_auth_db[("Auth MySQL<br/>user store<br/>[init.sql]")]
  node_order_db[("Order MySQL<br/>order store<br/>[init.sql]")]
  node_inventory_db[("Inventory MySQL<br/>inventory store<br/>[init.sql]")]
  node_product_db[("Product MongoDB<br/>catalog store")]
  node_compose["Local deployment<br/>Docker Compose<br/>[docker-compose.yml]"]
end

node_frontend -->|"uses"| node_client_state
node_frontend -->|"API requests"| node_gateway
node_gateway -->|"applies"| node_jwt_filter
node_jwt_filter -->|"authenticated routes"| node_auth
node_gateway -->|"routes"| node_products
node_gateway -->|"routes"| node_orders
node_auth -->|"persists users"| node_auth_db
node_products -->|"persists catalog"| node_product_db
node_orders -->|"persists orders"| node_order_db
node_orders -->|"publishes"| node_order_events
node_order_events -->|"produced to"| node_kafka
node_kafka -->|"order placement"| node_inventory
node_inventory -->|"reserves stock"| node_inventory_db
node_inventory -->|"publishes"| node_inventory_events
node_inventory_events -->|"produced to"| node_kafka
node_kafka -->|"inventory outcomes"| node_orders
node_kafka -->|"order and inventory events"| node_notifications
node_gateway -.->|"resolves services"| node_discovery
node_auth -.->|"registers"| node_discovery
node_products -.->|"registers"| node_discovery
node_orders -.->|"registers"| node_discovery
node_inventory -.->|"registers"| node_discovery
node_compose -.->|"runs"| node_gateway
node_compose -.->|"runs"| node_kafka

click node_frontend "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/frontend/src/App.jsx"
click node_client_state "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/frontend/src/context/AuthContext.jsx"
click node_gateway "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/api-gateway/src/main/java/com/example/ecommerce/apigateway/ApiGatewayApplication.java"
click node_jwt_filter "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/api-gateway/src/main/java/com/example/ecommerce/apigateway/filter/JwtAuthenticationFilter.java"
click node_auth "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/auth-service/src/main/java/com/example/ecommerce/auth/service/AuthService.java"
click node_products "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/product-service/src/main/java/com/example/ecommerce/product/service/ProductService.java"
click node_orders "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/order-service/src/main/java/com/example/ecommerce/order/service/OrderService.java"
click node_order_events "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/order-service/src/main/java/com/example/ecommerce/order/event/OrderPlacedEvent.java"
click node_inventory "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/inventory-service/src/main/java/com/example/ecommerce/inventory/service/InventoryService.java"
click node_inventory_events "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/inventory-service/src/main/java/com/example/ecommerce/inventory/event/InventoryReservedEvent.java"
click node_notifications "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/notification-service/src/main/java/com/example/ecommerce/notification/consumer/NotificationConsumer.java"
click node_discovery "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/discovery-server/src/main/java/com/example/ecommerce/discoveryserver/DiscoveryServerApplication.java"
click node_auth_db "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/docker/mysql/init.sql"
click node_order_db "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/docker/mysql/init.sql"
click node_inventory_db "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/docker/mysql/init.sql"
click node_compose "https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/docker-compose.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_frontend,node_client_state,node_gateway,node_jwt_filter toneBlue
class node_auth,node_products,node_orders,node_order_events,node_inventory,node_inventory_events,node_notifications toneAmber
class node_discovery,node_kafka,node_auth_db,node_order_db,node_inventory_db,node_product_db,node_compose toneMint
```

## Components

### Client & ingress

- [React storefront](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/frontend/src/App.jsx): Vite/React app · UI composition and client entry point. · `frontend/src/App.jsx`
- [Auth & cart state](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/frontend/src/context/AuthContext.jsx): React contexts · `frontend/src/context/AuthContext.jsx`
- [API gateway](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/api-gateway/src/main/java/com/example/ecommerce/apigateway/ApiGatewayApplication.java): Spring Cloud Gateway · Ingress and dynamic service routing. · `api-gateway/src/main/java/com/example/ecommerce/apigateway/ApiGatewayApplication.java`
- [JWT gateway filter](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/api-gateway/src/main/java/com/example/ecommerce/apigateway/filter/JwtAuthenticationFilter.java): gateway filter · Validates tokens and forwards identity headers. · `api-gateway/src/main/java/com/example/ecommerce/apigateway/filter/JwtAuthenticationFilter.java`

### Business services

- [Auth service](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/auth-service/src/main/java/com/example/ecommerce/auth/service/AuthService.java): Spring Boot service · Owns users, credentials, roles, and JWT issuance. · `auth-service/src/main/java/com/example/ecommerce/auth/service/AuthService.java`
- [Product service](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/product-service/src/main/java/com/example/ecommerce/product/service/ProductService.java): Spring Boot service · Owns the product catalog API and domain logic. · `product-service/src/main/java/com/example/ecommerce/product/service/ProductService.java`
- [Order service](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/order-service/src/main/java/com/example/ecommerce/order/service/OrderService.java): Spring Boot service · Creates orders and completes their inventory-driven lifecycle. · `order-service/src/main/java/com/example/ecommerce/order/service/OrderService.java`
- [Order placed event](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/order-service/src/main/java/com/example/ecommerce/order/event/OrderPlacedEvent.java): Kafka contract · `order-service/src/main/java/com/example/ecommerce/order/event/OrderPlacedEvent.java`
- [Inventory service](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/inventory-service/src/main/java/com/example/ecommerce/inventory/service/InventoryService.java): Spring Boot service · Reserves stock and emits inventory outcomes. · `inventory-service/src/main/java/com/example/ecommerce/inventory/service/InventoryService.java`
- [Inventory outcomes](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/inventory-service/src/main/java/com/example/ecommerce/inventory/event/InventoryReservedEvent.java): Kafka contracts · Reserved, failed-reservation, and low-stock outcomes. · `inventory-service/src/main/java/com/example/ecommerce/inventory/event/InventoryReservedEvent.java`
- [Notification service](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/notification-service/src/main/java/com/example/ecommerce/notification/consumer/NotificationConsumer.java): event consumer · Delivers notifications from order and inventory events. · `notification-service/src/main/java/com/example/ecommerce/notification/consumer/NotificationConsumer.java`

### Runtime & data

- [Eureka discovery](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/discovery-server/src/main/java/com/example/ecommerce/discoveryserver/DiscoveryServerApplication.java): service registry · `discovery-server/src/main/java/com/example/ecommerce/discoveryserver/DiscoveryServerApplication.java`
- **Kafka**: event broker · Durable boundary for saga progression and alerts.
- [Auth MySQL](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/docker/mysql/init.sql): user store · `docker/mysql/init.sql`
- [Order MySQL](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/docker/mysql/init.sql): order store · `docker/mysql/init.sql`
- [Inventory MySQL](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/docker/mysql/init.sql): inventory store · `docker/mysql/init.sql`
- **Product MongoDB**: catalog store
- [Local deployment](https://github.com/mathesh04/ecommerce-microservices-platform/blob/main/docker-compose.yml): Docker Compose · Orchestrates local services and infrastructure. · `docker-compose.yml`

## Connections

- React storefront → Auth & cart state: uses
- React storefront → API gateway: API requests
- API gateway → JWT gateway filter: applies
- JWT gateway filter → Auth service: authenticated routes
- API gateway → Product service: routes
- API gateway → Order service: routes
- Auth service → Auth MySQL: persists users
- Product service → Product MongoDB: persists catalog
- Order service → Order MySQL: persists orders
- Order service → Order placed event: publishes
- Order placed event → Kafka: produced to
- Kafka → Inventory service: order placement
- Inventory service → Inventory MySQL: reserves stock
- Inventory service → Inventory outcomes: publishes
- Inventory outcomes → Kafka: produced to
- Kafka → Order service: inventory outcomes · Updates orders to CONFIRMED or FAILED.
- Kafka → Notification service: order and inventory events
- API gateway → Eureka discovery: resolves services
- Auth service → Eureka discovery: registers
- Product service → Eureka discovery: registers
- Order service → Eureka discovery: registers
- Inventory service → Eureka discovery: registers
- Local deployment → API gateway: runs
- Local deployment → Kafka: runs
