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).
- 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
- 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://)
# From the project root
npx serve .
# or
python3 -m http.server 8080Then 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.
- Open the app.
- Enter a username (max 32 characters).
- 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.
- Expand Daily goals under the summary.
- Set protein, carbs, fat, fiber (g), and calories.
- Click Save goals.
Defaults (if you never change them): 150 g protein, 200 g carbs, 65 g fat, 30 g fiber, 2000 kcal.
- Type what you ate in What did you eat?
Examples:50g tofu,chicken breast,oatmeal. - Choose a result from the suggestions list.
- Set Amount, Unit, and Meal.
- Check the nutrition preview.
- Click Add to log.
Search uses Open Food Facts with no key. To also use USDA’s reference database:
- Expand API settings (optional).
- Get a free key at fdc.nal.usda.gov/api-key-signup.
- 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.
- 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.
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.
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
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:
- Built-in catalog of common foods (chicken, rice, eggs, oats, …) — exact matches work offline; weak matches still try the network when possible
- Memory + localStorage search cache so successful queries skip the network (degraded fallbacks revalidate quickly)
- Sequential, single-host API calls (no multi-mirror races that burn the rate limit)
- Short timeouts + host cooldown after 503s (no same-host retry under rate limits)
- 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.
- Everything is stored in the browser under the key
macro-tracker-v1(plus optional USDA key undermacro-tracker-usda-keyand 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.
- Vanilla HTML, CSS, and JavaScript (ES modules)
- No build step or framework required
- localStorage for persistence
Use and modify as you like for personal or educational projects.