Skip to content

Repository files navigation

πŸ“± Raj Shop - Order Management System

A comprehensive web-based order management system for phone parts wholesalers. This system enables market retailers/shopkeepers to place delivery orders for phone parts, while admins and superadmins can efficiently manage and track these orders.

🎯 Features

Shopkeeper Module

  • Simple login/registration with name, shop name, and phone number
  • Notepad-style order entry interface
  • View order history with status tracking
  • Real-time order status updates

Admin Module

  • Secure password-based authentication
  • View all orders from shopkeepers
  • Process and mark orders as delivered
  • Real-time notifications for new orders
  • Order statistics dashboard
  • Filter orders by status

Superadmin Module

  • Complete system oversight
  • Admin account management (create, activate, deactivate, delete)
  • Final order confirmation after admin delivery
  • Monitor all system activities
  • Real-time notifications for all order events
  • Comprehensive statistics dashboard

πŸ› οΈ Technology Stack

  • Backend: Node.js, Express.js
  • Database: MongoDB
  • Authentication: JWT (JSON Web Tokens)
  • Real-time Communication: Socket.IO
  • Frontend: HTML5, CSS3, Vanilla JavaScript
  • Security: bcryptjs for password hashing

πŸ“‹ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v14 or higher)
  • MongoDB (v4.4 or higher)
  • npm or yarn package manager

πŸš€ Installation & Setup

1. Clone or Navigate to the Project

cd d:\raj.shop

2. Install Dependencies

npm install

3. Configure Environment Variables

Create a .env file in the root directory by copying .env.example:

copy .env.example .env

Edit the .env file with your configuration:

# Server Configuration
PORT=3000
NODE_ENV=development

# MongoDB Configuration
MONGODB_URI=mongodb://localhost:27017/rajshop

# JWT Secret (Generate a strong random string)
JWT_SECRET=your_jwt_secret_key_change_this_in_production

# Session
SESSION_TIMEOUT=24h

# Superadmin Initial Credentials
SUPERADMIN_USERNAME=superadmin
SUPERADMIN_PASSWORD=SuperAdmin@123
SUPERADMIN_NAME=Super Administrator

Important: Change the JWT_SECRET and superadmin credentials in production!

4. Start MongoDB

Ensure MongoDB is running on your system:

# Windows
net start MongoDB

# Or if using MongoDB installed locally
mongod

5. Start the Application

# Development mode with auto-reload
npm run dev

# Production mode
npm start

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

πŸ“± Usage Guide

First Time Setup

  1. Access the Application: Open your browser and navigate to http://localhost:3000

  2. Superadmin Login:

    • Click "Superadmin Login"
    • Use the default credentials from your .env file
    • Default: Username: superadmin, Password: SuperAdmin@123
    • ⚠️ Change these credentials immediately after first login
  3. Create Admin Accounts:

    • Go to the "Manage Admins" tab
    • Create admin accounts for your staff
    • Each admin will need these credentials to log in

Shopkeeper Workflow

  1. Navigate to http://localhost:3000
  2. Click "Shopkeeper Login"
  3. Enter your details (name, shop name, phone number)
  4. Type your order in the notepad-style text area
  5. Submit your order
  6. Track order status in real-time

Admin Workflow

  1. Navigate to http://localhost:3000
  2. Click "Admin Login"
  3. Enter your username and password (provided by superadmin)
  4. View all pending orders
  5. Process orders and mark them as delivered
  6. Receive real-time notifications for new orders

Superadmin Workflow

  1. Navigate to http://localhost:3000
  2. Click "Superadmin Login"
  3. Enter your credentials
  4. Orders Tab: Monitor all orders and confirm deliveries
  5. Manage Admins Tab: Create, activate, deactivate, or delete admin accounts
  6. Receive notifications for all system events

πŸ“Š System Flow

Shopkeeper β†’ Places Order (Pending)
     ↓
Admin β†’ Receives Notification
     ↓
Admin β†’ Marks as Delivered
     ↓
Superadmin β†’ Receives Notification
     ↓
Superadmin β†’ Confirms as Completed

πŸ” Security Features

  • JWT Authentication: Secure token-based authentication
  • Role-Based Access Control: Separate permissions for each user type
  • Password Hashing: bcryptjs with salt for password security
  • Session Management: Configurable session timeout
  • Active Status: Admins can be deactivated without deletion

