How mathesh04/ecommerce-microservices-platform works
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: ApiGatewayApplication.java API gateway · OrderService.java Order service · DiscoveryServerApplication.java Eureka discovery · InventoryService.java Inventory service
Components 18
Client & ingress
- React storefront · UI composition and client entry point.
frontend/src/App.jsx - Auth & cart state
frontend/src/context/AuthContext.jsx - API gateway · Ingress and dynamic service routing.
api-gateway/src/main/java/com/example/ecommerce/apigateway/ApiGatewayApplication.java - JWT gateway filter · Validates tokens and forwards identity headers.
api-gateway/src/main/java/com/example/ecommerce/apigateway/filter/JwtAuthenticationFilter.java
Business services
- Auth service · Owns users, credentials, roles, and JWT issuance.
auth-service/src/main/java/com/example/ecommerce/auth/service/AuthService.java - Product service · Owns the product catalog API and domain logic.
product-service/src/main/java/com/example/ecommerce/product/service/ProductService.java - Order service · Creates orders and completes their inventory-driven lifecycle.
order-service/src/main/java/com/example/ecommerce/order/service/OrderService.java - Order placed event
order-service/src/main/java/com/example/ecommerce/order/event/OrderPlacedEvent.java - Inventory service · Reserves stock and emits inventory outcomes.
inventory-service/src/main/java/com/example/ecommerce/inventory/service/InventoryService.java - Inventory outcomes · Reserved, failed-reservation, and low-stock outcomes.
inventory-service/src/main/java/com/example/ecommerce/inventory/event/InventoryReservedEvent.java - Notification service · Delivers notifications from order and inventory events.
notification-service/src/main/java/com/example/ecommerce/notification/consumer/NotificationConsumer.java
Runtime & data
- Eureka discovery
discovery-server/src/main/java/com/example/ecommerce/discoveryserver/DiscoveryServerApplication.java - Kafka · Durable boundary for saga progression and alerts.
- Auth MySQL
docker/mysql/init.sql - Order MySQL
docker/mysql/init.sql - Inventory MySQL
docker/mysql/init.sql - Product MongoDB
- Local deployment · Orchestrates local services and infrastructure.
docker-compose.yml
Connections 24
- 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