Event-Driven-E-Commerce
Full-stack e-commerce platform: Next.js 16 storefront + Spring Boot 3.5 / Java 21 backend (microservices + deployable monolith).
A production-grade full-stack e-commerce platform with a Next.js frontend and Spring Boot microservices backend. The backend combines four domain services (User, Product, Order, Inventory) into a single deployable monolith using build-helper-maven-plugin. Cross-module communication uses Spring ApplicationEvent with @TransactionalEventListener and @Async, with optional Kafka for distributed deployments. Demo Credentials | Role | Email | Password | |---|---|---| | User | Register at /register | your choice | 1. Register at /register, then browse Products. 2.
Summary extracted from the README.
ShopFlow β Full-Stack E-Commerce Platform
A production-grade full-stack e-commerce platform with a Next.js frontend and Spring Boot microservices backend. The backend combines four domain services (User, Product, Order, Inventory) into a single deployable monolith using build-helper-maven-plugin. Cross-module communication uses Spring ApplicationEvent with @TransactionalEventListener and @Async, with optional Kafka for distributed deployments.
π Live Demo
| Link | |
|---|---|
| ποΈ Frontend (Vercel) | https://event-driven-e-commerce.vercel.app |
| βοΈ REST API (Render) | https://event-driven-e-commerce.onrender.com |
| π Swagger UI | https://event-driven-e-commerce.onrender.com/swagger-ui.html |
β οΈ The free Render backend spins down after inactivity. First request may take 30β60 seconds to wake up. A scheduled GitHub Action (
.github/workflows/keep-alive.yml) pings it every 10 minutes during daytime hours (US Central) to reduce cold starts, and the site shows a "waking up the server" notice when a request is slow.
Demo Credentials
| Role | Password | |
|---|---|---|
| User | Register at /register |
your choice |
Admin credentials are available on request.
Try it in 2 minutes
-
Register at /register, then browse Products.
-
Add to cart β add two or more products (or use Buy now on a product page).
-
Open the Cart β Proceed to checkout, then enter a delivery address (tick Save this address to reuse it next time).
-
Click Place order & pay. You land on Stripe's hosted page β it runs in test mode, so no real money moves:
Field Value Card number 4242 4242 4242 4242Expiry / CVC any future date / any 3 digits Name / ZIP anything -
You return to a Payment received page; My Orders shows the order as CONFIRMED with its Ship to address.
-
Cancel an order from an admin account and the stock is restocked and the payment is refunded automatically.
Screenshots
| Browse | Cart |
|---|---|
![]() |
![]() |
| Checkout (delivery address) | Payment received |
|---|---|
![]() |
![]() |

π€ AI Integration (MCP Server)
ShopFlow includes a Model Context Protocol (MCP) server that lets Claude AI manage the store through natural language.

