DevTotti / mainstack-products

MainStack Backend Engineer test

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mainstack Products API

Project Overview

Mainstack Products API is a Node.js RESTful API built with TypeScript and MongoDB. The API allows users to manage products, providing endpoints for creating, retrieving, updating, and deleting product data. This application is containerized using Docker for easy deployment and development.

Project Structure

The project is organized as follows:

mainstack-products/
├── src/
│   ├── components/
│   │   └── products/
│   │       ├── controller.ts         # Handles HTTP requests
│   │       ├── service.ts            # Business logic for products
│   │       ├── route.ts              # Product API routes
│   ├── models/
│   │   └── Product.ts                # Mongoose Product model
│   ├── middleware/
│   │   └── auth.ts                   # Authentication middleware
│   ├── utils/
│   │   └── fetchpage.ts              # Utility functions
├── __api__/
│   └── MainStack Products Challenge.postman_collection.json # Postman API collection
├── test/
│   ├── unit/                         # Unit tests
│   │   ├── product.test.ts           # Product service unit tests
│   │   └── user.test.ts              # User service unit tests
│   └──  setup.ts                     # Test setup
├── Dockerfile                        # Docker configuration
├── docker-compose.yml                # Docker Compose for multi-container setup
├── jest.config.js                    # Jest configuration for testing
├── package.json                      # Project dependencies and scripts
└── tsconfig.json                     # TypeScript configuration

Features

  • Authentication: Secure routes using middleware for authentication.
  • Product Management: Create, update, delete, and retrieve product information.
  • Pagination: Handle large sets of product data efficiently.

Prerequisites

Ensure you have the following installed on your system:

Setup

  1. Clone the Repository:
    git clone https://github.com/DevTotti/mainstack-products.git
    cd mainstack-products
    
  2. Install dependencies:
    npm install
  3. Environment Variables:
    PORT=3000
    MONGO_URI=mongodb://localhost:27017/mainstack-products
    JWT_SECRET=your_jwt_secret_key
    JWT_EXPIRES_IN=1h
    

Running the Application

Locally

  • To start the application locally, run:
    npm run dev

The server will start on http://localhost:3000

With Docker

  • To run the application using Docker, use the following commands
  1. Build the Docker Image:
    docker-compose build
  2. Start the docker containers
    docker-compose up
    

This will start the application and MongoDB as containers. The application will be available at http://localhost:3000

Running Tests

  • Unit Tests

    Unit tests are located in the test/unit folder. To run the tests, use the following command:

    npm run test

Postman Documentation Postman Documentation

Live Api Link The initial Live API submitted in the google form was shut down by the service provider so I had to move it somewhere else LIVE API

About

MainStack Backend Engineer test

License:MIT License


Languages

Language:TypeScript 99.0%Language:JavaScript 0.6%Language:Dockerfile 0.5%