8000 GitHub - devevangel/code-challenge-server
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

devevangel/code-challenge-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Product Catalog Backend API

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.


πŸ“‹ Table of Contents


πŸ›  Setup Instructions

  1. Clone the repository:

    git clone https://github.com/your-github-username/your-repo-name.git
    cd your-repo-name/server-side
  2. Install dependencies:

    npm install
  3. Environment Variables:
    Create a .env file at the root of the server-side directory with the following contents:

    NODE_ENV=development
    PORT=8080
  4. Run the application:

    • For development with hot-reloading:
      npm run dev
    • For production:
      npm run start
  5. Run tests:

    npm run test

🎯 High-Level Design Decisions and Tradeoffs

  • 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.
  • Testing Strategy:
    • Unit tests for model layer.
    • Integration tests for routes.

βš–οΈ Tradeoffs

  • 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.

πŸ’š Potential Improvements (If Given More Time)

  • 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.

πŸ“š API Documentation

Base URL

http://localhost:8080/api/products

Endpoints

GET /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

GET /api/products/:id

  • Retrieve a single product by ID.

POST /api/products

  • Create a new product.
  • Request Body:
    {
      "name": "Sample Product",
      "unitCost": 100,
      "totalSales": 20,
      "inventory": 50
    }

PUT /api/products/:id

  • Update an existing product.
  • Request Body (partial updates allowed):
    {
      "inventory": 30
    }

DELETE /api/products/:id

  • Delete a product by ID.

πŸ§ͺ Testing Approach

  • Unit Tests:
    • Tested models/ directly (CRUD on the database).
  • Integration Tests:
    • Tested routes/ with API requests using supertest.
  • Coverage Focus:
    • Focused on core functionalities (create, update, delete, search, filter).
  • Tradeoff:
    • Did not cover exhaustive edge cases to focus on primary feature robustness.

πŸ›‚ Environment Variables

You need a .env file containing:

NODE_ENV=development
PORT=8080

πŸ—„οΈ Project Structure

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

πŸš€ Product Catalog Backend API

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.


πŸ“‹ Table of Contents


πŸ›  Setup Instructions

  1. Clone the repository:

    git clone https://github.com/your-github-username/your-repo-name.git
    cd your-repo-name/server-side
  2. Install dependencies:

    npm install
  3. Environment Variables:
    Create a .env file at the root of the server-side directory with the following contents:

    NODE_ENV=development
    PORT=8080
  4. Run the application:

    • For development with hot-reloading:
      npm run dev
    • For production:
      npm run start
  5. Run tests:

    npm run test

🎯 High-Level Design Decisions and Tradeoffs

  • 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.
  • Testing Strategy:
    • Unit tests for model layer.
    • Integration tests for routes.

βš–οΈ Tradeoffs

  • 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.

πŸ’š Potential Improvements (If Given More Time)

  • 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.

πŸ“š API Documentation

Base URL

http://localhost:8080/api/products

Endpoints

GET /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

GET /api/products/:id

  • Retrieve a single product by ID.

POST /api/products

  • 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"
    }

PUT /api/products/:id

  • Update an existing product.
  • Request Body (partial updates allowed):
    {
      "inventory": 30
    }

DELETE /api/products/:id

  • Delete a product by ID.

πŸ§ͺ Testing Approach

  • Unit Tests:
    • Tested models/ directly (CRUD on the database).
  • Integration Tests:
    • Tested routes/ with API requests using supertest.
  • Coverage Focus:
    • Focused on core functionalities (create, update, delete, search, filter).
  • Tradeoff:
    • Did not cover exhaustive edge cases to focus on primary feature robustness.

πŸ›‚ Environment Variables

You need a .env file containing:

NODE_ENV=development
PORT=8080

πŸ—„οΈ Project Structure

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

πŸ€– Use of AI Assistance

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.


πŸ‘¨β€πŸ’» Author

Built with ❀️ by Evangel Iheukwumere
GitHub Profile


🏁 Summary

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!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0