A comprehensive RESTful API backend service for an ecommerce platform built with Spring Boot, featuring user authentication, product management, shopping cart functionality, order processing with Stripe integration, and wishlist management.
- User Management: Registration, authentication, and profile management
- Product Management: CRUD operations for products with category support
- Category Management: Product categorization and organization
- Shopping Cart: Add, remove, and manage cart items
- Order Processing: Complete order lifecycle with Stripe payment integration
- Wishlist: Save and manage favorite products
- Authentication: Token-based authentication system
- RESTful API: Well-structured REST endpoints
- Database Integration: MySQL database with JPA/Hibernate
- API Documentation: Swagger/OpenAPI documentation
- Exception Handling: Comprehensive error handling and validation
- Payment Integration: Stripe payment gateway integration
- CORS Support: Cross-origin resource sharing configuration
graph TB
subgraph "Client Applications"
Web[Web Frontend]
Mobile[Mobile App]
Admin[Admin Dashboard]
end
subgraph "API Gateway"
API[Spring Boot REST API]
Swagger[Swagger Documentation]
end
subgraph "Business Logic Layer"
Auth[Authentication Service]
User[User Service]
Product[Product Service]
Cart[Cart Service]
Order[Order Service]
Wishlist[Wishlist Service]
end
subgraph "Data Layer"
JPA[Spring Data JPA]
MySQL[(MySQL Database)]
end
subgraph "External Services"
Stripe[Stripe Payment API]
end
Web --> API
Mobile --> API
Admin --> API
API --> Swagger
API --> Auth
API --> User
API --> Product
API --> Cart
API --> Order
API --> Wishlist
Auth --> JPA
User --> JPA
Product --> JPA
Cart --> JPA
Order --> JPA
Wishlist --> JPA
JPA --> MySQL
Order --> Stripe
erDiagram
USERS {
int id PK
string first_name
string last_name
string email UK
string password
}
AUTHENTICATION_TOKEN {
int id PK
string token UK
date created_date
int user_id FK
}
CATEGORY {
int id PK
string category_name UK
string description
string image_url
}
PRODUCT {
int id PK
string name
string image_url
double price
string description
int category_id FK
}
CART {
int id PK
int user_id FK
int product_id FK
int quantity
date created_date
}
WISHLIST {
int id PK
int user_id FK
int product_id FK
date created_date
}
ORDERS {
int id PK
date created_date
double total_price
string session_id
int user_id FK
}
ORDER_ITEM {
int id PK
int order_id FK
int product_id FK
int quantity
double price
date created_date
}
USERS ||--o{ AUTHENTICATION_TOKEN : "has"
USERS ||--o{ CART : "has"
USERS ||--o{ WISHLIST : "has"
USERS ||--o{ ORDERS : "places"
CATEGORY ||--o{ PRODUCT : "contains"
PRODUCT ||--o{ CART : "added_to"
PRODUCT ||--o{ WISHLIST : "saved_in"
PRODUCT ||--o{ ORDER_ITEM : "included_in"
ORDERS ||--o{ ORDER_ITEM : "contains"
sequenceDiagram
participant Client
participant API as Spring Boot API
participant Auth as Auth Service
participant Service as Business Service
participant DB as Database
participant Stripe as Stripe API
Note over Client, Stripe: User Registration Flow
Client->>API: POST /user/signup
API->>Service: UserService.signUp()
Service->>DB: Save user
DB-->>Service: User saved
Service-->>API: SignUpResponse
API-->>Client: Success response
Note over Client, Stripe: User Authentication Flow
Client->>API: POST /user/signIn
API->>Auth: UserService.signIn()
Auth->>DB: Validate credentials
DB-->>Auth: User data
Auth->>DB: Generate token
Auth-->>API: SignInResponse with token
API-->>Client: Authentication token
Note over Client, Stripe: Product Management Flow
Client->>API: POST /product/add
API->>Service: ProductService.addProduct()
Service->>DB: Save product
DB-->>Service: Product saved
Service-->>API: Success response
API-->>Client: Product created
Note over Client, Stripe: Shopping Cart Flow
Client->>API: POST /cart/add?token=xxx
API->>Auth: Validate token
Auth-->>API: User data
API->>Service: CartService.addToCart()
Service->>DB: Save cart item
DB-->>Service: Cart item saved
Service-->>API: Success response
API-->>Client: Item added to cart
Note over Client, Stripe: Order Processing Flow
Client->>API: POST /order/create-checkout-session
API->>Service: OrderService.createSession()
Service->>Stripe: Create checkout session
Stripe-->>Service: Session ID
Service-->>API: StripeResponse
API-->>Client: Checkout session
Client->>API: POST /order/add?token=xxx&sessionId=xxx
API->>Auth: Validate token
Auth-->>API: User data
API->>Service: OrderService.placeOrder()
Service->>DB: Save order and items
Service->>DB: Clear cart
DB-->>Service: Order saved
Service-->>API: Success response
API-->>Client: Order placed
graph LR
subgraph "Presentation Layer"
Controllers[Controllers]
DTOs[DTOs]
Exceptions[Exception Handler]
end
subgraph "Business Logic Layer"
Services[Services]
Validation[Validation]
end
subgraph "Data Access Layer"
Repositories[Repositories]
Entities[Entities]
end
subgraph "Infrastructure"
Database[(MySQL)]
Stripe[Stripe API]
Config[Configuration]
end
Controllers --> DTOs
Controllers --> Services
Controllers --> Exceptions
Services --> Repositories
Services --> Validation
Services --> Stripe
Repositories --> Entities
Entities --> Database
Config --> Database
Config --> Stripe
- Framework: Spring Boot 2.7.0
- Language: Java 11
- Database: MySQL 8.0
- ORM: Spring Data JPA with Hibernate
- API Documentation: Swagger 2 (SpringFox 3.0.0)
- Payment Gateway: Stripe API
- Build Tool: Maven
- Validation: Bean Validation API
Before running this application, ensure you have the following installed:
- Java 11 or higher
- Maven 3.6 or higher
- MySQL 8.0 or higher
- Stripe Account (for payment processing)
Create a MySQL database named ecommerce:
CREATE DATABASE ecommerce;Update the database configuration in src/main/resources/application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/ecommerce
spring.datasource.username=your_username
spring.datasource.password=your_passwordAdd your Stripe secret key to application.properties:
STRIPE_SECRET_KEY=your_stripe_secret_key# Clone the repository
git clone <repository-url>
cd Ecommerce_BE
# Build the project
./mvnw clean install
# Run the application
./mvnw spring-boot:runThe application will start on http://localhost:8081
Access the Swagger UI documentation at:
http://localhost:8081/swagger-ui/
POST /user/signup- User registrationPOST /user/signIn- User login
GET /category/- Get all categoriesPOST /category/create- Create new categoryPOST /category/update/{categoryID}- Update category
GET /product/- Get all productsPOST /product/add- Add new productPOST /product/update/{productID}- Update product
GET /cart/- Get user's cart itemsPOST /cart/add- Add item to cartDELETE /cart/delete/{cartItemId}- Remove item from cart
GET /order/- Get user's ordersGET /order/{id}- Get specific order detailsPOST /order/create-checkout-session- Create Stripe checkout sessionPOST /order/add- Place order after payment
GET /wishlist/{token}- Get user's wishlistPOST /wishlist/add- Add product to wishlist
src/main/java/com/demo/ecommerce/
βββ common/
β βββ ApiResponse.java # Standard API response wrapper
βββ config/
β βββ SwaggerConfig.java # Swagger API documentation config
β βββ WebConfig.java # Web configuration (CORS, etc.)
β βββ MessageStrings.java # Application message constants
βββ controllers/ # REST API controllers
β βββ UserController.java # User authentication endpoints
β βββ ProductController.java # Product management endpoints
β βββ CategoryController.java # Category management endpoints
β βββ CartController.java # Shopping cart endpoints
β βββ OrderController.java # Order management endpoints
β βββ WishListController.java # Wishlist endpoints
βββ dto/ # Data Transfer Objects
β βββ users/ # User-related DTOs
β βββ product/ # Product-related DTOs
β βββ cart/ # Cart-related DTOs
β βββ checkout/ # Checkout-related DTOs
βββ exceptions/ # Custom exception classes
βββ model/ # JPA entity models
β βββ User.java # User entity
β βββ Product.java # Product entity
β βββ Category.java # Category entity
β βββ Cart.java # Cart entity
β βββ Order.java # Order entity
β βββ OrderItem.java # Order item entity
β βββ WishList.java # Wishlist entity
β βββ AuthenticationToken.java # Auth token entity
βββ repository/ # JPA repositories
βββ service/ # Business logic services
βββ EcommerceApplication.java # Main application class
The application uses token-based authentication:
- Registration: Users register with email and password
- Login: Users sign in and receive an authentication token
- Protected Endpoints: Most endpoints require the token as a query parameter
Example usage:
GET /cart/?token=your_auth_token
The application integrates with Stripe for payment processing:
- Checkout Session: Creates a Stripe checkout session for cart items
- Payment Processing: Handles payment through Stripe
- Order Placement: Places order after successful payment
- Users: User accounts and authentication
- Categories: Product categories
- Products: Product information with category relationships
- Cart: Shopping cart items for users
- Orders: Order information with payment details
- OrderItems: Individual items within orders
- WishList: User's saved products
- AuthenticationToken: User authentication tokens
Run the test suite:
./mvnw test| Variable | Description | Default |
|---|---|---|
spring.datasource.url |
Database connection URL | jdbc:mysql://localhost:3306/ecommerce |
spring.datasource.username |
Database username | root |
spring.datasource.password |
Database password | root |
STRIPE_SECRET_KEY |
Stripe secret key | Required |
BASE_URL |
Application base URL | http://localhost:8081/ |
- 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
Lekhraj Kumar
- GitHub: @lekhrocks
- Email: lekh.nith@gmail.com
For support and questions, please contact:
- Email: lekh.nith@gmail.com
- GitHub Issues: Create an issue