CartFlow
E-commerce checkout API — Redis cart, Stripe payments, inventory reservation
About This Project
Build a production e-commerce checkout system in .NET: Redis-backed cart service, inventory reservation with optimistic concurrency, idempotent Stripe payment integration, and a checkout saga with full compensation logic. Covers the real failure modes of checkout — double charges, oversold inventory, and abandoned carts.
What You'll Learn
Key Features
Project Structure
CartFlow/ ├── src/ │ ├── CartFlow.Api/ # Minimal API endpoints │ ├── CartFlow.Application/ # Checkout saga, commands, handlers │ ├── CartFlow.Domain/ # Product, Order, InventoryReservation │ └── CartFlow.Infrastructure/ # EF Core, Redis cart, Stripe client ├── tests/ │ ├── CartFlow.Unit/ # Saga and handler unit tests │ └── CartFlow.Integration/ # Testcontainers: Postgres + Redis └── docker-compose.yml
Setup Guide
Clone and start infrastructure
Start PostgreSQL, Redis, and the Stripe webhook forwarder.
git clone https://github.com/asmanasir/CartFlow.git cd CartFlow docker-compose up -d
Configure Stripe keys
Add your Stripe test keys to user secrets.
dotnet user-secrets set "Stripe:SecretKey" "sk_test_..." dotnet user-secrets set "Stripe:WebhookSecret" "whsec_..."
Run migrations
Create the orders and inventory schema.
dotnet ef database update --project src/CartFlow.Infrastructure
Running the Project
Run the API
Start CartFlow — Scalar docs at /scalar/v1.
dotnet run --project src/CartFlow.Api
Run the checkout flow
Add to cart, reserve inventory, and complete payment.
# Add item to cart
curl -X POST http://localhost:5000/api/cart/items \
-H "Content-Type: application/json" \
-d '{"productId": 1, "quantity": 2}'
# Start checkout (reserves inventory)
curl -X POST http://localhost:5000/api/checkout/start
# Complete payment
curl -X POST http://localhost:5000/api/checkout/confirm \
-d '{"paymentMethodId": "pm_card_visa"}'Project Info
Tech Stack
Prerequisites
- .NET 9 SDK installed
- Docker Desktop installed
- Stripe test account (free) — test card numbers provided
Learnixo
Project Author
Checkout is the most failure-sensitive flow in e-commerce. This project shows the real patterns — optimistic concurrency for inventory, idempotency keys for Stripe, and a saga with working compensation — not the tutorial version that collapses under concurrent load.