← All posts

Recipes and saponification

A recipe in Plan.Make.Trace is not a static document. It is a formulation that can be turned into manufacturing quantities. This post covers how the saponification calculator works and what it has to support.

What we built

The saponification calculator takes a recipe's oil ingredients and produces the lye and water quantities required to manufacture it. Given the oils, their weights, the lye type, the water calculation method, and the superfat percentage, it returns the required lye in milligrams and the required liquid in milligrams.

Those outputs are stored on the recipe's soap bar configuration and used as the basis for scaling a production batch. The calculator itself is a pure module with no database access. The service layer handles authorisation, loads the ingredients and their saponification values, and delegates the math.

The problem it solves

Saponification is the chemical reaction that turns oils and lye into soap. The amount of lye required depends on which oils are in the recipe: different oils have different saponification values, and the calculation has to account for all of them weighted by mass.

A soap maker also makes several choices that change the result. NaOH produces a hard bar; KOH is used for softer or liquid soaps. Superfat reduces the calculated lye below the amount required for complete saponification, leaving an intentional excess of oils in the finished formulation. Water can be calculated as a percentage of oils, as a lye concentration, or as a lye-to-water ratio, and soap makers have preferences about which method they use.

The system has to support those choices consistently and produce quantities that can actually be used at the bench. Getting the lye calculation wrong in either direction matters.

The challenge

The calculation is not one formula. It is a composition of decisions: which lye type, which water calculation method, what superfat. Each combination has to produce a correct result, and the inputs arrive from different parts of the recipe rather than a single form.

Precision was a deliberate design decision. All weights are stored and calculated as integer milligrams, with intermediate float arithmetic rounded at the boundary. The rationale is straightforward: sub-milligram precision is below the noise floor of any soap-making scale. The software precision is matched to what can actually be measured in production, rather than carrying arbitrary decimal places that imply accuracy the measurement cannot support.

What makes this different

The calculator is a pure, shared module. It has no knowledge of the database or the service layer. The service fetches the inputs, pairs each oil ingredient with its saponification value, and hands a clean list to the calculator. That separation means the calculator can be unit tested in isolation against known values without standing up the application.

It is also designed to be reused. The oil shape the calculator expects is generic: a weight and a saponification value. A liquid soap recipe using KOH would use the same calculator with different inputs. The choice of lye type determines which saponification value is looked up per oil; the calculator does not need to know anything else about the recipe type.

What this unlocks

A soap maker can build a recipe in Plan.Make.Trace and get back the lye and water quantities for that specific formulation, calculated correctly for their chosen production method. When they scale the recipe to a batch, those quantities scale with it.

What's next

The next post covers soap properties and formulation: predicting the qualities of the finished bar from the recipe's ingredient profile.

Liked this post? Tap the heart to let us know.

Get early access

Be the first to hear about early access, roadmap updates, and exclusive early adopter pricing.

Join the early access list