Skip to content

About

Simple browser-based macro and calorie tracker

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Macro Tracker

A simple, browser-based app for logging meals and tracking daily macros. Log food by name, set personal goals, and see progress for any day on a monthly calendar.

All data stays on your device — no account server, no cloud sync. Multi-user support is local only (username-based profiles in localStorage).

Features

  • Daily macro summary — calories, protein, carbs, fat, and fiber with progress bars against your goals
  • Extra nutrients — sugar, saturated fat, sodium, and cholesterol
  • Live food search — powered by Open Food Facts by default; optional USDA FoodData Central with your own free API key
  • Flexible amounts — g, oz, cup, tbsp, tsp, or piece/serving
  • Meal tags — breakfast, lunch, dinner, snack
  • Date navigation — jump to any day, edit past entries
  • Monthly calendar — visual status for met / partial / missed / empty goal days
  • Local multi-user — separate logs and goals per username on the same browser

Requirements

  • A modern browser (Chrome, Firefox, Safari, Edge)
  • Network access for food search (Open Food Facts; USDA only if you add a key)
  • A local web server for development (ES modules do not load reliably from file://)

Quick start

# From the project root
npx serve .
# or
python3 -m http.server 8080

Then open the URL shown in the terminal (for example http://localhost:3000 or http://localhost:8080).

Enter a username on the login screen and click Continue. Use the same name later to return to that profile’s data.

How to use

Log in

  1. Open the app.
  2. Enter a username (max 32 characters).
  3. Click Continue, or pick a name under Recent users.

Switch user in the header returns you to the login screen. Data for each user stays in the browser until you clear site data.

Set daily goals

  1. Expand Daily goals under the summary.
  2. Set protein, carbs, fat, fiber (g), and calories.
  3. Click Save goals.

Defaults (if you never change them): 150 g protein, 200 g carbs, 65 g fat, 30 g fiber, 2000 kcal.

Add food

  1. Type what you ate in What did you eat?
    Examples: 50g tofu, chicken breast, oatmeal.
  2. Choose a result from the suggestions list.
  3. Set Amount, Unit, and Meal.
  4. Check the nutrition preview.
  5. Click Add to log.

Search uses Open Food Facts with no key. To also use USDA’s reference database:

  1. Expand API settings (optional).
  2. Get a free key at fdc.nal.usda.gov/api-key-signup.
  3. Paste it and click Save.

Keys are stored only in your browser’s localStorage. Do not use DEMO_KEY — it is heavily rate-limited and often fails with CORS errors.

Review a day

  • Use ‹ / ›, the date picker, or Today to change the selected day.
  • The Food log lists items for that day only; you can still add or edit entries for past dates.
  • Totals and progress bars update from the log for the selected date.

Monthly calendar

The calendar marks each day by goal status:

Color Meaning
Met Goals met for tracked macros
Partial Some progress toward goals
Missed Logged food but fell short
Empty No entries that day

Navigate months with ‹ / › or Today’s month. Click a day to open it.

Project structure

macro-tracker/
├── index.html          # App shell and UI
├── styles.css          # Layout and theme
├── js/
│   ├── main.js         # Entry point
│   ├── state.js        # In-memory app state
│   ├── storage.js      # localStorage users, logs, goals
│   ├── dates.js        # Date helpers
│   ├── nutrients.js    # Nutrient model and default goals
│   ├── food-api/       # Search, providers, units, cache
│   ├── ui/             # Auth, summary, log, calendar, add-food, goals
│   └── utils/          # DOM and number helpers
└── README.md

Food search reliability

Open Food Facts is free and shared. Their API:

  • Rate-limits search to roughly 10 requests/minute per IP
  • Returns HTTP 503 when overloaded or when limits are hit
  • Explicitly warns not to use search as type-ahead without caching

This app is designed so real users still get results:

  1. Built-in catalog of common foods (chicken, rice, eggs, oats, …) — exact matches work offline; weak matches still try the network when possible
  2. Memory + localStorage search cache so successful queries skip the network (degraded fallbacks revalidate quickly)
  3. Sequential, single-host API calls (no multi-mirror races that burn the rate limit)
  4. Short timeouts + host cooldown after 503s (no same-host retry under rate limits)
  5. Optional USDA key — when set, USDA is still queried even for common foods

For many concurrent production users, the sustainable approach is a small backend that caches OFF/USDA (or a local Product Opener instance), not every browser calling OFF directly.

Data & privacy

  • Everything is stored in the browser under the key macro-tracker-v1 (plus optional USDA key under macro-tracker-usda-key and a food-search cache key).
  • Clearing site data for this origin deletes logs, goals, and API keys.
  • No backend and no account passwords — a username is only a local profile label.
  • Food search may call third-party APIs (Open Food Facts; USDA if configured) after the local catalog/cache.

Tech stack

  • Vanilla HTML, CSS, and JavaScript (ES modules)
  • No build step or framework required
  • localStorage for persistence

License

Use and modify as you like for personal or educational projects.

About

Simple browser-based macro and calorie tracker

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages