The Calorie Counting App is a web application built using Java for the backend and React/TypeScript for the frontend. It solves the Advent of Code Day 1: Calorie Counting problem by processing a list of calorie values (either entered as text or uploaded via file). The app computes the maximum calories carried by a single elf and the sum of the top 3 calories carried by different elves. You can solve the problem using either JavaScript or Java, with both solutions provided within the app.
- JavaScript Solution: Implemented in the
getTopCalories
function within the CaloriesCalculator.ts file. - Java Solution: Implemented in the
getTopCalories
method in the CaloriesCalculator class.
- Java (Spring Boot)
- React (TypeScript)
- Docker
- Nginx
- Swagger
- Maven
Make sure you have Docker installed and running on your machine before proceeding with the setup.
git clone https://github.com/JoyProg/CalorieCountingApp.git
cd CalorieCountingApp
-
Create a
.env
file in thefrontend
directory, or copy the provided.env.example
and rename it to.env
. The.env.example
file has the following line to set the API base URL:REACT_APP_CALORIES_API_BASE_URL=http://localhost:8080
-
Use Docker Compose to build and run both the frontend and backend:
docker-compose up --build
This will start:
- The React frontend on
http://localhost:3000
. - The Java backend on
http://localhost:8080
.
- Open your browser and go to
http://localhost:3000
. - You can either:
- Enter a string of calorie values (e.g., 1000\n2000\n3000\n) into the text box.
- Upload a file containing calorie numbers (a sample input file is provided as puzzleInput.txt).
- Choose one of the options:
- Solve with JavaScript: To use the JavaScript implementation.
- Solve with Java: To use the Java backend via the API.
- The result will display the maximum calories and the sum of the top 3 highest calorie counts.
- Navigate to the Swagger UI for the backend API:
http://localhost:8080/swagger-ui.html
. - Click on the
api/v1/calories
endpoint to test the calorie counting API. - Click the Try it out button.
- Enter a string of calorie numbers and specify the number of top
k
calories you want to calculate (in the problem,k = 3
). - Execute the request to see the results from the Java API.
-
Frontend (React):
- Source code is located in the
frontend/src/
directory. - The primary logic for solving the problem with JavaScript is in CaloriePuzzle.tsx.
- Source code is located in the
-
Backend (Java):
- The Spring Boot application is in the
CaloriesApi
directory. - The core logic for solving the problem with Java is in CaloriesCalculator.java.
- API routes are available under
/api/v1/calories
.
- The Spring Boot application is in the