# luuthuong/e-shop-microservices architecture

> Architecture diagram of the GitHub repository luuthuong/e-shop-microservices, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/luuthuong/e-shop-microservices
- Repository: https://github.com/luuthuong/e-shop-microservices

## Overview

##### Main Components
- Front Door/API Gateway: In the “src/CentralizedServices/ApiGateway.Ocelot” directory, you have an API Gateway built with Ocelot. This component is the entry point for all client requests.
- Centralized Identity Service: Located under “src/CentralizedServices/Identity”. It is responsible for user authentication, registration, and token issuance.
- Domain-Specific Microservices:
– Customer Service (“src/Services/CustomerService”): Manages customer-related operations and contains API endpoints, application logic, and domain rules.
– Order Service (“src/Services/OrderService”): Handles order processing, order state changes, and orchestrates communication with inventory, payment, and shipping (at least conceptually, as shown in the workflow).
– Payment Service (“src/Services/PaymentService”): Responsible for processing payments, managing payment events, and integrating with external payment processing systems.
– Product Sync Service (“src/Services/ProductSyncService”): Manages product-related operations such as product creation, update, and category management.
– Additionally, there is a Node.js payment service variant under “src/Services/nodejs/payment-service” which might serve as a companion or experimental service.
- Cross-Cutting / Core Infrastructure:
– “src/Core” includes cross-cutting concerns like logging (Serilog), caching (Redis and in-memory), CQRS pipelines, repository patterns, HTTP client configuration, and outbox/event bus implementations.
- Database & Persistence Layers:
– Each service and the Identity module includes EF Core projects (under “Infrastructure”, “EF”, or “Persistence”) to handle migrations, repositories, and Unit Of Work patterns.
- External Tools and Build/Deployment:
– Docker and Docker Compose files (e.g., “docker-compose.yml”, Dockerfiles in each service) define containerization; build scripts and CI/CD configuration (in “.github/workflows”) indicate the deployment pipelines.
- Integration/Event Driven Architecture:
– The Core and some service folders include integrations with Kafka, RabbitMQ, and Outbox patterns. These ensure that events such as order updates, payments, and stock changes are propagated reliably.

##### Relationships & Interactions
- The API Gateway routes incoming requests from external clients to appropriate microservices. This includes routing to Identity for login or token retrieval.
- Each microservice (Customer, Order, Payment, Product Sync) exposes its own endpoints and is independently deployable. They communicate with each other asynchronously (via event bus mechanisms) and also synchronously when needed.
- Core layers (CQRS components, domain events, outbox messaging) tie the services together with consistent patterns for logging, caching, and background jobs.

##### Architectural Patterns & Design Principles
- Clean Architecture (Onion Architecture): Separates the concerns between API endpoints, application logic, domain rules, and infrastructure.
- CQRS (using MediatR): Clearly separates command and query pipelines and incorporates pipeline behaviors for caching, validation, and logging.
- Repository & Unit-of-Work patterns: These are evident across the “Core” and “Infrastructure” layers.
- Dockerized Containers and CI/CD: The solution is containerized using Docker, with scripts and configuration for deployment and testing.

##### Technologies & Frameworks
- ASP.NET Core 8 (Minimal APIs for many endpoints)
- Ocelot for API Gateway management
- Entity Framework Core for ORM and code-first migrations
- MediatR for implementing CQRS
- AutoMapper for object-to-object mapping
- Redis, Kafka, RabbitMQ (for caching and message/event-based communication)
- Serilog for logging support
- Docker with docker-compose for containerization and deployment pipelines

##### Important Reminders
- Interactions crossing bounded contexts: how the API Gateway directs traffic, how the Order Service interacts with Payment Service and triggers domain events, and how asynchronous message distribution is handled.
- Not only the service structure but also shared libraries like the “Core” project that is pervasive throughout the system.

## Diagram (Mermaid)

```mermaid
graph TB

%% Frontend/Entry Layer
subgraph "Frontend/Entry Layer"
    A["Client"]:::client
    B["API Gateway"]:::gateway
end

%% Centralized Services
subgraph "Centralized Services"
    C["Identity Service"]:::centralized
end

%% Microservices Layer
subgraph "Microservices"
    D["Customer Service"]:::microservice
    E["Order Service"]:::microservice
    F["Payment Service"]:::microservice
    G["Product Sync Service"]:::microservice
    H["Node.js Payment Service"]:::microservice
end

%% Core/Infrastructure Layer
subgraph "Core/Infrastructure"
    I["Core Infrastructure"]:::core
    J["CQRS & MediatR Pipeline"]:::core
    K["Event Bus & Outbox"]:::core
end

%% Data Layer
subgraph "Data Layer"
    L(("Customer DB")):::data
    M(("Order DB")):::data
    N(("Payment DB")):::data
    O(("Product DB")):::data
    P(("Identity DB")):::data
end

%% External Integration
subgraph "External Integration"
    Q["Kafka"]:::external
    R["RabbitMQ"]:::external
    S["Redis"]:::external
    T["Docker & CI/CD"]:::external
end

%% Connections from Frontend to Centralized & Microservices
A --> B
B --> C
B --> D
B --> E
B --> F
B --> G
B --> H

%% Microservices interacting with Core/Infrastructure
D --> I
E --> I
F --> I
G --> I
H --> I

%% Internal Core Structure
I --> J
I --> K

%% Order Service specific interaction with Payment Service
E -->|"calls"| F

%% Each service's data layer association
D --> L
E --> M
F --> N
G --> O
C --> P

%% Core Infrastructure integration with External Systems
I --> Q
I --> R
I --> S
I --> T

%% Class Definitions for Colour Styles
classDef client fill:#6a4c93,stroke:#333,stroke-width:2px;
classDef gateway fill:#f9c74f,stroke:#333,stroke-width:2px;
classDef centralized fill:#90be6d,stroke:#333,stroke-width:2px;
classDef microservice fill:#577590,stroke:#333,stroke-width:2px;
classDef core fill:#f94144,stroke:#333,stroke-width:2px;
classDef data fill:#277da1,stroke:#333,stroke-width:2px;
classDef external fill:#f3722c,stroke:#333,stroke-width:2px;

%% Click Events Mapping
click B "https://github.com/luuthuong/e-shop-microservices/blob/master/src/CentralizedServices/ApiGateway.Ocelot"
click C "https://github.com/luuthuong/e-shop-microservices/tree/master/src/CentralizedServices/Identity"
click D "https://github.com/luuthuong/e-shop-microservices/tree/master/src/Services/CustomerService"
click E "https://github.com/luuthuong/e-shop-microservices/tree/master/src/Services/OrderService"
click F "https://github.com/luuthuong/e-shop-microservices/tree/master/src/Services/PaymentService"
click G "https://github.com/luuthuong/e-shop-microservices/tree/master/src/Services/ProductSyncService"
click H "https://github.com/luuthuong/e-shop-microservices/tree/master/src/Services/nodejs/payment-service"
click I "https://github.com/luuthuong/e-shop-microservices/tree/master/src/Core"
```
