A comprehensive full-stack web application for managing office departments and employees with a modern, responsive interface and secure authentication.
- 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.