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.
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
- Authentication: Secure routes using middleware for authentication.
- Product Management: Create, update, delete, and retrieve product information.
- Pagination: Handle large sets of product data efficiently.
Ensure you have the following installed on your system:
- Clone the Repository:
git clone https://github.com/DevTotti/mainstack-products.git cd mainstack-products
- Install dependencies:
npm install
- Environment Variables:
PORT=3000 MONGO_URI=mongodb://localhost:27017/mainstack-products JWT_SECRET=your_jwt_secret_key JWT_EXPIRES_IN=1h
- To start the application locally, run:
npm run dev
The server will start on http://localhost:3000
- To run the application using Docker, use the following commands
- Build the Docker Image:
docker-compose build
- 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
-
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