Skip to content

πŸ›’ E-Commerce Mini Store | Spring Boot & Java backend ⚑ JWT Auth πŸ” | MySQL πŸ’Ύ | REST APIs for Products, Cart & Orders πŸ“¦

License

Notifications You must be signed in to change notification settings

Anmol283/E-commerceMiniStore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

35 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›’πŸ›οΈ E-commerce Mini Store


Shopping GIF

Secure shopping, smooth coding.

✨ Overview

E-Commerce Mini Store is a full-stack web application leveraging Spring Boot, Java, JWT, and MySQL, designed with a scalable microservices architecture. It provides a complete platform for product management, cart handling, order checkout, and user authentication with roles (CUSTOMER and MANAGER).


🌟 Features

  • πŸ‘€ User Authentication

    • Register and login functionality
    • Role-based access (CUSTOMER and MANAGER)
    • JWT-based stateless authentication
  • πŸ›οΈ Product Mangement

    • Managers can add, update, and delete products
    • Customers and Managers can view all available products
  • πŸ›’ Cart System

    • Add, update, and remove items from cart
    • Customers can checkout orders

πŸ› οΈ Tech Stack

Category Technologies
Backend Spring Boot Java
Database MySQL
Security JWT Spring Security
Frontend Thymeleaf HTML5 CSS3
Microservices Gateway Circuit Breaker

πŸ“ Directory Structure

.idea/
    β”œβ”€β”€ .gitignore
    β”œβ”€β”€ compiler.xml
    β”œβ”€β”€ encodings.xml
    β”œβ”€β”€ jarRepositories.xml
    β”œβ”€β”€ misc.xml
    └── vcs.xml
api-gateway/
    β”œβ”€β”€ .mvn/
        └── wrapper/
            └── maven-wrapper.properties
    β”œβ”€β”€ src/
        β”œβ”€β”€ main/
            β”œβ”€β”€ java/
                └── com/
                    └── example/
                        └── api_gateway/
                            β”œβ”€β”€ config/
                                β”œβ”€β”€ CircuitBreakerConfig.java
                                └── GatewayConfig.java
                            β”œβ”€β”€ fallback/
                                └── FallbackController.java
                            └── ApiGatewayApplication.java
            └── resources/
                └── application.properties
        └── test/
            └── java/
                └── com/
                    └── example/
                        └── api_gateway/
                            └── ApiGatewayApplicationTests.java
    β”œβ”€β”€ .gitattributes
    β”œβ”€β”€ .gitignore
    β”œβ”€β”€ mvnw
    β”œβ”€β”€ mvnw.cmd
    └── pom.xml
E-commerceMiniStore/
    β”œβ”€β”€ .mvn/
        └── wrapper/
            └── maven-wrapper.properties
    β”œβ”€β”€ src/
        β”œβ”€β”€ main/
            β”œβ”€β”€ java/
                └── com/
                    └── example/
                        └── E_commerceMiniStore/
                            β”œβ”€β”€ config/
                                └── PasswordConfig.java
                            β”œβ”€β”€ controller/
                                β”œβ”€β”€ AuthController.java
                                β”œβ”€β”€ CartItemController.java
                                β”œβ”€β”€ OrderController.java
                                β”œβ”€β”€ ProductController.java
                                └── ViewController.java
                            β”œβ”€β”€ entity/
                                β”œβ”€β”€ CartItem.java
                                β”œβ”€β”€ Order.java
                                β”œβ”€β”€ Product.java
                                β”œβ”€β”€ Role.java
                                └── User.java
                            β”œβ”€β”€ repository/
                                β”œβ”€β”€ CartItemRepository.java
                                β”œβ”€β”€ OrderRepository.java
                                β”œβ”€β”€ ProductRepository.java
                                └── UserRepository.java
                            β”œβ”€β”€ security/
                                β”œβ”€β”€ JwtAuthenticationFilter.java
                                β”œβ”€β”€ JwtService.java
                                └── SecurityConfig.java
                            β”œβ”€β”€ service/
                                β”œβ”€β”€ CartItemService.java
                                β”œβ”€β”€ OrderService.java
                                β”œβ”€β”€ ProductService.java
                                └── UserService.java
                            └── ECommerceMiniStoreApplication.java
            └── resources/
                β”œβ”€β”€ META-INF/
                    └── additional-spring-configuration-metadata.json
                β”œβ”€β”€ static/
                    β”œβ”€β”€ Login.html
                    β”œβ”€β”€ navbar.js
                    β”œβ”€β”€ QR.jpeg
                    └── Register.html
                β”œβ”€β”€ templates/
                    β”œβ”€β”€ cart.html
                    β”œβ”€β”€ dashboard.html
                    β”œβ”€β”€ inventory.html
                    β”œβ”€β”€ login.html
                    β”œβ”€β”€ payment.html
                    β”œβ”€β”€ products.html
                    └── register.html
                └── application.properties
        └── test/
            └── java/
                └── com/
                    └── example/
                        └── E_commerceMiniStore/
                            └── ECommerceMiniStoreApplicationTests.java
    β”œβ”€β”€ .gitattributes
    β”œβ”€β”€ .gitignore
    β”œβ”€β”€ mvnw
    β”œβ”€β”€ mvnw.cmd
    └── pom.xml
