A professional-grade Spring Boot REST API for e-commerce applications, featuring complete CRUD operations, complex JPA relationships, and production-ready PostgreSQL deployment on Render.
Production API: https://spring-boot-ecommerce-api.onrender.com/
Test the API using Postman or any REST client with the endpoints documented below.
- โ Complete RESTful API with full CRUD operations (GET, POST, PUT, DELETE)
- โ Spring Boot 3.5.3 with Java 21 LTS
- โ Production PostgreSQL database on Render
- โ H2 Database for development and testing
- โ Professional Architecture (Controller โ Service โ Repository)
- โ E-commerce Domain Model with Users, Orders, Products, Categories, Payments
- โ Complex JPA Relationships with proper associations and cascading
- โ Order Management System with OrderItems, OrderStatus enum, and Payment tracking
- โ Exception Handling with custom error responses
- โ Connection Pooling with HikariCP for production
- โ Environment Profiles (dev, test, prod)
- โ Maven Build System with optimized dependencies
- โ Production Ready with proper logging and monitoring
- Java 21 or higher
- Maven 3.6 or higher
- PostgreSQL (for production)
- Postman or REST client for testing
-
Clone the repository:
git clone https://github.com/mateusribeirocampos/spring-boot-crud-api-template.git cd spring-boot-crud-api-template -
Build the project:
mvn clean install
-
Run locally (H2 database):
# Switch to test profile for H2 mvn spring-boot:run -Dspring-boot.run.profiles=test -
Access the application:
- API Base URL:
http://localhost:8080 - H2 Console:
http://localhost:8080/h2-console
- API Base URL:
The application is configured for production deployment on Render with PostgreSQL.
- Console:
http://localhost:8080/h2-console - JDBC URL:
jdbc:h2:mem:testdb - Username:
sa - Password: (empty)
- Database: PostgreSQL 16
- Connection Pool: HikariCP optimized for production
- Environment Variables:
DATABASE_HOST,DATABASE_PORT,DATABASE_NAME,DATABASE_USERNAME,DATABASE_PASSWORD
- Production:
https://spring-boot-ecommerce-api.onrender.com - Local:
http://localhost:8080
| Method | Endpoint | Description | Status |
|---|---|---|---|
| GET | /users |
Get all users | โ |
| GET | /users/{id} |
Get user by ID | โ |
| POST | /users |
Create new user | โ |
| PUT | /users/{id} |
Update user | โ |
| DELETE | /users/{id} |
Delete user | โ |
| Method | Endpoint | Description | Status |
|---|---|---|---|
| GET | /orders |
Get all orders | โ |
| GET | /orders/{id} |
Get order by ID | โ |
| Method | Endpoint | Description | Status |
|---|---|---|---|
| GET | /products |
Get all products | โ |
| GET | /products/{id} |
Get product by ID | โ |
| Method | Endpoint | Description | Status |
|---|---|---|---|
| GET | /categories |
Get all categories | โ |
| GET | /categories/{id} |
Get category by ID | โ |
The application automatically seeds the database with comprehensive sample data through the TestConfig class:
| ID | Name | Phone | |
|---|---|---|---|
| 1 | Maria Brown | [maria@gmail.com] | 988888888 |
| 2 | Alex Green | [alex@gmail.com] | 977777777 |
| ID | Name |
|---|---|
| 1 | Electronics |
| 2 | Books |
| 3 | Computers |
| 4 | Finance |
| 5 | Games |
| 6 | Health |
| 7 | Internet |
| 8 | Education |
| 9 | Science |
| 10 | Sports |
| ID | Name | Price | Categories |
|---|---|---|---|
| 1 | The Lord of the Rings | $90.50 | Books |
| 2 | Smart TV | $2190.00 | Electronics, Computers |
| 3 | Macbook Pro | $1250.00 | Computers |
| 4 | PC Gamer | $1200.00 | Computers |
| 5 | Rails for Dummies | $100.99 | Books |
| ID | Date | Status | User | Items |
|---|---|---|---|---|
| 1 | 2025-06-20 | PAID | Maria Brown | 2x The Lord of the Rings + 1x Macbook Pro |
| 2 | 2025-07-21 | WAITING_PAYMENT | Alex Green | 2x Macbook Pro |
| 3 | 2025-07-22 | WAITING_PAYMENT | Maria Brown | 2x Rails for Dummies |
| 4 | 2025-07-07 | DELIVERED | Alex Green | Various items |
-
Get all users:
GET https://spring-boot-ecommerce-api.onrender.com/users
-
Get user by ID:
GET https://spring-boot-ecommerce-api.onrender.com/users/1
-
Create new user:
POST https://spring-boot-ecommerce-api.onrender.com/users Content-Type: application/json { "name": "Joรฃo Silva", "email": "joao@email.com", "phone": "999999999", "password": "123456" } -
Get all products:
GET https://spring-boot-ecommerce-api.onrender.com/products-รง
-
Get order details:
GET https://spring-boot-ecommerce-api.onrender.com/orders/1
src/
โโโ main/
โ โโโ java/com/campos/backend/
โ โ โโโ BackendApplication.java # ๐ Main application class
โ โ โโโ config/
โ โ โ โโโ TestConfig.java # โ๏ธ Database seeding configuration
โ โ โโโ entities/ # ๐ JPA Entities
โ โ โ โโโ User.java # ๐ค User entity
โ โ โ โโโ Order.java # ๐ฆ Order entity
โ โ โ โโโ Product.java # ๐๏ธ Product entity
โ โ โ โโโ Category.java # ๐ Category entity
โ โ โ โโโ OrderItem.java # ๐ Order item entity
โ โ โ โโโ Payment.java # ๐ณ Payment entity
โ โ โ โโโ enums/
โ โ โ โ โโโ OrderStatus.java # ๐ Order status enum
โ โ โ โโโ pk/
โ โ โ โโโ OrderItemPK.java # ๐ Composite primary key
โ โ โโโ repositories/ # ๐๏ธ Data Access Layer
โ โ โ โโโ UserRepository.java
โ โ โ โโโ OrderRepository.java
โ โ โ โโโ ProductRepository.java
โ โ โ โโโ CategoryRepository.java
โ โ โ โโโ OrderItemRepository.java
โ โ โโโ resources/ # ๐ REST Controllers
โ โ โ โโโ UserResource.java
โ โ โ โโโ OrderResource.java
โ โ โ โโโ ProductResource.java
โ โ โ โโโ CategoryResource.java
โ โ โ โโโ exceptions/ # โ ๏ธ Exception handlers
โ โ โ โโโ ResourceExceptionHandler.java
โ โ โ โโโ StandardError.java
โ โ โโโ services/ # ๐ผ Business Logic Layer
โ โ โโโ UserService.java
โ โ โโโ OrderService.java
โ โ โโโ ProductService.java
โ โ โโโ CategoryService.java
โ โ โโโ exceptions/ # โ ๏ธ Custom exceptions
โ โ โโโ DatabaseException.java
โ โ โโโ ResourceNotFoundException.java
โ โโโ resources/
โ โโโ application.properties # ๐ง Production config
โ โโโ application-prod.properties # ๐ญ Production config
โ โโโ application-test.properties # ๐งช Test config
โโโ test/
โโโ java/com/campos/backend/
โโโ BackendApplicationTests.java # โ
Test class# PostgreSQL Database
spring.datasource.url=jdbc:postgresql://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}
spring.datasource.username=${DATABASE_USERNAME}
spring.datasource.password=${DATABASE_PASSWORD}
# HikariCP Connection Pool
spring.datasource.hikari.maximum-pool-size=20
spring.datasource.hikari.minimum-idle=5
# JPA Configuration
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=false# H2 In-Memory Database
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
# JPA Configuration
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>mvn testmvn clean install# Test profile (H2 database)
mvn spring-boot:run -Dspring-boot.run.profiles=test
# Production profile (PostgreSQL)
mvn spring-boot:run -Dspring-boot.run.profiles=prodโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ REST Layer โ
โ (UserResource, OrderResource) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ ๐ผ Service Layer โ
โ (UserService, OrderService) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ ๐๏ธ Repository Layer โ
โ (UserRepository, OrderRepository) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ ๐ Entity Layer โ
โ (User, Order, Product) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ ๐ Database Layer โ
โ (PostgreSQL / H2) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| Entity | Description | Key Features |
|---|---|---|
| User | System users | Personal info, order history |
| Order | Customer orders | Timestamps, status tracking |
| Product | Items for sale | Pricing, categorization |
| Category | Product categories | Many-to-many relationships |
| OrderItem | Order-Product association | Quantity, pricing |
| Payment | Payment information | One-to-one with orders |
- OneToMany: User โ Orders
- ManyToOne: Order โ User
- ManyToMany: Product โ Category
- ManyToMany with Extra Attributes: Order โ Product (via OrderItem)
- OneToOne: Order โ Payment
| Status | Description |
|---|---|
WAITING_PAYMENT |
Order created, awaiting payment |
PAID |
Payment processed successfully |
SHIPPED |
Order shipped to customer |
DELIVERED |
Order delivered to customer |
CANCELED |
Order canceled |
- โ Full CRUD operations for Users
- โ Read operations for Orders, Products, Categories
- โ Complex JPA relationships
- โ Exception handling
- โ Production PostgreSQL deployment
- โ Connection pooling with HikariCP
- โ Environment-specific configurations
- โ Comprehensive sample data
- ๐ Complete CRUD for all entities
- ๐ Authentication & authorization (Spring Security)
- ๐ API documentation (Swagger/OpenAPI)
- ๐งช Comprehensive testing suite
- ๐ Monitoring and metrics
- ๐ Advanced search and filtering
- ๐ Input validation
- ๐ฐ Payment processing integration
Contributions are welcome! Please follow these steps:
-
Fork the repository
-
Create a feature branch
git checkout -b feature/amazing-feature
-
Commit your changes
git commit -m 'Add some amazing feature' -
Push to the branch
git push origin feature/amazing-feature
-
Open a Pull Request
This project is open source and available under the MIT License.
- ๐ Portfolio: mateusribeirocampos
- ๐ผ LinkedIn: Mateus Ribeiro de Campos
- ๐ GitHub: @mateusribeirocampos
โญ Star this repository if you find it helpful!
๐ Live API: https://spring-boot-ecommerce-api.onrender.com/
๐ง Questions? Feel free to reach out via LinkedIn or create an issue in this repository.