A comprehensive e-commerce REST API built with Spring Boot, featuring user authentication, product management, shopping cart functionality, payment processing with Stripe, and order management.
- JWT-based authentication with access and refresh tokens
- Secure login/logout functionality
- Token refresh mechanism
- Role-based access control
- CRUD operations for products and categories
- Product filtering by category
- Product search and listing
- Create and manage shopping carts
- Add/remove items from cart
- Update item quantities
- Clear cart functionality
- Stripe integration for secure payments
- Webhook handling for payment events
- Checkout session management
- Order creation and tracking
- Order history for users
- Order status management
- User registration and profile management
- User addresses and preferences
- Wishlist functionality
- Spring Boot 3.4.1 - Main application framework
- Java 17 - Programming language
- Maven - Dependency management
- MySQL - Primary database
- Spring Data JPA - Data access layer
- Flyway - Database migration tool
- Spring Security - Authentication and authorization
- JWT (JSON Web Tokens) - Stateless authentication
- BCrypt - Password hashing
- Stripe Java SDK - Payment gateway integration
- MapStruct - Object mapping
- Lombok - Code generation
- SpringDoc OpenAPI - API documentation
- Thymeleaf - Template engine (for admin views)
- Spring Validation - Input validation
- Java 17 or higher
- Maven 3.6+
- MySQL 8.0+
- Stripe account (for payment processing)
git clone <repository-url>
cd spring-store-- Create the database (will be created automatically if using the default config)
CREATE DATABASE store_api;Create a .env file in the root directory or set environment variables:
# Database Configuration
DB_USERNAME=root
DB_PASSWORD=your_mysql_password
# JWT Configuration
JWT_SECRET=your_jwt_secret_key
JWT_ACCESS_TOKEN_EXPIRATION=900000
JWT_REFRESH_TOKEN_EXPIRATION=604800000
# Stripe Configuration
STRIPE_SECRET_KEY=your_stripe_secret_key
STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret
# Application Configuration
WEBSITE_URL=http://localhost:8080mvn flyway:migrate# Build the application
mvn clean package
# Run the application
mvn spring-boot:runThe application will start on http://localhost:8080
POST /auth/login
Content-Type: application/json
{
"email": "[email protected]",
"password": "password123"
}POST /auth/refresh
Cookie: refreshToken=your_refresh_tokenGET /auth/me
Authorization: Bearer your_access_tokenGET /products
# Optional: Filter by category
GET /products?categoryId=1POST /products
Authorization: Bearer your_access_token
Content-Type: application/json
{
"name": "Product Name",
"description": "Product description",
"price": 29.99,
"categoryId": 1
}PUT /products/{id}
Authorization: Bearer your_access_token
Content-Type: application/json
{
"name": "Updated Product Name",
"description": "Updated description",
"price": 34.99,
"categoryId": 1
}DELETE /products/{id}
Authorization: Bearer your_access_tokenPOST /cartsGET /carts/{cartId}POST /carts/{cartId}/items
Content-Type: application/json
{
"productId": 1
}PUT /carts/{cartId}/items/{productId}
Content-Type: application/json
{
"quantity": 3
}DELETE /carts/{cartId}/items/{productId}DELETE /carts/{cartId}/itemsPOST /checkout
Authorization: Bearer your_access_token
Content-Type: application/json
{
"cartId": "cart-uuid",
"customerEmail": "[email protected]"
}POST /checkout/webhook
Stripe-Signature: webhook_signature
Content-Type: application/json
{
"webhook_payload": "..."
}GET /orders
Authorization: Bearer your_access_tokenGET /orders/{orderId}
Authorization: Bearer your_access_token- users - User accounts and credentials
- profiles - Extended user information
- addresses - User shipping addresses
- categories - Product categories
- products - Product catalog
- carts - Shopping carts
- cart_items - Cart line items
- orders - Order records
- order_items - Order line items
- wishlist - User wishlists
Key configuration in src/main/resources/application.yaml:
spring:
application:
name: spring-store
datasource:
url: jdbc:mysql://localhost:3306/store_api?createDatabaseIfNotExist=true
username: ${DB_USERNAME:root}
password: ${DB_PASSWORD:Password}
jpa:
show-sql: true
jwt:
secret: ${JWT_SECRET:default_secret}
accessTokenExpiration: 900000
refreshTokenExpiration: 604800000
stripe:
secretKey: ${STRIPE_SECRET_KEY}
webhookSecretKey: ${STRIPE_WEBHOOK_SECRET}mvn testYou can use tools like Postman, curl, or any HTTP client to test the API endpoints. The application also includes Swagger UI for interactive API documentation.
Access Swagger UI at: http://localhost:8080/swagger-ui.html
mvn clean packagejava -jar target/store-0.0.1-SNAPSHOT.jarThe application can be containerized using Docker. Create a Dockerfile in the project root:
FROM openjdk:17-jdk-slim
COPY target/store-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to clone the repo and extend it. You can also create PRs if you wish to contribute in this repo. However, I won't be extending this project further myself.