https://github.com/permaficus/lef4cart
Shopping cart with RESTFul API and Message Broker
https://github.com/permaficus/lef4cart
api e-commerce event-driven-architecture express-js microservices nodejs rabbitmq rest-api shopping-cart typescript
Last synced: about 1 month ago
JSON representation
Shopping cart with RESTFul API and Message Broker
- Host: GitHub
- URL: https://github.com/permaficus/lef4cart
- Owner: permaficus
- License: mit
- Created: 2024-01-23T03:29:34.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-20T14:47:49.000Z (about 2 years ago)
- Last Synced: 2024-05-22T04:27:09.774Z (about 2 years ago)
- Topics: api, e-commerce, event-driven-architecture, express-js, microservices, nodejs, rabbitmq, rest-api, shopping-cart, typescript
- Language: TypeScript
- Homepage:
- Size: 140 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# LEF4CART
## Overview
Lef4Cart is a micro shopping cart app that is FREE and open source. One of its standout features is the use of RabbitMQ as a message broker. Additionally, Lef4Cart uses the standard HTTP protocol for data transmission
See environment example
## ENVIRONMENT EXAMPLE
```shell
# USING AT DOCKER CONTAINER
DATABASE_URL="mongodb://username:password@host.docker.internal:27017/shoppingCart?retryWrites=true&authSource=admin&directConnection=true"
# USING AT LOCALHOST
DATABASE_URL="mongodb://username:password@localhost:27017/shoppingCart?retryWrites=true&authSource=admin&directConnection=true"
## APP ENV
NODE_ENV="DEVELOPMENT"
## RABBITMQ ENV
RBMQ_URL="amqp://username:password@localhost:5672"
# CONFIG FOR CONSUMER
RBMQ_CART_EXCHANGE="lef4cart"
RBMQ_CART_QUEUE="sub.cartMessageQueue"
RBMQ_CART_ROUTING_KEY="cartMessageRoutingKey"
# CONFIG FOR PUBLISHER
RBMQ_PUB_QUEUE="pub.cartMessageQueue"
RBMQ_PUB_ROUTING_KEY="pub.MessageRouting"
## LOCAL SERVICE ENV
SERVICE_LOCAL_PORT="8081"
## DOCKER ENV
COMPOSE_PROJECT_NAME="shopping-cart"
```
## API
Endpoint :
* `/v1/shopping-cart` : method would be `POST, PATCH, DELETE`
* `/v1/shopping-cart/{userId}` : method `GET`
POST Body JSON attribute
```json
{
"task": "create",
"payload": {
"apps_id": "6606cc8ed9c25c6c5f00b48b",
"merchant_id": "5798426b-8c7c-4064-b43b-d51e5ef6067b",
"merchant_name": "My Favorite Store",
"session_id": "a0a8ae1a-aa31-488c-9a6c-cfda44202446",
"user_id": "deanknowles@valpreal.com",
"product_id": "6606cc8e1b69fbabf8a3b534",
"product_image": "https://images.mediaservice.io/example.jpeg",
"product_name": "Apple Vision Pro",
"price": 1000000,
"quantity": 1
}
}
```
READ Body JSON attribute
```json
{
"task": "read",
"payload": {
"user_id": "deanknowles@valpreal.com"
}
}
```
> [!NOTE]
>
> Payload on READ Request Body only works when you're using RabbitMQ
PATCH Body JSON attribute
```json
{
"task": "update",
"payload": {
"user_id": "deanknowles@valpreal.com",
"product_id": "6606cc8e1b69fbabf8a3b534",
"quantity": 2,
"params": "params"
}
}
```
> `PARAMS:` value must be `increment` or `decrement`
DELETE Body JSON attribute
```json
{
"task": "delete",
"payload": {
"id": ["arrayOfIDs"]
}
}
```
>`arrayOfIDs`: ID must be in array format consist of cart ID / ID's. eg: [1, 2, 3, 4]
>[!NOTE]
> `task` consist of `create`, `read`, `update` and `delete`
## 📍 Task Description & Method
| Task | Method | Minimum Payload |
| ---- | ------ | ------- |
| `create` | POST | `user_id`, `product_id`, `product_image`, `product_name`, `price`, `quantity` |
| `read` | GET | `user_id` |
| `update` | PATCH | `user_id`, `product_id`, `quantity` |
| `remove` | DELETE | `[id]` or `[cartId]` |
## RabbitMQ
Message Payload:
```json
{
"task": "create",
"payload": {
"apps_id": "6606cc8ed9c25c6c5f00b48b",
"merchant_id": "5798426b-8c7c-4064-b43b-d51e5ef6067b",
"merchat_name": "XYZ Company",
"merchant_name": "My Favorite Store",
"session_id": "a0a8ae1a-aa31-488c-9a6c-cfda44202446",
"user_id": "deanknowles@valpreal.com",
"product_id": "6606cc8e1b69fbabf8a3b534",
"product_image": "https://images.mediaservice.io/example.jpeg",
"product_name": "Apple Vision Pro",
"price": 1000000,
"quantity": 1
},
"origin": {
"queue": "customerOrder",
"routingKey": "customerOrderKey"
}
}
```
## Attribute descriptions
| Element | Description| Required |
| ------- | ----------- | -------- |
| `task` | `create`, `read`, `update`, `delete` | Required
| `payload` | `Object`: Item details | Required
| `apps_id` | `String`: (eg: server-key or service id) | Optional
| `merchant_id` | `String` | Optional
| `merchant_name` | `String` | Optional
| `session_id` | `String` | Optional
| `user_id` | `String`: (eg: email or random token) | Required
| `product_id` | `String`: (eg: Product SKU) | Required
| `product_image` | `String`: value must be valid URL format | Required
| `product_name` | `String` | Required
| `price` | `Number` | Required
| `quantity` | `Number` | Required
| `custom_fields` | `Object`: [see example](#custom-fields-on-payload) | Optional
| `product_links` | `Object`: [see example](#product-links-attribute-example) | Optional
| `origin` | `Object`: consist of two key [`queue`, `routingKey`] only required when using MQTT protocols | Required
| `params` | `String`: value must be `decrement` or `increment`. Required when updating items quantity | Required
## Custom Fields on Payload
Custom fields allow you to add any extra info on user items, such as brand name, item size, color, and more.
Body JSON Attribute
```json
{
"task": "create",
"payload": {
"custom_fields": {
"brand": "XYZ",
"color": "Green",
"size": "XL"
}
}
}
```
## Product Links Attribute Example
In the `product_links` field, you can include attributes such as URL, shortened URL, catalog link, etc. To facilitate the Front-End team, you can add attributes like href, rel, and others.
Example
```json
{
"product_links": {
"url": "https://resource.e-commerce.app/product/apple-vision-pro-x",
"rel": "_blank",
"brochure": {
"url": "https://resource.e-commerce.app/product/apple-vision-pro-x/brochure.pdf",
"method": "GET"
}
}
}
```
OR
```json
{
"product_links": {
"video_preview": "https://preview.media.app/dasno238as3/demo.video",
"video_link": "https://www.youtube.com/watch?v=abcdef"
}
}
```