How adrian0511/orderflow works
1. Repository shape
- This is a multi-module microservices monorepo. Each top-level folder is an independent Spring Boot application with its own pom.xml, application.yaml, tests, and packaging boundary.
- The architecture is not a single backend; it is a distributed system organized around synchronous service calls plus Kafka-based events.
2. Edge and routing layer
- api-gateway is the public entry point. It sits in front of the domain services and handles centralized routing, token-aware security, and resilience concerns.
- The gateway also contains circuit-breaker-related configuration and a controller, so it is more than a dumb proxy: it is the main boundary between clients and internal services.
3. Service discovery
- discovery-server is a dedicated Eureka registry. All runtime services register there and use it for client-side service lookup.
- This means internal service addresses are not hardwired; the system is designed for dynamic discovery and gateway/service-to-service resolution.
4. Authentication and identity
- auth-server is the authorization boundary. It handles user registration and authentication, issues JWTs, and is configured as an OAuth2 Authorization Server.
- It contains user persistence, custom user details, role handling, and a Kafka configuration. The README indicates an Authorization Code flow through the gateway.
- The auth service also emits a UserCreatedEvent, which makes identity onboarding part of the event stream.
5. User profile subsystem
- user-service owns user-profile data separate from auth credentials. It has its own entity, repository, mapper, service layer, and REST controller.
- It consumes UserCreatedEvent from Kafka, so user profile state is partially driven by events rather than only direct API calls.
6. Product catalog subsystem
- product-service is the catalog boundary for products. It is a standard CRUD-style service with controller, entity, repository, mapper, and service layers.
- Security is enforced here too, and the README indicates admin-only write access.
7. Inventory subsystem
- inventory-service owns stock state and reservation logic. It includes a domain entity, repository, request/response DTOs, mapper, and a dedicated controller/service layer.
- It also has a ProductClient, indicating synchronous integration with the product service.
- Kafka is used for order-related events, and the service includes custom exceptions plus a global handler, which suggests stock validation and reservation failures are first-class domain outcomes.
8. Order orchestration subsystem
- order-service is the main business orchestrator. It coordinates user, product, and inventory interactions and models the order lifecycle with several event types.
- It has Feign clients for UserClient, ProductClient, and InventoryClient, plus circuit-breaker and custom error-decoder configuration.
- The presence of PaymentCompletedEvent, PaymentFailedEvent, and OrderStockReservedEvent shows that orders are driven by a saga-like process rather than a single transaction.
9. Payment processing subsystem
- payment-service listens for reserved-stock events and simulates payment processing. It then emits payment outcome events.
- This service is intentionally isolated: it has its own entity, repository, service, consumer, and Kafka configuration, making payment a separate bounded context.
10. Notification subsystem
- notification-service consumes domain events and turns them into emails. It includes Mail templates for welcome, payment success, and payment failure cases.
- This service is the output side of the event-driven architecture: it reacts to business events rather than being directly called by users.
11. Primary data flow
- External client → api-gateway → target service through Eureka-resolved routes.
- Authentication begins at auth-server; JWTs are then propagated by the gateway to protected services.
- Business flow for ordering is event-heavy: order creation triggers inventory reservation, reservation drives payment, payment outcome feeds back into order state, and downstream notifications are emitted by events.
12. Communication styles
- The system mixes synchronous HTTP/Feign calls for lookups and command-style interactions with Kafka for decoupled state propagation.
- This split is important for the diagram: direct calls are used where an immediate answer is needed, while Kafka is used for lifecycle events and side effects.
13. Resilience and failure handling
- Circuit breakers and custom error decoders appear in the gateway, order service, and inventory service, so remote calls are treated as unreliable dependencies.
- Each service also has its own exception hierarchy and global handler, indicating localized error translation at service boundaries.
14. Cross-cutting security boundary
- Security is configured per service, not only at the gateway. Each domain service has its own SecurityConfig, plus custom authentication/authorization handlers where needed.
- The architecture therefore assumes both central gateway enforcement and service-level protection.
15. Infrastructure dependencies
- The repo includes docker-compose.yml for Kafka/Zookeeper, and the README adds MailHog as a separate container.
- Those are the only explicit external runtime dependencies visible in the repository tree, and they support the event backbone plus email delivery/testing.
16. Implementation style
- Across services, the codebase follows the same layered pattern: controller → service → repository, with DTOs, mappers, entities, and handlers around that core.
- That consistency makes the system diagram easy to draw: each service is a self-contained bounded context with its own persistence and API, connected by the gateway, discovery, Kafka, and a few Feign-based integrations.
Main entry points: ApiGatewayApplication.java Gateway · docker-compose.yml Kafka · OrderServiceApplication.java Orders · InventoryServiceApplication.java Inventory
Components 18
Platform
Entry, discovery, and cross-cutting runtime boundaries
- Gateway · Public routing and security boundary
api-gateway/src/main/java/com/adrian/apigateway/ApiGatewayApplication.java - Discovery · Service registry for dynamic lookup
discovery-server/src/main/java/com/adrian/discoveryserver/DiscoveryServerApplication.java - Gateway Sec · Central gateway security and resilience configuration
api-gateway/src/main/java/com/adrian/apigateway/security/SecurityConfig.java
Services
Domain bounded contexts and orchestration
- Auth · Registration, login, JWT issuance, OAuth2 boundary
auth-server/src/main/java/com/adrian/authserver/AuthServerApplication.java - Users · User profile data and event-driven onboarding
user-service/src/main/java/com/adrian/userservice/UserServiceApplication.java - Products · Product catalog and admin-controlled CRUD
product-service/src/main/java/com/adrian/productservice/ProductServiceApplication.java - Inventory · Stock state, reservation, and product lookup integration
inventory-service/src/main/java/com/adrian/inventoryservice/InventoryServiceApplication.java - Orders · Order lifecycle coordination and saga-style flow
order-service/src/main/java/com/adrian/orderservice/OrderServiceApplication.java - Payments · Consumes reservation events and emits payment outcomes
payment-service/src/main/java/com/adrian/paymentservice/PaymentServiceApplication.java - Notify · Event-driven email delivery for business outcomes
notification-service/src/main/java/com/adrian/notificationservice/NotificationServiceApplication.java - Auth Config · Authorization server security and Kafka setup
auth-server/src/main/java/com/adrian/authserver/config/SecurityConfig.java - Order Int · User, product, and inventory integrations
order-service/src/main/java/com/adrian/orderservice/integration/UserIntegrationService.java - Inv Int · Synchronous product lookup from inventory
inventory-service/src/main/java/com/adrian/inventoryservice/integration/ProductIntegrationService.java
Infrastructure
External runtime dependencies for events and email
- Kafka · Asynchronous backbone for domain events
docker-compose.yml - Zookeeper · Kafka coordination dependency
docker-compose.yml - MailHog · Local email capture/runtime for notification delivery
README.md - Kafka Config · Shared Kafka producer/consumer wiring
notification-service/src/main/java/com/adrian/notificationservice/config/KafkaConfig.java
Other components
- Client · External consumers of the public API
Connections 27
- Client → Gateway: HTTP · Public traffic enters through the gateway
- Gateway → Discovery: lookup · Routes are resolved through service discovery
- Gateway → Auth: login · Authentication and token issuance boundary
- Gateway → Users: route · Protected traffic forwarded to user profile service
- Gateway → Products: route · Protected traffic forwarded to product service
- Gateway → Inventory: route · Protected traffic forwarded to inventory service
- Gateway → Orders: route · Protected traffic forwarded to order service
- Gateway → Payments: route · Protected traffic forwarded to payment service
- Gateway → Notify: route · Notification service remains internal and event-driven
- Auth → Kafka: publish · User creation events enter the event stream
- Kafka → Users: consume · User profile onboarding reacts to user creation
- Orders → Users: Feign · Order service reads user data synchronously
- Orders → Products: Feign · Order service reads product data synchronously
- Orders → Inventory: Feign · Order service reserves stock through inventory
- Orders → Kafka: publish · Order lifecycle events are emitted asynchronously
- Kafka → Payments: consume · Payment processing starts from reserved-stock events
- Payments → Kafka: publish · Payment outcomes are emitted as events
- Kafka → Notify: consume · Notifications react to lifecycle events
- Inventory → Products: Feign · Inventory pulls product data when needed
- Inventory → Kafka: publish · Inventory and order outcomes are broadcast
- Kafka → MailHog: deliver · Email templates are rendered and sent to local mail sink
- Kafka → Zookeeper: coord · Kafka depends on Zookeeper coordination
- Gateway Sec → Gateway: protects · Centralized gateway security policy
- Auth Config → Auth: protects · Authorization server and JWT configuration
- Order Int → Orders: uses · Order service integration layer
- Inv Int → Inventory: uses · Inventory service product integration layer
- Kafka Config → Kafka: configures · Kafka producer and consumer wiring