# Challenges I Ran Into

One of the biggest challenges was getting the **frontend, Spring Boot backend, and MySQL database to work together reliably**. A feature could work correctly on one side but still fail when the complete request-response flow was tested.

### Authentication and Authorization

Implementing JWT authentication was one of the more challenging parts.

I had to make sure that the JWT generated during login was correctly stored on the frontend and attached to protected API requests. On the backend, `JwtAuthenticationFilter` validates the token and establishes the authenticated user through Spring Security.

I also had to handle the difference between authentication and authorization. A valid logged-in USER should still be rejected when trying to access an ADMIN-protected endpoint, resulting in a `403 Forbidden` response.

### Persistent Cart

Another hurdle was making the shopping cart persistent and user-specific.

The cart could not simply exist in frontend state. It needed to be stored in MySQL and associated with the authenticated user so that the same cart could be restored after logout and login.

I tested the complete flow by adding products, logging out, logging back in, refreshing the page, and verifying that the correct cart was restored.

### Validation and Error Handling

As more APIs were added, invalid requests and unexpected situations became increasingly important.

For example, adding an invalid quantity should not simply fail somewhere inside the application. It should produce a proper validation response.

I introduced Jakarta Validation and a centralized `GlobalExceptionHandler` to handle validation, authentication, product, stock, and cart-related errors consistently.

### Order Flow

Moving from cart functionality to checkout and orders introduced another layer of complexity.

The flow had to remain consistent from:

```plaintext
Cart
 ↓
Checkout
 ↓
Create Order
 ↓
Order Success
 ↓
Order Details
 ↓
Order History
```

I tested multiple orders for the same user, user-specific order history, order ID propagation, order status updates, and invalid order-status transitions.

These challenges helped me understand that implementing a feature is only one part of development. The harder part is making sure the feature behaves correctly when different parts of the application interact with each other.

By Shitanshu Jha

![](https://cdn.hashnode.com/uploads/covers/6a8501ae552e968823a1653d/7c7c5b17-9f4a-4add-970e-125368839b7f.png align="center")
