This project is a Spring Boot-based backend template designed for frontend and mobile developers to unleash their creativity on the client-side. It provides essential APIs for user authentication, product management, order processing, and more.
The Grocery Store - Backend Project aims to simplify the backend setup for developers working on e-commerce applications. By offering a robust API template, this project allows developers to focus on crafting unique user experiences on the frontend while leveraging pre-built, scalable backend features. Key motivations include:
- Reducing development overhead for client-side teams.
- Demonstrating modern backend design best practices.
- Providing a ready-to-use API that integrates essential e-commerce functionality.
Whether you're developing a grocery delivery app or exploring backend concepts, this project provides a reliable starting point.
For a detailed API reference, you can check out the API Documentation. The API Documentation also includes the Postman collection of the whole backend project.
-
Authentication and Authorization
- JWT-based token authentication.
- Token refresh mechanism for seamless user sessions.
-
Product Management
- Endpoints to fetch products, view details, and manage reviews.
-
Cart and Wishlist
- APIs to manage shopping carts and user wishlists.
-
Order Processing
- Create and view order details.
-
Email Notifications
- Integrated email service for account activation and password recovery.
-
Dockerized Deployment
- Ready-to-run setup using Docker Compose.
-
Comprehensive API Documentation
- Detailed documentation to help developers utilize the backend effectively.
- Spring Boot for backend framework.
- Spring Security for a robust security infrastructure.
- Spring Data MongoDB for database interactions.
- MongoDB for database.
- JWT for authentication.
- Lombok for reducing boilerplate code.
- Thymeleaf for server-side rendering.
- Java Mail Sender for email functionality.
- Docker for containerization.
- Install Docker and Docker Compose.
- Ensure you have Java 17 and Maven installed if running locally.
-
Clone the repository:
git clone https://github.com/CAPELLAX02/grocery-app-backend.git cd grocery-app-backend
-
Start the application with Docker Compose:
sudo docker compose up -d
-
Access the application:
- Base URL of the API will be live on
http://localhost:8080/api/v1
.
- There is a sample
products.json
file in the/src/main/resources/static
directory. - You can import this json file to your MongoDB database via either MongoDB Atlas or MongoDB Compass.
- Additionally, you can edit all the product fields in the json file before loading the sample data to the database. For example, for better user experience, you can change the dummy
imageURL
links with actual product image URLs.
There is a yml
file named example.application.yml
in the src/main/resources
directory. You should change the name of this file as application.yml
, and change the following environment variables for your convenience:
- The MongoDB connection URI.
- Example:
mongodb+srv://username:[email protected]/database_name
. - To set up MongoDB Atlas, follow this guide.
- The name of your MongoDB database.
- The SMTP host for sending emails. For example, use
smtp.gmail.com
for Gmail.
- The SMTP port. For Gmail's SMTP, this is typically
587
.
- Your email address used for sending emails.
- The app-specific password generated by your email provider.
- For Gmail, you can create this password under your Google Account settings
(Security > App Passwords)
.
- A secret key for signing JWT tokens.
- You can generate an appropriate jwt secret using:
-
openssl rand -base64 129 | tr -d '\n'
- Access token expiration time in milliseconds.
- Example:
86400000
for 24 hours.
- Refresh token expiration time in milliseconds.
- Example:
604800000
for 7 days.
spring:
# other configurations...
data:
mongodb:
uri: YOUR_MONGODB_URI_WITH_CREDENTIALS/YOUR_DB_NAME
database: YOUR_DB_NAME
# other configurations...
mail:
host: smtp.gmail.com
port: 587
username: [email protected]
password: your-email-app-password
# other configurations...
security:
jwt:
access-token:
secret: YOUR_GENERATED_SECRET
expiration: 86400000
refresh-token:
expiration: 604800000
# other configurations...
We welcome contributions to make this project even better. Here's how you can contribute:
- Fork the repository:
-
Click the "Fork" button on the top-right corner of this page.
-
Clone your forked repository:
git clone https://github.com/your-username/grocery-app-backend.git cd grocery-app-backend
- Create a new branch for your changes:
-
git checkout -b feature/your-feature-name
- Make your changes and commit them:
-
git add . git commit -m "Add your message here"
- Push your changes to your fork:
-
git push origin feature/your-feature-name
- Submit a Pull Request:
- Open a pull request from your feature branch to the main repository.