/CSTechAgents

Internship Assignment Project

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

MERN Stack Application - Agent Management System

A full-stack application built with MongoDB, Express.js, React, and Node.js for managing agents and distributing tasks through CSV uploads.

๐Ÿš€ Features

Backend Features

  • User Authentication: JWT-based authentication with bcrypt password hashing
  • Agent Management: CRUD operations for agent management
  • CSV Processing: Upload and parse CSV/XLSX files with validation
  • Smart Distribution: Automatic distribution of items among agents
  • File Validation: Support for CSV, XLS, and XLSX formats
  • Database Integration: MongoDB with Mongoose ODM

Frontend Features

  • Modern UI: Responsive design with Tailwind CSS
  • TypeScript: Full type safety throughout the application
  • Authentication: Secure login with protected routes
  • Agent Management: Create, view, and manage agents
  • CSV Upload: Drag-and-drop file upload with validation
  • Distribution Overview: View distributed items per agent
  • Real-time Updates: Dynamic data updates and notifications

๐Ÿ“ Project Structure

CSTechAgents/
โ”œโ”€โ”€ Backend/                 # Node.js/Express backend
โ”‚   โ”œโ”€โ”€ Controllers/        # Route controllers
โ”‚   โ”œโ”€โ”€ Database/          # Database connection
โ”‚   โ”œโ”€โ”€ Helper/           # Utility functions
โ”‚   โ”œโ”€โ”€ Middleware/       # Custom middleware
โ”‚   โ”œโ”€โ”€ Model/           # Mongoose models
โ”‚   โ”œโ”€โ”€ Routes/          # API routes
โ”‚   โ””โ”€โ”€ uploads/         # File upload directory
โ”œโ”€โ”€ Frontend/             # React TypeScript frontend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/   # React components
โ”‚   โ”‚   โ”œโ”€โ”€ contexts/    # React contexts
โ”‚   โ”‚   โ”œโ”€โ”€ services/    # API services
โ”‚   โ”‚   โ””โ”€โ”€ types/      # TypeScript types
โ”‚   โ””โ”€โ”€ public/         # Static assets
โ””โ”€โ”€ README.md          # This file

๐Ÿ› ๏ธ Tech Stack

Backend

  • Node.js - Runtime environment
  • Express.js - Web framework
  • MongoDB - Database
  • Mongoose - ODM for MongoDB
  • JWT - Authentication
  • bcrypt - Password hashing
  • Multer - File upload handling
  • CSV-Parse - CSV file parsing
  • XLSX - Excel file processing

Frontend

  • React 19 - UI library
  • TypeScript - Type safety
  • React Router - Navigation
  • Axios - HTTP client
  • React Hook Form - Form management
  • React Hot Toast - Notifications
  • Lucide React - Icons
  • Tailwind CSS - Styling

๐Ÿš€ Getting Started

Prerequisites

  • Node.js (v16 or higher)
  • MongoDB
  • npm or yarn

Backend Setup

  1. Navigate to the backend directory:

    cd Backend
  2. Install dependencies:

    npm install
  3. Create a .env file in the Backend directory:

    PORT=8001
    MONGODB_URI=mongodb://localhost:27017/cstechagents
    JWT_Secret=your_jwt_secret_key
    JWT_Timeout=1h
  4. Start the backend server:

    npm start

The backend will run on http://localhost:8001

Frontend Setup

  1. Navigate to the frontend directory:

    cd Frontend
  2. Install dependencies:

    npm install
  3. Start the development server:

    npm run dev

The frontend will run on http://localhost:5173

๐Ÿ“‹ API Endpoints

Authentication

  • POST /api/user/register - Register new user
  • POST /api/user/login - User login
  • POST /api/user/logout - User logout
  • GET /api/user/profile - Get user profile

Agent Management

  • POST /api/agent/new - Create new agent
  • GET /api/agent/list - Get all agents
  • GET /api/agent/:id - Get agent items

File Upload

  • POST /api/upload/upload-csv - Upload CSV file

๐ŸŽฏ Usage

1. Admin Login

  • Access the application at http://localhost:5173
  • Login with admin credentials
  • Secure JWT-based authentication

2. Agent Management

  • Create new agents with name, email, mobile, and password
  • View all agents in a responsive grid layout
  • Click on agents to view details

3. CSV Upload & Distribution

  • Upload CSV, XLS, or XLSX files
  • Files must contain columns: FirstName, Phone, Notes
  • Items are automatically distributed among all agents
  • View distribution summary after upload

4. Distribution Overview

  • View items assigned to each agent
  • Expandable cards showing detailed item information
  • Real-time statistics and summaries

๐Ÿ“Š Database Schema

User Model

{
  username: String,
  name: String,
  email: String (unique),
  password: String (hashed),
  role: String (admin/agent)
}

Agent Model

{
  name: String,
  email: String (unique),
  mobile: String,
  password: String
}

ListItem Model

{
  firstName: String,
  phone: String,
  notes: String,
  assignedTo: ObjectId (ref: Agents)
}

๐Ÿ”’ Security Features

  • JWT token-based authentication
  • Password hashing with bcrypt
  • CORS configuration
  • File upload validation
  • Input sanitization
  • Protected routes

๐ŸŽจ UI/UX Features

  • Responsive design for all screen sizes
  • Modern, clean interface
  • Drag-and-drop file upload
  • Real-time notifications
  • Loading states and animations
  • Form validation with error messages
  • Accessible design patterns

๐Ÿงช Testing

Backend Testing

cd Backend
npm test

Frontend Testing

cd Frontend
npm test

๐Ÿ“ฆ Deployment

Backend Deployment

  1. Set up MongoDB Atlas or local MongoDB
  2. Configure environment variables
  3. Deploy to Heroku, Railway, or similar platform

Frontend Deployment

  1. Build the production version:
    npm run build
  2. Deploy to Vercel, Netlify, or similar platform

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Support

If you encounter any issues or have questions:

  1. Check the existing issues on GitHub
  2. Create a new issue with detailed information
  3. Contact the development team

๐ŸŽ‰ Acknowledgments

  • React team for the amazing framework
  • MongoDB team for the database solution
  • Express.js team for the web framework
  • All contributors and testers

Happy Coding! ๐Ÿš€