πŸ”” Notification System

  • Real-time notifications using Socket.IO
  • Admins receive notifications for:
    • New orders from shopkeepers
  • Superadmin receives notifications for:
    • New orders from shopkeepers
    • Orders delivered by admins
  • Visual notification badges
  • Notification history panel

🌐 API Endpoints

Authentication

  • POST /api/auth/shopkeeper/login - Shopkeeper login/registration
  • POST /api/auth/admin/login - Admin login
  • POST /api/auth/superadmin/login - Superadmin login

Orders

  • GET /api/orders - Get orders (filtered by role)
  • POST /api/orders - Create new order (Shopkeeper)
  • GET /api/orders/:id - Get single order
  • PUT /api/orders/:id/deliver - Mark as delivered (Admin)
  • PUT /api/orders/:id/complete - Mark as completed (Superadmin)
  • GET /api/orders/stats/dashboard - Get order statistics

Admin Management

  • GET /api/admin/list - Get all admins (Superadmin)
  • POST /api/admin/create - Create new admin (Superadmin)
  • PUT /api/admin/:id/activate - Activate admin (Superadmin)
  • PUT /api/admin/:id/deactivate - Deactivate admin (Superadmin)
  • DELETE /api/admin/:id - Delete admin (Superadmin)

Notifications

  • GET /api/notifications - Get notifications
  • PUT /api/notifications/:id/read - Mark as read
  • PUT /api/notifications/read-all - Mark all as read

πŸ“ Project Structure

raj.shop/
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ database.js          # MongoDB connection
β”‚   └── constants.js         # Application constants
β”œβ”€β”€ middleware/
β”‚   β”œβ”€β”€ auth.js              # Authentication middleware
β”‚   └── errorHandler.js      # Error handling
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ User.js              # User model (Shopkeeper/Admin/Superadmin)
β”‚   β”œβ”€β”€ Order.js             # Order model
β”‚   └── Notification.js      # Notification model
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ auth.js              # Authentication routes
β”‚   β”œβ”€β”€ orders.js            # Order management routes
β”‚   β”œβ”€β”€ admin.js             # Admin management routes
β”‚   └── notifications.js     # Notification routes
β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   └── style.css        # Stylesheet
β”‚   β”œβ”€β”€ js/
β”‚   β”‚   └── config.js        # Frontend configuration
β”‚   β”œβ”€β”€ index.html           # Landing page
β”‚   β”œβ”€β”€ shopkeeper-login.html
β”‚   β”œβ”€β”€ shopkeeper-dashboard.html
β”‚   β”œβ”€β”€ admin-login.html
β”‚   β”œβ”€β”€ admin-dashboard.html
β”‚   β”œβ”€β”€ superadmin-login.html
β”‚   └── superadmin-dashboard.html
β”œβ”€β”€ server.js                # Main server file
β”œβ”€β”€ package.json
β”œβ”€β”€ .env.example
└── README.md

πŸ› Troubleshooting

MongoDB Connection Issues

  • Ensure MongoDB service is running
  • Check the MONGODB_URI in your .env file
  • Verify MongoDB is installed correctly

Port Already in Use

  • Change the PORT in your .env file
  • Or stop the application using that port

Authentication Errors

  • Clear browser localStorage
  • Check if JWT_SECRET is properly set in .env
  • Verify user credentials

Socket.IO Connection Issues

  • Ensure the server is running
  • Check browser console for connection errors
  • Verify SOCKET_URL in public/js/config.js

πŸ”§ Development

Running in Development Mode

npm run dev

This uses nodemon for auto-reloading on file changes.

Database Reset

If you need to reset the database:

# Connect to MongoDB
mongo
# Switch to database
use rajshop
# Drop database
db.dropDatabase()

The superadmin account will be recreated on next server start.

πŸ“ Default Credentials

Superadmin (after first run):

  • Username: superadmin
  • Password: SuperAdmin@123

⚠️ Change these immediately in production!

🌟 Features Highlights

  • βœ… Simple notepad-style order entry
  • βœ… Real-time notifications
  • βœ… Role-based access control
  • βœ… Order status tracking
  • βœ… Admin management
  • βœ… Responsive design
  • βœ… Session management
  • βœ… Audit trail (who delivered, who completed)
  • βœ… Statistics dashboard
  • βœ… Order filtering

πŸ“ž Support

For issues or questions:

  1. Check the troubleshooting section
  2. Review the API endpoints documentation
  3. Check server logs for error messages

πŸ“„ License

ISC

πŸŽ‰ Version

1.0.0


Built with ❀️ for Raj Shop

About

Seller project for Mobile inventory

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages