demo.mp4
This is a full-stack inventory management system designed to manage products and user authentication for a small business. It exposes REST APIs for user login, product management, and inventory tracking, with an optional admin portal and analytics. The application is built using React for the frontend, Node.js with Express for the backend, and MongoDB for the database, all containerized with Docker.
- User authentication with JWT (Login).
- Product addition, editing, and deletion.
- Product quantity updates.
- Paginated product listing with search.
- Analytics for most added products, top expensive products, and total inventory value.
- Admin portal for management (stretch goal).
- Responsive dashboard (stretch goal).
- Frontend: React, JavaScript, Tailwind CSS
- Backend: Node.js, Express.js
- Database: MongoDB
- Authentication: JSON Web Tokens (JWT)
- Containerization: Docker, Docker Compose
- API Documentation: OpenAPI(via backend integration)
- Testing: Postman collection included
- Build Tools: npm
- Docker: Ensure Docker and Docker Compose are installed on your system.
- Git: To clone the repository.
- Node.js (optional, for local development if not using Docker).
- MongoDB (optional, for local development if not using Docker).
-
Clone the Repository
git clone https://github.com/navinbhagat322/Inventory-management-project.git cd Inventory_management -
Configure Environment Variables
- Create a
.envfile in thebackenddirectory with the following variables:JWT_SECRET=your-secret-key MONGO_URI=mongodb://mongo:27017/inventory PORT=5000 - Replace
your-secret-keywith a secure random string for JWT authentication.
- Create a
-
Build and Run with Docker
- Use Docker Compose to build and start the application:
docker-compose build docker-compose up -d
- The
-dflag runs the containers in detached mode.
- Use Docker Compose to build and start the application:
-
Verify the Application
- Open your browser and navigate to:
http://localhost:3000for the frontend (dashboard).http://localhost:5000for the backend API (optional, for testing).
- The admin portal will be available at
http://localhost:3000/adminafter logging in as an admin.
- Open your browser and navigate to:
- Login: Initially, no users are set up. Modify the backend (
backend/src/routes/auth.js) to include a default admin user or implement a registration endpoint. Use the POST/loginendpoint with:{ "username": "string", "password": "string" }- Success: Returns a JWT token.
- Failure: Returns an error message.
- Dashboard: View product lists and analytics.
- Admin Portal: Manage products (add, edit, delete) with search and pagination.
- POST /login: Authenticate user and return JWT token.
- POST /products: Add a new product.
- Payload:
{ "name": "string", "type": "string", "sku": "string", "image_url": "string", "description": "string", "quantity": integer, "price": number } - Response: Product ID and confirmation.
- Payload:
- PUT /products/{id}/quantity: Update product quantity.
- Payload:
{ "quantity": integer } - Response: Updated product details or confirmation.
- Payload:
- GET /products: Retrieve paginated product list.
- Parameters:
page,limit,name(search). - Response: List of products with pagination metadata.
- Parameters:
Note: All endpoints require JWT authentication in the Authorization header.
- Frontend: Located in the
frontenddirectory. Runnpm installandnpm startif developing locally without Docker. - Backend: Located in the
backenddirectory. Runnpm installandnode index.jsafter setting up MongoDB locally. - Use
docker-compose logs <service>(e.g.,backendorfrontend) to debug issues.
- Rebuild:
docker-compose build - Restart:
docker-compose up -d - Stop:
docker-compose down - Logs:
docker-compose logs
- Collection:
products_id: ObjectId (auto-generated)name: Stringtype: Stringsku: String (unique)image_url: Stringdescription: Stringquantity: Numberprice: NumbercreatedAt: DateupdatedAt: Date
- Collection:
users(for authentication)_id: ObjectId (auto-generated)username: String (unique)password: String (hashed)role: String (e.g., "admin")
Initialization: The schema is created automatically by MongoDB when data is inserted. No separate script is required.
- OpenAPI documentation is integrated into the backend. Access it at
http://localhost:5000/api-docsafter running the application.
- A sample Postman collection is included in the
postmandirectory. Import it into Postman to test the APIs. - Test script example (run in backend directory):
const axios = require('axios'); const assert = require('assert'); async function testApi() { try { // Test login const loginResponse = await axios.post('http://localhost:5000/login', { username: 'admin', password: 'password' }); const token = loginResponse.data.token; assert(token, 'Login failed'); // Test add product const addResponse = await axios.post('http://localhost:5000/products', { name: 'Test Product', type: 'Test Type', sku: 'TEST123', quantity: 10, price: 99.99 }, { headers: { Authorization: `Bearer ${token}` } }); const productId = addResponse.data.id; assert(productId, 'Product addition failed'); // Test update quantity const updateResponse = await axios.put(`http://localhost:5000/products/${productId}/quantity`, { quantity: 15 }, { headers: { Authorization: `Bearer ${token}` } }); assert(updateResponse.data.quantity === 15, 'Quantity update failed'); // Test get products const getResponse = await axios.get('http://localhost:5000/products', { headers: { Authorization: `Bearer ${token}` } }); assert(getResponse.data.products.length > 0, 'Get products failed'); console.log('All tests passed!'); } catch (err) { console.error('Test failed:', err.message); } } testApi();
For questions or support, open an issue or contact navinbhagat322@gmail.com.