What you can ask Claude
- "Show me all pending orders"
- "Get all products"
- "Update inventory for product X to 50 units"
- "Confirm order abc-123"
- "Show me store statistics"
Setup
cd shopflow-mcp
python -m venv venv
venv\Scripts\activate # Windows
pip install -r requirements.txt
Add to Claude Desktop config (%APPDATA%\Claude\claude_desktop_config.json):
{
"mcpServers": {
"shopflow": {
"command": "/path/to/shopflow-mcp/venv/Scripts/python.exe",
"args": ["/path/to/shopflow-mcp/server.py"],
"env": {
"SHOPFLOW_ADMIN_EMAIL": "admin@shopflow.com",
"SHOPFLOW_ADMIN_PASSWORD": "your-admin-password"
}
}
}
}
Frontend (shopflow-frontend/)
Built with Next.js 14, Tailwind CSS, and shadcn/ui. Connects to the Spring Boot backend via REST API.
| Page | Description |
|---|---|
/ |
Home page with hero and features |
/products |
Product catalog with search, category filter, pagination |
/products/[id] |
Product detail page with stock level, add to cart and buy now |
/cart |
Shopping cart (saved in the browser) with one multi-item checkout |
/orders |
My orders with cancel button (user) |
/orders/confirmation |
Order success screen (payments disabled) |
/orders/success |
Shown after Stripe payment; waits for the order to be confirmed |
/profile |
Account details and order statistics |
/login / /register |
Auth pages with JWT |
/admin |
Dashboard with stats and recent orders |
/admin/products |
Product CRUD |
/admin/categories |
Category management |
/admin/inventory |
Stock adjustment |
/admin/orders |
All orders with status update |
/admin/users |
All users |
Stack: Next.js 14 Β· TypeScript Β· Tailwind CSS Β· shadcn/ui Β· React Query Β· Zustand Β· Axios
Features
- JWT authentication with role-based access (USER / ADMIN)
- Product catalog with full-text search and category filtering
- Shopping cart with multi-item orders, a saved address book, and a checkout step with a delivery address on every order
- Optional Stripe Checkout payments (card details never touch the app), with automatic refunds when a paid order is cancelled
- Order placement with automatic PENDING β CONFIRMED fulfillment
- User-initiated order cancellation (PENDING orders only)
- Product images (admin pastes an image URL; category-themed placeholders otherwise)
- Admin dashboard: revenue chart (last 14 days), orders by status, and management of orders, users, inventory, and categories
- Email notifications via Resend API (order confirmed, order cancelled, welcome)
- IP-based rate limiting via Bucket4j (20 req/min)
- Paginated responses throughout
- RFC 9457 Problem Details error format
- OpenAPI 3 spec at
/openapi.yaml
Architecture
flowchart LR
Browser["Next.js frontend<br/>(Vercel)"] -->|REST + JWT| API
subgraph API["shopflow-monolith (Spring Boot 3, Render)"]
U[user-service<br/>auth, profiles, addresses]
P[product-service<br/>catalog, search]
O[order-service<br/>orders, payments]
I[inventory-service<br/>stock, reservations]
end
O -- "order created (event)" --> I
I -- "stock reserved (event)" --> O
O <-->|"Checkout session / webhook / refund"| Stripe[(Stripe)]
API --> DB[(PostgreSQL)]
API -. "optional" .-> Kafka[(Apache Kafka)]
O -->|emails| Resend[Resend]
Order lifecycle
sequenceDiagram
actor C as Customer
participant F as Frontend
participant O as Order service
participant I as Inventory
participant S as Stripe
C->>F: Checkout (cart + delivery address)
F->>O: POST /orders (items, shippingAddress)
O->>I: reserve stock
O-->>F: order PENDING
F->>O: POST /orders/{id}/checkout
O->>S: create Checkout Session
S-->>C: hosted payment page (card details)
S->>O: webhook checkout.session.completed (signature verified)
O->>I: commit stock
O-->>C: order CONFIRMED + email
Note over O,S: Admin cancels a paid order β stock released + Stripe refund.<br/>Unpaid orders are cancelled automatically after 35 min.
When Kafka is unavailable (Render free tier), fulfillment runs synchronously via Spring ApplicationEvent β the order auto-confirms within seconds.
Tech Stack
| Layer | Technology |
|---|---|
| Language | Java 21 (Virtual Threads) |
| Framework | Spring Boot 3.x |
| Security | Spring Security 6 + JWT (JJWT 0.12) |
| Database | PostgreSQL |
| Messaging | Apache Kafka (optional) |
| Resend HTTP API | |
| Rate Limiting | Bucket4j 8.x (in-memory) |
| Build | Maven + build-helper-maven-plugin |
| Deployment | Docker + Render.com |
API Reference
Base URL: https://event-driven-e-commerce.onrender.com
All protected endpoints require:
Authorization: Bearer <token>
Auth
Register
POST /api/v1/auth/register
Content-Type: application/json
{
"name": "Alice",
"email": "alice@example.com",
"password": "secret123"
}
Response β 201 Created
{
"token": "eyJhbGci...",
"userId": "a1b2c3d4-...",
"email": "alice@example.com",
"name": "Alice",
"role": "USER"
}
A welcome email is sent to the registered address.
Login
POST /api/v1/auth/login
Content-Type: application/json
{
"email": "alice@example.com",
"password": "secret123"
}
Response β 200 OK β same shape as register response.
Admin account: created at startup from the
ADMIN_EMAIL(defaultadmin@shopflow.com) andADMIN_PASSWORDenvironment variables. There is no default password β ifADMIN_PASSWORDis unset (or under 12 characters) no admin is created or changed.
User Profile
Get my profile
GET /api/v1/users/me
Authorization: Bearer <token>
Response β 200 OK
{
"id": "a1b2c3d4-...",
"name": "Alice",
"email": "alice@example.com",
"role": "USER",
"createdAt": "2026-06-17T03:26:27"
}
Get user by ID (Admin only)
GET /api/v1/users/{id}
Authorization: Bearer <admin-token>
Categories
List all categories (public)
GET /api/v1/categories
Response β 200 OK
[
{
"id": "9129a5e4-99be-4720-b886-4bb0f01813cc",
"name": "Electronics",
"description": "Electronic devices and accessories"
}
]
Create category (Admin only)
POST /api/v1/categories
Content-Type: application/json
Authorization: Bearer <admin-token>
{
"name": "Electronics",
"description": "Electronic devices and accessories"
}
Response β 201 Created β category object.
Products
List products (public)
GET /api/v1/products?page=0&size=20&q=headphones&categoryId=<uuid>
| Param | Description |
|---|---|
q |
Full-text search on name and description |
categoryId |
Filter by category UUID |
page |
Page number (0-indexed, default 0) |
size |
Items per page (default 20) |
Response β 200 OK β paginated product list.
Get product by ID (public)
GET /api/v1/products/{id}
Create product (Admin only)
POST /api/v1/products
Content-Type: application/json
Authorization: Bearer <admin-token>
{
"name": "Wireless Headphones",
"description": "Noise-cancelling headphones",
"price": 99.99,
"sku": "WH-001",
"categoryId": "9129a5e4-99be-4720-b886-4bb0f01813cc"
}
Required: name, price, sku
Response β 201 Created β product object.
Update product (Admin only)
PUT /api/v1/products/{id}
Content-Type: application/json
Authorization: Bearer <admin-token>
{
"name": "Wireless Headphones Pro",
"price": 129.99,
"sku": "WH-001-PRO",
"categoryId": "9129a5e4-99be-4720-b886-4bb0f01813cc"
}
Delete product (Admin only)
DELETE /api/v1/products/{id}
Authorization: Bearer <admin-token>
Response β 204 No Content (soft delete β preserves order history)
Inventory
Check stock (public)
GET /api/v1/inventory/{productId}
Response β 200 OK
{
"id": "...",
"productId": "ee04ec8d-...",
"productName": "Wireless Headphones",
"quantity": 200,
"reservedQuantity": 0,
"availableQuantity": 200
}
Add stock (Admin only)
POST /api/v1/inventory
Content-Type: application/json
Authorization: Bearer <admin-token>
{
"productId": "ee04ec8d-...",
"productName": "Wireless Headphones",
"quantityToAdd": 100
}
Set absolute stock quantity (Admin only)
PUT /api/v1/inventory/{productId}
Content-Type: application/json
Authorization: Bearer <admin-token>
{
"quantity": 200
}
Response β 200 OK β updated inventory object.
Orders
Place order (authenticated)
POST /api/v1/orders
Content-Type: application/json
Authorization: Bearer <token>
{
"items": [
{
"productId": "ee04ec8d-...",
"quantity": 1
}
]
}
Names and prices are always taken from the product catalogue on the server; productName / unitPrice in the request are ignored. Repeated lines for the same product are merged, and unknown or deleted products return 400.
Response β 201 Created
{
"id": "f07d7d48-...",
"userId": "a1b2c3d4-...",
"userEmail": "alice@example.com",
"status": "PENDING",
"totalAmount": 99.99,
"items": [...],
"createdAt": "2026-06-18T22:10:08",
"updatedAt": "2026-06-18T22:10:08"
}
A confirmation email is sent once the order moves to CONFIRMED.
Order status lifecycle
PENDING β CONFIRMED (stock reserved; with Stripe enabled, once the payment succeeds)
β CANCELLED (insufficient stock, unpaid after the timeout, or cancelled by user/admin)
Pay for an order (authenticated β Stripe, optional)
POST /api/v1/orders/{id}/checkout
Authorization: Bearer <token>
Response β 200 OK β { "url": "https://checkout.stripe.com/..." }: redirect the customer there. url is null when payments are not enabled. 409 if the order is no longer PENDING.
See Payments (Stripe) for setup.
List my orders (authenticated)
GET /api/v1/orders?page=0&size=10
Authorization: Bearer <token>
Get order by ID (authenticated)
GET /api/v1/orders/{id}
Authorization: Bearer <token>
Cancel order (authenticated β PENDING only)
POST /api/v1/orders/{id}/cancel
Authorization: Bearer <token>
Only the order owner can cancel. Only PENDING orders can be cancelled.
Response β 200 OK β updated order with status: CANCELLED.
Response β 409 Conflict β if order is not in PENDING status.
A cancellation email is sent to the order owner.
Admin β Orders
Get all orders (paginated)
GET /api/v1/admin/orders?page=0&size=20&status=PENDING
Authorization: Bearer <admin-token>
status filter accepts: PENDING, CONFIRMED, CANCELLED
Get any order by ID
GET /api/v1/admin/orders/{id}
Authorization: Bearer <admin-token>
Update order status
PATCH /api/v1/admin/orders/{id}/status
Content-Type: application/json
Authorization: Bearer <admin-token>
{
"status": "CONFIRMED"
}
Response β 200 OK β updated order object. A status email is sent to the customer.
Admin β Users
List all users (paginated)
GET /api/v1/admin/users?page=0&size=20
Authorization: Bearer <admin-token>
Get user by ID
GET /api/v1/admin/users/{id}
Authorization: Bearer <admin-token>
π Cart, addresses & checkout
Browse β Add to cart β Checkout: pick a saved delivery address (or add a new one, optionally saving it to your account) β Place order & pay, which sends you to Stripe's hosted page for card details.
- Saved addresses live in the user service (
/api/v1/users/me/addresses, max 10 per user, one default). - Each order stores a copy of the address it ships to (
shippingAddressis required onPOST /api/v1/orders), so later edits don't change past orders. - Card and bank details are entered only on Stripe's page β the app never sees or stores them.
π³ Payments (Stripe)
Payment is optional. With no Stripe keys configured, orders are confirmed automatically (no payment step). With keys set:
POST /api/v1/orderscreates the order asPENDINGand reserves the stock.- The frontend calls
POST /api/v1/orders/{id}/checkoutand redirects to Stripe's hosted payment page. Card data never touches this app. - Stripe calls
POST /api/v1/payments/webhook(signature-verified). A paid session confirms the order and commits the stock. - Orders still unpaid after
UNPAID_ORDER_TIMEOUT_MINUTES(default 35) are cancelled and their stock is released. A payment that arrives for an order that can no longer be confirmed, or with the wrong amount, is refunded automatically. - If an admin cancels an order that was already paid, the stock is released and the payment is refunded (the Stripe payment ID is stored on the order). A failed refund is logged as
REFUND FAILEDso it can be done by hand in the Stripe dashboard.
Setup (test mode)
- Create a free Stripe account and stay in test mode. Copy the secret key (
sk_test_...) from Developers β API keys. - Developers β Webhooks β add endpoint
https://<your-api>/api/v1/payments/webhook, eventcheckout.session.completed. Copy its signing secret (whsec_...). - Set
STRIPE_SECRET_KEY,STRIPE_WEBHOOK_SECRETandFRONTEND_URL(the deployed frontend, used for the success/cancel redirects) on the backend. Never commit them. - Pay with the test card
4242 4242 4242 4242, any future expiry, any CVC.
ποΈ Database migrations (Flyway)
The monolith's schema is managed by Flyway (shopflow-monolith/src/main/resources/db/migration), and Hibernate runs with ddl-auto: validate, so the app refuses to start if the entities and the database disagree instead of silently altering tables.
V1__baseline_schema.sqlcreates the full schema. Every statement is idempotent, so it is a no-op on the original live database (built earlier byddl-auto: update, adopted by Flyway as baseline version 0) and builds everything on a fresh one.- To change the schema, add
V2__describe_change.sql(and so on). Never edit a migration that has already been applied β Flyway checksums them and will refuse to start. - The microservice modules keep their own migrations; only the monolith uses this folder.
Integration tests
mvn verify also runs integration tests in shopflow-monolith (Testcontainers: real Postgres 16 + Redis in Docker, needs Docker running; they are skipped automatically without it):
- Fresh database β Flyway builds the schema, Hibernate validates it, then a full order is placed, confirmed and restocked on cancel over HTTP; address books are isolated per user.
- Legacy database β a Hibernate-built schema with existing data (the production upgrade path) is adopted by Flyway with no data loss.
Email Notifications
Sent via Resend HTTP API:
| Trigger | |
|---|---|
| User registers | Welcome email |
| Order confirmed | Order confirmation with items and total |
| Order cancelled (by user) | Cancellation notice |
| Admin updates order to CONFIRMED | Confirmation email |
| Admin updates order to CANCELLED | Cancellation notice |
Rate Limiting
IP-based, in-memory via Bucket4j:
- 20 requests per minute per IP
- Exceeding the limit returns
429 Too Many Requests
Error Format
All errors follow RFC 9457 Problem Details:
{
"type": "about:blank",
"title": "Bad Request",
"status": 400,
"detail": "name is required",
"instance": "/api/v1/products"
}
| Status | Meaning |
|---|---|
| 400 | Validation failed |
| 401 | Missing or invalid JWT |
| 403 | Insufficient role |
| 404 | Resource not found |
| 409 | Business rule conflict (e.g. cancel non-PENDING order, duplicate SKU) |
| 429 | Rate limit exceeded |
| 500 | Internal server error |
Running Locally
Prerequisites: Java 21, Maven 3.9+, Docker Desktop
1. Start infrastructure
docker compose up -d
Starts the full microservices stack: PostgreSQL, Redis, Kafka (KRaft, no Zookeeper), Eureka, the API gateway on http://localhost:8080, and the user / product / order / inventory / notification services. JWT_SECRET is required (see below); set it in a .env file next to docker-compose.yml.
To run only the infrastructure for the monolith: docker compose up -d postgres redis kafka.
2. Set environment variables
export JWT_SECRET="$(openssl rand -base64 48)" # required, 32+ bytes
export ADMIN_PASSWORD="choose-a-strong-password" # required to create the admin account, 12+ chars
export RESEND_API_KEY=re_your_key_here # optional β emails are skipped without it
3. Run the monolith
cd shopflow-monolith
mvn spring-boot:run
API available at http://localhost:10000
Environment variables
| Variable | Default | Description |
|---|---|---|
SPRING_DATASOURCE_URL |
jdbc:postgresql://localhost:5432/shopflow_db |
PostgreSQL URL |
SPRING_DATASOURCE_USERNAME |
shopflow |
DB username |
SPRING_DATASOURCE_PASSWORD |
shopflow123 |
DB password |
JWT_SECRET |
β (required) | 32+ bytes; the app refuses to start without it |
ADMIN_EMAIL |
admin@shopflow.com |
Admin account email |
ADMIN_PASSWORD |
β | Admin password (12+ chars). Admin is not created/updated when unset |
KAFKA_LISTENERS_ENABLED |
false |
Monolith only: run the Kafka saga listeners (the in-process fulfilment is the default) |
RATE_LIMIT_CLIENT_IP_HEADER |
CF-Connecting-IP |
Trusted header with the real client IP for rate limiting |
SPRING_KAFKA_BOOTSTRAP_SERVERS |
localhost:9092 |
Kafka broker (optional) |
RESEND_API_KEY |
β | Resend API key for emails (optional) |
STRIPE_SECRET_KEY |
β | Stripe secret key (sk_test_...). Payments are enabled only when this and the webhook secret are set |
STRIPE_WEBHOOK_SECRET |
β | Stripe webhook signing secret (whsec_...) |
FRONTEND_URL |
http://localhost:3000 |
Frontend base URL for Stripe's success/cancel redirects |
UNPAID_ORDER_TIMEOUT_MINUTES |
35 |
Unpaid orders are cancelled and their stock released after this long |
Project Structure
shopflow/
βββ docker-compose.yml
βββ Dockerfile.monolith
βββ shopflow-monolith/ β deployable artifact
β βββ src/main/java/com/shopflow/monolith/
β βββ config/ β Security, JWT filter, rate limiting, event listeners
β βββ controller/ β Admin controllers
β βββ exception/ β Global exception handler
β βββ notification/ β Email service (Resend)
βββ user-service/
βββ product-service/
βββ order-service/
βββ inventory-service/
Each service follows:
src/main/java/com/shopflow/<service>/
βββ controller/
βββ service/
βββ repository/
βββ entity/
βββ dto/
βββ event/
βββ config/
βββ exception/



