Skip to content

Full-stack Office Management System with Node.js, Express, MongoDB & JWT authentication. Features CRUD operations, search, pagination, location API integration & comprehensive documentation.

License

Notifications You must be signed in to change notification settings

vvinit594/Node.js_Assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏒 Office Management System# Office Management System

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.

Node.js## πŸš€ Features

MongoDB

License- Department Management: Create, Read, Update, and Delete departments

Status- 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

πŸ“‹ Table of Contents- Pagination: Server-side pagination for efficient data handling

---Before running this project, make sure you have the following installed:

✨ Features- Node.js (v14 or higher)

  • MongoDB (v4.4 or higher)

Core Functionality- npm or yarn package manager

  • πŸ” 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)

πŸ“ Project Structure

Verify Installation

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

βš™οΈ Configuration- GET /employees/:id - View employee details

  • 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

🎯 Running the Application- jobTitle - Filter by job title

Development Mode## πŸ“Έ Screenshots

npm start*(Screenshots will be added after complete implementation)*

πŸ§ͺ Testing with Postman

Access Application


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

Login

POST /auth/login
Body: email, password
Response: JWT cookie + redirect to dashboard

Logout

GET /auth/logout
Response: Clear cookie + redirect to login

Departments

GET    /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          # Delete

Employees

GET    /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            # Delete

Query Parameters

  • page - Page number (default: 1)
  • search - Search by name/email
  • department - Filter by department ID
  • jobTitle - Filter by job title

Location API

GET /api/countries               # Get all countries
GET /api/states/:country         # Get states by country
GET /api/cities/:country/:state  # Get cities by state

πŸ” Authentication

JWT Flow

  1. Signup β†’ Password hashed β†’ JWT token β†’ httpOnly cookie
  2. Login β†’ Password verified β†’ JWT token β†’ httpOnly cookie
  3. Access Protected Route β†’ Token verified β†’ Access granted
  4. Logout β†’ Cookie cleared β†’ Redirect to login

Security Features

βœ… 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


πŸ’Ύ Database Schema

Admin

{
  name: String,
  email: String (unique),
  password: String (hashed),
  isActive: Boolean,
  lastLogin: Date,
  loginAttempts: Number,
  lockUntil: Date
}

Department

{
  name: String,
  code: String (unique),
  description: String,
  isActive: Boolean
}

Employee

{
  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
}

πŸ§ͺ Testing

Manual Testing

  1. Auth Flow:

    • Signup new admin
    • Logout and login
    • Try wrong password (test lockout)
    • Access protected routes without login
  2. CRUD Operations:

    • Create/Edit/Delete departments
    • Create/Edit/Delete employees
    • Test search and filters
    • Test pagination
  3. Location Cascade:

    • Select country β†’ states load
    • Select state β†’ cities load
    • Edit mode β†’ values restore

Postman Collection

See AUTH_DOCUMENTATION.md for detailed API testing guide.


πŸš€ Deployment

Environment Setup

NODE_ENV=production
MONGODB_URI=mongodb+srv://...
JWT_SECRET=strong-random-key

Heroku

heroku create app-name
heroku config:set MONGODB_URI=...
heroku config:set JWT_SECRET=...
git push heroku main

Security Checklist

  • 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

πŸ“„ License

This project is licensed under the MIT License.


πŸ‘¨β€πŸ’» Author

Internship Assignment Project

Built with ❀️ using Node.js, Express, MongoDB, and JWT


πŸ™ Acknowledgments

  • Node.js & Express.js communities
  • MongoDB documentation
  • Tailwind CSS framework
  • CountriesNow API
  • Font Awesome icons

πŸ“ž Support

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

About

Full-stack Office Management System with Node.js, Express, MongoDB & JWT authentication. Features CRUD operations, search, pagination, location API integration & comprehensive documentation.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published