Back to portfolio
WebappClient work

Calorie Calculator

Laravel + Livewire application that combines a meal builder with calorie and macronutrient values, goals and a personal journal, recurring groups, and a suite of calculators for BMR/TDEE, weight, body composition, protein, and calories burned.

Calorie Calculator

Core stack

PHP 8.2
Laravel 11
Livewire 3
Blade
Eloquent ORMMySQLTailwind CSS 3Alpine.js 3Vite 6Carbonhtml2canvasLaravel MailPHPUnit 11cPanel

The challenge

The challenge was unifying two types of logic into a single experience: independent nutritional formulas, with different units and validation limits, and a persistent food journal where the same foods have different values depending on preparation and quantity. On top of that, goals had to account for both actually saved meals and recurring groups, without double-counting calories in aggregations.

The solution

The solution uses dedicated Livewire components for each calculator and a relational FoodItem → PreparationMethod → MealItem model for per-portion calculations. The main calculator keeps the current meal in the session, allows custom foods, saves authenticated meals into groups, and calculates goal progress over the relevant interval. Recurring groups store only the repetition rule, and the dashboard determines the applicable dates and deduplicates meal-date pairs during aggregation. Catalog administration, the blog, and SEO are integrated into the same Laravel monolith.

Notable complexity

Calorie Calculator is a nutrition web application that goes beyond an isolated formula. The main surface allows searching for foods, choosing a preparation method, entering a quantity, and calculating calorie, protein, carbohydrate, and fat values proportional to the portion. Unauthenticated users can temporarily compose a meal, while verified accounts can save meals, create their own foods, and organize them into groups.

The data model separates the food from its preparation methods, since the same raw ingredient can have different values depending on how it's cooked. Meal and MealItem keep the food journal, MealGroup organizes meals and can define weekly or monthly repetition, and CalorieGoal keeps the active goal for daily, weekly, or monthly periods. Nutritional values are calculated from the quantity relative to 100 g, and the dashboard aggregates meals over periods and includes logic to virtually project recurring groups without materializing copies of meals in the database.

The application includes separate pages for weight loss, weight gain, body fat, ideal weight, protein, macronutrients, and calories burned. BMR uses the Mifflin–St Jeor formula, TDEE applies activity multipliers, and the calories-burned calculator uses MET values and a formula based on weight and duration. The distance mode estimates time from distance and speed and interpolates the MET value for walking, running, or cycling. The body-fat calculator uses the US Navy formula and additionally provides BMI and lean mass, while the ideal-weight calculator compares the Robinson, Miller, Devine, and Hamwi formulas.

The interface is server-driven through Livewire 3, with Blade for markup, Alpine.js for local interactions, and Tailwind CSS for the responsive layout and dark mode. The main calculator has a two-column structure on desktop and a slide-over for the meal summary on mobile. Food search is debounced, results are limited, and there is quick-add and automatic selection of the default preparation method by category. The meal summary can be rendered in a dedicated layout and exported locally as a PNG via html2canvas, loaded on demand.

Accounts use Laravel authentication, email verification via a signed URL, and password reset. A separate middleware blocks deactivated users, and the admin area is protected by the is_admin flag. The administrator can manage the food and category catalog, preparation methods, users, blog articles, and SEO settings. The layout reads per-page metadata from the database and can enable Google Analytics when an ID is configured.

Persistence uses MySQL and Eloquent relations with foreign keys and cascade where the domain model requires it. The meal list is paginated and eager-loads the nutritional relations used in the UI. Food search uses a leading-wildcard LIKE and inRandomOrder for quick-add, and recurring-group aggregation iterates the data in PHP; these are sufficient for the application's size in this snapshot, but would need a search/indexing strategy and pre-aggregation if the volume grew significantly.

The snapshot also includes legacy operational infrastructure: a cPanel manifest, a Laravel health endpoint, and endpoints for GitHub webhook / administrative execution. There are no GitHub Actions, Docker, or a test suite for the nutritional formulas; the tests present mainly cover the authentication and profile scaffolding. The audit also identified sensitive configuration committed to the repository, publicly accessible debug routes, and a few incomplete ownership checks. These elements are not presented as product advantages and must be hardened before any production reuse.

Key results

  • Meal builder with food search, preparation methods, quantities, and totals for calories, protein, carbohydrates, and fat
  • Persistence for meals and journal entries associated with the user, organized into groups
  • Meal groups with weekly or monthly repetition rules and virtual calculation in statistics
  • Daily, weekly, and monthly calorie goals with progress calculated from the current journal
  • Seven specialized routed calculators for weight loss, weight gain, body fat, ideal weight, protein, macronutrients, and calories burned
  • BMR/TDEE logic based on Mifflin–St Jeor and energy-expenditure estimation via MET
  • Dashboard with nutritional statistics and today/week/month/all/custom filters
  • Persistent custom foods for authenticated users and multiple preparation methods per food
  • Local export of a meal summary as a PNG image
  • Administration for the food catalog, categories, users, blog, and SEO
  • Authentication with email verification, password reset, and administrative account deactivation
  • Responsive interface with dark mode, a two-column desktop layout, and a mobile slide-over summary
  • Laravel health endpoint and cPanel deployment configuration present in the repository

Related projects

Want something similar?

Start with the estimate wizard — answer a few questions and get a realistic price range and timeline.