Skip to content

DatMV01/urbanx-sample

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

141 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

UrbanX - Multi-Merchant Commerce Platform

A modern, event-driven multi-merchant commerce platform built with .NET 10 microservices.

Architecture

Microservices

Service Description
Catalog Service Product catalog with CQRS: PostgreSQL write side, Elasticsearch read side
Order Service Cart management, checkout, order tracking
Merchant Service Merchant registration and product management
Payment Service Payment processing via Stripe
Inventory Service Stock reservation and management
Identity Service Authentication and authorization (Duende IdentityServer)
API Gateway Single entry point with YARP reverse proxy and rate limiting

Frontend

  • React 19 + TypeScript (Vite, Tailwind CSS 4) β€” customer-facing SPA located in src/Frontend/urbanx-react

Infrastructure

  • PostgreSQL β€” dedicated database per service
  • Apache Kafka β€” asynchronous event messaging between services
  • Elasticsearch β€” product search index (Catalog read side)
  • .NET Aspire β€” orchestration, service discovery, health checks, and distributed tracing

Key Features

Customer Features

  • Product search and browse (Elasticsearch-powered)
  • Shopping cart management
  • Checkout and online payment (Stripe)
  • Order tracking with status timeline

Merchant Features

  • Product CRUD with inventory management
  • Order acceptance and fulfillment workflow

Architecture Patterns

  • Transactional Outbox β€” Catalog, Order, Payment, and Inventory services atomically persist domain events to an outbox table before publishing to Kafka, ensuring no message loss.
  • Saga (Choreography) β€” Order fulfillment is coordinated via events:
    OrderCreated β†’ Inventory reserved/failed β†’ Payment processed/failed β†’ Merchant notified
  • CQRS β€” Catalog service writes to PostgreSQL and reads from Elasticsearch.
  • Rate Limiting β€” API Gateway enforces 100 requests per minute per IP with HTTP 429 + Retry-After header.
  • Policy-Based Authorization β€” All sensitive endpoints require JWT bearer tokens; policies: CustomerOnly, MerchantOnly, CustomerOrMerchant.

Getting Started

Prerequisites

  • .NET 10 SDK
  • Node.js 20+
  • Docker & Docker Compose

Option 1: .NET Aspire (Recommended)

Aspire automatically provisions PostgreSQL and Kafka, wires up service discovery, and streams all logs and traces to a dashboard.

  1. Install the Aspire workload (if not already installed):
dotnet workload install aspire
  1. Start all backend services:
cd src/AppHost/UrbanX.AppHost
dotnet run

This starts the Aspire dashboard at http://localhost:15260 and launches all microservices.

  1. Start the frontend (in a separate terminal):
cd src/Frontend/urbanx-react
npm install
npm run dev

The application is available at:

Option 2: Manual Setup

  1. Start infrastructure (PostgreSQL & Kafka):
docker-compose up -d
  1. Start each backend service in separate terminals:
# Identity Service
cd src/Services/Identity/UrbanX.Services.Identity && dotnet run

# Catalog Service
cd src/Services/Catalog/UrbanX.Services.Catalog && dotnet run

# Order Service
cd src/Services/Order/UrbanX.Services.Order && dotnet run

# Merchant Service
cd src/Services/Merchant/UrbanX.Services.Merchant && dotnet run

# Payment Service
cd src/Services/Payment/UrbanX.Services.Payment && dotnet run

# Inventory Service
cd src/Services/Inventory/UrbanX.Services.Inventory && dotnet run

# API Gateway
cd src/Gateway/UrbanX.Gateway && dotnet run
  1. Start the frontend:
cd src/Frontend/urbanx-react
npm install
npm run dev

The application is available at:

API Endpoints

All routes below are accessed via the API Gateway. Endpoints marked πŸ”’ require a JWT bearer token.

Catalog Service (/api/products)

Method Path Auth Description
GET /api/products Public List/search products
GET /api/products/{id} Public Get product by ID
GET /api/products/merchant/{merchantId} Public List merchant products
POST /api/products πŸ”’ Merchant Create product
PUT /api/products/{id} πŸ”’ Merchant Update product
DELETE /api/products/{id} πŸ”’ Merchant Delete product

Order Service (/api/cart, /api/orders)

Method Path Auth Description
GET /api/cart/{customerId} πŸ”’ Customer Get customer cart
POST /api/cart/{customerId}/items πŸ”’ Customer Add item to cart
DELETE /api/cart/{customerId}/items/{itemId} πŸ”’ Customer Remove item from cart
POST /api/orders πŸ”’ Customer Create order
GET /api/orders/{orderId} πŸ”’ Customer/Merchant Get order details
GET /api/orders/customer/{customerId} πŸ”’ Customer List customer orders
PUT /api/orders/{orderId}/status πŸ”’ Merchant Update order status

Merchant Service (/api/merchants)

Method Path Auth Description
GET /api/merchants/{id} Public Get merchant details
POST /api/merchants πŸ”’ Merchant Register merchant
GET /api/merchants/{merchantId}/products Public List merchant products
POST /api/merchants/{merchantId}/products πŸ”’ Merchant Add product
PUT /api/merchants/{merchantId}/products/{productId} πŸ”’ Merchant Update product
DELETE /api/merchants/{merchantId}/products/{productId} πŸ”’ Merchant Delete product

