Skip to content

tenzinkabsang/myEcomShop

Repository files navigation

myEcomShop

A sample e-commerce reference application built with ASP.NET Core (.NET 9) demonstrating a microservices architecture. The solution is fully containerized with Docker Compose and showcases common patterns such as API gateway communication, event-driven messaging, hybrid caching, and structured logging.


Architecture Overview

+----------------+          +--------------------+          +--------------------+
|                | -------> |   Catalog API      | -------> |                    |
|   Web App      |          |  (Controllers)     |          |                    |
| (Razor Pages   |          +--------------------+          |    SQL Server      |
|   + MVC)       | -------> |   Orders API       | -------> |                    |
|                |          |  (Minimal APIs)    |          |                    |
+----------------+          +--------------------+          +--------------------+
                                     |
                                     | Publish
                                     v
                            +--------------------+
                            |     RabbitMQ       |
                            +--------------------+
                                     |
                                     | Consume
                                     v
                            +--------------------+
                            |  Queue Processor   |
                            | (Worker Service)   |
                            +--------------------+

The application is composed of the following services:

Service Project Description
Web Ecom.Web Customer-facing storefront built with ASP.NET Core MVC and Razor Pages. Communicates with backend APIs via HttpClient with Microsoft resilience (Polly) policies.
Catalog API Ecom.Catalog.Api REST API serving product catalog data (products, categories, recommendations). Uses controller-based routing.
Orders API Ecom.Orders.Api REST API handling shopping cart and checkout operations. Uses Minimal APIs with endpoint groups. Publishes order events to RabbitMQ.
Queue Processor Ecom.QueueProcessor .NET Worker Service (BackgroundService) that consumes order.received messages from RabbitMQ for downstream processing (e.g., fulfillment, email notifications).

Shared Libraries

Project Purpose
Ecom.Core Domain entities, caching abstractions (HybridCache + Redis), event publishing infrastructure, and custom middleware.
Ecom.Data Entity Framework Core DbContext, generic repository pattern, and database migrations.

Tech Stack

Category Technology
Framework .NET 9 / C#
Web UI ASP.NET Core MVC + Razor Pages
APIs ASP.NET Core Web API (Controllers & Minimal APIs)
Database SQL Server 2022
ORM Entity Framework Core + Dapper
Messaging RabbitMQ
Caching Redis + HybridCache
Resilience Microsoft.Extensions.Http.Resilience (Polly)
Logging Serilog -> Seq
Containers Docker & Docker Compose

Prerequisites


Getting Started

Option 1 -- Docker Compose (recommended)

Run all services with a single command from the repository root (where the .sln file is located):

docker-compose build
docker-compose up

Option 2 -- Visual Studio

Open the solution in Visual Studio and press F5. The docker-compose project is configured as the startup project.

Accessing the Services

Once the containers are running, the following endpoints are available:

Service URL
Web App https://localhost:5201
Catalog API (Swagger) http://localhost:5011/swagger/index.html
Orders API (Swagger) http://localhost:5012/swagger/index.html
RabbitMQ Management http://localhost:8088 (guest / guest)
Seq (Structured Logs) http://localhost:5342

Key Patterns & Features

  • Microservice Communication -- The Web app calls backend APIs through typed HttpClient instances registered with IHttpClientFactory.
  • Resilience -- All outbound HTTP calls use AddStandardResilienceHandler() (retry, circuit breaker, timeout) powered by Polly via Microsoft.Extensions.Http.Resilience.
  • Event-Driven Messaging -- When an order is placed, the Orders API publishes an order.received message to RabbitMQ. The Queue Processor worker service consumes these messages asynchronously.
  • Hybrid Caching -- The Catalog API and Web app leverage HybridCache (in-memory + Redis L2) for scalable, tag-based cache invalidation.
  • Health Checks -- Each API exposes a /health endpoint; Docker Compose uses these for container health monitoring.
  • Structured Logging -- All services ship structured logs to Seq via Serilog, enriched with request host and user-agent metadata.
  • Global Exception Handling -- A custom CustomExceptionHandlingMiddleware provides consistent error responses across APIs.
  • Repository Pattern -- A generic IRepository<T> abstraction backed by EF Core, complemented by Dapper for performance-sensitive queries.

Screenshots

Home Page

myEcomShop landing page screenshot

Product Details

myEcomShop details page

RabbitMQ Management

myEcomShop Rabbit page

Seq Structured Logs

myEcomShop Seq page

About

A sample .NET microservices and container based application. Powered by .NET 9, C# 12, Docker, HybridCache, Redis, RabbitMq & Sql Server. Consists of two API projects, a Web frontend and a Queue processor.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors