A full-stack web application built with MongoDB, Express.js, React, and Node.js for managing customer orders and purchases with shopkeeper authentication.
- Shopkeeper Registration: Create account with shop details
- Secure Login: Email and password authentication
- Auto Login: Authentication token stored in localStorage - no need to login repeatedly
- User-Specific Data: Each shopkeeper can only access their own orders
- Protected Routes: Automatic redirect to login if not authenticated
- Order Form: Create new orders with customer details (name, phone, address, product)
- Real-time Data: Orders are saved to MongoDB with exact timestamp
- Purchased Products Page: View all your orders as bills with complete details
- Search Functionality: Search orders by customer name, phone, product, or address
- Delete Orders: Remove orders from the database
- User Isolation: Each shopkeeper sees only their own orders
- Responsive Design: Beautiful gradient UI that works on all devices
- Modern Interface: Clean and professional design
- User Info Display: Shows shop name and owner name in navbar
mern-order-system/
├── backend/
│ ├── models/
│ │ ├── Order.js
│ │ └── User.js
│ ├── middleware/
│ │ └── auth.js
│ ├── .env
│ ├── package.json
│ └── app.js
└── frontend/
├── public/
│ └── index.html
├── src/
│ ├── components/
│ │ ├── Login.js
│ │ ├── Register.js
│ │ ├── OrderForm.js
│ │ ├── PurchasedProducts.js
│ │ └── PrivateRoute.js
│ ├── context/
│ │ └── AuthContext.js
│ ├── App.js
│ ├── App.css
│ ├── index.js
│ └── index.css
└── package.json
Before running this application, make sure you have the following installed:
- Node.js (v14 or higher)
- MongoDB (v4.4 or higher)
- npm or yarn
Navigate to the project directory:
cd mern-order-systemcd backend
npm installcd ../frontend
npm install-
Install MongoDB on your system: https://www.mongodb.com/try/download/community
-
Start MongoDB service:
- Windows: MongoDB should start automatically as a service
- macOS:
brew services start mongodb-community - Linux:
sudo systemctl start mongod
-
Verify MongoDB is running:
mongoshThe backend will automatically create a database called orderSystemDB.
-
Create a free account at https://www.mongodb.com/cloud/atlas
-
Create a new cluster
-
Get your connection string
-
Update the
.envfile in the backend folder:
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/orderSystemDB?retryWrites=true&w=majority
Open a terminal and navigate to the backend folder:
cd backend
npm startThe server will start on http://localhost:5000
You should see:
Server is running on port 5000
MongoDB connected successfully
Open a new terminal and navigate to the frontend folder:
cd frontend
npm startThe React app will start on http://localhost:3000 and automatically open in your browser.
- Open
http://localhost:3000in your browser - You'll be redirected to the login page
- Click "Register here" to create a new account
- Fill in your shop details:
- Shop Name
- Owner Name
- Email (must be unique)
- Phone Number
- Shop Address
- Password (minimum 6 characters)
- Confirm Password
- Click "Create Account"
- You'll be automatically logged in and redirected to the order form
- Open
http://localhost:3000 - If your authentication token is still valid (stored in localStorage), you'll be automatically logged in
- If not, enter your email and password on the login page
- Click "Login"
- Navigate to the "New Order" page (home page)
- Fill in the form:
- Customer Name
- Customer Phone Number
- Customer Address
- Product
- Click the "Add Order" button
- You'll see a success message and the form will reset
- Click on "Purchased Products" in the navigation
- You'll see all orders displayed as cards
- Each card shows:
- Product name
- Order date and time
- Customer name
- Phone number
- Address
- Delete button
- On the "Purchased Products" page
- Use the search bar at the top
- Type any part of:
- Customer name
- Phone number
- Product name
- Address
- Results will filter in real-time
- Click the "Delete Order" button on any order card
- Confirm the deletion
- The order will be removed from the database
- Click the "Logout" button in the navigation bar
- Your authentication token will be removed from localStorage
- You'll need to login again to access the system
- Each shopkeeper can only see and manage their own orders
- Orders are linked to your user account
- Other shopkeepers cannot access your data
- Your authentication token is stored securely in browser localStorage
- POST
/api/auth/register - Body:
{
"shopName": "My Shop",
"ownerName": "John Doe",
"email": "john@example.com",
"password": "password123",
"phone": "123-456-7890",
"address": "123 Main St, City, State"
}- Response:
{ success, message, token, user }
- POST
/api/auth/login - Body:
{
"email": "john@example.com",
"password": "password123"
}- Response:
{ success, message, token, user }
- GET
/api/auth/me - Headers:
Authorization: Bearer <token> - Response:
{ success, user }
- POST
/api/orders - Headers:
Authorization: Bearer <token> - Body:
{
"customerName": "Jane Smith",
"customerPhone": "123-456-7890",
"customerAddress": "456 Oak St, City, State",
"product": "Laptop"
}- GET
/api/orders - Headers:
Authorization: Bearer <token>
- GET
/api/orders/search?query=searchterm - Headers:
Authorization: Bearer <token>
- DELETE
/api/orders/:id - Headers:
Authorization: Bearer <token>
- Node.js: JavaScript runtime
- Express.js: Web application framework
- MongoDB: NoSQL database
- Mongoose: MongoDB object modeling
- bcryptjs: Password hashing
- jsonwebtoken: JWT authentication
- CORS: Cross-origin resource sharing
- dotenv: Environment variable management
- React: UI library
- React Router DOM: Client-side routing
- React Context API: State management
- Axios: HTTP client
- CSS3: Styling with gradients and animations
- LocalStorage: Persistent authentication
- User registration with validation
- Secure password hashing with bcrypt
- JWT token generation
- Token verification middleware
- Auto-login via localStorage
- Protected routes
- User-specific data isolation
- Input validation
- Real-time form state management
- Success/error messaging
- Automatic form reset after submission
- User authentication integration
- Real-time data fetching
- Live search filtering
- Date/time formatting
- Responsive grid layout
- Delete functionality with confirmation
- User-specific order display
Edit frontend/src/App.css:
/* Main gradient */
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
/* Accent color */
color: #667eea;Backend - Edit backend/.env:
PORT=5000
Frontend - Create frontend/.env:
PORT=3000
Edit backend/.env:
MONGODB_URI=mongodb://localhost:27017/yourDatabaseName
Problem: MongoDB connection error
Solution:
- Ensure MongoDB is running
- Check connection string in
.env - Verify network access if using MongoDB Atlas
Problem: Access to XMLHttpRequest has been blocked by CORS policy
Solution:
- Ensure backend is running on port 5000
- Check CORS configuration in
server.js
Problem: Port 5000 is already in use
Solution:
- Change port in
backend/.env - Or kill the process using the port:
- Windows:
netstat -ano | findstr :5000thentaskkill /PID <PID> /F - macOS/Linux:
lsof -ti:5000 | xargs kill
- Windows:
Problem: Package installation fails
Solution:
- Clear npm cache:
npm cache clean --force - Delete
node_modulesandpackage-lock.json - Run
npm installagain
Problem: "Invalid token" or "Access denied" errors
Solution:
- Logout and login again
- Clear browser localStorage
- Check if JWT_SECRET is set in backend
.env
Problem: "Email already registered" error
Solution:
- Use a different email address
- Or login with existing credentials
- Or delete the user from MongoDB and re-register
Problem: Still need to login after closing browser
Solution:
- Check browser localStorage (should have 'token' key)
- Ensure token hasn't expired (valid for 30 days)
- Check browser console for errors
- Add to
backend/package.json:
"engines": {
"node": "18.x"
}- Create Procfile:
web: node server.js
- Set environment variables on your hosting platform
- Build the app:
npm run build-
Update API URL in axios calls to your backend URL
-
Deploy the
buildfolder
- Password reset functionality
- Email verification
- Profile editing
- Order status tracking (pending, completed, cancelled)
- Invoice generation (PDF)
- Email notifications
- Payment integration
- Advanced filtering and sorting
- Order editing capability
- Dashboard with analytics and sales reports
- Multi-shop management
- Customer management system
- Inventory tracking
MIT License - feel free to use this project for learning or commercial purposes.
For issues or questions, please create an issue in the project repository.