To implement this e-commerce platform, a microservices architecture was chosen to ensure scalability, modularity, and fault tolerance. The system comprises multiple independent services, each responsible for a specific domain, enabling seamless integration, efficient scaling, and isolated fault management. This approach aligns with best practices for building modern, cloud-native applications and provides flexibility for independent development and deployment.
Several key features were developed, each powered by different microservices that work together to provide a cohesive and efficient user experience while maintaining separation of concerns.
- User Service: Manages user registration, authentication, and profile management, ensuring secure access and user data privacy.
- Product Service: Handles product catalog management, including product search, categorization, and detailed information retrieval.
- Cart Service: Manages user cart operations such as adding, removing, and updating products in the cart.
- Order Management Service: Facilitates the order processing flow, including order creation, status tracking, and historical order management.
- Payment Service: Integrates with external payment gateways to handle secure payment processing and transaction verification.
- Email Service: Sends notifications and confirmations, such as order receipts and updates, to keep users informed about their transactions.
- Service Discovery: Ensures dynamic registration and discovery of microservices, enabling efficient communication and scaling across the platform.
- API Gateway: Manages incoming API requests, directing them to the appropriate microservices while handling authentication, authorization, and load balancing.
The User Service is responsible for managing user-related operations such as registration, login, authentication, and authorization.
- User Registration (Sign-Up): Securely hashes and stores credentials using BCrypt with salting.
- User Login: Authenticates users and issues a JWT for secure, stateless session management.
- Token-Based Authentication: Uses JWT to manage user sessions, reducing server-side overhead.
- OAuth2 Authorization: Supports third-party logins through OAuth2.
- Password Security: Utilizes BCrypt for password hashing with salting.
- Session Management: Tracks JWT tokens and session status.
- Logout: Ends user sessions by invalidating JWT tokens.
- Role-Based Access Control (RBAC): Manages user permissions based on assigned roles.
- AuthController:
POST /auth/signup: Registers a new user.POST /auth/login: Authenticates user and returns a JWT token.POST /auth/logout: Invalidates the current session.POST /auth/validateToken: Validates a JWT token.
- RoleController:
POST /roles: Assigns a role to a user.
- UserController:
GET /users: Fetches details of all users.GET /users/{id}: Fetches user details by user ID.POST /users/{id}/roles: Assigns roles to a user.
- Users Table:
id,email,password
- Roles Table:
id,role
- User Roles Table:
roles_id,users_id
- Sessions Table:
id,token,created_at,expiring_at,last_logged_in_at,logged_out_at,user_id,status
The Product Service manages all product-related operations, ensuring efficient handling of product data.
- Product Management: Allows creation, update, retrieval, and deletion of product entries.
- Product Retrieval and Search: Supports pagination and category-based filtering.
- Category Management: Retrieves and displays product categories.
- Search Functionality: Implements search features for product queries.
- ProductController:
POST /products: Creates a new product entry.GET /products: Retrieves a list of all products.GET /products/{id}: Fetches details of a specific product.PUT /products/{id}: Updates a product by ID.DELETE /products/{id}: Deletes a product.GET /products/categories: Lists all product categories.GET /products/categories/{categoryName}: Retrieves products within a specific category.
- Products Table:
id,currency,price
- Prices Table:
id,currency,price
- Categories Table:
id,name
The Cart Service manages user shopping carts, providing functionalities like adding items to the cart.
- Add to Cart: Enables users to add products with custom attributes.
- View Cart: Retrieves the contents of the cart.
- Remove Product from Cart: Allows removal of specific products.
- Clear Cart: Provides functionality to empty the cart.
- CartController:
POST /api/cart: Adds an item to the user's cart.GET /api/cart/{userId}: Fetches cart details for the given user ID.DELETE /api/cart/{userId}: Clears the cart.DELETE /api/cart/{userId}/product/{productId}: Removes a specific product.
The Order Management Service manages the checkout process and order management.
- Create Order: Validates cart and payment details to create an order entry.
- Track Order: Allows users to track order statuses.
- Order History: Provides APIs to fetch past orders.
- Order Cancellation: Enables order cancellations before shipping.
- Update Order Status: Manages order lifecycle updates.
POST /api/orders/create: Initiates order creation.GET /api/orders/{userId}: Retrieves a list of all orders for a user.GET /api/orders/track/{orderId}: Fetches order details by ID.PUT /api/orders/{orderId}/update-status: Updates order status.PUT /api/orders/{orderId}/cancel: Cancels an order.
- Orders Table:
id,order_date,status,user_id,total_amount,delivery_address,expected_delivery_date
- Order Items Table:
id,price,product_id,quantity,order_id,total_item_price
The Payment Service manages payment operations, integrating with the RazorPay API.
- Payment Link Generation: Creates secure payment links based on order details.
- Payment Initiation: Processes payment requests.
- Integration with RazorPay: Uses RazorPay client library for payment management.
POST /payments: Initiates the payment process for a given order.
The Email Service manages email notifications and uses Apache Kafka for message communication.
- Asynchronous Email Processing: Listens for user events to send emails.
- Kafka Integration: Uses Kafka to handle email messages.
The Service Discovery microservice manages the registration and discovery of other microservices.
- Service Registration: Automatically registers microservices upon startup.
- Service Discovery: Queries Eureka for available instances.
- Client-Side Load Balancing: Uses RestTemplate for inter-service communication.
The API Gateway serves as the central entry point for client requests and routes them to appropriate microservices.
- Routing & Forwarding: Routes client requests based on URL patterns.
- Load Balancing: Distributes traffic among multiple instances.
- Service Discovery Integration: Locates microservices dynamically for routing.