# adrian0511/orderflow architecture

> Architecture diagram of the GitHub repository adrian0511/orderflow, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adrian0511/orderflow
- Repository: https://github.com/adrian0511/orderflow

## Overview

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: [`api-gateway/src/main/java/com/adrian/apigateway/ApiGatewayApplication.java`](https://github.com/adrian0511/orderflow/blob/main/api-gateway/src/main/java/com/adrian/apigateway/ApiGatewayApplication.java) (Gateway), [`docker-compose.yml`](https://github.com/adrian0511/orderflow/blob/main/docker-compose.yml) (Kafka), [`order-service/src/main/java/com/adrian/orderservice/OrderServiceApplication.java`](https://github.com/adrian0511/orderflow/blob/main/order-service/src/main/java/com/adrian/orderservice/OrderServiceApplication.java) (Orders), [`inventory-service/src/main/java/com/adrian/inventoryservice/InventoryServiceApplication.java`](https://github.com/adrian0511/orderflow/blob/main/inventory-service/src/main/java/com/adrian/inventoryservice/InventoryServiceApplication.java) (Inventory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_platform["Platform"]
  node_gateway["Gateway"]
  node_discovery[("Discovery<br/>eureka registry")]
  node_gateway_sec["Gateway Sec<br/>security config"]
end

subgraph group_services["Services"]
  node_auth["Auth"]
  node_users["Users<br/>profile service"]
  node_products["Products<br/>catalog service"]
  node_inventory["Inventory<br/>stock service"]
  node_orders["Orders<br/>orchestrator"]
  node_payments["Payments<br/>payment worker"]
  node_notify["Notify<br/>mail service"]
  node_auth_cfg["Auth Config<br/>oauth2/jwt"]
  node_order_int["Order Int<br/>feign clients"]
  node_inventory_int["Inv Int<br/>product client"]
end

subgraph group_infra["Infrastructure"]
  node_kafka["Kafka<br/>event bus<br/>[docker-compose.yml]"]
  node_zookeeper(("Zookeeper<br/>coordination<br/>[docker-compose.yml]"))
  node_mailhog(("MailHog<br/>mail sink<br/>[README.md]"))
  node_kafka_cfg["Kafka Config<br/>messaging config<br/>[KafkaConfig.java]"]
end

node_client(("Client<br/>external caller"))

node_client -->|"HTTP"| node_gateway
node_gateway -->|"lookup"| node_discovery
node_gateway -->|"login"| node_auth
node_gateway -->|"route"| node_users
node_gateway -->|"route"| node_products
node_gateway -->|"route"| node_inventory
node_gateway -->|"route"| node_orders
node_gateway -->|"route"| node_payments
node_gateway -.->|"route"| node_notify
node_auth -->|"publish"| node_kafka
node_kafka -->|"consume"| node_users
node_orders -->|"Feign"| node_users
node_orders -->|"Feign"| node_products
node_orders -->|"Feign"| node_inventory
node_orders -->|"publish"| node_kafka
node_kafka -->|"consume"| node_payments
node_payments -->|"publish"| node_kafka
node_kafka -->|"consume"| node_notify
node_inventory -->|"Feign"| node_products
node_inventory -->|"publish"| node_kafka
node_kafka -.->|"deliver"| node_mailhog
node_kafka -.->|"coord"| node_zookeeper
node_gateway_sec -->|"protects"| node_gateway
node_auth_cfg -->|"protects"| node_auth
node_order_int -->|"uses"| node_orders
node_inventory_int -->|"uses"| node_inventory
node_kafka_cfg -->|"configures"| node_kafka

click node_gateway "https://github.com/adrian0511/orderflow/blob/main/api-gateway/src/main/java/com/adrian/apigateway/ApiGatewayApplication.java"
click node_discovery "https://github.com/adrian0511/orderflow/blob/main/discovery-server/src/main/java/com/adrian/discoveryserver/DiscoveryServerApplication.java"
click node_auth "https://github.com/adrian0511/orderflow/blob/main/auth-server/src/main/java/com/adrian/authserver/AuthServerApplication.java"
click node_users "https://github.com/adrian0511/orderflow/blob/main/user-service/src/main/java/com/adrian/userservice/UserServiceApplication.java"
click node_products "https://github.com/adrian0511/orderflow/blob/main/product-service/src/main/java/com/adrian/productservice/ProductServiceApplication.java"
click node_inventory "https://github.com/adrian0511/orderflow/blob/main/inventory-service/src/main/java/com/adrian/inventoryservice/InventoryServiceApplication.java"
click node_orders "https://github.com/adrian0511/orderflow/blob/main/order-service/src/main/java/com/adrian/orderservice/OrderServiceApplication.java"
click node_payments "https://github.com/adrian0511/orderflow/blob/main/payment-service/src/main/java/com/adrian/paymentservice/PaymentServiceApplication.java"
click node_notify "https://github.com/adrian0511/orderflow/blob/main/notification-service/src/main/java/com/adrian/notificationservice/NotificationServiceApplication.java"
click node_kafka "https://github.com/adrian0511/orderflow/blob/main/docker-compose.yml"
click node_zookeeper "https://github.com/adrian0511/orderflow/blob/main/docker-compose.yml"
click node_mailhog "https://github.com/adrian0511/orderflow/blob/main/README.md"
click node_gateway_sec "https://github.com/adrian0511/orderflow/blob/main/api-gateway/src/main/java/com/adrian/apigateway/security/SecurityConfig.java"
click node_auth_cfg "https://github.com/adrian0511/orderflow/blob/main/auth-server/src/main/java/com/adrian/authserver/config/SecurityConfig.java"
click node_order_int "https://github.com/adrian0511/orderflow/blob/main/order-service/src/main/java/com/adrian/orderservice/integration/UserIntegrationService.java"
click node_inventory_int "https://github.com/adrian0511/orderflow/blob/main/inventory-service/src/main/java/com/adrian/inventoryservice/integration/ProductIntegrationService.java"
click node_kafka_cfg "https://github.com/adrian0511/orderflow/blob/main/notification-service/src/main/java/com/adrian/notificationservice/config/KafkaConfig.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_gateway,node_discovery,node_gateway_sec toneBlue
class node_auth,node_users,node_products,node_inventory,node_orders,node_payments,node_notify,node_auth_cfg,node_order_int,node_inventory_int toneAmber
class node_kafka,node_zookeeper,node_mailhog,node_kafka_cfg toneMint
class node_client toneNeutral
```

## Components

### Platform

Entry, discovery, and cross-cutting runtime boundaries

- [Gateway](https://github.com/adrian0511/orderflow/blob/main/api-gateway/src/main/java/com/adrian/apigateway/ApiGatewayApplication.java): api gateway · Public routing and security boundary · `api-gateway/src/main/java/com/adrian/apigateway/ApiGatewayApplication.java`
- [Discovery](https://github.com/adrian0511/orderflow/blob/main/discovery-server/src/main/java/com/adrian/discoveryserver/DiscoveryServerApplication.java): eureka registry · Service registry for dynamic lookup · `discovery-server/src/main/java/com/adrian/discoveryserver/DiscoveryServerApplication.java`
- [Gateway Sec](https://github.com/adrian0511/orderflow/blob/main/api-gateway/src/main/java/com/adrian/apigateway/security/SecurityConfig.java): security config · Central gateway security and resilience configuration · `api-gateway/src/main/java/com/adrian/apigateway/security/SecurityConfig.java`

### Services

Domain bounded contexts and orchestration

- [Auth](https://github.com/adrian0511/orderflow/blob/main/auth-server/src/main/java/com/adrian/authserver/AuthServerApplication.java): auth server · Registration, login, JWT issuance, OAuth2 boundary · `auth-server/src/main/java/com/adrian/authserver/AuthServerApplication.java`
- [Users](https://github.com/adrian0511/orderflow/blob/main/user-service/src/main/java/com/adrian/userservice/UserServiceApplication.java): profile service · User profile data and event-driven onboarding · `user-service/src/main/java/com/adrian/userservice/UserServiceApplication.java`
- [Products](https://github.com/adrian0511/orderflow/blob/main/product-service/src/main/java/com/adrian/productservice/ProductServiceApplication.java): catalog service · Product catalog and admin-controlled CRUD · `product-service/src/main/java/com/adrian/productservice/ProductServiceApplication.java`
- [Inventory](https://github.com/adrian0511/orderflow/blob/main/inventory-service/src/main/java/com/adrian/inventoryservice/InventoryServiceApplication.java): stock service · Stock state, reservation, and product lookup integration · `inventory-service/src/main/java/com/adrian/inventoryservice/InventoryServiceApplication.java`
- [Orders](https://github.com/adrian0511/orderflow/blob/main/order-service/src/main/java/com/adrian/orderservice/OrderServiceApplication.java): orchestrator · Order lifecycle coordination and saga-style flow · `order-service/src/main/java/com/adrian/orderservice/OrderServiceApplication.java`
- [Payments](https://github.com/adrian0511/orderflow/blob/main/payment-service/src/main/java/com/adrian/paymentservice/PaymentServiceApplication.java): payment worker · Consumes reservation events and emits payment outcomes · `payment-service/src/main/java/com/adrian/paymentservice/PaymentServiceApplication.java`
- [Notify](https://github.com/adrian0511/orderflow/blob/main/notification-service/src/main/java/com/adrian/notificationservice/NotificationServiceApplication.java): mail service · Event-driven email delivery for business outcomes · `notification-service/src/main/java/com/adrian/notificationservice/NotificationServiceApplication.java`
- [Auth Config](https://github.com/adrian0511/orderflow/blob/main/auth-server/src/main/java/com/adrian/authserver/config/SecurityConfig.java): oauth2/jwt · Authorization server security and Kafka setup · `auth-server/src/main/java/com/adrian/authserver/config/SecurityConfig.java`
- [Order Int](https://github.com/adrian0511/orderflow/blob/main/order-service/src/main/java/com/adrian/orderservice/integration/UserIntegrationService.java): feign clients · User, product, and inventory integrations · `order-service/src/main/java/com/adrian/orderservice/integration/UserIntegrationService.java`
- [Inv Int](https://github.com/adrian0511/orderflow/blob/main/inventory-service/src/main/java/com/adrian/inventoryservice/integration/ProductIntegrationService.java): product client · 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](https://github.com/adrian0511/orderflow/blob/main/docker-compose.yml): event bus · Asynchronous backbone for domain events · `docker-compose.yml`
- [Zookeeper](https://github.com/adrian0511/orderflow/blob/main/docker-compose.yml): coordination · Kafka coordination dependency · `docker-compose.yml`
- [MailHog](https://github.com/adrian0511/orderflow/blob/main/README.md): mail sink · Local email capture/runtime for notification delivery · `README.md`
- [Kafka Config](https://github.com/adrian0511/orderflow/blob/main/notification-service/src/main/java/com/adrian/notificationservice/config/KafkaConfig.java): messaging config · Shared Kafka producer/consumer wiring · `notification-service/src/main/java/com/adrian/notificationservice/config/KafkaConfig.java`

### Other components

- **Client**: external caller · External consumers of the public API

## Connections

- 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
