How minhchinhdo/scalable-e-commerce works
Purpose and topology
This is a Maven multi-service Spring Boot system for library-style book, employee, and borrowing workflows, despite the README’s e-commerce framing. It uses CQRS/event-sourcing patterns in the core domain services and separates edge routing, configuration, discovery, identity, and notifications.
Service entry points
Each deployable service has its own Spring Boot launcher:
• Gateway: api-gateway/src/main/java/com/chinhbean/apigateway/ApiGatewayApplication.java
• Book domain: bookservice/src/main/java/com/chinhbean/bookservice/BookserviceApplication.java
• Borrowing domain: borrowingservice/src/main/java/com/tanthanh/borrowingservice/BorrowingserviceApplication.java
• Employee, user, notification, config, and discovery services have equivalent application classes, e.g. employeeservice/src/main/java/com/tanthanh/employeeservice/EmployeeserviceApplication.java and configserver/src/main/java/com/tanthanh2706/configserver/ConfigserverApplication.java.
Edge, identity, and platform control plane
The API gateway is the external request boundary and includes an authentication filter: api-gateway/src/main/java/com/chinhbean/apigateway/config/AuthFilter.java. User management is centralized in userservice, with controller/service/repository layers and custom authentication and authorization filters:
userservice/src/main/java/com/tanthanh/userservice/controller/UserController.java,
userservice/src/main/java/com/tanthanh/userservice/security/SecurityConfig.java,
userservice/src/main/java/com/tanthanh/userservice/filter/CustomeAuthorizationFilter.java.
Centralized configuration and service discovery are separate infrastructure services:
configserver/src/main/java/com/tanthanh2706/configserver/ConfigserverApplication.java and
discoveryserver/src/main/java/com/chinhbean/bookservice/DiscoveryServer.java.
Their runtime behavior is configured through each service’s application.properties/application.yml.
CQRS/event-sourced book and employee domains
Book and employee services share the same architectural shape: command controllers submit create/update/delete commands to aggregates; aggregates emit domain events; event handlers persist command-side entities; projections answer query-side requests.
• Book: bookservice/src/main/java/com/chinhbean/bookservice/command/api/aggregate/BookAggregate.java, bookservice/src/main/java/com/chinhbean/bookservice/command/api/events/BookEventsHandler.java, bookservice/src/main/java/com/chinhbean/bookservice/query/api/projection/BookProjection.java.
• Employee: employeeservice/src/main/java/com/tanthanh/employeeservice/command/api/aggregate/EmployeeAggregate.java, employeeservice/src/main/java/com/tanthanh/employeeservice/command/api/events/EmployeeEventsHandler.java, employeeservice/src/main/java/com/tanthanh/employeeservice/query/api/projection/EmployeeProjection.java.
Axon-specific configuration in both services is the event/command infrastructure boundary.
Borrowing orchestration
Borrowing is the cross-domain workflow owner. BorrowCommandController accepts borrowing commands, BorrowAggregate produces borrowing events, and BorrowingProjection serves read models:
borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/controller/BorrowCommandController.java,
borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/aggregate/BorrowAggregate.java,
borrowingservice/src/main/java/com/tanthanh/borrowingservice/query/api/projection/BorrowingProjection.java.
BorrowingSaga is the key distributed-control component. Its presence alongside send-message and book-return/status commands indicates asynchronous coordination, including book status updates/rollback and notification-related actions:
borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/saga/BorrowingSaga.java,
borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/command/UpdateBookReturnCommand.java.
Shared cross-service contracts
commonservice is a contract module/service for cross-domain queries, DTOs, and book-status commands/events. It defines book and employee detail queries plus status-update and rollback semantics:
commonservice/src/main/java/com/tanthanh/commonservice/query/GetDetailsBookQuery.java,
commonservice/src/main/java/com/tanthanh/commonservice/command/UpdateStatusBookCommand.java,
commonservice/src/main/java/com/tanthanh/commonservice/events/BookRollBackStatusEvent.java.
This is an important compatibility boundary: services should exchange these contract types/events rather than directly depending on each other’s persistence entities.
Notifications and persistence boundaries
Notification delivery is isolated as notificationservice, with application configuration and message/employee response models:
notificationservice/src/main/java/com/tanthanh/notificationservice/NotificationserviceApplication.java,
notificationservice/src/main/java/com/tanthanh/notificationservice/Message.java.
Book, employee, borrowing, and user services each own repository/entity types, such as BookRepository, EmployeeRepository, BorrowRepository, and UserRepository. No database technology or concrete external notification provider is identifiable from the supplied tree; those details reside in Maven dependencies and runtime properties.
Main entry points: ApiGatewayApplication.java API Gateway · BookAggregate.java Book Aggregate · BookserviceApplication.java Book Service · EmployeeserviceApplication.java Employee Service
Components 19
Platform Control
- Config Server
configserver/src/main/java/com/tanthanh2706/configserver/ConfigserverApplication.java - Discovery Server
discoveryserver/src/main/java/com/chinhbean/bookservice/DiscoveryServer.java
Book CQRS
- Book Service
bookservice/src/main/java/com/chinhbean/bookservice/BookserviceApplication.java - Book Aggregate
bookservice/src/main/java/com/chinhbean/bookservice/command/api/aggregate/BookAggregate.java - Book Event Handler · Persists command-side book entities.
bookservice/src/main/java/com/chinhbean/bookservice/command/api/events/BookEventsHandler.java - Book Projection
bookservice/src/main/java/com/chinhbean/bookservice/query/api/projection/BookProjection.java
Employee CQRS
- Employee Service
employeeservice/src/main/java/com/tanthanh/employeeservice/EmployeeserviceApplication.java - Employee Aggregate
employeeservice/src/main/java/com/tanthanh/employeeservice/command/api/aggregate/EmployeeAggregate.java - Employee Event Handler · Persists command-side employee entities.
employeeservice/src/main/java/com/tanthanh/employeeservice/command/api/events/EmployeeEventsHandler.java - Employee Projection
employeeservice/src/main/java/com/tanthanh/employeeservice/query/api/projection/EmployeeProjection.java
Borrowing Workflow
- Borrow Command Controller
borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/controller/BorrowCommandController.java - Borrow Aggregate
borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/aggregate/BorrowAggregate.java - Borrowing Saga · Coordinates book status, rollback, and notification actions.
borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/saga/BorrowingSaga.java - Borrowing Projection
borrowingservice/src/main/java/com/tanthanh/borrowingservice/query/api/projection/BorrowingProjection.java
Other components
- API Gateway · External request boundary.
api-gateway/src/main/java/com/chinhbean/apigateway/ApiGatewayApplication.java - Gateway Auth Filter
api-gateway/src/main/java/com/chinhbean/apigateway/config/AuthFilter.java - User Service · Centralized user management and authorization.
userservice/src/main/java/com/tanthanh/userservice/controller/UserController.java - Common Contracts · Cross-service queries, DTOs, and book-status events.
commonservice/src/main/java/com/tanthanh/commonservice/command/UpdateStatusBookCommand.java - Notification Service
notificationservice/src/main/java/com/tanthanh/notificationservice/NotificationserviceApplication.java
Connections 23
- API Gateway → Gateway Auth Filter: authenticates
- Gateway Auth Filter → User Service: authorizes via
- API Gateway → Book Service: routes requests
- API Gateway → Employee Service: routes requests
- API Gateway → Borrow Command Controller: routes commands
- Config Server → API Gateway: central config
- Config Server → Book Service: central config
- Config Server → Employee Service: central config
- Discovery Server → API Gateway: service discovery
- Discovery Server → Book Service: registers
- Discovery Server → Employee Service: registers
- Book Service → Book Aggregate: dispatches commands
- Book Aggregate → Book Event Handler: emits events
- Book Aggregate → Book Projection: updates read model
- Employee Service → Employee Aggregate: dispatches commands
- Employee Aggregate → Employee Event Handler: emits events
- Employee Aggregate → Employee Projection: updates read model
- Borrow Command Controller → Borrow Aggregate: submits commands
- Borrow Aggregate → Borrowing Saga: publishes borrowing events
- Borrow Aggregate → Borrowing Projection: updates read model
- Borrowing Saga → Common Contracts: uses status contracts
- Common Contracts → Book Aggregate: book status commands
- Borrowing Saga → Notification Service: triggers notifications