This is the server-side component for a simple Product Catalog CRUD application built for the coding challenge.
The API provides endpoints to manage products, including Create, Read, Update, Delete (CRUD) operations, and supports search and filtering capabilities.
- Setup Instructions
- Design Decisions and Tradeoffs
- Potential Improvements
- API Documentation
- Testing Approach
- Environment Variables
- Project Structure
- Running the Application
- Author
-
Clone the repository:
git clone https://github.com/your-github-username/your-repo-name.git cd your-repo-name/server-side
-
Install dependencies:
npm install
-
Environment Variables:
Create a.env
file at the root of theserver-side
directory with the following contents:NODE_ENV=development PORT=8080
-
Run the application:
- For development with hot-reloading:
npm run dev
- For production:
npm run start
- For development with hot-reloading:
-
Run tests:
npm run test
- Framework Choice: Used
Express.js
for simplicity, robustness, and middleware support. - Database Choice: Used
lowdb
(lightweight JSON file database) for quick setup and simplicity. - Architecture: Followed MVC pattern (models, controllers, routes).
- Error Handling:
- Created custom error classes (
AppError
,BadRequestError
,NotFoundError
) for better API responses.
- Created custom error classes (
- Testing Strategy:
- Unit tests for model layer.
- Integration tests for routes.
- Chose
lowdb
instead of full SQL/NoSQL database for lightweight development. - Focused testing primarily on main CRUD and search/filter functions.
- No authentication (e.g., JWT) to stay within project scope.
- Add authentication and authorization.
- Replace
lowdb
with PostgreSQL or MongoDB. - Implement pagination, sorting, and field selection.
- Add input validation middleware (
express-validator
). - Better error logging (e.g.,
winston
). - Containerization with Docker.
http://localhost:8080/api/products
- Retrieve all products.
- Optional Query Parameters:
name
- search by product name (partial match)cost
,costOp
(e.g.,gt
,gte
,lt
,lte
)sales
,salesOp
(e.g.,gt
,gte
,lt
,lte
)
Example:
GET /api/products?cost=1000&costOp=lte
- Retrieve a single product by ID.
- Create a new product.
- Request Body:
{ "name": "Sample Product", "unitCost": 100, "totalSales": 20, "inventory": 50 }
- Update an existing product.
- Request Body (partial updates allowed):
{ "inventory": 30 }
- Delete a product by ID.
- Unit Tests:
- Tested
models/
directly (CRUD on the database).
- Tested
- Integration Tests:
- Tested
routes/
with API requests usingsupertest
.
- Tested
- Coverage Focus:
- Focused on core functionalities (create, update, delete, search, filter).
- Tradeoff:
- Did not cover exhaustive edge cases to focus on primary feature robustness.
You need a .env
file containing:
NODE_ENV=development
PORT=8080
server-side/
βββ app.js
βββ server.js # Main server file
βββ routes/
β βββ product.route.js
βββ controllers/
β βββ product.controller.js
βββ models/
β βββ product.model.js
βββ db/
β βββ db.json
β βββ index.js
βββ utils/
β βββ index.js
βββ tests/
β βββ product.model.test.js
β βββ product.routes.test.js
βββ .env
βββ package.json
βββ README.md
This is the server-side component for a simple Product Catalog CRUD application built for the coding challenge.
The API provides endpoints to manage products, including Create, Read, Update, Delete (CRUD) operations, and supports search and filtering capabilities.
- Setup Instructions
- Design Decisions and Tradeoffs
- Potential Improvements
- API Documentation
- Testing Approach
- Environment Variables
- Project Structure
- Use of AI Assistance
- Author
-
Clone the repository:
git clone https://github.com/your-github-username/your-repo-name.git cd your-repo-name/server-side
-
Install dependencies:
npm install
-
Environment Variables:
Create a.env
file at the root of theserver-side
directory with the following contents:NODE_ENV=development PORT=8080
-
Run the application:
- For development with hot-reloading:
npm run dev
- For production:
npm run start
- For development with hot-reloading:
-
Run tests:
npm run test
- Framework Choice: Used
Express.js
for simplicity, robustness, and middleware support. - Database Choice: Used
lowdb
(lightweight JSON file database) for quick setup and simplicity. - Architecture: Followed MVC pattern (models, controllers, routes).
- Error Handling:
- Created custom error classes (
AppError
,BadRequestError
,NotFoundError
) for better API responses.
- Created custom error classes (
- Testing Strategy:
- Unit tests for model layer.
- Integration tests for routes.
- Chose
lowdb
instead of full SQL/NoSQL database for lightweight development. - Focused testing primarily on main CRUD and search/filter functions.
- No authentication (e.g., JWT) to stay within project scope.
- Add authentication and authorization.
- Replace
lowdb
with PostgreSQL or MongoDB. - Implement pagination, sorting, and field selection.
- Add input validation middleware (
express-validator
). - Better error logging (e.g.,
winston
). - Containerization with Docker.
http://localhost:8080/api/products
- Retrieve all products.
- Optional Query Parameters:
name
- search by product name (partial match)cost
,costOp
(e.g.,gt
,gte
,lt
,lte
)sales
,salesOp
(e.g.,gt
,gte
,lt
,lte
)
Example:
GET /api/products?cost=1000&costOp=lte
- Retrieve a single product by ID.
- Create a new product.
- Request Body:
{ "name": "Zero Fanta77", "unitCost": 50, "totalSales": 400, "inventory": 100, "description": "Removal of Drainage Device from", "imageUrl": "http://dummyimage.com/197x100.png/cc0000/f54654777" }
- Update an existing product.
- Request Body (partial updates allowed):
{ "inventory": 30 }
- Delete a product by ID.
- Unit Tests:
- Tested
models/
directly (CRUD on the database).
- Tested
- Integration Tests:
- Tested
routes/
with API requests usingsupertest
.
- Tested
- Coverage Focus:
- Focused on core functionalities (create, update, delete, search, filter).
- Tradeoff:
- Did not cover exhaustive edge cases to focus on primary feature robustness.
You need a .env
file containing:
NODE_ENV=development
PORT=8080
server-side/
βββ app.js # Main server file
βββ routes/
β βββ product.route.js
βββ controllers/
β βββ product.controller.js
βββ models/
β βββ product.model.js
βββ db/
β βββ index.js
βββ utils/
β βββ errors.js
βββ tests/
β βββ product.model.test.js
β βββ product.routes.test.js
βββ .env
βββ package.json
βββ README.md
During the development of this project, I utilized AI tools to assist with:
- Generating ideas for writing cleaner and more efficient code.
- Planning and structuring better unit and integration tests.
- Drafting detailed and professional documentation and comments.
- Accelerating development speed by helping brainstorm edge cases and spotting potential improvements.
Important:
All core logic, critical decisions, architectural choices, and testing approaches were designed, reviewed, and implemented personally to ensure they matched the challenge requirements and industry best practices.
Using AI thoughtfully allowed me to focus more deeply on solving the real business problems, optimizing the code quality, and delivering the project on time.
Built with β€οΈ by Evangel Iheukwumere
GitHub Profile
This project satisfies the coding challenge's goals by:
- Delivering a fully working CRUD API.
- Using modular MVC architecture.
- Implementing custom error handling.
- Writing comprehensive tests.
- Documenting setup, usage, and design clearly.
Thank you for reviewing this submission!