This document captures the current architecture of the Employee Management System so that contributors and operators can understand how the solution is structured today, which guarantees are already implemented, and where further hardening is required. The description below is based solely on the source code and infrastructure assets that live in this repository.
frontend/
, backend under backend/
, infrastructure helpers under docker-compose.yml
, kubernetes/
, terraform/
, and scripts/
.frontend/
)src/App.js
configures routing with React Router v6, wrapping pages in a Material UI Container
and global Navbar
/Footer
components.Login
, Register
, ResetPassword
, VerifyUsername
), and profile/404 pages.src/components/
and rely on React hooks for state management (useState
, useEffect
).Dashboard.js
combines live API data with static samples to render Chart.js bar/line/pie charts for metrics such as employee count, age distribution, and growth trends.EmployeeList.js
, EmployeeForm.js
, DepartmentList.js
, DepartmentForm.js
, NewDepartmentForm.js
) share a consistent pattern: fetch data on mount, expose form interactions, and invoke service helpers for persistence.Login.js
, Register.js
, ResetPassword.js
, VerifyUsername.js
) render forms but do not store tokens locally—the backend currently permits all requests (see §4.5).flowchart LR
Router[React Router
`src/App.js`] -->|renders| Landing[LandingPage]
Router --> Dashboard
Router --> Employees[EmployeeList]
Router --> Departments[DepartmentList]
Router --> Forms[EmployeeForm / DepartmentForm]
Router --> Auth[Auth Pages]
subgraph Services
EmpSvc[employeeService.js]
DeptSvc[departmentService.js]
end
Dashboard -->|axios| EmpSvc
Employees -->|axios| EmpSvc
Departments -->|axios| DeptSvc
Forms -->|axios| EmpSvc
Forms -->|axios| DeptSvc
src/services/employeeService.js
and src/services/departmentService.js
. Both modules use Axios and point to the Render-hosted backend (https://employee-management-app-gdm5.onrender.com/...
)..env
(REACT_APP_API_URL
), though conditional switching logic is not present in code—contributors must update the service files or provide proxy settings when pointing to a different backend.react-chartjs-2
) powers dashboard charts; Chart.register(...)
is called within Dashboard.js
to ensure the required controllers are available.CircularProgress
.jest.config.js
and jest.setup.js
. Component tests live in frontend/__tests__/
(e.g., Dashboard.spec.js
, EmployeeList.test.js
, Login.test.js
).package.json
script npm test
currently proxies to cd frontend && npm start
, so running tests requires invoking npm test
inside frontend/
directly or wiring the script appropriately.backend/
)EmployeeManagementApplication.java
(Spring Boot) bootstraps the application.pom.xml
) and integrates Spring Boot starters for web, data JPA, security, MongoDB, OpenAPI, and testing.model/
):
Employee
links to Department
via @ManyToOne
with eager fetch.Department
maintains a @OneToMany
collection of Employee
instances with cascading deletes.User
represents authentication principals stored in a users
table.repository/
):
EmployeeRepository
extends JpaRepository
and exposes findAllWithDepartments()
using a JOIN FETCH
query to avoid N+1 problems.DepartmentRepository
offers standard CRUD.UserRepository
enables lookup by username for authentication flows.config/DataInitializer.java
) seeds 50 fake departments and 295 employees on startup using Java Faker. The initializer clears existing tables before inserting fresh demo data, which makes the demo deterministic but unsuitable for production without guards.EmployeeService
and DepartmentService
wrap repository interactions to encapsulate CRUD logic. Both expose getAll
, getById
, save
, and delete
style methods.controller/
):
EmployeeController
and DepartmentController
expose RESTful CRUD endpoints under /api/employees
and /api/departments
. They apply @CrossOrigin(origins = "http://localhost:3000")
and annotate operations with Swagger metadata (@Operation
, @ApiResponses
).AuthController
implements user registration, authentication (JWT issuance), username verification, and password reset endpoints. Responses return simple status messages or a token
JSON payload.HomeController
serves a default view (used for Swagger UI landing).ResourceNotFoundException
annotated with @ResponseStatus(HttpStatus.NOT_FOUND)
.springdoc-openapi-ui
and exposes Swagger UI at /swagger-ui.html
.sequenceDiagram
participant UI as React Client
participant Ctrl as EmployeeController
participant Svc as EmployeeService
participant Repo as EmployeeRepository
participant DB as MySQL
UI->>Ctrl: GET /api/employees
Ctrl->>Svc: getAllEmployees()
Svc->>Repo: findAllWithDepartments()
Repo->>DB: SELECT employees JOIN departments
DB-->>Repo: Row set
Repo-->>Svc: List<Employee>
Svc-->>Ctrl: List<Employee>
Ctrl-->>UI: 200 OK (JSON)
application.properties
imports an optional config.properties
file, enabling secrets and connection strings to be defined outside version control. By default the application expects MySQL and MongoDB credentials through environment variables.CorsConfig
registers a permissive CORS policy allowing any origin, headers, and credentials.config.properties
in the repo contains sample managed service credentials. Treat these values as placeholders—they should be rotated before real deployments.SecurityConfig
extends WebSecurityConfigurerAdapter
, wires CustomUserDetailsService
with BCrypt password encoding, but ultimately disables CSRF and permits all requests (http.csrf().disable().authorizeRequests().anyRequest().permitAll()
).JwtTokenUtil
, JwtRequestFilter
) and CustomUserDetailsService
are present; however JwtRequestFilter
is not registered with the HTTP security chain, and no request paths are currently protected. The authentication endpoints can issue tokens, but downstream controllers do not enforce them yet.users
table.src/test/java/com/example/employeemanagement/
, covering repository CRUD operations and data integrity (BackendAPITests
, AdditionalAPITests
, etc.). Tests rely on H2 (via Spring Boot test dependencies) and validate typical workflows like saving, retrieving, and deleting employees and departments.spring.jpa.show-sql=true
. No additional logging, tracing, or metrics providers are configured yet.employees
, departments
, users
). Hibernate ddl-auto=update
evolves the schema at runtime, which is convenient for demos but risky for production.spring.data.mongodb.uri
) but no repository currently consumes it. Future Mongo use would require additional Spring Data Mongo repositories.DataInitializer
recreates data on every application start (see §3.2). Remove or guard this behavior before deploying to persistent environments.openapi.yaml
at the repo root enumerates the REST API and aligns with the annotated controllers.graph TD
A[React Frontend] -->|HTTP| B[Spring Boot Backend]
B -->|JDBC| C[MySQL Database]
B -->|MongoDB Driver| D[MongoDB - optional]
A -->|Fetch API / Axios| B
B -->|Swagger UI| E[OpenAPI Documentation]
B -->|JWT Tokens| F[Authentication - not enforced]
F -->|User Credentials| B
B -->|Data Seeding| C
docker-compose.yml
spins up MySQL, MongoDB, the Spring Boot backend, and a React build served through Nginx. Health checks are configured for the backend (/actuator/health
), MySQL, and Mongo.Makefile
provides automation targets for building and running backend/frontend code, generating Docker images, managing Kubernetes manifests, and generating OpenAPI clients.scripts/
(e.g., build-images.sh
, deploy-k8s.sh
, test-backend.sh
) encapsulate common workflows.kubernetes/
contains raw manifests for backend/frontend deployments and services plus a config map. The manifests currently mount code via hostPath
volumes and expose container ports 3000
/3001
; align these values with the Spring Boot (8080
) and React build (80
) ports before production use.terraform/
defines a modular AWS deployment comprising VPC networking, an EKS cluster, managed node groups, an RDS MySQL instance, and ECR repositories. Modules use terraform-aws-modules/*
under the hood and output cluster credentials and repository URLs.flowchart LR
DevEnv[Developer Workstation]
Jenkins[Jenkins Pipeline]
ECR[ECR Repositories]
EKS[EKS Cluster]
RDS[(RDS MySQL)]
DevEnv -->|git push| Jenkins
Jenkins -->|docker build & push| ECR
ECR -->|pull images| EKS
EKS -->|JDBC 3306| RDS
subgraph Local Tooling
Compose[Docker Compose]
Scripts[Makefile + scripts]
end
DevEnv --> Compose
DevEnv --> Scripts
subgraph AWS
VPC[VPC & Subnets]
VPC --> EKS
VPC --> RDS
end
Jenkins -->|terraform apply| VPC
Jenkinsfile
) that installs frontend dependencies (npm install
) and builds the React bundle (npm run build
). Additional stages (tests, Docker builds, deployments) can be added as the stack matures.nginx/
holds a Dockerfile and configuration intended for load balancing. The current config proxies to moodify-emotion-music-app.onrender.com
, indicating it is a placeholder that must be replaced with the Employee Management services before reuse.img/
and referenced by README.md
.JwtRequestFilter
, protecting controller methods with @PreAuthorize
or request matchers, and storing secrets securely.backend/config.properties
with environment-specific secrets (AWS Secrets Manager, SSM Parameter Store, or Kubernetes Secrets) before production deployment.ddl-auto=update
to an explicit migration tool (Flyway/Liquibase) is recommended to control schema evolution.DataInitializer
outside of sandbox environments.flowchart TD
A[Public Internet] -->|HTTP| B[Load Balancer / Nginx]
B -->|HTTP| C[Spring Boot Backend]
C -->|JDBC| D[MySQL Database]
C -->|MongoDB Driver| E[MongoDB - optional]
subgraph Security Layers
F[WAF / Firewall]
G[Authentication & Authorization]
H[Secrets Management]
I[Database Migrations]
J[Data Seeding Controls]
K[CORS Policies]
end
A --> F
F --> B
B --> G
C --> H
C --> I
C --> J
C --> K
Capability | Primary Location |
---|---|
React SPA | frontend/src |
API controllers | backend/src/main/java/com/example/employeemanagement/controller |
Services | backend/src/main/java/com/example/employeemanagement/service |
Repositories | backend/src/main/java/com/example/employeemanagement/repository |
Entities | backend/src/main/java/com/example/employeemanagement/model |
Security configuration | backend/src/main/java/com/example/employeemanagement/security |
Data seeding | backend/src/main/java/com/example/employeemanagement/config/DataInitializer.java |
Docker Compose | docker-compose.yml |
Kubernetes manifests | kubernetes/ |
Terraform AWS stack | terraform/ |
Scripts & automation | scripts/ and Makefile |
Document version: 2024-06-10 Author: Son Nguyen Version: 1.0.0