A modern, fullstack inventory management system built with Next.js 14, TypeScript, and MySQL.
- 📊 Dashboard - Overview of inventory statistics and recent transactions
- 📦 Products Management - Full CRUD operations for products
- 📋 Inventory Management - Track stock at multiple locations
- 🔄 Stock Movements - Transfer stock between locations with approval workflow
- 📈 Activity Logs - Track all system activities
- 🔐 Authentication - JWT-based authentication with role-based access control
- 👥 Multi-role Support - Super Admin, Warehouse Manager, Distributor, Sales Agent, Store Manager
- Frontend: Next.js 14, React, TypeScript, Bootstrap 5
- Backend: Next.js API Routes
- Database: MySQL
- Authentication: JWT (JSON Web Tokens)
- Password Hashing: bcryptjs
- Node.js 18+ installed
- MySQL 8.0+ installed and running
- npm or yarn package manager
-
Clone the repository (if applicable) or navigate to the project directory
-
Install dependencies:
npm install
-
Set up MySQL database:
- Make sure MySQL is running
- Create a
.env.localfile in the root directory:DB_HOST=localhost DB_PORT=3306 DB_USER=root DB_PASSWORD=your_mysql_password DB_NAME=inventory_db JWT_SECRET=your_super_secret_jwt_key_change_this_in_production JWT_REFRESH_SECRET=your_super_secret_refresh_key_change_this_in_production NEXT_PUBLIC_API_URL=http://localhost:3000
-
Initialize the database:
node scripts/init-db.js
This will:
- Create the database and all tables
- Insert default locations
- Create default users with hashed passwords
-
Start the development server:
npm run dev
-
Open your browser and navigate to
http://localhost:3000
After running the database initialization script, you can log in with:
- Super Admin:
admin@inventory.com/admin123 - Warehouse Manager:
warehouse@inventory.com/warehouse123 - Distributor:
distributor@inventory.com/distributor123 - Sales Agent:
agent@inventory.com/agent123 - Store Manager:
store@inventory.com/store123
├── app/ # Next.js app directory
│ ├── api/ # API routes
│ │ ├── auth/ # Authentication endpoints
│ │ ├── products/ # Product management
│ │ ├── inventory/ # Inventory management
│ │ ├── movements/ # Stock movements
│ │ └── locations/ # Location management
│ ├── dashboard/ # Dashboard page
│ ├── login/ # Login page
│ └── layout.tsx # Root layout
├── components/ # React components
│ └── Layout.tsx # Main layout component
├── lib/ # Utility libraries
│ ├── db.ts # Database connection
│ └── auth.ts # Authentication utilities
├── database/ # Database files
│ └── schema.sql # Database schema
└── scripts/ # Utility scripts
└── init-db.js # Database initialization script
POST /api/auth/login- Login userGET /api/auth/me- Get current user
GET /api/products- Get all productsPOST /api/products- Create productGET /api/products/[id]- Get product by IDPUT /api/products/[id]- Update productDELETE /api/products/[id]- Delete product
GET /api/inventory- Get inventory (filtered by user location)POST /api/inventory- Update inventory
GET /api/movements- Get all movementsPOST /api/movements- Create movementGET /api/movements/[id]- Get movement by IDPUT /api/movements/[id]- Update movement status
GET /api/locations- Get all locations
GET /api/activity-logs- Get activity logs
The database includes the following main tables:
users- User accountslocations- Warehouse, distributor, sales agent, and store locationsproducts- Product cataloginventory- Stock levels at each locationmovements- Stock transfer requestsmovement_items- Items in each movementmovement_activities- Activity log for movementsactivity_logs- General activity tracking
The system enforces a location hierarchy:
- Warehouse → can send to Distributor
- Distributor → can send to Sales Agent
- Sales Agent → can send to Store
- Store → cannot send to anyone
npm run devnpm run build
npm startnpm run lint- Change the
JWT_SECRETandJWT_REFRESH_SECRETin production - Use strong passwords for MySQL database
- Implement rate limiting for API endpoints in production
- Use HTTPS in production
- Regularly update dependencies
MIT License - feel free to use this project for your own purposes.
For issues or questions, please open an issue in the repository.