service-discovery/
    β”œβ”€β”€ .mvn/
        └── wrapper/
            └── maven-wrapper.properties
    β”œβ”€β”€ src/
        β”œβ”€β”€ main/
            β”œβ”€β”€ java/
                └── ServiceDiscoveryApplication.java
            └── resources/
                └── application.properties
        └── test/
            └── java/
                └── com/
                    └── example/
                        └── service_discovery/
                            └── ServiceDiscoveryApplicationTests.java
    β”œβ”€β”€ .gitattributes
    β”œβ”€β”€ .gitignore
    β”œβ”€β”€ mvnw
    β”œβ”€β”€ mvnw.cmd
    └── pom.xml
LICENSE
README.md

πŸš€ Getting Started

Prerequisites

  • Java 21
  • Maven
  • MySQL
  • Postman (for API testing)

Installation

  1. Clone the Repository:

    git clone https://github.com/Anmol283/E-commerceMiniStore
    cd E-Commerce-MiniStore
  2. Configure Database: Update application.properties with your MySQL credentials:

    spring.datasource.url=jdbc:mysql://localhost:3306/ecommerce_db
    spring.datasource.username=root
    spring.datasource.password=your_password
    spring.jpa.hibernate.ddl-auto=update
    jwt.secret=YourSecretKey
    jwt.expirationMs=3600000
  3. Build and run the application:

    mvn clean install
    mvn spring-boot:run
    

🧭 API USAGE FOR TESTING IN POSTMAN

Auth

  • POST /api/auth/register – Register new user
  • POST /api/auth/login – Login and get JWT

Products

  • GET /api/products – Get all products (any role)
  • POST /api/products – Add product (MANAGER only)
  • PUT /api/products/{id} – Update product (MANAGER only)
  • DELETE /api/products/{id} – Delete product (MANAGER only)

Cart

  • GET /api/cart?userId={id} – Get cart items (CUSTOMER only)
  • POST /api/cart/add – Add item to cart (CUSTOMER only)
  • PUT /api/cart/{id} – Update cart item (CUSTOMER only)
  • DELETE /api/cart/{id} – Remove cart item (CUSTOMER only)

Orders

  • GET /api/orders/my?userId={id} – Get user orders (CUSTOMER only)
  • POST /api/orders/checkout?userId={id} – Checkout cart (CUSTOMER only)

πŸ”’ Security Features

  • JWT-based stateless authentication
  • Role-based access (CUSTOMER and MANAGER)
  • Password hashing with BCrypt
  • Protected API routes using Spring Security

🌐 API Gateway

  • Routing: All requests go through the API Gateway before reaching microservices
  • Load Balancing: Can distribute traffic between service instances
  • Fallbacks: Resilience4j circuit breakers ensure safe fallback responses if a service is down

⚑ Resilience & Fault Tolerance

  • Resilience4j Circuit Breaker: Protects services from cascading failures
  • Fallback Mechanisms: If a microservice fails, the gateway provides default/fallback responses
  • Timeouts & Retry Policies: Ensures API responsiveness even during service downtime

🀝 Contributing

  1. Fork the repository
  2. Create a new branch (git checkout -b feature-branch)
  3. Make your changes and commit (git commit -m "Add feature")
  4. Push to the branch (git push origin feature-branch)
  5. Create a Pull Request

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.


⭐ Star this repository if you find it useful! ⭐

About

πŸ›’ E-Commerce Mini Store | Spring Boot & Java backend ⚑ JWT Auth πŸ” | MySQL πŸ’Ύ | REST APIs for Products, Cart & Orders πŸ“¦

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •