Inventory service for icommerce, this is the example of creating extensible & scalable nodeJS backend microservices. This project is follow The Twelve-Factor App
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
This solution follow Microservice, Services must be loosely coupled so that they can be developed, deployed and scaled independently and different services have different data storage requirements
https://www.getpostman.com/collections/56b3f4b8a42c3aa2cc4d
Create Postman environment: development
Add 3 variables:
- token: null
- INVENTORY_URL: http://localhost:3001
- ACCOUNT_URL: http://localhost:3000
├── dist # Build folder
├── libs # Library folder
│ └── slug
├── migrations # Migration scripts
│ ├── factories
│ └── seeds
├── src
│ ├── product # Product Module
│ │ ├── controllers # API Controller
│ │ ├── entities # Data Model
│ │ ├── guards # App Guard/Firewall
│ │ └── services
│ └── tracking # Tracking Module
│ ├── controllers
│ ├── entities
│ └── services
└── test # E2E Test
We use 3 Postgres Databases, each microservice’s persistent data private to that service and accessible only via its API. A service’s transactions only involve its database.
- User Register SD
- User Login SD
- Product Search SD
What things you need to install & start development
- Node.js v10 or above
- Docker & Docker Compose to start Redis & PostgresDB
- Start docker containers
docker-compose up -d
- Install all package using yarn
yarn install
- Running the app
# development
$ yarn start
# watch mode
$ yarn start:dev
This project use Jest & NestJS test
This project only have 1 sample test for /libs.
yarn test
Run end to end test, you should stop the development server first
yarn test:e2e
Get the coverage report
yarn test:cov
We using eslint standard
yarn lint
All the environment config store in .env
# Development will enable Data Synchronize
NODE_ENV=development
# Application/Service PORT
PORT=3001
USER_SERVICE_PORT=4000
AUTH_SERVICE_PORT=4010
# Product Database
POSTGRES_HOST=localhost
POSTGRES_PORT=5456
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=inventory
# Tracking Database
TRACKING_POSTGRES_HOST=localhost
TRACKING_POSTGRES_PORT=5457
TRACKING_POSTGRES_USER=postgres
TRACKING_POSTGRES_PASSWORD=postgres
TRACKING_POSTGRES_DB=tracking
# Tracking Redis
TRACKING_REDIS_HOST=localhost
TRACKING_REDIS_PORT=6381
# JWT Config
JWT_SECRET=(this)(I)sSecre(t)
JWT_EXPIRES_IN=1h
http://localhost:3001/docs
- Author - [email protected]
This project is MIT licensed.