Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation


**File: README.md**

# 🚀 MERN Task Distribution System

A full-stack MERN application designed to automate the distribution of tasks (leads) among agents. Admins can upload CSV or Excel files, and the system intelligently distributes the rows equally among the created agents using a Round Robin algorithm.

---

## 📋 Features

### **1. Admin Authentication**
- Secure Login & Registration system using **JWT (JSON Web Tokens)**.
- Passwords encrypted using **Bcrypt**.
- **Data Isolation:** Admins only see agents and tasks they created.

### **2. Agent Management**
- Create new agents with validation (Email regex, Mobile number length).
- View list of all active agents.
- Agents are linked specifically to the admin who created them.

### **3. File Upload & Distribution**
- Supports **.csv**, **.xlsx**, and **.xls** file formats.
- **Validation:** automatically checks for required headers (`FirstName`, `Phone`, `Notes`).
- **Algorithm:** Distributes tasks equally (e.g., 25 tasks ÷ 5 agents = 5 tasks each).
- **Sequential Remainder Handling:** If tasks don't divide evenly, remainders are distributed sequentially.

### **4. Dashboard Features**
- **Visual Distribution Board:** See exactly which tasks are assigned to which agent.
- **Master List View:** View raw uploaded data in a table format.
- **Redistribute Feature:** Re-shuffle existing tasks when new agents are added without re-uploading.
- **Reset Data:** One-click clear all tasks for re-testing.

---

## 🛠️ Tech Stack

- **Frontend:** React.js (Vite), Tailwind CSS, Lucide React (Icons), Axios.
- **Backend:** Node.js, Express.js.
- **Database:** MongoDB (Mongoose).
- **File Handling:** Multer, CSV-Parser, XLSX.
- **Security:** Helmet, CORS, Dotenv.

---

## ⚙️ Installation & Setup

Follow these steps to run the application locally.

### **Prerequisites**
- Node.js installed (v14+ recommended).
- MongoDB installed locally or a MongoDB Atlas connection string.

### **Step 1: Clone the Repository**
```bash
git clone <repository_url>
cd mern-task-distributor

Step 2: Backend Setup

  1. Navigate to the root folder (or backend folder if separated).
  2. Install dependencies:
npm install
  1. Create a .env file in the root directory and add the following:
PORT=5000
MONGO_URI=your_mongodb_connection_string_here
JWT_SECRET=your_super_secret_key_123
  1. Start the Server:
npm start
# or for development with nodemon:
npm run dev

Server should run on http://localhost:5000

Step 3: Frontend Setup

  1. Open a new terminal and navigate to the client folder:
cd client
  1. Install dependencies:
npm install
  1. Start the React App:
npm run dev

Frontend should run on http://localhost:5173


📝 Usage Guide

  1. Register/Login:
  • Open the frontend URL.
  • Click "Create Admin Account" to register.
  • Log in with your credentials.
  1. Create Agents:
  • On the Dashboard, use the "Add Agent" form on the left.
  • Add at least 2 agents to see distribution in action.
  1. Upload Data:
  • Prepare a CSV or Excel file with the following headers:
FirstName,Phone,Notes
John Doe,1234567890,Interested
Jane Smith,9876543210,Follow up
  • Upload the file using the "Manage Data" section.
  1. View Results:
  • The "Distribution Board" will automatically update to show tasks assigned to each agent.
  • Use the "Master List" toggle to view raw data.

📡 API Endpoints

Method Endpoint Description Access
POST /api/users/login Authenticate admin & get token Public
POST /api/users Register a new admin Public
GET /api/agents Get all agents created by admin Private
POST /api/agents Create a new agent Private
POST /api/upload Upload CSV/Excel & distribute Private
GET /api/leads Get distributed leads Private
PUT /api/leads Redistribute existing leads Private
DELETE /api/leads Clear all leads Private

📂 Project Structure

├── config/             # Database connection
├── controllers/        # Logic for Agents, Users, Uploads
├── middleware/         # Auth & Error handling
├── models/             # Mongoose Schemas (User, Agent, Lead)
├── routes/             # API Routes
├── utils/              # Helper functions (Token generation)
├── client/             # React Frontend (Vite)
│   ├── src/
│   │   ├── pages/      # Dashboard, Login, Register
│   │   └── App.jsx     # Main Router
└── server.js           # Entry point


🧪 Valid CSV Format Example

Create a file named data.csv:

FirstName,Phone,Notes
Alice Johnson,555-0101,High Priority
Bob Smith,555-0102,Callback requested
Charlie Brown,555-0103,Not interested
Diana Prince,555-0104,Send email
Evan Wright,555-0105,Meeting scheduled

Developed for MERN Stack Machine Test.


About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages