A modern, scalable, and feature-rich e-commerce backend built with Spring Boot
Features β’ Installation β’ API Documentation β’ Architecture β’ Contributing
- JWT-based Authentication with secure token management
- Role-based Access Control (Admin, Merchant, Customer)
- Password encryption using BCrypt
- Token expiration handling with refresh mechanism
- Product Management with image upload via Cloudinary
- Category Management with hierarchical structure
- Shopping Cart with persistent sessions
- Order Management with status tracking
- Payment Integration with multiple payment methods
- Inventory Management with stock tracking
- Real-time Analytics for business insights
- User Behavior Tracking for personalized experiences
- Product Recommendations based on user preferences
- Sales Analytics with comprehensive reporting
- RESTful API Design with standardized responses
- Data Validation with comprehensive error handling
- Database Optimization with JPA/Hibernate
- File Upload Support with Cloudinary integration
- Security Best Practices with Spring Security
- Clean Architecture with layered design pattern
βββ π config/ # Configuration classes
βββ π controller/ # REST API controllers
βββ π dto/ # Data Transfer Objects
βββ π entity/ # JPA entities
βββ π enums/ # Enum definitions
βββ π exceptions/ # Custom exception handling
βββ π mapper/ # MapStruct mappers
βββ π repository/ # Data access layer
βββ π security/ # Security configurations
βββ π service/ # Business logic layer
- JWT token-based authentication
- Method-level security annotations
- CORS configuration for cross-origin requests
- Password encoding with BCrypt
- PostgreSQL database with JPA/Hibernate
- Repository pattern for data access
- Entity relationships with proper cascading
- Database migrations and versioning
- β Java 17 or higher
- π PostgreSQL 12+
- π¦ Maven 3.6+
- π Git
-
Clone the repository
git clone https://github.com/sumanbisunkhe/ecommerce-system-backend.git cd ecommerce-system-backend -
Database Setup
CREATE DATABASE ecommerce_db; CREATE USER ecommerce_user WITH PASSWORD 'your_password'; GRANT ALL PRIVILEGES ON DATABASE ecommerce_db TO ecommerce_user;
-
Configure Environment
# application.properties spring.datasource.url=jdbc:postgresql://localhost:5432/ecommerce_db spring.datasource.username=your_username spring.datasource.password=your_password # JWT Configuration jwt.secret=your-secret-key jwt.expiration=3600000 # Cloudinary Configuration cloudinary.cloud-name=your-cloud-name cloudinary.api-key=your-api-key cloudinary.api-secret=your-api-secret
-
Build and Run
./mvnw clean install ./mvnw spring-boot:run
The application will start on http://localhost:8080
POST /auth/register # User registration
POST /auth/login # User login
POST /auth/refresh # Token refresh
PUT /auth/password # Change password
GET /products # Get all products (paginated)
GET /products/{id} # Get product by ID
POST /products # Create product (Admin/Merchant)
PUT /products/{id} # Update product (Admin/Merchant)
DELETE /products/{id} # Delete product (Admin/Merchant)
GET /products/category/{categoryId} # Get products by category
GET /products/search # Search products
GET /cart # Get user's cart
POST /cart/items # Add item to cart
PUT /cart/items/{itemId} # Update cart item
DELETE /cart/items/{itemId} # Remove item from cart
DELETE /cart # Clear cart
GET /orders # Get user's orders
GET /orders/{id} # Get order details
POST /orders # Create new order
PUT /orders/{id}/status # Update order status (Admin)
GET /orders/analytics # Order analytics (Admin)
POST /payments/initiate # Initiate payment
POST /payments/callback # Payment callback
GET /payments/{orderId} # Get payment status
GET /users/profile # Get user profile
PUT /users/profile # Update user profile
GET /users # Get all users (Admin)
PUT /users/{id}/role # Update user role (Admin)
GET /analytics/dashboard # Dashboard analytics (Admin)
GET /analytics/sales # Sales analytics
GET /recommendations # Get user recommendations
POST /analytics/track # Track user activity
- Spring Boot 3.5.5 - Application framework
- Spring Security - Authentication & authorization
- Spring Data JPA - Data persistence
- Spring Validation - Input validation
- PostgreSQL - Primary database
- Cloudinary - Image storage and management
- Hibernate - ORM framework
- MapStruct - Object mapping
- Lombok - Boilerplate code reduction
- JWT - Token-based authentication
- Maven - Dependency management
- DotEnv - Environment variable management
spring:
datasource:
url: jdbc:postgresql://localhost:5432/ecommerce_db
username: ${DB_USERNAME:postgres}
password: ${DB_PASSWORD:password}
jpa:
hibernate:
ddl-auto: update
show-sql: false
properties:
hibernate:
format_sql: truejwt:
secret: ${JWT_SECRET:your-secret-key}
expiration: ${JWT_EXPIRATION:3600000}cloudinary:
cloud-name: ${CLOUDINARY_CLOUD_NAME:your-cloud-name}
api-key: ${CLOUDINARY_API_KEY:your-api-key}
api-secret: ${CLOUDINARY_API_SECRET:your-api-secret}Run the test suite:
./mvnw testRun with coverage:
./mvnw test jacoco:reportsrc/
βββ main/
β βββ java/com/example/ecommerce/
β β βββ config/ # Configuration classes
β β β βββ CloudinaryConfig.java
β β β βββ SecurityConfig.java
β β βββ controller/ # REST controllers
β β β βββ AuthController.java
β β β βββ ProductController.java
β β β βββ OrderController.java
β β β βββ ...
β β βββ dto/ # Data Transfer Objects
β β βββ entity/ # JPA entities
β β βββ enums/ # Enumerations
β β βββ exceptions/ # Exception handling
β β βββ mapper/ # MapStruct mappers
β β βββ repository/ # Data access layer
β β βββ security/ # Security components
β β βββ service/ # Business logic
β βββ resources/
β βββ application.properties
β βββ static/
βββ test/ # Test classes
FROM openjdk:17-jdk-slim
COPY target/ecommerce-*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]Build and run:
docker build -t ecommerce-backend .
docker run -p 8080:8080 ecommerce-backendversion: '3.8'
services:
app:
build: .
ports:
- "8080:8080"
depends_on:
- db
environment:
- DB_URL=jdbc:postgresql://db:5432/ecommerce_db
db:
image: postgres:15
environment:
POSTGRES_DB: ecommerce_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
ports:
- "5432:5432"We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow Java coding conventions
- Write comprehensive tests
- Update documentation for new features
- Use meaningful commit messages
- Ensure all tests pass before submitting PR
This project is licensed under the MIT License - see the LICENSE file for details.
Suman Bisunkhe
- GitHub: @sumanbisunkhe
- Email: sumanbisunkhe304@gmail.com
- Spring Boot team for the amazing framework
- PostgreSQL community for the robust database
- Cloudinary for seamless image management
- All contributors who helped improve this project
Made with β€οΈ by Suman Bisunkhe
If this project helped you, please consider giving it a β!