Payment Service (/api/payments)

Method Path Auth Description
POST /api/payments πŸ”’ Customer Process payment (Stripe)
GET /api/payments/{id} πŸ”’ Customer/Merchant Get payment by ID
GET /api/payments/order/{orderId} πŸ”’ Customer/Merchant Get payment by order

Inventory Service (/api/inventory)

Method Path Auth Description
GET /api/inventory/{productId} πŸ”’ Merchant Get inventory item
POST /api/inventory πŸ”’ Merchant Create inventory item
PUT /api/inventory/{productId} πŸ”’ Merchant Update stock quantity
GET /api/inventory/reservations/{orderId} πŸ”’ Customer/Merchant Get reservations for order

Technology Stack

Backend

  • .NET 10 / ASP.NET Core Minimal APIs
  • .NET Aspire (orchestration, service discovery, observability)
  • Entity Framework Core + PostgreSQL (per-service database)
  • Apache Kafka (event streaming)
  • Elasticsearch (product search)
  • Duende IdentityServer (JWT authentication)
  • Stripe SDK (payment processing)
  • YARP (API Gateway reverse proxy)
  • OpenTelemetry (distributed tracing & metrics)

Frontend

  • React 19 + TypeScript
  • Vite
  • Tailwind CSS 4
  • React Router
  • oidc-client-ts (OIDC authentication)
  • Lucide React (icons)

Shared Libraries

  • UrbanX.Shared.Security β€” JWT authorization policies, input validation, global exception handler
  • UrbanX.ServiceDefaults β€” Aspire service defaults (health checks, telemetry, resilience)

Project Structure

urbanx-sample/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ AppHost/
β”‚   β”‚   └── UrbanX.AppHost/          # .NET Aspire orchestrator
β”‚   β”œβ”€β”€ ServiceDefaults/
β”‚   β”‚   └── UrbanX.ServiceDefaults/  # Shared Aspire configuration
β”‚   β”œβ”€β”€ Services/
β”‚   β”‚   β”œβ”€β”€ Catalog/                 # Product catalog (CQRS + Elasticsearch)
β”‚   β”‚   β”œβ”€β”€ Order/                   # Cart, orders, saga coordinator
β”‚   β”‚   β”œβ”€β”€ Merchant/                # Merchant & product management
β”‚   β”‚   β”œβ”€β”€ Payment/                 # Stripe payment processing
β”‚   β”‚   β”œβ”€β”€ Inventory/               # Stock reservation & management
β”‚   β”‚   └── Identity/                # Duende IdentityServer
β”‚   β”œβ”€β”€ Gateway/
β”‚   β”‚   └── UrbanX.Gateway/          # YARP reverse proxy + rate limiting
β”‚   β”œβ”€β”€ Frontend/
β”‚   β”‚   └── urbanx-react/            # Customer-facing React SPA
β”‚   └── Shared/
β”‚       β”œβ”€β”€ UrbanX.Shared/           # Shared domain models
β”‚       └── UrbanX.Shared.Security/  # Security utilities
β”œβ”€β”€ tests/                           # Unit and integration tests
β”œβ”€β”€ kubernetes/                      # Kubernetes manifests
β”œβ”€β”€ docker-compose.yml               # Infrastructure (PostgreSQL, Kafka)
β”œβ”€β”€ docker-compose.production.yml    # Production Docker Compose
β”œβ”€β”€ generate-migrations.sh           # EF Core migration helper script
└── UrbanX.sln                       # Solution file

Development

Using Aspire (Recommended)

Run dotnet run from src/AppHost/UrbanX.AppHost to start everything. The Aspire Dashboard provides real-time logs, traces, and health status for all services.

Running Tests

dotnet test UrbanX.sln

Both unit and integration tests are provided for each service under the tests/ directory.

Database Migrations

Migrations are applied automatically on service startup. To generate a new migration:

cd src/Services/<Service>/UrbanX.Services.<Service>
dotnet ef migrations add <MigrationName> --context <Service>DbContext

See DATABASE_MIGRATIONS.md for detailed guidance.

Environment Configuration

Copy .env.example to .env and fill in the required values (database passwords, Stripe keys, etc.) before running manually.

Security

  • JWT bearer authentication on all sensitive endpoints
  • Policy-based authorization (CustomerOnly, MerchantOnly, CustomerOrMerchant)
  • Per-IP rate limiting in the API Gateway (100 req/min)
  • Input validation on all write endpoints (UrbanX.Shared.Security.RequestValidation)
  • Global exception handler with environment-aware error details
  • Security headers (X-Content-Type-Options, X-Frame-Options, X-XSS-Protection, Referrer-Policy)

See SECURITY.md for production security guidance.

Deployment

Docker and Kubernetes manifests are included:

# Production Docker Compose
docker-compose -f docker-compose.production.yml up -d

# Kubernetes
kubectl apply -f kubernetes/

See PRODUCTION_DEPLOYMENT.md for a full deployment guide.

License

MIT

About

A real-world on-demand commerce system design showcase using microservices, DDD, and Saga/Outbox patterns for scalable, reliable order processing.

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C# 65.2%
  • TypeScript 24.8%
  • CSS 6.3%
  • Dockerfile 1.6%
  • Shell 0.8%
  • HTML 0.8%
  • Other 0.5%