HOST: https://stage-expressapp.onrender.com
API endpoints
{
"userId": "51cface4-5a2c-4eaf-a4df-4c4b736bcf9d",
"itemId": "51cface4-5a2c-4eaf-a4df-4c4b736bcf3d",
"itemType": "Movie"
}- GET https://stage-expressapp.onrender.com/api/mylist?userId=51cface4-5a2c-4eaf-a4df-4c4b736bcf9d&page=1&limit=10
- DELETE https://stage-expressapp.onrender.com/api/mylist/
{
"userId": "51cface4-5a2c-4eaf-a4df-4c4b736bcf9d",
"itemId": "51cface4-5a2c-4eaf-a4df-4c4b736bcf4d"
}| Action | Command |
|---|---|
| 💻 Install dependencies | npm install |
| ⚙️ Setup environment variables. Create a .env file | MONGODB_URI=mongodb://localhost:27017/mylist PORT=3000 |
| ⚡ Run Script to initialize DB | npx ts-node initializeDBScript.ts |
| 🚀 Run the application | npm run dev-start |
npm test
| HTTP Method | API Endpoint | Request Body | Query Parameters |
|---|---|---|---|
| ❇️ GET | /api/mylist |
- | page=1&limit=10 |
| ✏️ POST | /api/mylist |
userId:"UUID",itemId:"UUID", itemType:"Movie/ TvSHow" | - |
| ❌ DELETE | /api/mylist |
userId:"UUID",itemId:"UUID" | - |
| HTTP Method | API Endpoint | Request Body | Query Parameters |
|---|---|---|---|
| ❇️ GET | /api/user/:user_id/mylist |
- | page=1&limit=10 |
| ✏️ POST | /api/user/:user_id/mylist |
itemId, itemType | - |
| ❌ DELETE | /api/user/:user_id/mylist/:item_id |
- | - |
Put myList field inside User Schema
User: {
id: string,
username: string,
...
...
myList: {
itemId: string,
itemType: string,
dateAddedOn: Date,
}
}✅ PROS:
- ✔️ Faster: No need to make extra call to fetch myList data.
- ✔️ Mylist information can be fetched initially from /api/me and save in local cache
- ✔️ Scalable: Any additional metadata can be added
🚨 CONS:
- ❗Tight Coupling: Dependency on User Schema
- ❗Not preferable for microservice arcitechure
- ❗UserService and MyList Service can not scale independently
Consider myList as a separate collection
== 2.1 ==
User: {
id: string,
username: string,
...
...
}
myList: {
userId: string,
itemId: string,
itemType: string,
dateAddedOn: Date,
}✅ PROS:
- ✔️ ListItems can be handled separately for all users
- ✔️ Addition and removal of new record is faster
- ✔️ Mongo Can filter or sort on the
dateAddedOnfield easily
🚨 CONS:
- ❗ Need to touch multiple documents to fetch myList of single user.
- ❗ Slower GET request
== 2.2 ==
User: {
id: string,
username: string,
...
...
}
myList: {
userId: string,
wishList: [{
itemId: string,
itemType: string,
dateAddedOn: Date,
}]
}✅ PROS:
- ✔️ List of items for a single user can be fetched from a single document
- ✔️ Faster GET request
- ✔️ FutureProof / Scalable: Can add user's metadata to this schema
🚨 CONS:
- ❗ Nested Array of objects difficult to handle(filter / sort) in Mongo.
- ❗ Removal of item from list is slower
Assumption: We have monolithic service
- Choosing first approach considering
- Easier to implement
- Low Maintenance
- High performance (GET/POST)
sequenceDiagram
participant Client
participant BE
participant Mongo
Note over Client,Mongo: Add to my list
autonumber 1
Client ->> BE: POST /api/myList/ {userId, ItemId, ...}
BE -->> BE: Validates request
BE -->> Mongo: Fetch User by userId
BE -->> BE: add item to list if ItemId not in list
BE ->> Client: Success (201)
Note over Client,Mongo: Remove Item from list
autonumber 1
Client ->> BE: DELETE /api/myList/ {userId, ItemId}
BE -->> BE: Validates request
BE -->> Mongo: Fetch User by userId
BE -->> BE: remove item from the list if ItemId is present in list
BE ->> Client: Success (201)
Note over Client,Mongo: List My Items
autonumber 1
Client ->> BE: GET /api/myList?userid:123
BE -->> Mongo: Fetch User by userId
BE ->> Client: Success (201), return MyList
- For CI/CD:
Render Pipeline - Deployed On:
Render Cloud
graph LR
A[Developer] -- 1. Push Commit to Origin --> B((Github))
B -- 2. Trigger Pipeline--> C(Render)
C -- 3. Pull latest code --> B
C -- Build and deploy --> D{Render Cloud}
- MongoDB Integration
- Script to initialize database
- Write Unit test cases
- Validate request body: Using Joi
- Generate random values: using Faker
- CI/CD
- Deploy on any cloud service
- Check for test coverage results in CI/CD pipeline
- Setup Pre-Commit hooks to ensure
- Consistent commit messages
- Language standards: linting
- Map Foreign Key in MyList
- Make file to setup repository with single command