A modern, scalable e-commerce application built with a microservices architecture. This project demonstrates a decoupled system design where distinct business domains are handled by independent services, orchestrating a seamless shopping experience from product discovery to shipping.
Project 005 is designed to simulate a real-world e-commerce ecosystem. It features a responsive Next.js frontend interacting with a suite of backend microservices via REST APIs. The platform supports key e-commerce flows including user authentication, product catalog browsing, cart management, checkout with promotions, order tracking, and shipping dispatch.
The system is composed of the following microservices:
- Frontend (Dashboard-Admin): A Next.js application (React) with Tailwind CSS, acting as the user interface and API gateway aggregator.
- User Service: Manages user authentication (JWT) and profiles.
- Product Service: Handles product catalog, details, and enriched data (aggregated from Inventory).
- Order Service: Manages order creation, lifecycle (Pending -> Delivered), and history.
- Cart Service: persistent shopping cart management with support for promotions and shipping address association.
- Inventory Service: Tracks stock levels and handles reservations/deductions.
- Shipping Service: Manages shipping addresses, mock distributor integration, and shipment tracking.
- Promotions Service: specific logic for validating and applying discount codes.
- Wishlist Service: Allows users to save products for later.
- Customer Service: An aggregation layer ("BFF" pattern) for providing comprehensive customer views to the frontend (e.g., Admin Customer Details).
- Frontend: Next.js 14 (App Router), TypeScript, Tailwind CSS, Lucide Icons.
- Backend: Node.js, Express, TypeScript.
- Infrastructure: Docker, Docker Compose for orchestration.
- Communication: REST over HTTP.
- Data: In-memory mock databases (for demonstration simplicity) with persistent patterns.
- Node.js (v18+)
- Docker & Docker Compose
The easiest way to run the entire system is via Docker Compose.
-
Build and Start Services:
docker-compose up -d --build
-
Access the Application: Open http://localhost:3000 in your browser.
Services will be running on ports 3001-3009 mapping to host localhost.
-
Stop Services:
docker-compose down
If you prefer running services individually (e.g., for debugging):
-
Frontend:
cd Dashboard-Admin npm install npm run devAccess at
http://localhost:3000. -
Backend Services: Each service in the
/servicesdirectory needs to be started separately.cd services/cart # (or any other service) npm install npm run dev
- Storefront: Browse products with "New Arrival" badges and rich details.
- Shopping Cart: Real-time cart updates, promo code application, and shipping address selection.
- User Accounts: Login/Register validation and profile management.
- Order Management: Detailed order history, status tracking, and dispatch simulation.
- Admin Dashboard:
- Promotions: Create and toggle discount codes.
- Customers: View customer details, order history, and addresses.
- Shipping: Dispatch orders to mock distributors.
- Responsive Design: Fully optimized for mobile and desktop experiences.
project-005/
βββ services/ # Backend Microservices
β βββ cart/
β βββ customer/
β βββ inventory/
β βββ order/
β βββ product/
β βββ promotions/
β βββ shipping/
β βββ user/
β βββ wishlist/
βββ Dashboard-Admin/ # Next.js Frontend
βββ docs/ # Documentation (Architecture, OpenAPI Specs)
βββ scripts/ # Utility and test scripts
βββ docker-compose.yml # Orchestration config
βββ README.md # This file
To ensure stability across the microservice ecosystem, all changes must strictly adhere to the OpenAPI specification.
- Backend Services:
- Must NOT change port numbers (3001, 3002, 3003, etc.).
- Must NOT change route signatures without explicit approval.
- Frontend (Dashboard-Admin):
- Must use the exact endpoints defined in the OpenAPI spec.
We employ a multi-layered testing strategy to ensure reliability across the microservices and frontend hierarchy.
- Backend (Unit & Integration): Jest, Supertest, ts-jest
- Frontend (Unit): Vitest, React Testing Library
- Frontend (E2E): Playwright
To run tests, you must first install dependencies in the respective directories:
1. Backend Services:
Navigate to any service (e.g., services/cart) and run:
cd services/cart
npm install # Installing dependencies
npm test # Runs Jest unit and API tests2. Frontend Unit Tests:
cd Dashboard-Admin
npm install # Installing dependencies
npm test # Runs Vitest unit tests3. Frontend E2E Tests (Playwright): For E2E tests, you need to install Playwright browsers first:
cd Dashboard-Admin
npm install
npx playwright install chromium --with-deps # Isolate browser binary installation
npm run test:e2e # Runs Playwright E2E testsThe test suite covers the following areas:
Each microservice is tested independently using Supertest and Jest.
- Customer Service:
GET /customers/me/orders: Fetching user order history.GET /customers/me/wishlist: Retrieving user wishlist items.- Unit tests for
CustomerControllerlogic.
- Product Service:
GET /store/products: Aggregating product data with inventory status.- Logic for calculating order statistics (e.g., "Total Orders").
- Order Service:
POST /orders: Order creation flow, including stock deduction via Inventory service mocks.GET /orders: Retrieving order details.
- Cart Service:
POST /cart/:id/items: Adding items, validating stock availability.POST /cart/:id/checkout: Converting cart to order.
- Inventory Service:
POST /products: Creating new inventory items.POST /products/:id/deduct: Handling stock reservations and insufficient stock errors.
- Shipping Service:
POST /shipping/dispatch: Generating tracking numbers and shipments.- Address management endpoints.
- Promotions Service:
POST /promotions/apply: Validating codes (percentage/fixed) and minimum order values.
- User Service:
POST /auth/register: User creation and duplicate checks.POST /auth/login: Credential validation and token generation.
- Wishlist Service:
- CRUD operations for managing user wishlists.
- Unit Tests (Vitest):
- Dashboard: Verifies rendering of "Recent Orders" and "Active Carts" components.
- Validation of client-side logic for data fetching hooks.
- E2E Tests (Playwright):
- Dashboard Loading: Verifies the application loads and displays critical information.
- Network Mocking: Demonstrates how to intercept calls to backend services (Cart, Customer, Promotions) to ensure UI tests are not flaky due to backend state.
While the current strategy ensures code quality and isolation, the following areas are planned for future improvements:
- Database Integration: Currently, services use in-memory mock databases. Future tests will integrate Testcontainers (Postgres/MongoDB) to validate actual SQL/NoSQL queries and transactions.
- Contract Testing: Implementing Pact to ensure API contracts between microservices (e.g., Order -> Inventory) are strictly accepted, preventing regression when API schemas change.
- Full E2E Integration: Adding a suite of "Live System" tests that run against the actual Dockerized environment (no mocks) to verify network connectivity and service discovery in a production-like setting.
- Error Scenarios: Expanding test coverage to simulate timeout/500 errors from dependent services (e.g., how Order Service handles Inventory downtime).
- Authentication: Implementing more rigorous JWT validation tests across all protected endpoints.
- Complex Promotions: Adding tests for edge cases like conflicting promotion rules or expiration dates.
- Frontend Flows: Expanding Playwright coverage to include the full "Checkout" wizard and "Product Details" interactions.