A full-stack web application for managing office departments and employees with JWT authentication, built with Node.js, Express, MongoDB, and EJS templating.A comprehensive RESTful Office Management System built with Node.js, Express, MongoDB, and EJS templating engine. This system enables efficient management of departments and employees with advanced features like pagination, search, filters, and external API integration for location data.
- Department Management: Create, Read, Update, and Delete departments
- Employee Management: Full CRUD operations for employees
- Hierarchical Structure: Self-referencing supervisor relationships
---- Advanced Search: Search employees by name or email
- Filtering: Filter employees by department or job title
-
Location Integration: Dynamic Country, State, and City selection using external API
-
Features- Responsive UI: Modern interface built with Tailwind CSS
-
Tech Stack- RESTful API: Clean and well-structured API endpoints
-
Installation## π οΈ Technology Stack
-
Running the Application- Backend: Node.js, Express.js
-
Project Structure- Database: MongoDB with Mongoose ODM
-
API Documentation- Frontend: EJS (Embedded JavaScript Templates)
-
Authentication- Styling: Tailwind CSS
-
Database Schema- External API: CountriesNow API for location data
-
Testing- Tools: Postman (API Testing)
-
License## π Prerequisites
---Before running this project, make sure you have the following installed:
- MongoDB (v4.4 or higher)
-
π JWT Authentication System - Secure login/signup with bcrypt password hashing
-
π₯ Employee Management - Complete CRUD operations for employees## π§ Installation & Setup
-
π’ Department Management - Full CRUD functionality for departments
-
π Advanced Search & Filters - Search by name/email, filter by department/job title### 1. Clone the Repository
-
π Server-Side Pagination - Efficient data loading with customizable page limits
-
π Location API Integration - Dynamic Country β State β City cascade dropdowns```bash
-
π Supervisor Relationships - Self-referencing employee hierarchygit clone
-
π Dashboard Statistics - Real-time employee/department counts and insightscd Assignment1
### Security Features
- π Password hashing using bcrypt (10 salt rounds)### 2. Install Dependencies
- π« JWT tokens with 1-hour expiry
- πͺ httpOnly cookies for XSS protection```bash
- π« Account lockout after 5 failed login attemptsnpm install
- β
Protected routes with authentication middleware```
- π Environment-based secret key management
### 3. Environment Configuration
### User Experience
- π¨ Modern UI with Tailwind CSSCreate a `.env` file in the root directory (already provided) and configure:
- π± Fully responsive design
- π Beautiful gradient login/signup pages```env
- π« Smooth animations and transitionsPORT=3000
- π Toast notifications and alertsNODE_ENV=development
- π Form validations (client & server-side)MONGODB_URI=mongodb://localhost:27017/office_management_system
- π±οΈ Intuitive navigation with dropdown menusCOUNTRIES_API_URL=https://countriesnow.space/api/v0.1
APP_NAME=Office Management System
---```
## π οΈ Tech Stack### 4. Start MongoDB
### BackendMake sure MongoDB is running on your system:
- **Runtime:** Node.js v18+
- **Framework:** Express.js v4.18.2```bash
- **Database:** MongoDB v6+# Windows
- **ODM:** Mongoose v8.0.0net start MongoDB
- **Authentication:** JWT (jsonwebtoken v9.0.0)
- **Password Hashing:** bcryptjs v2.4.3# macOS/Linux
sudo systemctl start mongod
### Frontend```
- **Template Engine:** EJS
- **CSS Framework:** Tailwind CSS v3 (CDN)### 5. Run the Application
- **Icons:** Font Awesome v6.4.0
- **JavaScript:** Vanilla JS (ES6+)**Development Mode** (with auto-restart):
```bash
### External APIsnpm run dev
- **CountriesNow API** - For location data```
---**Production Mode**:
```bash
## π¦ Prerequisitesnpm start
-
Node.js (v18 or higher) - Download
-
MongoDB (v6 or higher) - DownloadThe application will be available at:
http://localhost:3000 -
npm (comes with Node.js)
bash
node --version # Should be v18+office-management-system/
npm --version # Should be v9+βββ config/
mongod --version # Should be v6+β βββ database.js # MongoDB connection configuration
β βββ departmentController.js # Department business logic
---β βββ employeeController.js # Employee business logic
βββ models/
## π Installationβ βββ Department.js # Department schema
β βββ Employee.js # Employee schema
### 1. Clone or Downloadβββ routes/
```bashβ βββ departmentRoutes.js # Department API routes
git clone <repository-url>β βββ employeeRoutes.js # Employee API routes
cd office-management-systemβββ views/
```β βββ layouts/
β β βββ header.ejs # Common header template
### 2. Install Dependenciesβ β βββ footer.ejs # Common footer template
```bashβ βββ departments/
npm installβ β βββ list.ejs # Department listing page
```β β βββ form.ejs # Department create/edit form
β βββ employees/
### 3. Setup MongoDBβ β βββ list.ejs # Employee listing with pagination
```bashβ β βββ form.ejs # Employee create/edit form
# Start MongoDB serviceβ βββ index.ejs # Home page
# Windowsβββ public/
net start MongoDBβ βββ css/
β β βββ style.css # Custom styles
# macOS/Linuxβ βββ js/
sudo systemctl start mongodβ βββ main.js # Main JavaScript file
```β βββ location-api.js # Location API integration
βββ middleware/
### 4. Configure Environmentβ βββ errorHandler.js # Global error handling
βββ utils/
Create `.env` file:β βββ apiHelper.js # External API helper functions
```envβββ .env # Environment variables
# Serverβββ .gitignore # Git ignore rules
PORT=3000βββ app.js # Application entry point
NODE_ENV=developmentβββ package.json # Project dependencies
βββ README.md # Project documentation
# Database```
MONGODB_URI=mongodb://127.0.0.1:27017/office_management_system
## π API Endpoints
# JWT
JWT_SECRET=your-secret-key-change-in-production### Departments
JWT_EXPIRE=1h
- `GET /departments` - List all departments
# External API- `GET /departments/new` - Show create form
COUNTRIES_API_URL=https://countriesnow.space/api/v0.1- `POST /departments` - Create new department
```- `GET /departments/:id/edit` - Show edit form
- `PUT /departments/:id` - Update department
### 5. Seed Database (Optional)- `DELETE /departments/:id` - Delete department
```bash
node seed.js### Employees
GET /employees- List employees (with pagination, search, filter)
---- GET /employees/new - Show create form
POST /employees- Create new employee
GET /employees/:id/edit- Show edit form
| Variable | Description | Default |- PUT /employees/:id - Update employee
|----------|-------------|---------|- DELETE /employees/:id - Delete employee
| PORT | Server port | 3000 |
| MONGODB_URI | MongoDB connection string | mongodb://127.0.0.1:27017/office_management_system |### Query Parameters for Employee Listing
| JWT_SECRET | JWT secret key | Required |
| JWT_EXPIRE | Token expiration | 1h |- page - Page number (default: 1)
limit- Items per page (default: 10)
---- search - Search by name or email
department- Filter by department ID
npm start*(Screenshots will be added after complete implementation)*
http://localhost:3000
```*(Postman collection will be added in final phase)*
### First-Time Setup## π₯ Author
1. Visit `http://localhost:3000`
2. Redirected to `/auth/signup`**Your Name**
3. Create admin account- GitHub: [@yourusername]
4. Auto-login to dashboard- LinkedIn: [Your LinkedIn Profile]
5. Start managing!
## π License
---
This project is licensed under the ISC License.
## π Project Structure
## π Acknowledgments
office-management-system/- CountriesNow API for location data
βββ config/- Express.js team
β βββ database.js # MongoDB connection- MongoDB team
βββ controllers/- Tailwind CSS team
β βββ authController.js # Auth logic
β βββ departmentController.js # Department CRUD---
β βββ employeeController.js # Employee CRUD
βββ middleware/Note: This project is built as part of an internship assignment to demonstrate full-stack development skills with Node.js, Express, and MongoDB.
β βββ auth.js # JWT middleware β βββ errorHandler.js # Error handling βββ models/ β βββ Admin.js # Admin schema β βββ Department.js # Department schema β βββ Employee.js # Employee schema βββ public/ β βββ css/style.css # Custom styles β βββ js/ β βββ main.js # Utilities β βββ location-api.js # Location logic βββ routes/ β βββ authRoutes.js # Auth endpoints β βββ departmentRoutes.js # Department routes β βββ employeeRoutes.js # Employee routes β βββ apiRoutes.js # API proxy βββ utils/ β βββ apiHelper.js # API wrapper βββ views/ β βββ auth/ # Auth pages β βββ departments/ # Department views β βββ employees/ # Employee views β βββ layouts/ # Common layouts β βββ index.ejs # Dashboard βββ .env # Environment vars βββ app.js # Entry point βββ package.json # Dependencies βββ seed.js # Seeding script
---
## π API Documentation
### Authentication
#### Signup
```http
POST /auth/signup
Body: name, email, password, confirmPassword
Response: JWT cookie + redirect to dashboard
POST /auth/login
Body: email, password
Response: JWT cookie + redirect to dashboardGET /auth/logout
Response: Clear cookie + redirect to loginGET /departments # List all
GET /departments/new # Show create form
POST /departments # Create new
GET /departments/:id/edit # Show edit form
PUT /departments/:id # Update
DELETE /departments/:id # DeleteGET /employees # List with pagination/filters
GET /employees/new # Show create form
POST /employees # Create new
GET /employees/:id # View details
GET /employees/:id/edit # Show edit form
PUT /employees/:id # Update
DELETE /employees/:id # Deletepage- Page number (default: 1)search- Search by name/emaildepartment- Filter by department IDjobTitle- Filter by job title
GET /api/countries # Get all countries
GET /api/states/:country # Get states by country
GET /api/cities/:country/:state # Get cities by state- Signup β Password hashed β JWT token β httpOnly cookie
- Login β Password verified β JWT token β httpOnly cookie
- Access Protected Route β Token verified β Access granted
- Logout β Cookie cleared β Redirect to login
β
bcrypt password hashing (10 rounds)
β
JWT with 1-hour expiry
β
httpOnly cookies (XSS prevention)
β
Account lockout (5 failed attempts)
β
Login attempt tracking
β
Environment-based secrets
{
name: String,
email: String (unique),
password: String (hashed),
isActive: Boolean,
lastLogin: Date,
loginAttempts: Number,
lockUntil: Date
}{
name: String,
code: String (unique),
description: String,
isActive: Boolean
}{
firstName: String,
lastName: String,
email: String (unique),
phone: String,
jobTitle: String,
department: ObjectId (ref: Department),
supervisor: ObjectId (ref: Employee),
salary: Number,
dateOfJoining: Date,
country: String,
state: String,
city: String,
address: String,
isActive: Boolean
}-
Auth Flow:
- Signup new admin
- Logout and login
- Try wrong password (test lockout)
- Access protected routes without login
-
CRUD Operations:
- Create/Edit/Delete departments
- Create/Edit/Delete employees
- Test search and filters
- Test pagination
-
Location Cascade:
- Select country β states load
- Select state β cities load
- Edit mode β values restore
See AUTH_DOCUMENTATION.md for detailed API testing guide.
NODE_ENV=production
MONGODB_URI=mongodb+srv://...
JWT_SECRET=strong-random-keyheroku create app-name
heroku config:set MONGODB_URI=...
heroku config:set JWT_SECRET=...
git push heroku main- Change JWT_SECRET to strong random string
- Enable HTTPS (secure cookies)
- Use MongoDB Atlas (cloud database)
- Set NODE_ENV=production
- Configure CORS if needed
- Enable rate limiting
- Set up logging
This project is licensed under the MIT License.
Internship Assignment Project
Built with β€οΈ using Node.js, Express, MongoDB, and JWT
- Node.js & Express.js communities
- MongoDB documentation
- Tailwind CSS framework
- CountriesNow API
- Font Awesome icons
For issues or questions:
- Check documentation in
AUTH_DOCUMENTATION.md - Review code comments
- Test with provided seed data
β Production-Ready Office Management System β
Complete with JWT Authentication, CRUD Operations, and Modern UI