https://github.com/brenimcode/product-api-spring-boot
RESTful API Java using the Spring Framework, features such as Spring Security, Swagger, Spring Data JPA, Spring HATEOAS, validation with JWT tokens, testing, creating a scalable and efficient application.
https://github.com/brenimcode/product-api-spring-boot
java junit jwt postgresql spring-boot spring-security sql
Last synced: 6 months ago
JSON representation
RESTful API Java using the Spring Framework, features such as Spring Security, Swagger, Spring Data JPA, Spring HATEOAS, validation with JWT tokens, testing, creating a scalable and efficient application.
- Host: GitHub
- URL: https://github.com/brenimcode/product-api-spring-boot
- Owner: brenimcode
- Created: 2024-08-16T04:51:21.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-19T14:08:23.000Z (over 1 year ago)
- Last Synced: 2025-06-19T05:05:44.794Z (10 months ago)
- Topics: java, junit, jwt, postgresql, spring-boot, spring-security, sql
- Language: Java
- Homepage: https://product-api-spring-boot.onrender.com/swagger-ui/index.html
- Size: 499 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# RESTful Java API | **Product Management |** Spring Boot
    
  

 
## Description
This project is a **RESTful API** built with **Spring Boot**, designed for product management, offering full **CRUD** (Create, Read, Update, Delete) functionalities and other useful features. It was developed through self-learning by combining YouTube tutorials, documentation, articles, and consulting AI for quick questions and repetitive task optimization.
### Key Features:
- **Data Persistence**:
- The API uses **Spring Data JPA** for database access abstraction, enabling the use of **JpaRepository** for predefined CRUD operations and queries.
- The product entity is modeled with annotations such as `@Entity` and `@Table`, and the primary key is auto-generated with `@GeneratedValue(strategy = GenerationType.AUTO)`.
- Unique global IDs are generated using **UUID.**
- Configured to use a PostgreSQL database.
- **Input Validation**:
- Validation is handled using **Bean Validation** annotations (e.g., `@NotNull`, `@Size`, etc.), ensuring the integrity of received data.
- A custom **GlobalExceptionHandler** centralizes error and exception handling.
- **Resource Navigation**:
- Implements hypermedia support with **Spring HATEOAS**, adding navigational links to API resources.
- **Authentication and Security**:
- **Spring Security** manages authentication and authorization, using **JWT (JSON Web Tokens)** for stateless endpoint protection.
- Permissions are defined in a dedicated class (`SecurityConfiguration`) with roles (`ROLE_ADMIN` and `ROLE_USER`) and token validation through a dedicated filter (`SecurityFilter`).
- Password hashing is implemented with **BCrypt** for secure credential storage.
- Only users with the **ADMIN** role can perform PUT/POST/DELETE operations.
- **Documentation**:
- **Springdoc-OpenAPI**: Automatically generates OpenAPI 3.0 documentation, integrated with **Swagger UI** for interactive visualization and testing in the browser.
- **Deployment:**
The application is deployed on **Render**, a platform providing free web app hosting. Configured for the server and PostgreSQL database with environment variables.
- Deployed on **Render**, with PostgreSQL database and proper environment variables.
- **Docker Container** configured for portability and efficient execution.
**URLs:**
- **API Base URL:** https://product-api-spring-boot.onrender.com
- **Swagger UI:** https://product-api-spring-boot.onrender.com/swagger-ui/index.html
### **Project Architecture:**
The project follows a **Layered Architecture**, adhering to best practices for modularity and separation of concerns:
- **Controller/Resource Layer**: Manages HTTP requests and sends responses to clients.
- **Service Layer**: Centralizes business logic for better reusability and cohesion.
- **Repository Layer**: Handles database access using the DAO pattern with Spring Data JPA.
- **Model and DTO Layer**: Organizes data, separating domain logic from transfer objects.
- **Security Layer**: Implements authentication and access control using Spring Security.
- **Exception Layer**: Centrally manages errors, providing standardized and clear responses.
### **Installation and Local Execution**
1. **Clone the repository:**
```bash
git clone
```
2. **Set up environment variables:**
1. {DATASOURCE_URL}
2. {DATASOURCE_USERNAME}
3. {DATASOURCE_PASSWORD}
3. **Run the project:**
```bash
./mvnw spring-boot:run
```
4. **Run with Docker:**
- Build the Docker image:
```bash
docker build -t product-api .
```
- Run the container:
```bash
docker run -p 8080:8080 product-api
```
### Visual Diagram of the Application