DEV Community

Cover image for Building an open-source TDEE calculator you can actually verify
aadifit
aadifit

Posted on

Building an open-source TDEE calculator you can actually verify

Every TDEE (Total Daily Energy Expenditure) calculator I found online was the same thing: a form behind a wall of ads, math you can't see, and no way to reuse it in your own project. So I pulled the formulas out into a small, tested, MIT-licensed package and a zero-permission browser extension.

The formulas

TDEE calculators are built from two numbers:
BMR (Basal Metabolic Rate) — calories your body burns at rest.
An activity multiplier — how much more you burn based on how active
you are (1.2x for sedentary, up to 1.9x for very active).
TDEE = BMR x activity multiplier
The part everyone gets subtly wrong is BMR. There are three formulas in
actual use, and they disagree with each other on purpose:
Mifflin-St Jeor (1990) — the default in most modern tools, and the most
accurate across the general population according to a 2005 validation study
in the Journal of the American Dietetic Association that compared it
against several older formulas:

male:   10 x weight(kg) + 6.25 x height(cm) - 5 x age + 5
female: 10 x weight(kg) + 6.25 x height(cm) - 5 x age - 161
Enter fullscreen mode Exit fullscreen mode

Katch-McArdle — uses lean body mass instead of total weight, so it's
more accurate if you actually know your body fat percentage (DEXA scan,
reliable calipers — not the scale-with-electrodes kind):

BMR = 370 + 21.6 x lean_mass_kg
lean_mass_kg = weight_kg x (1 - body_fat_pct / 100)
Enter fullscreen mode Exit fullscreen mode

Harris-Benedict (1984 revision) — the older standard, included mostly
for compatibility with tools that still use it:

male:   13.397 x weight(kg) + 4.799 x height(cm) - 5.677 x age + 88.362
female: 9.247 x weight(kg) + 3.098 x height(cm) - 4.330 x age + 447.593
Enter fullscreen mode Exit fullscreen mode

For a 30-year-old, 80kg, 180cm male, these three give 1780, ~1839 (at 15%
body fat), and ~1854 kcal respectively — a real 70+ kcal spread just from
formula choice, before you even touch activity level.

Macros

Once you have TDEE, splitting it into protein/carb/fat grams is a second
formula most calculators bolt on badly. I used a fixed-fat-percentage
approach — protein and fat needs scale with body weight and hormones, carbs
are the flexible lever:

targetKcal = tdee * (1 + goalAdjustment)   // cut: -20%, bulk: +10%
proteinG = proteinPerKg * weightKg          // cut: 2.2, maintain: 2.0, bulk: 1.8
fatG = (targetKcal * fatPct) / 9            // 25-28% of calories
carbG = (targetKcal - proteinKcal - fatKcal) / 4   // whatever's left
Enter fullscreen mode Exit fullscreen mode

The package

@aadifit/tdee-calc - zero dependencies, ~150 lines, MIT licensed, every formula checked against
hand-derived reference values in the test suite (16 tests):

npm install @aadifit/tdee-calc
Enter fullscreen mode Exit fullscreen mode

```js const { mifflinStJeor, tdee, macroSplit } = require('@aadifit/tdee-calc');

const bmr = mifflinStJeor({ weightKg: 80, heightCm: 180, age: 30, sex: 'male' });
// 1780

const maintenance = tdee(bmr, 'moderate');
// 2759

const macros = macroSplit(maintenance, { weightKg: 80, goal: 'maintain' });
// { targetKcal: 2759, proteinG: 160, fatG: 86, carbG: 336 }



Source: [github.com/aadifit/tdee-calc](github.com/aadifit/tdee-calc)

## The extension
Same formulas, wrapped in a [Firefox extension](addons.mozilla.org/en-US/firefox/addon/tdee-macro-calculator/) that's just a popup — no permissions, no network requests, no data
collection. If you're curious what a genuinely zero-permission
`manifest.json` looks like:


```json
{
  "manifest_version": 3,
  "action": { "default_popup": "popup.html" },
  "permissions": [],
  "browser_specific_settings": {
    "gecko": {
      "data_collection_permissions": { "required": ["none"] }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Source: github.com/aadifit/tdee-extension

Why

I maintain AadiFit, an AI coaching platform, and
wanted the calculation layer to be something people could actually check
instead of trusting a black box. If you want the full version — body
composition tracking, activity logging, an adaptive plan built around your
actual numbers instead of a static calculator — that's at
aadifit.com/tdee-calculator. But the math itself is free, open, and yours to use however you want.

Top comments (0)