Skip to content
SH-02ADetail A

PoupaNaEnergia

Solo product

An independent electricity-tariff comparator for the Portuguese market. Users upload a power bill, a Gemini-powered pipeline extracts their consumption, and a regulatory engine fed by ERSE data synced daily ranks fixed-price plans by real annual cost.

Type
AI / Energy
Status
Live
The promise: a bill in, the cheapest plan out
Fig. 01 — The promise: a bill in, the cheapest plan out
Problem
Households in Portugal cannot tell which electricity plan actually costs less against their own bill.
Constraint
Live ERSE data, messy PDF bills, and a product that has to be trusted with money.
Decision
Gemini extracts the bill; a regulatory engine ranks fixed-price plans by annual cost; Lighthouse CI runs on every pull request and every push to main with hard a11y, SEO and LCP budgets.
Outcome
Live at poupanaenergia.pt — bill in, ranked plans out.

One bill, from upload to verdict. In order: Upload, type allowlist · size cap · encrypted-PDF probe; then Storage, held until extraction ends; then Extraction ladder, a small model first, a larger one below the confidence bar; then Schema and bounds, JSON schema · temperature 0 · plausibility checks; then Delete the PDF, on success and on failure; then Confirmation form, the household states what the bill cannot; then Comparison engine, fixed-price offers × regulatory constants; then Verdict, bound to the uploading session.

Side lane — daily: Daily sweep, the regulator's simulator, 10 power tiers × 3 cycles; Offers, what the engine ranks against.

Fig. 02 — One bill, from upload to verdict
  1. 1Phantom savings: +38 % on a real bill, +5.8 % after — two net totals extracted, prices renormalised.
  2. 2Auto-validation was removed on purpose: a fact that lives in the household is not on the bill.
  3. 3An exhausted model quota stops with a typed error instead of retrying.
Upload: the visitor's own PDF bill
Fig. 03 — Upload: the visitor's own PDF bill
Extraction: the consumption Gemini read, confirmed by the visitor
Fig. 04 — Extraction: the consumption Gemini read, confirmed by the visitor
The verdict: fixed-price plans ranked by real annual cost
Fig. 05 — The verdict: fixed-price plans ranked by real annual cost
On a phone: the live upload screen, in a composed shot
Fig. 06 — On a phone: the live upload screen, in a composed shot

General notes

  1. 01Per-supplier templates were rejected; the model is anchored to the totals the bill itself guarantees.
  2. 02The PDF is deleted on success and on failure.

Bill of quantities · As-built 2026-11

Item, quantity, and the command that measured it.
ItemQuantity
API routesgit ls-tree -r --name-only origin/main | grep -c 'app/api/.*route.ts'17
Tablesgit grep -hoiE 'create table' origin/main -- 'supabase/migrations/*.sql' | wc -l21

Detail 1:1

The bill's net total is the anchor: the extracted unit prices are scaled until price × kWh adds up to it. One period with no price sends every period to one flat rate, so the missing share is never counted twice.

export function normalizeEnergyUnitPrices(input: NormalizeEnergyInput): Record<string, number> {  const { extracted, breakdown, net_total_eur } = input;   if (net_total_eur === 0) {    return Object.fromEntries(Object.keys(breakdown).map((k) => [k, 0]));  }   const breakdownKeys = Object.keys(breakdown);  if (breakdownKeys.length === 0) {    throw new Error('normalizeEnergyUnitPrices: cannot derive unit prices from empty breakdown');  }  const total_kwh = Object.values(breakdown).reduce((sum, v) => sum + v, 0);  if (total_kwh === 0) {    throw new Error('normalizeEnergyUnitPrices: total_kwh is zero, cannot derive');  }   // Invariant: Σ result[p] × breakdown[p] === net_total_eur. Ratios can only be  // preserved when EVERY breakdown period has an extracted price; with a gap,  // scaling the known periods and pricing the missing ones flat counts the  // missing share twice (fake savings). A flat rate keeps the total exact.  const flat = () => Object.fromEntries(breakdownKeys.map((k) => [k, net_total_eur / total_kwh]));  if (breakdownKeys.some((p) => extracted[p] === undefined)) return flat();   const gross_total = breakdownKeys.reduce((s, p) => s + extracted[p] * breakdown[p], 0);  if (gross_total === 0) return flat();   const correction = net_total_eur / gross_total;  return Object.fromEntries(breakdownKeys.map((p) => [p, extracted[p] * correction]));}
Detail 1:1 — lib/compare/normalize-unit-prices.ts, lines 30–58, as of 2026-09-27 (8716fda).

Stack used

Next.js 16React 19TypeScriptTailwind CSS 4shadcn/uiSupabasePostgreSQLGoogle Gemini APInext-intlVitestPlaywrightLighthouse CIResendVercel
Detail AContact

Legend — the marks on these sheets

SH-xx
Sheet number. Every drawing in a set carries one, and the set is read in that order.
ESC 1:20
Scale. One unit on the drawing stands for twenty on the thing drawn.
DETAIL A/B/C
Detail callout. A lettered part of a drawing, enlarged on a sheet of its own.
SECTION C-C
Section mark. The line a cut is taken along, lettered at both ends.
BH-01
Borehole log. What a trial hole found, recorded downward by depth.
EOB
End of borehole. The depth at which the log stops.
REV. 2026
Revision. The issue a sheet belongs to; a later revision supersedes it.
As-built register
A table of what was actually built, set against what was drawn.

Press ? in the title block to open or close. Escape closes.