A comprehensive order management system built with Node.js, TypeScript, and PostgreSQL. Features include user authentication, product catalog, shopping cart functionality, order processing, and automated invoice generation with queue-based processing.
- User Management: Registration, authentication with JWT
- Product Catalog: Browse and filter products
- Shopping Cart: Add/remove items, manage quantities
- Order Processing: Create orders with inventory management
- Address Management: Multiple shipping addresses per user
- Automated Invoicing: Queue-based PDF invoice generation
- File Storage: S3-compatible storage for invoices
- Database: PostgreSQL with TypeORM migrations
- Runtime: Node.js with TypeScript
- Framework: Express.js
- Database: PostgreSQL
- ORM: TypeORM with migrations
- Authentication: JWT (JSON Web Tokens)
- Password Hashing: bcrypt
- Validation: class-validator, class-transformer
- Message Queue: Redis (simple list-based implementation)
- PDF Generation: PDFKit
- File Storage: AWS S3 SDK with LocalStack (for local development)
- Container Orchestration: Docker Compose
- TypeScript: Type safety and modern JavaScript features
- Docker: Containerized Redis and LocalStack services
- Jest: Testing framework
- Migration System: TypeORM migrations for database schema
order-management-system/
├── controllers/ # API route handlers
├── services/ # Business logic layer
├── repositories/ # Data access layer
├── entities/ # TypeORM database entities
├── dto/ # Data transfer objects
├── middlewares/ # Express middlewares (auth, logging, error)
├── routes/ # API route definitions
├── db/ # Database configuration and migrations
├── validators/ # Input validation
├── utils/ # Utility functions and constants
├── docker-compose.yml # Local development services
├── invoice-consumer.ts # Standalone invoice processing service
└── app.ts # Main application entry point
- Node.js (v16 or higher)
- PostgreSQL database
- Docker and Docker Compose (for Redis and LocalStack)
- Clone the repository
git clone <repository-url>
cd order-management-system- Install dependencies
npm install- Set up environment variables
Create a
.envfile with the following:
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=password
DB_DATABASE=order_management
# JWT Configuration
JWT_SECRET=your-secret-key
# Redis Configuration
REDIS_URL=redis://localhost:6379
# AWS/LocalStack Configuration
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=test
AWS_SECRET_ACCESS_KEY=test
S3_ENDPOINT=http://localhost:4566
S3_BUCKET_NAME=order-invoices- Start infrastructure services
# Start Redis and LocalStack
docker-compose up -d
# Verify services are running
docker-compose ps- Run database migrations
npm run migration:run- Build the application
npm run build- Start the main API server (in one terminal):
npm run start-serverThe API will be available at http://localhost:3000
- Start the invoice consumer (in another terminal):
npm run start-consumernpm run start-server- Start the main API servernpm run start-consumer- Start the invoice processing consumernpm run build- Compile TypeScript to JavaScriptnpm run dev-consumer- Start consumer with auto-rebuildnpm run migration:generate- Generate new database migrationnpm run migration:run- Run pending migrationsnpm run migration:revert- Revert last migration
The system implements a Redis-based queue that processes order events and generates PDF invoices, which are then stored in S3 (LocalStack for local development).
- QueueService: Redis-based message queue implementation
- PDFInvoiceService: Generates professional PDF invoices
- S3Service: Handles uploading invoices to S3 (LocalStack)
- InvoiceProcessorService: Consumes queue messages and orchestrates invoice generation
- OrderService: Publishes order created events to the queue
- When an order is created via the API, the
OrderServicepublishes anORDER_CREATEDevent to theorder-eventsqueue - The invoice consumer (
InvoiceProcessorService) processes these events - For each order event, it generates a professional PDF invoice and uploads it to S3
- The invoice URL is logged and can be accessed via the S3 endpoint
Order Creation API
↓
OrderService
↓ (publishes ORDER_CREATED event)
Redis Queue (order-events)
↓ (consumer processes)
InvoiceProcessorService
↓
PDFInvoiceService
↓ (generates PDF)
S3Service
↓ (uploads to)
LocalStack S3
POST http://localhost:3000/api/orders
Content-Type: application/json
Authorization: Bearer <your-jwt-token>
{
"addressId": 1,
"items": [
{
"productId": 1,
"quantity": 2
}
]
}- Check consumer logs to see invoice processing
- Check S3 bucket for uploaded invoices:
# List all invoices (requires AWS CLI)
aws --endpoint-url=http://localhost:4566 s3 ls s3://order-invoices/invoices/- Access invoice URLs directly:
http://localhost:4566/order-invoices/invoices/order-X-invoice-timestamp.pdf
Monitor queue length:
redis-cli LLEN order-eventsCheck Docker services:
docker-compose ps
docker-compose logs redis
docker-compose logs localstackConnect to PostgreSQL:
psql -h localhost -U postgres -d order_management- Ensure Redis is running:
docker-compose ps - Check Redis logs:
docker-compose logs redis - Restart Redis:
docker-compose restart redis
- Ensure LocalStack is running and healthy:
docker-compose ps - Check LocalStack logs:
docker-compose logs localstack - Restart LocalStack:
docker-compose restart localstack
- Check consumer logs for errors
- Verify queue has messages:
redis-cli LLEN order-events - Restart consumer:
npm run start-consumer
- Run migrations:
npm run migration:run - Check database connection in logs
- Verify PostgreSQL is running and accessible
- New API Endpoints: Add controllers, routes, and services
- Database Changes: Generate and run migrations
- Queue Events: Update
QueueMessageinterface and add handlers - Tests: Add unit and integration tests
# Start consumer with auto-rebuild
npm run dev-consumer
# Generate new migration
npm run migration:generate -- -n NewFeatureName
# Run tests
npm testPOST /api/auth/register- User registrationPOST /api/auth/login- User login
GET /api/products- List products (with filters)GET /api/products/:id- Get product details
POST /api/cart/add- Add item to cartGET /api/cart- Get cart contentsDELETE /api/cart/remove- Remove item from cart
POST /api/orders- Create new orderGET /api/orders- Get user ordersGET /api/orders/:id- Get order detailsPUT /api/orders/:id- Update order status
POST /api/addresses- Create addressGET /api/addresses- Get user addresses
MIT License - see LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
Built with ❤️ using TypeScript, Node.js, and modern development practices.