How leanthuyen/microserviceslearning works
Project type and purpose
• This is a .NET 6 “Clean Architecture” microservices solution orchestrated via Docker Compose.
• It comprises an Ocelot API Gateway at the edge, a set of domain‐centric API services (Product, Customer, Basket, Inventory, Ordering, Hangfire) plus a background subscriber, all sharing common Building-Blocks libraries for logging, contracts, event bus integration, and shared DTOs/configurations.
• It’s designed for an e-commerce workflow: product catalog, customer management, shopping basket, inventory, order placement via events, and email notifications.
File structure
• Top level: solution file (TanaMicroservices.sln), Docker files, Compose files, global.json.
• src/ApiGateways/OcelotApiGW → API Gateway project.
• src/BuildingBlocks → shared libraries (Common.Logging, Contracts, EventBus, Infrastructure, Shared DTOs).
• src/Services → each microservice in its own folder; each follows Clean Architecture layering (API host, Application, Domain, Infrastructure/Persistence, Migrations).
• docker-compose.yml & override → container definitions for all services plus RabbitMQ, Redis, Postgres, MongoDB, Kibana, Portainer, Jenkins.
README
• Confirms ports for each service in local vs Docker.
• Lists external infrastructure: Portainer, Kibana, RabbitMQ, Postgres GUI, Jenkins.
• Mentions Clean Architecture layers and EF Core migration commands.
Main components
a. Edge Layer
• OcelotApiGW (HTTP entry point)
b. Microservices Layer
• Product.API (.NET 6, EF Core → Postgres)
• Customer.API (.NET 6, EF Core → Postgres)
• Basket.API (.NET 6, Redis cache)
• Inventory.API (.NET 6, MongoDB)
• Ordering.API (.NET 6, EF Core → Postgres)
• Hangfire.API (.NET 6, background job dashboard)
• Ordering.Subscriber (background event handler)
c. Integration Layer
• RabbitMQ message broker (pub/sub for integration events)
d. Data Layer
• Postgres/SQL Server instances for Product, Customer, Ordering
• MongoDB for Inventory
• Redis for Basket
e. Shared Building-Blocks
• Contracts (events, DTOs, interfaces)
• Common.Logging (Serilog)
• Infrastructure (UnitOfWork, Repositories, RabbitMQProducer)
f. External Infrastructure
• SMTP Email Service (SmtpEmailService)
• Jenkins (CI/CD)
• Kibana (log visualization)
• Portainer (container management)
Relationships and interactions
1. Client → HTTP calls → OcelotApiGW → Routes to individual Microservice endpoints
2. Microservice → own database for persistent data
3. Basket.API publishes BasketCheckoutEvent → RabbitMQ
4. Ordering.API & Ordering.Subscriber subscribe to BasketCheckoutEvent → process order, persist → send confirmation email via SMTP
5. Internal sync calls (if any) for product/customer lookups via Gateway
6. Hangfire.API exposes dashboards for scheduling/monitoring background jobs
Architectural patterns and design principles
• Microservices: independent deployable units, one database per service
• Clean Architecture: each service layered (API/Host → Application → Domain → Infrastructure → Persistence/Migrations)
• API Gateway pattern: Ocelot routing, aggregation, authentication, rate-limiting if needed
• Event-Driven Architecture: RabbitMQ for decoupled integration events
• DDD elements: Entities, Aggregates, Domain Events, Repositories, Behaviours (performance, validation)