# minhchinhdo/scalable-e-commerce architecture

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

- Interactive diagram: https://gitdiagram.com/minhchinhdo/scalable-e-commerce
- Repository: https://github.com/minhchinhdo/scalable-e-commerce

## Overview

#### 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: [`api-gateway/src/main/java/com/chinhbean/apigateway/ApiGatewayApplication.java`](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/api-gateway/src/main/java/com/chinhbean/apigateway/ApiGatewayApplication.java) (API Gateway), [`bookservice/src/main/java/com/chinhbean/bookservice/command/api/aggregate/BookAggregate.java`](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/bookservice/src/main/java/com/chinhbean/bookservice/command/api/aggregate/BookAggregate.java) (Book Aggregate), [`bookservice/src/main/java/com/chinhbean/bookservice/BookserviceApplication.java`](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/bookservice/src/main/java/com/chinhbean/bookservice/BookserviceApplication.java) (Book Service), [`employeeservice/src/main/java/com/tanthanh/employeeservice/EmployeeserviceApplication.java`](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/employeeservice/src/main/java/com/tanthanh/employeeservice/EmployeeserviceApplication.java) (Employee Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_platform["Platform Control"]
  node_config_server["Config Server<br/>configuration service"]
  node_discovery_server["Discovery Server<br/>service registry"]
end

subgraph group_book["Book CQRS"]
  node_book_service["Book Service<br/>CQRS service"]
  node_book_aggregate["Book Aggregate<br/>command aggregate<br/>[BookAggregate.java]"]
  node_book_events["Book Event Handler"]
  node_book_projection["Book Projection<br/>query projection"]
end

subgraph group_employee["Employee CQRS"]
  node_employee_service["Employee Service<br/>CQRS service"]
  node_employee_aggregate["Employee Aggregate<br/>command aggregate"]
  node_employee_events["Employee Event Handler"]
  node_employee_projection["Employee Projection<br/>query projection"]
end

subgraph group_borrowing["Borrowing Workflow"]
  node_borrow_commands["Borrow Command Controller<br/>command API"]
  node_borrow_aggregate["Borrow Aggregate<br/>command aggregate"]
  node_borrow_saga{{"Borrowing Saga<br/>distributed saga<br/>[BorrowingSaga.java]"}}
  node_borrow_projection["Borrowing Projection<br/>query projection"]
end

node_gateway["API Gateway<br/>edge service"]
node_gateway_auth["Gateway Auth Filter<br/>authentication filter<br/>[AuthFilter.java]"]
node_user_service["User Service<br/>identity service"]
node_contracts["Common Contracts<br/>shared contract module"]
node_notification_service["Notification Service"]

node_gateway -->|"authenticates"| node_gateway_auth
node_gateway_auth -->|"authorizes via"| node_user_service
node_gateway -->|"routes requests"| node_book_service
node_gateway -->|"routes requests"| node_employee_service
node_gateway -->|"routes commands"| node_borrow_commands
node_config_server -.->|"central config"| node_gateway
node_config_server -.->|"central config"| node_book_service
node_config_server -.->|"central config"| node_employee_service
node_discovery_server -.->|"service discovery"| node_gateway
node_discovery_server -.->|"registers"| node_book_service
node_discovery_server -.->|"registers"| node_employee_service
node_book_service -->|"dispatches commands"| node_book_aggregate
node_book_aggregate -->|"emits events"| node_book_events
node_book_aggregate -->|"updates read model"| node_book_projection
node_employee_service -->|"dispatches commands"| node_employee_aggregate
node_employee_aggregate -->|"emits events"| node_employee_events
node_employee_aggregate -->|"updates read model"| node_employee_projection
node_borrow_commands -->|"submits commands"| node_borrow_aggregate
node_borrow_aggregate -->|"publishes borrowing events"| node_borrow_saga
node_borrow_aggregate -->|"updates read model"| node_borrow_projection
node_borrow_saga -->|"uses status contracts"| node_contracts
node_contracts -->|"book status commands"| node_book_aggregate
node_borrow_saga -->|"triggers notifications"| node_notification_service

