https://github.com/rapter1990/flightsearchapi
Case Study - Flight Search Api (Java 21, Spring Boot, Mongodb, JUnit, Spring Security, JWT, Docker, AOP, Kubernetes, Prometheus, Grafana, Github Actions (CI/CD), Jenkins)
https://github.com/rapter1990/flightsearchapi
aop ci-cd docker docker-compose github-actions grafana integration-test jacoco java jenkins junit jwt kubernetes maven mongodb nosql openapi prometheus spring-boot spring-security
Last synced: 11 months ago
JSON representation
Case Study - Flight Search Api (Java 21, Spring Boot, Mongodb, JUnit, Spring Security, JWT, Docker, AOP, Kubernetes, Prometheus, Grafana, Github Actions (CI/CD), Jenkins)
- Host: GitHub
- URL: https://github.com/rapter1990/flightsearchapi
- Owner: Rapter1990
- License: other
- Created: 2025-01-04T19:38:59.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-02T18:51:52.000Z (12 months ago)
- Last Synced: 2025-02-02T19:34:17.904Z (12 months ago)
- Topics: aop, ci-cd, docker, docker-compose, github-actions, grafana, integration-test, jacoco, java, jenkins, junit, jwt, kubernetes, maven, mongodb, nosql, openapi, prometheus, spring-boot, spring-security
- Language: Java
- Homepage:
- Size: 266 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# Case Study - Flight Search Api
### 📖 Information
-
This project provides a Spring Boot API for managing user authentication,
airport management, flight management, and flight search functionalities. It
includes advanced logging and security features.
-
User Authentication:
-
User Registration: Register users with an email and password.
-
User Login: Authenticate users with email and password, generating
access and refresh tokens.
-
Token Refresh: Refresh expired access tokens using refresh tokens.
-
User Logout: Invalidate tokens to log users out.
-
-
Airport Management:
-
Create Airports: Accessible only to ADMIN users.
-
Retrieve Airports: Paginated airport list retrieval, accessible to both
ADMIN and USER roles.
-
Retrieve Specific Airport: Search by airport ID, accessible to both
ADMIN and USER roles.
-
Update Airports: Modify an existing airport by ID, accessible only to
ADMIN users.
-
Delete Airports: Remove airports by ID, accessible only to ADMIN
users.
-
-
Flight Management:
-
Create Flights: Accessible only to ADMIN users.
-
Retrieve Flights: Paginated flight list retrieval, accessible to both
ADMIN and USER roles.
-
Retrieve Specific Flight: Search by flight ID, accessible to both
ADMIN and USER roles.
-
Update Flights: Modify an existing flight by ID, accessible only to
ADMIN users.
-
Delete Flights: Remove flights by ID, accessible only to ADMIN
users.
-
-
Flight Search:
-
Search Flights: Search for flights based on departure, arrival airports,
and departure date. Accessible to both ADMIN and USER
roles. (One Way - Round-Trip)
-
-
Security:
-
User Roles: ADMIN and USER roles implemented using Spring Security.
-
JWT Authentication: Secure endpoints with JSON Web Tokens.
-
-
Logging:
-
Custom Logging Aspect: Logs details of REST controller method calls and
exceptions, including HTTP request and response details.
-
### Explore Rest APIs
Endpoints Summary
Method
Url
Description
Request Body
Path Variable
Response
POST
/api/v1/authentication/user/register
Register for Admin or User
RegisterRequest
CustomResponse<Void>
POST
/api/v1/authentication/user/login
Login for Admin or User
LoginRequest
CustomResponse<TokenResponse>
POST
/api/v1/authentication/user/refresh-token
Refresh Token for Admin or User
TokenRefreshRequest
CustomResponse<TokenResponse>
POST
/api/v1/authentication/user/logout
Logout for Admin or User
TokenInvalidateRequest
CustomResponse<Void>
POST
/api/v1/airports
Create a new Airport
CreateAirportRequest
CustomResponse<String>
GET
/api/v1/airports
Get all Airports
AirportPagingRequest
CustomResponse<CustomPagingResponse<AirportResponse>>
GET
/api/v1/airports/{id}
Get Airport by ID
UUID
CustomResponse<AirportResponse>
PUT
/api/v1/airports/{id}
Update an Airport
UpdateAirportRequest
UUID
CustomResponse<AirportResponse>
DELETE
/api/v1/airports/{id}
Delete an Airport
UUID
CustomResponse<String>
POST
/api/v1/flights
Create a new Flight
CreateFlightRequest
CustomResponse<String>
GET
/api/v1/flights
Get all Flights
AirportPagingRequest
CustomResponse<CustomPagingResponse<FlightResponse>>
GET
/api/v1/flights/{id}
Get Flight by ID
UUID
CustomResponse<FlightResponse>
PUT
/api/v1/flights/{id}
Update a Flight
UpdateFlightRequest
UUID
CustomResponse<FlightResponse>
DELETE
/api/v1/flights/{id}
Delete a Flight
UUID
CustomResponse<String>
POST
/api/v1/flights/search
Search for Flights
SearchFlightRequest
CustomResponse<CustomPagingResponse<FlightResponse>>
### Technologies
---
- Java 21
- Spring Boot 3.0
- Restful API
- Mapstruct
- Open Api (Swagger)
- Maven
- Junit5
- Mockito
- Integration Tests
- Docker
- Docker Compose
- CI/CD (Github Actions - Jenkins)
- Postman
- TestContainer
- Mongo
- Prometheus
- Grafana
- Kubernetes
- JaCoCo (Test Report)
### Postman
```
Import postman collection under postman_collection folder
```
### Prerequisites
#### Define Variable in .env file
```
MONGO_DB_NAME=flightdatabase
MONGO_DB_HOST=localhost
MONGO_DB_PORT=27017
```
### Open Api (Swagger)
```
http://localhost:1133/swagger-ui/index.html
```
---
### JaCoCo (Test Report)
After the command named `mvn clean install` completes, the JaCoCo report will be available at:
```
target/site/jacoco/index.html
```
Navigate to the `target/site/jacoco/` directory.
Open the `index.html` file in your browser to view the detailed coverage report.
---
### Maven, Docker and Kubernetes Running Process
### Maven Run
To build and run the application with `Maven`, please follow the directions shown below;
```sh
$ cd flightsearchapi
$ mvn clean install
$ mvn spring-boot:run
```
---
### Docker Run
The application can be built and run by the `Docker` engine. The `Dockerfile` has multistage build, so you do not need to build and run separately.
Please follow directions shown below in order to build and run the application with Docker Compose file;
```sh
$ cd flightsearchapi
$ docker-compose up -d
```
If you change anything in the project and run it on Docker, you can also use this command shown below
```sh
$ cd flightsearchapi
$ docker-compose up --build
```
To monitor the application, you can use the following tools:
- **Prometheus**:
Open in your browser at [http://localhost:9090](http://localhost:9090)
Prometheus collects and stores application metrics.
- **Grafana**:
Open in your browser at [http://localhost:3000](http://localhost:3000)
Grafana provides a dashboard for visualizing the metrics.
**Default credentials**:
- Username: `admin`
- Password: `admin`
- Define prometheus data source url, use this link shown below
```
http://prometheus:9090
```
---
### Kubernetes Run
To build and run the application with `Maven`, please follow the directions shown below;
- Start Minikube
```sh
$ minikube start
```
- Open Minikube Dashboard
```sh
$ minikube dashboard
```
- To deploy the application on Kubernetes, apply the Kubernetes configuration file underneath k8s folder
```sh
$ kubectl apply -f k8s
```
- To open Prometheus, click tunnel url link provided by the command shown below to reach out Prometheus
```sh
minikube service prometheus-service
```
- To open Grafana, click tunnel url link provided by the command shown below to reach out Prometheus
```sh
minikube service grafana-service
```
- Define prometheus data source url, use this link shown below
```
http://prometheus-service.default.svc.cluster.local:9090
```
---
### Docker Image Location
```
https://hub.docker.com/repository/docker/noyandocker/flightsearchapi/general
https://hub.docker.com/repository/docker/noyandocker/flightsearchapi-jenkins/general
```
### Jenkins
- Go to `jenkins` folder
- Run `docker-compose up -d`
- Open Jenkins in the browser via `localhost:8080`
- Go to pipeline named `flightsearchapi`
- Run Pipeline
- Show `Pipeline Step` to verify if it succeeded or failed
### Screenshots
Click here to show the screenshots of project
Figure 1
Figure 2
Figure 3
Figure 4
Figure 5
Figure 6
Figure 7
Figure 8
Figure 9
Figure 10
Figure 11
Figure 12
Figure 13
Figure 14
Figure 15
Figure 16
Figure 17
Figure 18
Figure 19
Figure 20
Figure 21
Figure 22
Figure 23
Figure 24
### Contributors
- [Sercan Noyan GermiyanoÄŸlu](https://github.com/Rapter1990)
- [Furkan Tarık Göçmen](https://github.com/furkantarikgocmen)