A comprehensive RESTful API for an eCommerce platform built with Spring Boot, featuring user authentication, product management, shopping cart functionality, and category management.
- User Authentication & Authorization - JWT-based authentication with role-based access control
- Product Management - CRUD operations for products with pagination and search
- Category Management - Organize products into categories
- Shopping Cart - Add, update, and manage cart items
- User Management - User registration, login, and profile management
- Image Upload - Support for product image uploads
- Search & Filtering - Search products by keywords with pagination
- JWT token-based authentication
- Role-based authorization (USER, ADMIN)
- Password encryption with BCrypt
- CORS configuration
- Secure endpoints with Spring Security
- Framework: Spring Boot 3.4.2
- Language: Java 21
- Security: Spring Security with JWT
- Database: H2 (In-memory for development)
- ORM: Spring Data JPA with Hibernate
- Build Tool: Maven
- Documentation: Swagger/OpenAPI
- Validation: Bean Validation (Hibernate Validator)
- Mapping: ModelMapper
- Utilities: Lombok
src/
├── main/
│ ├── java/com/bytedistrict/eCommerceAPI/
│ │ ├── config/ # Configuration classes
│ │ ├── controller/ # REST controllers
│ │ ├── model/ # Entity classes
│ │ ├── payload/ # DTOs and response objects
│ │ ├── repositories/ # Data access layer
│ │ ├── security/ # Security configuration and JWT
│ │ ├── service/ # Business logic layer
│ │ ├── util/ # Utility classes
│ │ └── exceptions/ # Custom exception classes
│ └── resources/
│ ├── application.properties
│ └── application.properties.example
└── test/ # Test classes
- Java 21 or higher
- Maven 3.6+
- Git
-
Clone the repository
git clone <repository-url> cd eCommerceAPI-Web-Server
-
Configure the application
cp src/main/resources/application.properties.example src/main/resources/application.properties
Update the JWT secret and other sensitive configurations in
application.properties
:spring.app.jwtSecret=your_jwt_secret_here spring.app.jwtExpirationMs=your_expiration_time_here
-
Build the project
./mvnw clean install
-
Run the application
./mvnw spring-boot:run
The application will start on http://localhost:8080
- H2 Console:
http://localhost:8080/h2-console
- JDBC URL:
jdbc:h2:mem:eComm
- Username:
sa
- Password: (leave empty)
http://localhost:8080/api
Method | Endpoint | Description | Access |
---|---|---|---|
POST | /auth/signin |
User login | Public |
POST | /auth/signup |
User registration | Public |
POST | /auth/signout |
User logout | Authenticated |
GET | /auth/user |
Get user details | Authenticated |
Method | Endpoint | Description | Access |
---|---|---|---|
GET | /public/products |
Get all products (paginated) | Public |
GET | /public/products/keyword/{keyword} |
Search products | Public |
POST | /admin/categories/{categoryId}/product |
Add new product | Admin |
PUT | /admin/products/{productId} |
Update product | Admin |
DELETE | /admin/products/{productId} |
Delete product | Admin |
Method | Endpoint | Description | Access |
---|---|---|---|
GET | /public/categories |
Get all categories (paginated) | Public |
POST | /public/categories |
Create category | Public |
PUT | /public/categories/{categoryId} |
Update category | Public |
DELETE | /admin/categories/{categoryId} |
Delete category | Admin |
Method | Endpoint | Description | Access |
---|---|---|---|
POST | /carts/products/{productId}/quantity/{quantity} |
Add product to cart | Authenticated |
GET | /carts |
Get all carts | Authenticated |
GET | /carts/users/cart |
Get user's cart | Authenticated |
PUT | /carts/products/{productId}/quantity/{operation} |
Update cart item | Authenticated |
Most endpoints support pagination and sorting:
pageNumber
(default: 0)pageSize
(default: 50)sortBy
(default: varies by endpoint)sortOrder
(default: asc)
The API uses JWT (JSON Web Tokens) for authentication:
- Register a new user via
/auth/signup
- Login via
/auth/signin
to receive a JWT token - Include the JWT token in subsequent requests via cookies or Authorization header
- Logout via
/auth/signout
to invalidate the token
- USER: Basic user with access to public endpoints and cart management
- ADMIN: Administrative access to product and category management
Run the test suite:
./mvnw test
Key configuration properties in application.properties
:
# Application
spring.application.name=eCommerceAPI
# Database
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:eComm
# JWT Configuration
spring.app.jwtSecret=your_secret_key
spring.app.jwtExpirationMs=3000000
spring.app.jwtCookieName=springBootEcom
# File Upload
project.image=images/
# Logging
logging.level.org.springframework=DEBUG
- 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 licensed under the MIT License - see the LICENSE file for details.
- Some admin endpoints are currently commented out in security configuration for testing
- Image upload functionality is implemented but may need additional configuration
For support and questions, please open an issue in the repository.
Built with ❤️ by ByteDistrict