- Overview
- Live Deployment
- Key Technologies
- User Interface
- File Structure
- API Endpoints
- Backend Setup
- Frontend Setup
- Detailed Component Instructions
- Containerization
- Kubernetes
- LoadBalancer Service
- Jenkins
- OpenAPI Specification
- Troubleshooting
- Contributing
- License
- Contact
The Employee Management System is a dynamic full-stack application that seamlessly combines cutting-edge and traditional technologies. By integrating a modern React frontend with a classic Spring Boot backend, this project demonstrates how new and established technologies can harmoniously work together to create a robust and efficient application for managing employee and department data!
The Employee Management System full-stack app is deployed with Vercel and is live at https://employee-manage-app.vercel.app for you to explore and interact with the application.
The backend is also deployed with Render and is available at https://employee-management-app.onrender.com. You can access the API endpoints directly from the browser at the root (/
) endpoint as we've set up the Swagger UI documentation for easy testing.
Note: The backend API may spin down due to inactivity, so you may need to wait for up to 2 minutes for the API to start up again. Feel free to test the API endpoints and explore the application. Or, you can run the backend locally and connect it to the frontend for a more seamless experience.
Additional Note: It may take a while to fetch the data and process your requests, as Render's free tier has VERY limited resources (only 512MB RAM and 0.1 CPU).
- React (Frontend): A modern JavaScript library for building user interfaces, providing a responsive and interactive experience.
- React Router: A routing library for React that enables navigation and URL handling in single-page applications.
- Chart.js: A JavaScript library for creating responsive and customizable charts and graphs.
- Axios: A promise-based HTTP client for making API requests.
- Tailwind CSS: A utility-first CSS framework for creating custom designs with minimal CSS.
- Redux: A predictable state container for managing application state.
- Jest and React Testing Library: Testing libraries for unit and integration testing React components.
- Java Spring Boot (Backend): A powerful, established Java framework for building production-ready applications with Java, offering robust backend support and data management.
- Spring Data JPA: A part of the Spring Data project that makes it easy to implement JPA-based repositories.
- Spring Boot Actuator: A set of production-ready features that help monitor and manage the application.
- Spring Hibernate: An object-relational mapping (ORM) library for Java that provides a framework for mapping an object-oriented domain model to a relational database.
- Spring Boot Starter Web: A starter for building web applications, including RESTful, application, and WebSocket services.
- Spring Boot Starter Data JPA: A starter for using Spring Data JPA with Hibernate.
- RESTful APIs: Representational state transfer (REST) APIs for communication between the frontend and backend.
- Java 11: The latest LTS version of Java, providing long-term support and stability.
- JUnit 5: A popular testing framework for Java that provides annotations for writing tests.
- Swagger: A tool for documenting and testing RESTful APIs.
- Docker: A containerization platform for packaging applications and their dependencies.
- Kubernetes: An open-source container orchestration platform for automating deployment, scaling, and management of containerized applications.
- Jenkins: An open-source automation server that helps automate the parts of software development related to building, testing, and delivering, facilitating continuous integration and continuous delivery (CI/CD).
- MySQL: A reliable relational database for structured data storage.
- MongoDB: A flexible NoSQL database for non-relational data.
- Style Guides: This project follows the following popular style guides to ensure clean and consistent code.
- Airbnb JavaScript Style Guide: A popular style guide for writing clean and consistent JavaScript code.
- Google Java Style Guide: A style guide for writing Java code that is readable and maintainable.
The frontend of the Employee Management System provides a user-friendly interface for managing employees and departments. It includes features for viewing, adding, editing, and deleting employees and departments. The app also includes visualizations for employee metrics such as growth over time and distribution by age range.
The frontend is also live at https://employee-management-fullstack-app.vercel.app for you to explore and interact with the application. Note that the backend is not hosted, so the API calls will not work and the data will not be present.
Landing Page:
Dashboard Page:
Employee List Page:
Department List Page:
Add Employee Form:
Edit Employee Form:
Edit Department Form:
Profile Page:
Login Page:
Register Page:
404 Page:
Footer:
Responsive Design Example - Dashboard Page:
And many more features & pages to explore! Feel free to navigate through the application and test the various functionalities.
Here's a table listing all the RESTful API endpoints provided by this application:
Endpoint | Method | Description |
---|---|---|
/api/employees |
GET | Get all employees |
/api/employees/{id} |
GET | Get an employee by ID |
/api/employees |
POST | Add a new employee |
/api/employees/{id} |
PUT | Update an employee by ID |
/api/employees/{id} |
DELETE | Delete an employee by ID |
/api/departments |
GET | Get all departments |
/api/departments/{id} |
GET | Get a department by ID |
/api/departments |
POST | Add a new department |
/api/departments/{id} |
PUT | Update a department by ID |
/api/departments/{id} |
DELETE | Delete a department by ID |
/swagger-ui.html |
GET | Access the Swagger UI documentation |
Employee-Management-Fullstack-App/
βββ docker-compose.yaml
βββ Jenkinsfile
βββ openapi.yaml
βββ README.md
βββ package.json
βββ .mvn/
β βββ wrapper
β βββ maven-wrapper.properties
βββ kubernetes/
β βββ configmap.yaml
β βββ backend-deployment.yaml
β βββ backend-service.yaml
β βββ frontend-deployment.yaml
β βββ frontend-service.yaml
βββ nginx/
β βββ Dockerfile
β βββ nginx.conf
βββ backend/
β βββ src/
β β βββ main/
β β β βββ java/
β β β β βββ com/
β β β β βββ example/
β β β β βββ employeemanagement/
β β β β βββ EmployeeManagementApplication.java
β β β β βββ config/
β β β β β βββ CorsConfig.java
β β β β β βββ DataInitializer.java
β β β β βββ controller/
β β β β β βββ DepartmentController.java
β β β β β βββ EmployeeController.java
β β β β βββ model/
β β β β β βββ Department.java
β β β β β βββ Employee.java
β β β β βββ repository/
β β β β β βββ DepartmentRepository.java
β β β β β βββ EmployeeRepository.java
β β β β βββ service/
β β β β β βββ DataInitializer.java
β β β β βββ exception/
β β β β βββ ResourceNotFoundException.java
β β β βββ resources/
β β β βββ application.properties
β β β βββ data.sql
β β βββ test/
β β βββ java/
β β βββ com/
β β βββ example/
β β βββ employeemanagement/
β β βββ EmployeeManagementApplicationTests.java
β βββ .gitignore
β βββ pom.xml
β βββ compose.yaml
β
βββ frontend/
βββ build/
βββ public/
β βββ index.html
β βββ favicon.ico
β βββ manifest.json
β βββ robots.txt
β βββ icon-192x192.webp
β βββ icon-512x512.webp
βββ src/
β βββ components/
β β βββ Dashboard.js
β β βββ EmployeeList.js
β β βββ EmployeeForm.js
β β βββ DepartmentList.js
β β βββ DepartmentForm.js
β β βββ Navbar.js
β βββ services/
β β βββ employeeService.js
β β βββ departmentService.js
β βββ App.js
β βββ index.js
β βββ index.css
β βββ reportWebVitals.js
β βββ App.css
β βββ theme.js
βββ Dockerfile
βββ postcss.config.js
βββ tailwind.config.js
βββ package.json
Ensure that you have Java 11 installed on your local machine. If not, follow the instructions below:
-
For MacOS:
brew install openjdk@11 export JAVA_HOME=/usr/local/opt/openjdk@11
-
For Windows: Download OpenJDK 11 from https://jdk.java.net/archive/ and follow the installation instructions.
-
Also, ensure that MongoDB and MySQL are installed and running on your local machine.
git clone https://github.com/hoangsonww/Employee-Management-Fullstack-App.git
cd Employee-Management-Fullstack-App # Fix the paths if necessary
cd backend
First, ensure you have Maven and Java JDK installed. Run the following command to install them:
- For MacOS:
brew install maven
- For Windows: Download Maven from https://maven.apache.org/download.cgi and follow the installation instructions.
Next, install the project dependencies:
mvn install
Update src/main/resources/application.properties
with your MySQL and MongoDB configuration:
# MySQL Configuration
spring.datasource.url=jdbc:mysql://localhost:3306/employee_management
spring.datasource.username=root
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=update
# MongoDB Configuration
spring.data.mongodb.uri=mongodb://localhost:27017/employee_management
Feel free to change the database name, username, and password, and even add more configurations as needed.
Alternatively, create a config.properties
file in the backend
directory and keep the application.properties
file as is. Add the following properties to the config.properties
file:
MYSQL_HOST=<mysql_host>
MYSQL_PORT=<mysql_port>
MYSQL_DB=<mysql_db>
MYSQL_USER=<mysql_user>
MYSQL_PASSWORD=<mysql_password>
MYSQL_SSL_MODE=<mysql_ssl_mode>
MONGO_URI=<mongo_host>
Before starting the server, ensure that MySQL and MongoDB are running and properly configured on your local machine!
Then, run the following command to start the Spring Boot application:
mvn spring-boot:run
The backend will be available at http://localhost:8080.
-
Get All Employees:
curl -X GET http://localhost:8080/api/employees
-
Get Employee by ID:
curl -X GET http://localhost:8080/api/employees/1
-
Get All Departments:
curl -X GET http://localhost:8080/api/departments
-
Get Department by ID:
curl -X GET http://localhost:8080/api/departments/1
-
Feel free to add more API endpoints as needed...
This application also uses Swagger to provide an interactive API documentation interface. The Swagger UI allows developers to explore the available API endpoints, view detailed information about each endpoint, and test the endpoints directly from the browser.
-
Start the Backend Server: Ensure that the backend server is running. You can start the server by navigating to the backend directory and running:
mvn spring-boot:run
-
Open the Swagger UI: Once the server is up and running, you can access the Swagger UI by navigating to the following URL in your web browser:
http://localhost:8080/swagger-ui.html
This will open the Swagger interface where you can explore the API endpoints.
-
Alternatively, for those who need the raw OpenAPI JSON, it is available at:
-
Explore the API Endpoints:
- Use the sidebar or the search bar to navigate through the available API endpoints.
- Click on an endpoint to view its details, including the request method (GET, POST, PUT, DELETE), parameters, request body, and possible responses.
- You can also test the endpoints directly by clicking the "Try it out" button, providing the necessary input, and executing the request.
- If you have everything set up correctly, you should see the following Swagger UI interface:
- Interactive Documentation: Developers can easily understand and use the API.
- Quick Testing: Test the API endpoints directly from the browser without needing a separate tool.
- Clear Communication: Provides a standardized way of documenting your API, making it easier for others to understand and consume.
To run the unit and integration tests, use:
mvn test
This will run the tests and provide you with the results. Ensure that all tests pass before making any changes to the application.
Feel free to add more tests as needed to ensure the reliability and correctness of your application.
git clone https://github.com/hoangsonww/Employee-Management-Fullstack-App.git
cd frontend
Ensure you have Node.js and npm installed. Run the following command to install the required dependencies:
npm install
Create a .env
file in the root of your project if it doesn't already exist. Add the following environment variable:
REACT_APP_API_URL=http://localhost:8080/api
Run the following command to start the React development server:
npm start
The frontend will be available at http://localhost:3000.
To create a production build of your application, run:
npm run build
The build files will be generated in the build
directory. You can deploy these files to your production server.
To run tests for the frontend application, use the following command:
npm test
NOTE: You might need different IDEs for the backend and the frontend. FYI, I used IntelliJ IDEA for the backend and Webstorm for the frontend.
Displays various metrics related to employees, such as total employee count, average age, employee growth over time, and distribution by age range. It uses react-chartjs-2
to render bar charts.
Shows a list of employees with options to search, paginate, and delete entries. Includes a link to add a new employee and edit existing employees.
Provides a form for adding or editing employee details. Fetches departments to populate the department dropdown. Uses useParams
to determine if it's in edit mode or add mode.
Displays a list of departments with options to search, paginate, and delete entries. Includes a link to add a new department and edit existing departments.
Provides a form for adding or editing department details.
The navigation bar component that includes links to various pages such as Dashboard, Employees, and Departments. Highlights the currently active page.
If you'd also like to containerize the project, the project also includes the dockerfile
and docker-compose.yaml
files for containerization. You can build and run the application in a Docker container using the following command:
docker compose up --build
This command will build the Docker images for the frontend and backend, create containers, and start the application. Feel free to view them in Docker Desktop.
Alternatively, you can navigate to the backend
and frontend
directories and build the Docker images separately using the following commands:
docker build -t <your_docker_username>/employee-management-app-backend .
docker build -t <your_docker_username>/employee-management-app-frontend .
Then, you can run the containers using the following commands:
docker run -p 8080:8080 <your_docker_username>/employee-management-app-backend
docker run -p 3000:3000 <your_docker_username>/employee-management-app-frontend
Also, you can push the Docker images to Docker Hub using the following commands:
docker push <your_docker_username>/employee-management-app-backend
docker push <your_docker_username>/employee-management-app-frontend
Additionally, you can access the image on Docker Hub here.
The project also includes Kubernetes configuration files in the kubernetes
directory for deploying the application to a Kubernetes cluster. You can deploy the application to a Kubernetes cluster using the following command:
kubectl apply -f kubernetes
This command will create the necessary deployments, services, and config maps for the frontend and backend. You can access the application using the NodePort or LoadBalancer service created.
The project also features Nginx as a LoadBalancer service for routing traffic to the frontend and backend services. The Nginx configuration file is located in the nginx
directory.
There is also a Dockerfile
for building the Nginx image. We are using this file to build the Nginx image and deploy it to the cloud with Render, which we are currently using to balance the traffic of the frontend and backend services.
Feel free to customize the Nginx configuration to suit your specific requirements and deployment process.
The project also includes a Jenkinsfile
for automating the build and deployment process using Jenkins. You can create a Jenkins pipeline job and use the Jenkinsfile
to build and deploy the application to a Kubernetes cluster.
Feel free to customize the Jenkins pipeline to suit your specific requirements and deployment process.
- View the API Documentation
- Open Swagger Editor.
- Upload the
openapi.yaml
file or paste its content. - Visualize and interact with the API documentation.
- Test the API
- Import
openapi.yaml
into Postman:- Open Postman β Import β Select
openapi.yaml
. - Test the API endpoints directly from Postman.
- Open Postman β Import β Select
- Or use Swagger UI:
- Provide the file URL or upload it to view and test endpoints.
- Generate Client Libraries
- Install OpenAPI Generator:
npm install @openapitools/openapi-generator-cli -g
- Generate a client library:
openapi-generator-cli generate -i openapi.yaml -g <language> -o ./client
- Replace
<language>
with the desired programming language.
- Generate Server Stubs
- Generate a server stub:
openapi-generator-cli generate -i openapi.yaml -g <framework> -o ./server
- Replace
<framework>
with the desired framework.
- Run a Mock Server
- Install Prism:
npm install -g @stoplight/prism-cli
- Start the mock server:
prism mock openapi.yaml
- Validate the OpenAPI File
- Use Swagger Validator:
- Upload
openapi.yaml
or paste its content to check for errors.
- Upload
This guide enables you to view, test, and utilize the API. Feel free to explore the OpenAPI Specification and integrate it into your development workflow.
-
Could not autowire
Errors: Ensure that all dependencies are correctly defined in thepom.xml
and that the repository interfaces are located in the correct package structure. -
Exception opening socket
for MongoDB: Verify that MongoDB is running and accessible atlocalhost:27017
. Check MongoDB logs for any connection issues. -
Build failed
: Ensure that you are using Java 11 and that all dependencies are correctly installed. Check thepom.xml
file for any missing dependencies. -
Regardless of the error, perhaps you can try running the following commands to clean and rebuild the project:
mvn clean install
If the issue persists, you can run Maven with more detailed logging to identify the problem:
mvn -X spring-boot:run
-
Error: Cannot read properties of undefined (reading 'id'): Ensure that the
employee
object inEmployeeForm
is correctly initialized and that theid
parameter is correctly passed. Check thegetEmployeeById
andupdateEmployee
functions for proper handling of data. -
Chart Issues: Ensure
Chart.js
andreact-chartjs-2
are correctly installed and configured. Verify that the chart data passed to components is in the correct format. -
Regardless of the error, perhaps you can try running the following commands to clean and rebuild the project:
npm install
If the issue persists, you can run the React development server with more detailed logging to identify the problem:
npm start --verbose
If you'd like to contribute to the project, please fork the repository and submit a pull request with your changes. Ensure that you follow the project's coding standards and include relevant tests for new features.
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or issues, please contact [email protected].
Thank you for checking out the Employee Management Full-Stack Application! Feel free to use this project for your own learning or development purposes.
Created with β€οΈ by Son Nguyen in 2024.