A comprehensive Spring Boot application for managing employees, departments, and leave requests with RabbitMQ notifications and Docker deployment.
- Features
- Technology Stack
- Architecture Overview
- Prerequisites
- Setup Instructions
- API Documentation
- Security
- Testing
- Docker Deployment
- Assumptions
- Employee Management: Create, read, update, and delete employee records
- Department Management: Organize employees by departments
- Leave Request System: Submit and manage leave requests with approval workflow
- Notification System: Real-time notifications via RabbitMQ for:
- New employee welcome messages
- Leave request status updates
- Security: Role-based access control (ADMIN and USER roles)
- Pagination & Sorting: Efficient data retrieval with pagination support
- Containerization: Full Docker support for easy deployment
- Java: 17
- Spring Boot: 3.2.1
- Database: PostgreSQL (production), H2 (testing)
- Message Queue: RabbitMQ
- Security: Spring Security with Basic Authentication
- Build Tool: Maven
- Testing: JUnit 5, Mockito, Spring Boot Test
- Containerization: Docker & Docker Compose
The application follows a layered architecture pattern:
┌─────────────────────────────────────────┐
│ REST Controllers │
│ (Employee, Department, LeaveRequest) │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ Service Layer │
│ (Business Logic & Validation) │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ Repository Layer (JPA) │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ Database (PostgreSQL) │
└─────────────────────────────────────────┘
Message Flow
┌─────────────────────────────────────────┐
│ RabbitMQ Message Publisher │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ RabbitMQ Broker │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ RabbitMQ Message Consumer │
│ (Simulates Email Sending) │
└─────────────────────────────────────────┘
- Entities: Employee, Department, LeaveRequest
- DTOs: Data Transfer Objects for API communication
- Repositories: Spring Data JPA repositories
- Services: Business logic implementation
- Controllers: REST API endpoints
- Message Publisher/Consumer: RabbitMQ integration
- Security Config: Spring Security configuration
- Java 17 or higher
- Maven 3.6+
- Docker and Docker Compose (for containerized deployment)
- PostgreSQL (if running locally without Docker)
- RabbitMQ (if running locally without Docker)
-
Clone the repository
git clone <repository-url> cd employee-management-system
-
Build and run with Docker Compose
docker-compose up --build
-
Access the application
- Application: http://localhost:8080
- RabbitMQ Management: http://localhost:15672 (guest/guest)
-
Stop the application
docker-compose down
-
Clone the repository
git clone <repository-url> cd employee-management-system
-
Configure database
- Install PostgreSQL
- Create database:
employeedb - Update
src/main/resources/application.ymlwith your database credentials
-
Configure RabbitMQ
- Install RabbitMQ
- Start RabbitMQ service
- Default credentials: guest/guest
-
Build the application
mvn clean install
-
Run the application
mvn spring-boot:run
-
Access the application
- Application: http://localhost:8080
All endpoints require Basic Authentication. Use the following credentials:
Admin User:
- Username:
admin - Password:
admin123 - Roles: ADMIN (full access)
Regular User:
- Username:
user - Password:
user123 - Roles: USER (limited access)
http://localhost:8080/api
GET /api/employees?page=0&size=10&sortBy=fullName&sortDirection=ASC&departmentId=1Query Parameters:
page(optional, default: 0): Page numbersize(optional, default: 10): Page sizesortBy(optional, default: fullName): Sort field (fullName, department, joiningDate)sortDirection(optional, default: ASC): Sort direction (ASC, DESC)departmentId(optional): Filter by department ID
Authorization: ADMIN, USER
Response:
{
"success": true,
"message": "Employees retrieved successfully",
"data": {
"content": [
{
"employeeId": 1,
"fullName": "John Doe",
"email": "john@example.com",
"departmentId": 1,
"departmentName": "Engineering",
"salary": 50000,
"joiningDate": "2024-01-15",
"createdAt": "2024-01-15T10:30:00",
"updatedAt": "2024-01-15T10:30:00"
}
],
"totalElements": 1,
"totalPages": 1,
"size": 10,
"number": 0
}
}GET /api/employees/{id}Authorization: ADMIN, USER
POST /api/employees
Content-Type: application/json
{
"fullName": "John Doe",
"email": "john@example.com",
"departmentId": 1,
"salary": 50000,
"joiningDate": "2024-01-15"
}Authorization: ADMIN only
Response: 201 Created
PUT /api/employees/{id}
Content-Type: application/json
{
"fullName": "John Doe Updated",
"email": "john@example.com",
"departmentId": 1,
"salary": 55000,
"joiningDate": "2024-01-15"
}Authorization: ADMIN only
DELETE /api/employees/{id}Authorization: ADMIN only
GET /api/departmentsAuthorization: ADMIN, USER
GET /api/departments/{id}Authorization: ADMIN, USER
POST /api/departments
Content-Type: application/json
{
"departmentName": "Engineering",
"location": "Building A"
}Authorization: ADMIN only
PUT /api/departments/{id}
Content-Type: application/json
{
"departmentName": "Engineering",
"location": "Building B"
}Authorization: ADMIN only
DELETE /api/departments/{id}Authorization: ADMIN only
Note: Cannot delete department with existing employees
GET /api/departments/{id}/employeesAuthorization: ADMIN, USER
POST /api/leaves
Content-Type: application/json
{
"employeeId": 1,
"startDate": "2024-02-01",
"endDate": "2024-02-05",
"reason": "Vacation"
}Authorization: ADMIN, USER
Response: 201 Created
PUT /api/leaves/{id}/status
Content-Type: application/json
{
"status": "APPROVED"
}Status Values: PENDING, APPROVED, REJECTED
Authorization: ADMIN only
GET /api/leaves/employee/{empId}Authorization: ADMIN, USER
GET /api/leaves/{id}Authorization: ADMIN, USER
GET /api/leavesAuthorization: ADMIN only
- Uses Spring Security with Basic Authentication
- Credentials are sent with each request
Two roles are defined:
ADMIN Role:
- Full CRUD operations on employees
- Full CRUD operations on departments
- Can approve/reject leave requests
- Can view all leave requests
USER Role:
- Can view employees and departments
- Can apply for leave
- Can view own leave requests
curl -u admin:admin123 http://localhost:8080/api/employeesmvn testmvn clean test jacoco:reportCoverage report will be available at: target/site/jacoco/index.html
Coverage Target: Minimum 70% line coverage
The project includes:
- Unit Tests: Service layer, mappers
- Integration Tests: Repository layer, controllers
- Message Queue Tests: RabbitMQ publisher/consumer
Test files are located in src/test/java/com/employee/management/
The docker-compose.yml defines three services:
-
PostgreSQL Database
- Image: postgres:16-alpine
- Port: 5432
- Database: employeedb
- Health check enabled
-
RabbitMQ
- Image: rabbitmq:3.12-management-alpine
- Ports: 5672 (AMQP), 15672 (Management UI)
- Health check enabled
-
Application
- Built from Dockerfile
- Port: 8080
- Depends on postgres and rabbitmq
Start all services:
docker-compose up -dView logs:
docker-compose logs -f appStop all services:
docker-compose downStop and remove volumes:
docker-compose down -vRebuild application:
docker-compose up --build appApplication configuration via environment variables:
DB_URL: Database connection URLDB_USERNAME: Database usernameDB_PASSWORD: Database passwordRABBITMQ_HOST: RabbitMQ hostRABBITMQ_PORT: RabbitMQ portRABBITMQ_USERNAME: RabbitMQ usernameRABBITMQ_PASSWORD: RabbitMQ password
-
Database: PostgreSQL is used as the primary database. The application uses JPA with Hibernate for ORM.
-
Email Simulation: The notification system simulates email sending by logging messages to the console. In production, integrate with actual email service (SMTP, SendGrid, etc.).
-
User Management: Uses in-memory user authentication with two predefined users (admin and user). In production, implement database-backed user management with registration and password management.
-
Leave Request Validation:
- End date must be after start date
- No overlap checking between leave requests
- No leave balance tracking
-
Department Deletion: Cannot delete a department that has employees. Employees must be reassigned or deleted first.
-
Unique Constraints:
- Employee email must be unique
- Department name should be unique (enforced at service layer)
-
Pagination: Default page size is 10 records. Maximum page size is 100.
-
Audit Fields: All entities include
createdAtandupdatedAttimestamps managed by JPA. -
Error Handling: Global exception handler provides consistent error responses across all endpoints.
-
Message Queue: RabbitMQ uses topic exchange with separate queues for employee and leave notifications.
-
Transaction Management: Service layer methods are transactional to ensure data consistency.
-
Soft Delete: Not implemented. Delete operations are hard deletes.
-
API Versioning: Not implemented. Consider adding
/api/v1/prefix for future versions. -
Rate Limiting: Not implemented. Consider adding for production deployment.
-
CORS: Disabled by default. Configure based on frontend requirements.
employee-management-system/
├── src/
│ ├── main/
│ │ ├── java/com/employee/management/
│ │ │ ├── config/ # Configuration classes
│ │ │ ├── controller/ # REST controllers
│ │ │ ├── dto/ # Data Transfer Objects
│ │ │ ├── entity/ # JPA entities
│ │ │ ├── exception/ # Custom exceptions
│ │ │ ├── mapper/ # Entity-DTO mappers
│ │ │ ├── messaging/ # RabbitMQ components
│ │ │ ├── repository/ # JPA repositories
│ │ │ ├── service/ # Business logic
│ │ │ └── EmployeeManagementSystemApplication.java
│ │ └── resources/
│ │ └── application.yml # Application configuration
│ └── test/
│ └── java/com/employee/management/ # Test classes
├── Dockerfile # Docker build configuration
├── docker-compose.yml # Docker Compose configuration
├── pom.xml # Maven dependencies
└── README.md # This file
- JWT Authentication: Replace Basic Auth with JWT tokens
- Email Integration: Integrate with actual email service
- Leave Balance: Track and enforce leave balance
- Audit Logging: Comprehensive audit trail for all operations
- File Upload: Support for employee documents
- Reporting: Generate reports for HR analytics
- API Documentation: Integrate Swagger/OpenAPI
- Caching: Implement Redis for performance
- Search: Full-text search capabilities
- Notifications: Add webhook support
For issues, questions, or contributions, please contact the development team or create an issue in the repository.
[Specify your license here]