How luuthuong/e-shop-microservices works
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.