A simple microservices infrastructure. All services are encapsulated in different virtual machines.
For the purpose of this exercise, the .env file is included in the repository.
- Core Technologies
- Installation: Development
- Database Migrations
- Installation: Production
- API Documentation
- Testing and Documentation Tools
- Node.js
- PostgreSQL
- RabbitMQ
- VirtualBox
- Vagrant
- PM2
- Postman
This project can be run in either development or production mode. The mode is controlled by the ENVIRONMENT variable in the .env file.
For this exercise, a pre-filled .env file is included in the repository.
The easiest way to get everything up and running is to run a single script that installs all the required packages, creates databases with users, performs database migrations and starts all 3 applications. Make sure that the .env file ENVIRONMENT value is set to DEVELOPMENT.
If you don't have a local PostgreSQL database set up, be sure to update the .env file. Databases run locally for both development and production environments.
./scripts/setup-development.sh
Set the production environment variable in the .env file.
ENVIRONMENT=DEVELOPMENTNavigate to the correct directory.
cd src/billing-app/Install the required packages.
npm installSetup the database.
cd ../.. && ./scripts/billing-app/setup-billing-db.shRun database migrations.
cd src/inventory-app/ && npm run db:migrateStart the server.
npm run startNavigate to the correct directory.
cd src/inventory-app/Install the required packages.
npm installSetup the database.
cd ../.. && ./scripts/inventory-app/setup-inventory-db.shRun database migrations.
cd src/inventory-app/ && npm run db:migrateStart the server.
npm run startNavigate to the correct directory.
cd src/api-gateway/Install the required packages.
npm installStart the server.
npm run startbilling-app and inventory-app use PostgreSQL database and have migrations set up with Sequalize. Make sure to be in the correct application folder.
Run database migrations
npm run db:migrateRoll back the last database migration.
npm run db:migrate:undoRoll back all database migrations.
npm run db:migrate:undo:all- Minimum 4GB RAM (for running 3 VMs).
- ~10GB available disk space.
- Processor with virtualization support enabled.
Set the environment variable in the .env file.
ENVIRONMENT=PRODUCTIONStart the virtual machines.
vagrant upThis will automatically:
- Configure all three virtual machines (gateway-vm, inventory-vm, billing-vm).
- Set up PostgreSQL databases.
- Configure RabbitMQ.
- Start all services using PM2. You can check the status of the virtual machines and services:
vagrant status # Check VM status
vagrant ssh <vm-name> # SSH into specific VM
sudo pm2 list # Check running servicesThe API is documented using OpenAPI 3.0 specification (openapi.yaml). The documentation includes:
- Complete endpoint descriptions
- Request/response schemas
- Example payloads
- Error responses
The documentation runs on the Gateway VM and provides a comprehensive overview of all available endpoints and their functionality.
http://localhost:8000/api-docshttps://192.168.56.10:8000/api-docsThe project includes comprehensive Postman collections for testing all API endpoints. It also includes two sets of environment variables. These can be used to test both production and development endpoints with the same Postman collection.
- Gateway Tests
- Movies (CRUD operations)
- Billing (Order creation)
- Direct API Tests
- Inventory API (direct testing of movie service)
- Test Suites
- Movie CRUD sequence
- DELETE All Movies (Clean Start)
- GET All Movies (Verify Empty)
- Create Movie
- Get Movie by ID
- Update Movie by ID
- Get Movie by Title
- Delete Movie by ID
- Movie CRUD sequence
To test the billing queue functionality:
-
Send order while billing-app is running
- Verify order appears in database
-
Stop billing-app:
pm2 stop billing-api- Send order
- Verify Gateway accepts it
-
Start billing-app:
pm2 start billing-api- Verify queued order appears in database