click node_gateway "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/api-gateway/src/main/java/com/chinhbean/apigateway/ApiGatewayApplication.java"
click node_gateway_auth "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/api-gateway/src/main/java/com/chinhbean/apigateway/config/AuthFilter.java"
click node_user_service "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/userservice/src/main/java/com/tanthanh/userservice/controller/UserController.java"
click node_config_server "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/configserver/src/main/java/com/tanthanh2706/configserver/ConfigserverApplication.java"
click node_discovery_server "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/discoveryserver/src/main/java/com/chinhbean/bookservice/DiscoveryServer.java"
click node_contracts "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/commonservice/src/main/java/com/tanthanh/commonservice/command/UpdateStatusBookCommand.java"
click node_book_service "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/bookservice/src/main/java/com/chinhbean/bookservice/BookserviceApplication.java"
click node_book_aggregate "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/bookservice/src/main/java/com/chinhbean/bookservice/command/api/aggregate/BookAggregate.java"
click node_book_events "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/bookservice/src/main/java/com/chinhbean/bookservice/command/api/events/BookEventsHandler.java"
click node_book_projection "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/bookservice/src/main/java/com/chinhbean/bookservice/query/api/projection/BookProjection.java"
click node_employee_service "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/employeeservice/src/main/java/com/tanthanh/employeeservice/EmployeeserviceApplication.java"
click node_employee_aggregate "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/employeeservice/src/main/java/com/tanthanh/employeeservice/command/api/aggregate/EmployeeAggregate.java"
click node_employee_events "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/employeeservice/src/main/java/com/tanthanh/employeeservice/command/api/events/EmployeeEventsHandler.java"
click node_employee_projection "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/employeeservice/src/main/java/com/tanthanh/employeeservice/query/api/projection/EmployeeProjection.java"
click node_borrow_commands "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/controller/BorrowCommandController.java"
click node_borrow_aggregate "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/aggregate/BorrowAggregate.java"
click node_borrow_saga "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/saga/BorrowingSaga.java"
click node_borrow_projection "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/borrowingservice/src/main/java/com/tanthanh/borrowingservice/query/api/projection/BorrowingProjection.java"
click node_notification_service "https://github.com/minhchinhdo/scalable-e-commerce/blob/main/notificationservice/src/main/java/com/tanthanh/notificationservice/NotificationserviceApplication.java"

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_server,node_discovery_server toneBlue
class node_book_service,node_book_aggregate,node_book_events,node_book_projection toneAmber
class node_employee_service,node_employee_aggregate,node_employee_events,node_employee_projection toneMint
class node_borrow_commands,node_borrow_aggregate,node_borrow_saga,node_borrow_projection toneRose
class node_gateway,node_gateway_auth,node_user_service,node_contracts,node_notification_service toneNeutral
```

## Components

### Platform Control

- [Config Server](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/configserver/src/main/java/com/tanthanh2706/configserver/ConfigserverApplication.java): configuration service · `configserver/src/main/java/com/tanthanh2706/configserver/ConfigserverApplication.java`
- [Discovery Server](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/discoveryserver/src/main/java/com/chinhbean/bookservice/DiscoveryServer.java): service registry · `discoveryserver/src/main/java/com/chinhbean/bookservice/DiscoveryServer.java`

### Book CQRS

- [Book Service](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/bookservice/src/main/java/com/chinhbean/bookservice/BookserviceApplication.java): CQRS service · `bookservice/src/main/java/com/chinhbean/bookservice/BookserviceApplication.java`
- [Book Aggregate](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/bookservice/src/main/java/com/chinhbean/bookservice/command/api/aggregate/BookAggregate.java): command aggregate · `bookservice/src/main/java/com/chinhbean/bookservice/command/api/aggregate/BookAggregate.java`
- [Book Event Handler](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/bookservice/src/main/java/com/chinhbean/bookservice/command/api/events/BookEventsHandler.java): event handler · Persists command-side book entities. · `bookservice/src/main/java/com/chinhbean/bookservice/command/api/events/BookEventsHandler.java`
- [Book Projection](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/bookservice/src/main/java/com/chinhbean/bookservice/query/api/projection/BookProjection.java): query projection · `bookservice/src/main/java/com/chinhbean/bookservice/query/api/projection/BookProjection.java`

### Employee CQRS

- [Employee Service](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/employeeservice/src/main/java/com/tanthanh/employeeservice/EmployeeserviceApplication.java): CQRS service · `employeeservice/src/main/java/com/tanthanh/employeeservice/EmployeeserviceApplication.java`
- [Employee Aggregate](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/employeeservice/src/main/java/com/tanthanh/employeeservice/command/api/aggregate/EmployeeAggregate.java): command aggregate · `employeeservice/src/main/java/com/tanthanh/employeeservice/command/api/aggregate/EmployeeAggregate.java`
- [Employee Event Handler](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/employeeservice/src/main/java/com/tanthanh/employeeservice/command/api/events/EmployeeEventsHandler.java): event handler · Persists command-side employee entities. · `employeeservice/src/main/java/com/tanthanh/employeeservice/command/api/events/EmployeeEventsHandler.java`
- [Employee Projection](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/employeeservice/src/main/java/com/tanthanh/employeeservice/query/api/projection/EmployeeProjection.java): query projection · `employeeservice/src/main/java/com/tanthanh/employeeservice/query/api/projection/EmployeeProjection.java`

### Borrowing Workflow

- [Borrow Command Controller](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/controller/BorrowCommandController.java): command API · `borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/controller/BorrowCommandController.java`
- [Borrow Aggregate](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/aggregate/BorrowAggregate.java): command aggregate · `borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/aggregate/BorrowAggregate.java`
- [Borrowing Saga](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/saga/BorrowingSaga.java): distributed saga · Coordinates book status, rollback, and notification actions. · `borrowingservice/src/main/java/com/tanthanh/borrowingservice/command/api/saga/BorrowingSaga.java`
- [Borrowing Projection](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/borrowingservice/src/main/java/com/tanthanh/borrowingservice/query/api/projection/BorrowingProjection.java): query projection · `borrowingservice/src/main/java/com/tanthanh/borrowingservice/query/api/projection/BorrowingProjection.java`

### Other components

- [API Gateway](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/api-gateway/src/main/java/com/chinhbean/apigateway/ApiGatewayApplication.java): edge service · External request boundary. · `api-gateway/src/main/java/com/chinhbean/apigateway/ApiGatewayApplication.java`
- [Gateway Auth Filter](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/api-gateway/src/main/java/com/chinhbean/apigateway/config/AuthFilter.java): authentication filter · `api-gateway/src/main/java/com/chinhbean/apigateway/config/AuthFilter.java`
- [User Service](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/userservice/src/main/java/com/tanthanh/userservice/controller/UserController.java): identity service · Centralized user management and authorization. · `userservice/src/main/java/com/tanthanh/userservice/controller/UserController.java`
- [Common Contracts](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/commonservice/src/main/java/com/tanthanh/commonservice/command/UpdateStatusBookCommand.java): shared contract module · Cross-service queries, DTOs, and book-status events. · `commonservice/src/main/java/com/tanthanh/commonservice/command/UpdateStatusBookCommand.java`
- [Notification Service](https://github.com/minhchinhdo/scalable-e-commerce/blob/main/notificationservice/src/main/java/com/tanthanh/notificationservice/NotificationserviceApplication.java): notification service · `notificationservice/src/main/java/com/tanthanh/notificationservice/NotificationserviceApplication.java`

## Connections

- 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
