technical case study

SaaS • Tax simulator / Web app

Safyr

Free simulator that estimates how Brazil's tax reform (IBS + CBS) changes a company's tax burden, comparing its current regime with the new model.

Lead developer at Karpaz: calculation rules and development Live MVP live, full app planned
HTML CSS JavaScript PHP Cloudflare Turnstile
executive summary

Problem

With the tax reform approved, business owners and accountants still lack a quick way to estimate whether a company will pay more or less tax under the new model.

Solution

A web simulator that takes revenue, tax regime, sector, margin, payroll, inputs and state, and compares the current monthly tax with the estimate under the dual VAT (IBS + CBS), including input credits.

Result

Instant results with no sign-up: current and reform values, the difference in reais and percent, a comparison chart and a written diagnosis with the assumptions used.

Current stage

Karpaz's own product, with the MVP live at safyr.com.br and a waitlist for the full app (saved profile and documents for tax filing).

context

A question every business owner is asking

Brazil's tax reform replaces PIS, COFINS, ICMS and ISS with a dual VAT: the federal CBS and the IBS, shared by states and municipalities. Safyr was created to quickly answer the most common question about it: will my company pay more or less? The simulation uses the Simples Nacional tables (LC 123/2006), the Lucro Presumido and Lucro Real rules and the IBS + CBS reference rate from LC 214/2025, and makes clear that it is an estimate, not a professional tax analysis.

goals and constraints

Goals

  • Compare the current regime with the reform scenario on a single screen
  • Cover Simples Nacional, Lucro Presumido and Lucro Real
  • Account for sector, state (ICMS), ISS and IPI depending on the business
  • Show input credits, which change the result under the new model
  • Capture interest in the full version of the app

Constraints

  • Simplified estimate: it does not replace a professional tax analysis
  • The LC 214/2025 reference rate is still pending Senate approval
  • No sign-up and no storage of the simulation numbers
  • Work well on phones, where the form gets longer
solution architecture

Front-end

A single page in HTML and CSS with JavaScript modules (ES modules): a form that shows the right fields for each sector, a detailed result, a custom bar chart with tooltips and a background of stripes that stack up over time.

Back-end

The calculation runs entirely in the browser (calc.js), with tables and rates kept in a separate data module. On the server, a PHP endpoint only receives the email of people who want to hear about the full app.

Database

The simulation numbers never leave the browser. Only the waitlist email goes to the server, after passing Cloudflare Turnstile, a honeypot field against bots and a rate limit.

security and safeguards

No data sent during simulation

Revenue, margin and the company's other numbers are calculated in the browser itself; none of it is sent to the server.

Bot protection

The email form uses Cloudflare Turnstile and a hidden field (honeypot) that only bots fill in.

Rate limiting

The server limits repeated submissions and the interface explains what to do when the limit is reached.

process
01

Calculation rules

Gathering the Simples Nacional tables, the Lucro Presumido presumptions, the Lucro Real rules and the IBS + CBS reference rate.

02

Calculation engine

Separate functions per regime and a module just for the tables, so rates can be updated without touching the logic.

03

Interface and results

A form that adapts to the sector, a detailed result, a comparison chart and a written diagnosis.

04

Launch and waitlist

Site live on its own domain, with protected email capture to announce the full app.

behind the scenes
js/calc.js JavaScript lines 192–204
export function calcularImpostoReforma(receitaMensal, baseCreditavel) {
  const ivaTotal = REFORMA.ibs + REFORMA.cbs;
  const impostoBruto = receitaMensal * ivaTotal;
  const credito = baseCreditavel * ivaTotal;
  const impostoFinal = impostoBruto - credito;

  return {
    valor: impostoFinal < 0 ? 0 : impostoFinal,
    ivaTotal,
    ibs: REFORMA.ibs,
    cbs: REFORMA.cbs
  };
}
Under the reform's VAT, the tax is the IBS + CBS rate on revenue minus the input credit, and the result never goes negative.
js/calc.js JavaScript lines 123–135
export function calcularLucroPresumido(receitaMensal, setor, aliquotaSetorial) {
  const baseIrpj = receitaMensal * (PRESUNCAO_IRPJ[setor] || 0);
  const baseCsll = receitaMensal * (PRESUNCAO_CSLL[setor] || 0);

  const irpj = baseIrpj * ALIQUOTAS_PRESUMIDO.irpj;
  const adicionalIrpj = Math.max(0, baseIrpj - IRPJ_ADICIONAL.limiteMensal) * IRPJ_ADICIONAL.aliquota;
  const csll = baseCsll * ALIQUOTAS_PRESUMIDO.csll;
  const pis = receitaMensal * ALIQUOTAS_PRESUMIDO.pis;
  const cofins = receitaMensal * ALIQUOTAS_PRESUMIDO.cofins;
  const impostoSetorial = receitaMensal * aliquotaSetorial;

  return irpj + adicionalIrpj + csll + pis + cofins + impostoSetorial;
}
Lucro Presumido: IRPJ and CSLL on the sector's presumed base, the IRPJ surcharge above the monthly limit, PIS, COFINS and the sector tax (ISS, ICMS or IPI).
js/chart.js JavaScript lines 46–75
export function renderGrafico(els, { impostoAtual, impostoReforma, diferencaReais }) {
  const maxValor = Math.max(impostoAtual, impostoReforma, 1);
  const larguraAtual = Math.min((impostoAtual / maxValor) * 100, 100);
  const larguraReforma = Math.min((impostoReforma / maxValor) * 100, 100);

  const valorAtualFormatado = formatCurrency(impostoAtual);
  const valorReformaFormatado = formatCurrency(impostoReforma);

  els.barAtualEl.style.width = `${larguraAtual}%`;
  els.barReformaEl.style.width = `${larguraReforma}%`;

  // A barra "Reforma" é a única com sentido de bom/ruim (é o que muda em
  // relação ao cenário atual), então ela usa uma cor de status; a barra
  // "Atual" é só o contexto/referência e fica neutra.
  let corReforma = "var(--warning)";
  if (diferencaReais > 0) corReforma = "var(--danger)";
  else if (diferencaReais < 0) corReforma = "var(--success)";
  els.barReformaEl.style.background = corReforma;

  els.graficoValorAtualEl.textContent = valorAtualFormatado;
  els.graficoValorReformaEl.textContent = valorReformaFormatado;

  els.barAtualEl.dataset.categoria = "Imposto atual";
  els.barAtualEl.dataset.valor = valorAtualFormatado;
  els.barReformaEl.dataset.categoria = "Imposto com a reforma";
  els.barReformaEl.dataset.valor = valorReformaFormatado;

  els.graficoVazioEl.classList.add("hidden");
  els.graficoComparativoEl.classList.remove("hidden");
}
A bar chart with no library: width is proportional to the larger value and only the reform bar gets a status color (green if it goes down, red if it goes up).
impact

Results

In a few seconds, a business owner sees an estimate of the reform's impact on their case, along with the numbers behind it. The simulator also measures interest in the full app through the email waitlist.

Learnings

Turning legislation into an interface means being clear about what is an estimate: the assumptions, the source of the rates and the limits of the calculation appear right next to the result.