A simplified marketplace ecommerce system for ordering and invoicing, built with NestJS microservices architecture and Domain-Driven Design patterns.
The system consists of two microservices that communicate asynchronously via RabbitMQ:
Manages the complete order lifecycle with 5 statuses:
- Created
- Accepted
- Rejected
- Shipping in progress
- Shipped
API Endpoints:
POST /orders- Create a new orderGET /orders- List all orders (supports filtering by sellerId)GET /orders/:id- Get order detailsPATCH /orders/:id/status- Update order status
Handles invoice management and automatic sending when orders are shipped.
API Endpoints:
POST /invoices- Upload invoice PDF for an orderGET /invoices/:orderId- Get invoice details for an order
- Framework: NestJS 10.x with TypeScript 5.x
- Database: MongoDB 7.0
- Message Broker: RabbitMQ 3.12
- Architecture: Domain-Driven Design with CQRS
- Testing: Jest
- Container: Docker & Docker Compose
- Node.js >= 18.0.0
- npm >= 9.0.0
- Docker and Docker Compose
npm installnpm run docker:upThis will start:
- MongoDB on port 27017
- RabbitMQ on port 5672 (management UI on 15672)
Order Service:
npm run start:dev:orderInvoice Service:
npm run start:dev:invoice- Order Service: http://localhost:3001
- Invoice Service: http://localhost:3002
- RabbitMQ Management: http://localhost:15672 (admin/admin123)
# Run all tests
npm test
# Run tests with coverage
npm run test:cov
# Run linting
npm run lintcurl -X POST http://localhost:3001/orders \
-H "Content-Type: application/json" \
-d '{
"productId": "prod-123",
"customerId": "cust-456",
"sellerId": "seller-789",
"price": 99.99,
"quantity": 2
}'curl -X PATCH http://localhost:3001/orders/{orderId}/status \
-H "Content-Type: application/json" \
-d '{
"status": "Accepted"
}'curl -X POST http://localhost:3002/invoices \
-F "orderId={orderId}" \
-F "file=@invoice.pdf"marketplace-microservices/
├── apps/
│ ├── order-service/ # Order management microservice
│ │ ├── src/
│ │ │ ├── domain/ # Domain layer (entities, value objects, events)
│ │ │ ├── application/ # Application layer (use cases)
│ │ │ ├── infrastructure/ # Infrastructure layer (repositories, controllers)
│ │ │ └── main.ts
│ │ ├── test/
│ │ ├── Dockerfile
│ │ └── package.json
│ └── invoice-service/ # Invoice management microservice
│ ├── src/
│ │ ├── domain/
│ │ ├── application/
│ │ ├── infrastructure/
│ │ └── main.ts
│ ├── test/
│ ├── Dockerfile
│ └── package.json
├── libs/ # Shared libraries
│ └── common/ # Common utilities and types
├── docker-compose.yml
└── package.json
Each service follows DDD principles:
- Domain Layer: Entities, value objects, aggregates, domain events
- Application Layer: Use cases, DTOs, application services
- Infrastructure Layer: Repositories, controllers, event handlers, external integrations
PORT- Service port (default: 3001)MONGODB_URI- MongoDB connection stringRABBITMQ_URI- RabbitMQ connection string
PORT- Service port (default: 3002)MONGODB_URI- MongoDB connection stringRABBITMQ_URI- RabbitMQ connection stringUPLOAD_DIR- Directory for storing uploaded PDFs
# Format code
npm run format
# Build all services
npm run buildEach service includes a production-ready Dockerfile:
# Build and start with Docker Compose
docker-compose up --buildThe project includes a GitHub Actions workflow that:
- Runs linting and type checking
- Executes all tests
- Builds production Docker images
- Runs security audits
ISC