https://github.com/hmika/carrentalshop
https://github.com/hmika/carrentalshop
assertj docker-compose java jpa junit jwt-token maven mockito postgres spring-boot spring-security
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hmika/carrentalshop
- Owner: HMika
- Created: 2025-02-20T19:57:13.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-13T23:19:01.000Z (over 1 year ago)
- Last Synced: 2025-03-22T15:18:14.803Z (about 1 year ago)
- Topics: assertj, docker-compose, java, jpa, junit, jwt-token, maven, mockito, postgres, spring-boot, spring-security
- Language: Java
- Homepage:
- Size: 4.52 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🚗 Car Rental Shop Application
## 📖 Overview
The **Car Rental Shop Application** is a **Spring Boot-based backend service** designed to streamline car rental operations. It provides a backend system that handles:
- **User authentication** using JWT-based security.
- **Car management** for listing, retrieving, and managing car data.
- **Rental transactions** to book and track car rentals.
The application ensures **secure and efficient rental management** through **role-based access control** and **RESTful API design**.
---
## 🎯 Motivation
The goal of this project is to **simplify car rental management** by offering:
- A **centralized platform** for managing rentals, users, and cars.
- **Role-based authentication** to differentiate between users and admins.
- A **structured relational database** for handling rental records efficiently.
- **Secure transactions** with JWT-based authentication and access control.
### **Main Goals**
✔️ Automating the car rental process with a **structured digital solution**.
✔️ Reducing reliance on **manual record-keeping**.
✔️ Ensuring **scalability and performance** with modern backend technologies.
---
## 🛠️ Technology Stack
This project leverages **modern technologies** to ensure **reliability, scalability, and security**.
### **Backend**
- **Spring Boot** – Main framework for backend development.
- **Spring Security & JWT** – Used for authentication and role-based access control.
- **Spring Data JPA & Hibernate** – ORM framework for database interactions.
### **Database**
- **PostgreSQL** – Relational database management system.
- **Flyway** – Database versioning and migrations.
### **Build & Dependency Management**
- **Maven** – Dependency management and project build tool.
### **Testing & Code Quality**
- **JUnit** – Unit testing framework.
- **AssertJ** – Fluent assertions for improved test readability.
- **JaCoCo** – Code coverage analysis.
- **SonarQube** – Code quality monitoring.
---
## 🔒 Security
The application follows best **security practices**:
- **JWT-based authentication** – Secure token-based authentication for users.
- **Role-based access control (RBAC)** – Different permissions for **users** and **admins**.
- **Stateless session management** – Ensures scalability by avoiding server-side session storage.
- **CSRF protection disabled** – Since it is a REST API intended for client-server communication.
---
## 📊 Database Schema
The application database consists of the following tables:
1️⃣ **Roles** – Stores role-based access control data.
2️⃣ **Users** – Stores user information, including authentication details.
3️⃣ **Cars** – Stores car details (make, model, year, price, etc.).
4️⃣ **Rentals** – Stores rental transaction details.
These tables define relationships between **users, roles, cars, and rental transactions**.

---
## Car Rental Shop Application – Startup Guide
### Prerequisites
Before running the application, ensure that you have the following tools installed and configured:
### 1. Install Docker
The application uses PostgreSQL as its database, which will run inside a Docker container. Ensure Docker is installed:
- Download and install Docker for your operating system.
### 2. Install Docker Compose
The database container is managed using Docker Compose.
- Docker Compose should be installed along with Docker.
- To verify installation, run:
```sh
docker-compose --version
```
### 3. Install Java & Maven
The backend application is built using Java 17+ and Maven.
- Install Java Development Kit (JDK 17+)
- Install Maven:
#### On Linux/macOS:
```sh
sudo apt install maven # Debian-based
brew install maven # macOS
```
#### On Windows:
Download from Apache Maven and configure the PATH variable.
#### Verify installation:
```sh
java -version
mvn -version
## Step-by-Step Guide to Start the Application
### 1. Clone the Repository
First, clone the project repository from your source control (GitHub, GitLab, etc.):
```sh
git clone https://github.com/your-repository/car-rental-shop.git
cd car-rental-shop
```
## Start the Database with Docker
The project includes a `docker-compose.yml` file that sets up the PostgreSQL database inside a Docker container.
### Steps:
1. Navigate to the project directory.
2. Run the following command to start the database container:
```sh
docker-compose up -d
```
This will:
- Pull the PostgreSQL image (if not already downloaded).
- Create and start a database container with the required configuration.
- Run the database in detached mode (`-d` flag) in the background.
3. Verify that the container is running:
```sh
docker ps
```
You should see a running PostgreSQL container.
## Configure Database Connection
The application uses an `application.properties` file to define database connection settings. Ensure that the connection details match the database container configuration.
The default settings in `src/main/resources/application.properties` should be:
```ini
spring.datasource.url=jdbc:postgresql://localhost:5432/carrent_db
spring.datasource.username=your_db_user
spring.datasource.password=your_db_password
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database=POSTGRESQL
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.format_sql=true
```
If necessary, update the username and password to match the credentials defined in your `docker-compose.yml` file.
## Build the Application
Once the database is running, you need to build the project using Maven.
Run the following command inside the project root directory:
```sh
mvn clean install
```
This will:
- Download all dependencies.
- Compile the Java source code.
- Run tests (optional).
- Package the application into a `.jar` file.
## Start the Backend Application
After building the project, start the backend service using:
```sh
mvn spring-boot:run
```
or run the compiled JAR file manually:
```sh
java -jar target/car-rental-shop.jar
```