A responsive React frontend showcasing a variety of premium dairy products, now powered by a robust Java backend. This project highlights product details, nutritional information, and provides an engaging, interactive user interface for browsing dairy items like milk, cheese, butter, and yogurt—all styled in a fresh Green & White theme!
- Dynamic Product Catalog: Reusable React components displaying various dairy products.
- Responsive Design: Fully accessible and optimized for both desktop and mobile viewing.
- Interactive UI: Smooth state transitions, hover effects, and fast client-side routing.
- API Backend: A lightweight Java Servlet backend providing endpoints (e.g.,
/api/ping). - Docker Ready: Effortlessly deployable to AWS or any VPS via a unified Docker Compose setup.
- Frontend: React, Tailwind CSS, Vite
- Backend: Java 21, Jakarta Servlets, Tomcat 10
- Database: MySQL 8
- Deployment & Infrastructure: Docker, Docker Compose, Nginx
To run this project locally without Docker, follow these steps to spin up the frontend and backend independently.
Before you begin, ensure you have the following installed on your machine:
- Node.js (v18+ recommended) & npm
- Java Development Kit (JDK) 21
- Apache Maven
- MySQL 8 (Running locally on port 3306)
- Open your local MySQL instance.
- Create the database:
CREATE DATABASE dairyfresh_db; - Ensure your local MySQL user/password matches what is defined in the environment variables, or update your local
.envconfiguration.
The frontend runs via Vite and serves the main UI interface.
# Clone the repository
git clone https://github.com/DistantMyth/DairyFresh.git
cd DairyFresh
# Install Javascript dependencies
npm install
# Start the Vite development server
npm run devNavigate to http://localhost:5173 to view the frontend interface.
The backend is a standard Maven web application running on Tomcat 10.
# Open a new terminal and navigate to the backend folder
cd DairyFresh/backend
# Use Maven to clean the target and package the project into a .war file
mvn clean packageThis produces a backend.war file in the backend/target/ directory.
- Deploy this
backend.warto your local Tomcat 10webapps/folder. - Start Tomcat.
- You can verify the API is running by hitting:
http://localhost:8080/backend/api/ping
The project is fully pre-configured for containerized deployment using Docker Compose. Here is a detailed guide to deploying this stack on an AWS EC2 instance.
- Launch an EC2 Instance:
- Go to the AWS EC2 Console and click "Launch Instance".
- Select Ubuntu Server 24.04 LTS (or 22.04 LTS).
- Choose an instance type (e.g.,
t3.microfor testing,t3.smallfor production). - Select or create a Key Pair for SSH access.
- Configure Security Groups (Firewall):
- Edit the inbound rules of the instance's security group to allow the following traffic:
- SSH (Port 22): Your IP
- HTTP (Port 80): Anywhere (0.0.0.0/0)
- HTTPS (Port 443): Anywhere (0.0.0.0/0)
- Edit the inbound rules of the instance's security group to allow the following traffic:
- Connect to your instance via SSH:
ssh -i /path/to/your-key.pem ubuntu@YOUR_EC2_PUBLIC_IP
- Install Docker and Docker Compose:
sudo apt-get update sudo apt-get install -y docker.io docker-compose-v2 sudo usermod -aG docker $USER # Log out and log back in for docker group changes to take effect
-
Clone the Repo on your Server:
git clone https://github.com/DistantMyth/DairyFresh.git cd DairyFresh -
Configure Environment Variables & Credentials: We use a
.envfile to securely inject database, Twilio, and Firebase credentials into the stack.cp .env.example .env nano .env
Edit the
.envfile to set your actual production database passwords, Firebase VAPID key, Twilio SID/Auth Token, etc. -
Add Firebase Service Account: If you are using Push Notifications, securely create the
firebase-service-account.jsonin the root of the project:nano firebase-service-account.json
Paste your Firebase Admin SDK JSON content here and save.
-
Build the Artifacts: Before building the Docker containers, you must build the React static files and the Java
.warfile locally on the server (Requires Node.js and Maven). Alternatively, build them locally and usescpto copy thedistandtargetfolders to the server.If compiling on the server:
# Install tools sudo apt install nodejs npm maven openjdk-21-jdk -y # Build Frontend npm install npm run build # Build Backend cd backend mvn clean package -DskipTests cd ..
-
Start the Containers: Launch the entire stack (Nginx, Tomcat, MySQL) in detached mode:
sudo docker compose up --build -d
-
Verify the Deployment:
- Visit
http://YOUR_EC2_PUBLIC_IPin your browser. - View live logs to ensure backend/database health:
sudo docker compose logs -f
- Visit
Thanks to the following people who have contributed to this project:
- Tarun Kumar - Lead Developer - @DistantMyth
- [Saksham Singhal] - Webpage Structuring - @saksham3100
- [Nilanjan Chavan] - dynamic elements - @nilanjanchavan
- [Aradhya Verma] - UI/UX Designer - @aradhyaverma2911-cyber
This project is open-source and available under the MIT License.