- Product service: serve and storage bussiness related to product.
- Activity service: listen user activity and persist to database, also serve API for marketing, analyzing.
Structure for both service:
├── Dockerfile <- packaging service
├── .dockerignore
├── .env.development <- environment variables
├── .eslintrc.json <- linter config
├── .gitignore <- gitignore
├── package.json
├── src
│ ├── config <- read config from .env and storage for apps
│ ├── controllers <- config routes && register controllers for each routes
│ ├── index.js <- entry point, declare app, register middlewares, trigger databases and message queue
│ ├── middlewares <- declare middleware
│ ├── queue <- init message queue, expose publisher and scribers
│ ├── schemas <- declare db connection, define data models
│ ├── services <- this layer interactive with datababase and message queue
│ └── utils <- include utilities function
├── tests <- include unit test
- Copy .env.development to .env at the current directory
- Run docker-compose up --build -d
- Wait a minutes, wait on the availability of a host and TCP port of Database and Message Queue containers.
- View log by run command docker-compose logs -f
For each service, following below step:
- Install mongodb, mysql, and rabbitmq on your local machine (1)
- Copy .env.development to .env for each service.
- Provide connection information of the software at (1) to .env for each service.
- Run npm install
- Run npm run start
curl --location --request POST 'localhost:3000/product/search' \
--header 'Content-Type: application/json' \
--data-raw '{
"page_size": 10,
"page_number": 1,
"filter": []
}'
curl --location --request POST 'localhost:3000/product/search' \
--header 'Content-Type: application/json' \
--data-raw '{
"page_size": 10,
"page_number": 1,
"filter": [
"id",
"name",
"price"
]
}'
curl --location --request POST 'localhost:3000/product/search' \
--header 'Content-Type: application/json' \
--data-raw '{
"page_size": 10,
"page_number": 1,
"filter": [
"id",
"name",
"price"
],
"sort": {
"price": "desc"
}
}'
curl --location --request POST 'localhost:3000/product/search' \
--header 'Content-Type: application/json' \
--data-raw '{
"page_size": 10,
"page_number": 1,
"filter": [
"id",
"name",
"price"
],
"sort": {
"price": "desc"
},
"search": {
"brand": "Apple",
"color": "RED"
}
}'
curl --location --request GET 'localhost:3001/activities' \
--header 'Content-Type: application/json'
npm run test
Locate the file coverage/index.html each repo and open it on Browser to see.
npm run eslint