A comprehensive full-stack web application for managing office departments and employees with a modern, responsive interface and secure authentication.
The frontend can now run completely independently without a backend server! Perfect for:
- ✅ Vercel/Netlify deployments
- ✅ Quick demos and prototypes
- ✅ Portfolio projects
- ✅ Frontend development/testing
- Authentication: Any credentials accepted (demo mode)
- Mock Data: 83 employees, 6 departments with full statistics
- Location API: Direct integration with CountriesNow API for country/state/city dropdowns
- All Features: Search, filter, sort, CSV export, dashboard charts
📖 See DEPLOYMENT_GUIDE.md for complete deployment instructions
- Features
- Technology Stack
- Project Structure
- Installation
- Configuration
- Running the Application
- API Documentation
- Authentication
- Database Schema
- Screenshots
- License
- Department Management: Create, read, update, and delete departments
- Employee Management: Comprehensive employee CRUD operations
- Employee-Department Relationship: Link employees to departments with automatic reference management
- Advanced Search & Filtering: Search by name, filter by department, location, and status
- Pagination: Efficient data loading with customizable page sizes
- Sorting: Multi-field sorting capabilities
- 📊 Interactive Dashboard: Real-time statistics with pie and bar charts using Recharts
- 🔐 JWT Authentication: Secure admin login/signup with token-based authentication
- 📥 CSV Export: Export employee and department data to CSV files
- 📱 Responsive Design: Mobile-first design with Tailwind CSS
- 🔔 Toast Notifications: User-friendly notifications for all actions
- 🎨 Modern UI: Clean, professional interface with gradient backgrounds
- RESTful API architecture
- MongoDB with Mongoose ODM
- Input validation and error handling
- Protected routes with JWT middleware
- Automatic department reference counting
- Password hashing with bcrypt
- CORS enabled for cross-origin requests
- Runtime: Node.js (v18+)
- Framework: Express.js (v4.18.2)
- Database: MongoDB (v7+) with Mongoose (v8.0.3)
- Authentication: JWT (jsonwebtoken v9.0.2) + bcryptjs (v2.4.3)
- Validation: Express Validator
- Environment: dotenv (v16.3.1)
- Security: CORS, bcrypt password hashing
- Library: React (v18.2.0)
- Build Tool: Vite (v5.4.21)
- Styling: Tailwind CSS (v3.4.0)
- Routing: React Router DOM (v6.21.0)
- HTTP Client: Axios (v1.6.2)
- Charts: Recharts (v2.15.0)
- Notifications: React Toastify (v10.0.6)
- Icons: React Icons (v4.12.0)
Node.js_Ass/
├── backend/
│ ├── config/
│ │ └── db.js # MongoDB connection
│ ├── controllers/
│ │ ├── departmentController.js
│ │ ├── employeeController.js
│ │ └── authController.js # Authentication logic
│ ├── middleware/
│ │ ├── errorHandler.js # Global error handler
│ │ └── auth.js # JWT verification middleware
│ ├── models/
│ │ ├── Department.js # Department schema
│ │ ├── Employee.js # Employee schema
│ │ └── User.js # User/Admin schema
│ ├── routes/
│ │ ├── departmentRoutes.js
│ │ ├── employeeRoutes.js
│ │ └── authRoutes.js
│ ├── .env # Environment variables
│ ├── server.js # Express app entry point
│ └── package.json
│
├── frontend/
│ ├── public/
│ ├── src/
│ │ ├── components/
│ │ │ ├── auth/
│ │ │ │ └── ProtectedRoute.jsx
│ │ │ ├── common/
│ │ │ │ ├── Button.jsx
│ │ │ │ ├── Input.jsx
│ │ │ │ ├── Modal.jsx
│ │ │ │ ├── Pagination.jsx
│ │ │ │ └── SearchBar.jsx
│ │ │ ├── layout/
│ │ │ │ ├── Layout.jsx
│ │ │ │ └── Navbar.jsx
│ │ │ ├── departments/
│ │ │ │ ├── DepartmentForm.jsx
│ │ │ │ └── DepartmentTable.jsx
│ │ │ └── employees/
│ │ │ ├── EmployeeForm.jsx
│ │ │ ├── EmployeeTable.jsx
│ │ │ └── EmployeeFilters.jsx
│ │ ├── pages/
│ │ │ ├── auth/
│ │ │ │ ├── Login.jsx
│ │ │ │ └── Signup.jsx
│ │ │ ├── departments/
│ │ │ │ └── DepartmentList.jsx
│ │ │ ├── employees/
│ │ │ │ └── EmployeeList.jsx
│ │ │ └── Dashboard.jsx
│ │ ├── services/
│ │ │ ├── api.js # Axios configuration
│ │ │ ├── authService.js # Auth API calls
│ │ │ ├── departmentService.js
│ │ │ └── employeeService.js
│ │ ├── utils/
│ │ │ └── toast.js # Toast configuration
│ │ ├── App.jsx # Main app component
│ │ ├── index.css # Global styles
│ │ └── main.jsx # React entry point
│ ├── .env # Frontend environment variables
│ ├── package.json
│ ├── vite.config.js
│ └── tailwind.config.js
│
└── README.md
- Node.js (v18 or higher)
- MongoDB (v7 or higher)
- npm or yarn package manager
git clone <repository-url>
cd Node.js_Ass# Navigate to backend directory
cd backend
# Install dependencies
npm install
# The required dependencies will be installed:
# express, mongoose, dotenv, cors, express-validator, jsonwebtoken, bcryptjs# Navigate to frontend directory
cd ../frontend
# Install dependencies
npm install
# The required dependencies will be installed:
# react, react-dom, react-router-dom, axios, tailwind CSS, react-icons,
# recharts, react-toastify, and moreCreate a .env file in the backend directory:
# Server Configuration
PORT=5000
NODE_ENV=development
# MongoDB Configuration
MONGODB_URI=mongodb://127.0.0.1:27017/office_management
# JWT Configuration
JWT_SECRET=your_super_secret_jwt_key_12345
JWT_EXPIRE=7dJWT_SECRET to a strong, unique secret in production!
Create a .env file in the frontend directory:
VITE_API_URL=http://localhost:5000/apiTerminal 1 - Backend:
cd backend
npm startThe backend server will start on http://localhost:5000
Terminal 2 - Frontend:
cd frontend
npm run devThe frontend will start on http://localhost:5173
Backend (with auto-reload):
cd backend
npm run dev # If nodemon is configuredFrontend (Vite dev server):
cd frontend
npm run dev- Frontend: http://localhost:5173
- Backend API: http://localhost:5000/api
- MongoDB: mongodb://127.0.0.1:27017
{
name: String (required, unique),
description: String,
manager: String,
employeeCount: Number (default: 0),
createdAt: Date,
updatedAt: Date
}{
firstName: String (required),
lastName: String (required),
email: String (required, unique),
phone: String (required),
department: ObjectId (ref: 'Department'),
position: String (required),
salary: Number (required, min: 0),
hireDate: Date (required),
isActive: Boolean (default: true),
location: {
city: String,
state: String,
country: String
},
createdAt: Date,
updatedAt: Date
}{
name: String (required),
email: String (required, unique, lowercase),
password: String (required, hashed with bcrypt),
role: String (default: 'admin'),
isActive: Boolean (default: true),
createdAt: Date,
updatedAt: Date
}The application includes sample data to get started quickly. When you run the backend for the first time, it automatically seeds:
6 Departments:
- IT Department
- Human Resources
- Finance
- Marketing
- Operations
- Sales
18 Employees:
- 3 employees per department with realistic data including names, emails, positions, salaries, and locations
- Signup: Create admin account at
/signup - Login: Authenticate at
/login - Token Storage: JWT token stored in localStorage
- Protected Routes: All management pages require authentication
- Auto-Logout: Token expires after 7 days
- Token Refresh: Automatic token attachment to API requests
POST /api/auth/signup
POST /api/auth/login
GET /api/auth/me (Protected)- Navigate to http://localhost:5173/signup
- Fill in the registration form:
- Name: Your Name
- Email: admin@example.com
- Password: (minimum 6 characters)
- Confirm Password: (must match)
- Click "Sign Up"
- You'll be automatically logged in and redirected to the dashboard
http://localhost:5000/api
POST /api/auth/signup
Content-Type: application/json
{
"name": "Admin User",
"email": "admin@example.com",
"password": "securepassword123"
}
Response: {
"success": true,
"token": "jwt_token_here",
"data": {
"_id": "user_id",
"name": "Admin User",
"email": "admin@example.com",
"role": "admin"
}
}POST /api/auth/login
Content-Type: application/json
{
"email": "admin@example.com",
"password": "securepassword123"
}
Response: {
"success": true,
"token": "jwt_token_here",
"data": {
"_id": "user_id",
"name": "Admin User",
"email": "admin@example.com",
"role": "admin"
}
}GET /api/auth/me
Authorization: Bearer <jwt_token>
Response: {
"success": true,
"data": {
"_id": "user_id",
"name": "Admin User",
"email": "admin@example.com",
"role": "admin"
}
}GET /api/departments
Authorization: Bearer <jwt_token>
Response: {
"success": true,
"count": 6,
"data": [...]
}GET /api/departments/:id
Authorization: Bearer <jwt_token>POST /api/departments
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"name": "Engineering",
"description": "Software development team",
"manager": "John Doe"
}PUT /api/departments/:id
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"description": "Updated description"
}DELETE /api/departments/:id
Authorization: Bearer <jwt_token>
Response: {
"success": true,
"message": "Department deleted successfully"
}GET /api/employees?page=1&limit=10&search=john&department=dept_id&location=New York&isActive=true&sortBy=firstName&sortOrder=asc
Authorization: Bearer <jwt_token>
Response: {
"success": true,
"count": 18,
"pagination": {
"page": 1,
"limit": 10,
"total": 18,
"pages": 2
},
"data": [...]
}GET /api/employees/:id
Authorization: Bearer <jwt_token>POST /api/employees
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com",
"phone": "+1234567890",
"department": "department_id",
"position": "Software Engineer",
"salary": 75000,
"hireDate": "2024-01-15",
"location": {
"city": "New York",
"state": "NY",
"country": "USA"
}
}PUT /api/employees/:id
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"position": "Senior Software Engineer",
"salary": 95000
}DELETE /api/employees/:id
Authorization: Bearer <jwt_token>
Response: {
"success": true,
"message": "Employee deleted successfully"
}GET /api/employees/stats/summary
Authorization: Bearer <jwt_token>
Response: {
"success": true,
"data": {
"totalEmployees": 18,
"activeEmployees": 17,
"departmentCount": 6,
"averageSalary": 71666.67,
"employeesByDepartment": [...],
"employeesByLocation": [...]
}
}- Signup: Create new admin account with validation
- Login: Secure login with JWT token generation
- Protected Routes: Automatic redirect to login for unauthenticated users
- Logout: Clear session and redirect to login page
- Statistics Cards: Total employees, active employees, departments, average salary
- Pie Chart: Employee distribution by department
- Bar Chart: Employee distribution by location
- Real-time Updates: Data refreshes automatically
- List View: All departments with employee count
- Search: Find departments by name
- Create: Add new departments with validation
- Edit: Update department information
- Delete: Remove departments (with employee count warning)
- Advanced Filters: Department, location, active status
- Search: Search by name or email
- Pagination: Configurable page size (10, 25, 50, 100)
- Sorting: Sort by any column
- Create: Add employees with full details
- Edit: Update employee information
- Delete: Remove employees (updates department count)
- CSV Export: Export filtered data to CSV
- Mobile Navigation: Hamburger menu for small screens
- Responsive Tables: Horizontal scroll on mobile
- Touch-Friendly: Large click targets for mobile
- Adaptive Layouts: Optimized for all screen sizes
Error: MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017
Solution: Ensure MongoDB is running:
# Windows
net start MongoDB
# macOS/Linux
sudo systemctl start mongodError: listen EADDRINUSE: address already in use :::5000
Solution: Change the port in .env or kill the process using the port:
# Windows
netstat -ano | findstr :5000
taskkill /PID <PID> /F
# macOS/Linux
lsof -ti:5000 | xargs kill -9Solution: Ensure backend CORS is configured correctly in server.js:
app.use(cors({
origin: 'http://localhost:5173',
credentials: true
}));- Check if JWT_SECRET is set in backend
.env - Clear localStorage in browser console:
localStorage.clear() - Ensure token is being sent in Authorization header
- Check backend logs for JWT verification errors
- Use functional components with React Hooks
- Keep components small and focused
- Use service layer for API calls
- Implement proper error handling
- Follow async/await patterns
- Validate all user inputs
- Use environment variables for configuration
- Handle errors gracefully with user-friendly messages
- Implement loading states for async operations
- Use meaningful variable and function names
- Comment complex logic
- Never commit
.envfiles - Use strong JWT secrets in production
- Implement rate limiting for API endpoints
- Validate and sanitize all inputs
- Use HTTPS in production
- Implement proper CORS policies
- Set environment variables in platform settings
- Update MongoDB URI to production database
- Set
NODE_ENV=production - Deploy code
- Update
VITE_API_URLto production backend URL - Build the project:
npm run build - Deploy the
distfolder
All API responses follow this structure:
Success Response:
{
"success": true,
"data": { ... },
"count": 10,
"pagination": { ... }
}Error Response:
{
"success": false,
"error": "Error message here"
}- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License.
Your Name - Office Management System
- React team for the amazing library
- Express.js community
- MongoDB team
- Tailwind CSS for the utility-first CSS framework
- Recharts for beautiful charts
- All open-source contributors
Made with ❤️ using Node.js, React, and MongoDB
For issues and questions, please open an issue on the repository.



