This project is a MERN (MongoDB, Express, React, Node.js) stack application created for the Roxiler coding challenge. The backend APIs perform data fetching, processing, and display functionalities for product transactions, including statistical summaries and chart visualizations based on monthly data.
The project consists of several endpoints to retrieve and visualize transaction data, with the following primary features:
- Database seeding from a third-party API
- Transaction listing with search and pagination
- Statistical data generation
- Data visualizations for a bar chart.
All backend APIs are implemented using Express.js in Node.js. These APIs provide comprehensive access to transaction data, including filtering, pagination, and statistical summaries.
-
Data Initialization:
- Fetches data from a third-party API at https://s3.amazonaws.com/roxiler.com/product_transaction.json and seeds it into the MongoDB database. The data is structured efficiently to enable fast querying and retrieval.
-
API Endpoints:
- Transaction Listing: Allows searching, filtering by product title/description/price, and paginating through all
transactions. - Statistics Generation: Provides summary statistics for a specified month, including:
- Total sale amount
- Number of items sold
- Number of items not sold
- Bar Chart Data: Returns price ranges and counts of items in each range for the selected month.
- Pie Chart Data: Lists unique product categories and item counts for each category in the selected month.
- Combined Data Endpoint: Aggregates the data from the above APIs into a single response for ease of frontend display.
- Transaction Listing: Allows searching, filtering by product title/description/price, and paginating through all
-
Data Visualization:
- Created a Statistics table that displays detailed statistics alongside bar chart data for easier data interpretation.
- The charts use dynamically processed data for enhanced visualization and reporting using
Chart.js.
-
API Documentation:
- All APIs have been thoroughly documented in a
Postman workspacefor easy testing and reference. Access the postman workspace.
- All APIs have been thoroughly documented in a
-
Deployment:
- The app is deployed on
Vercelfor reliable, serverless hosting. Access the live app at https://roxiler- assignment.deepanshu-sahu-projects.live/.
- The app is deployed on
Follow these steps to get the project running locally:
-
Clone the Repository:
git clone https://github.com/dee077/Roxiler_Assignment.git
-
Install Frontend Dependencies::
cd frontend npm install -
Install Backend Dependencies::
cd ../backend npm install -
Create .env file:
MONGO_URI=<Your_MongoDB_URI> THIRD_PARTY_API_URL=https://s3.amazonaws.com/roxiler.com/product_transaction.json PORT=5000
-
Start Backend and Frontend: In Terminal 1:
cd frontend npm startIn Terminal 2:
cd backend npm startAccess the app at
http://localhost:3000and keep the backend running onhttp://localhost:5000.
The following API endpoints have been created to fulfill the assignment requirements. Each endpoint accepts a month as input, which is matched against the dateOfSale field regardless of the year.
- Endpoint:
GET /api/initialize-db - Description: Initializes the database by fetching the product transaction data from a third-party API
(
https://s3.amazonaws.com/roxiler.com/product_transaction.json) and populating the MongoDB database with seed data. This is a one-time setup endpoint to populate the database with transaction records. - Example Request:
GET https://roxiler-assignment-be.vercel.app/api/init
- Endpoint:
GET /api/transactions - Description: Lists all product transactions, with support for search and pagination.
- Parameters:
search(optional): Filters transactions based on producttitle,description, orprice.page(optional): Page number for pagination (default: 1).perPage(optional): Number of records per page (default: 10).
- Example Request:
GET https://roxiler-assignment-be.vercel.app/api/list-transactions
- Endpoint:
GET /api/statistics - Description: Provides key statistics for a selected month.
- Response Data:
totalSaleAmount: Total sale amount for the selected month.soldItems: Total number of sold items for the month.notSoldItems: Total number of not-sold items for the month.
- Example Request:
GET https://roxiler-assignment-be.vercel.app/api/list-transactions
- Endpoint:
GET /api/barchart - Description: Provides data for a bar chart showing item counts in specific price ranges for the selected month.
- Price Ranges:
0 - 100101 - 200201 - 300301 - 400401 - 500501 - 600601 - 700701 - 800801 - 900901+
- Example Request:
GET https://roxiler-assignment-be.vercel.app/api/bar-chart?month=March
- Endpoint:
GET /api/piechart - Description: Provides data for a pie chart showing unique categories and the number of items in each category for the selected month.
- Example Request:
GET https://roxiler-assignment-be.vercel.app/api/pie-chart?month=March
- Endpoint:
GET /api/combined - Description: Combines responses from the
transactions,statistics,barchart, andpiechartendpoints for comprehensive data analysis. - Example Request:
GET https://roxiler-assignment-be.vercel.app/api/combined-data?month=March
I have completed the assignment as per the given requirements and it is ready for submission.
Thank you!
Deepanshu Sahu
