On this page
DocumentationContributing

Add a calculator

Use this guide when you need a new public calculation goal or report, such as a new withholding, annual tax or repayment calculation.

Before you start

  • Read Calculators.
  • Read the public boundary in API and SDK.
  • Inspect the calculator catalogue in @taxkit/calculators.

The rule package owns the calculator program, report schema and rule-pack layer. @taxkit/calculators owns reusable catalogue entries, CalculatorRunRequest, CalculatorRunResponse, CalculatorServiceError, metadata projections, graph construction and service execution.

Proposal

Describe:

  • the calculation goal and report fields
  • the accepted input facts and scenario context
  • the rule packs and parameter services required for each supported tax year
  • the canonical calculator ID, jurisdiction and tax-year literals
  • expected errors and validation help
  • API and SDK compatibility impact

Implementation

Keep the calculator small. It should require facts and return a schema-backed report. Rule layers should derive tax facts.

Plain text
accepted input facts
  -> scenario layer
  -> official rule pack layer
  -> calculator program
  -> schema-backed report

Do not place calculator business logic in @taxkit/api-http handlers, SDK helpers or docs-only examples. HTTP and SDK layers must call the canonical calculator boundary and preserve CalculatorRun* contracts.

File checklist

Adding a calculator touches these files. The examples name the existing annual income tax calculator; follow the same shape for a new one.

Calculator program and report, in the owning rule package (packages/rules/au/<pack>):

  • src/calculator/ — the calculator definition, its ID literal and report Schema, exported from src/index.ts and the ./schemas export in package.json.
  • test/ — golden scenarios (for example test/annual-tax.test.ts) and test/rule-graph.test.ts pins for the facts the calculator requires.

Catalogue and public contract, in packages/calculators:

  • src/catalog.ts — the catalogue entry, description and input Schema.
  • src/live.layer.ts — the program that runs the calculator for its ID.
  • src/schemas.ts — the run request and response unions.
  • src/summaries.ts — the browser-safe summary (ID and title).
  • src/form.ingress.ts — the Website form, its request builder and field messages.
  • type-tests/catalog.ts, test/public-calculator-service.test.ts and test/form.test.ts — descriptor inference, service and form tests.

HTTP API and SDK:

  • packages/api/http/__snapshots__/openapi.json — regenerate the OpenAPI snapshot with the HTTP package tests.
  • packages/sdk/typescript/src/au.ts, src/au-effect.ts and src/au/schemas.ts — any jurisdiction helper and re-exported Schemas.
  • packages/sdk/typescript/test/http-parity.test.ts and type-tests/plain-client.test.ts — SDK parity and type tests.
  • apps/api/scripts/smoke-public-routes.runtime.ts and apps/api/test/smoke-boundaries.test.ts — when the API smoke check should call the new calculator.

Website and native pair, when the calculator has a page:

  • apps/web/src/lib/calculators/caveats.ts — only for a known limitation.
  • tools/apps-local/test/native-pair-calculator-server.checks.ts and native-pair-calculator-browser.checks.ts — the server and browser page checks.

Documentation: docs/architecture/calculators.md, content/docs/concepts/calculators.mdx, content/docs/concepts/reports.mdx, content/docs/api/agent-tools.mdx and a taxkit Changeset.

A new rule package also needs, beside a new packages/rules/au/<pack> workspace:

  • packages/sdk/typescript/package.json — a workspace:* devDependency. The SDK assembler derives its bundled sources from these workspace imports.
  • packages/sdk/typescript/tsconfig.build.json — an include entry for the package's src. tools/workspace/sdk-bundle.test.ts fails until both agree.
  • packages/calculators/package.json — a workspace dependency.
  • tools/oxlint/package-roles.ts — the package's browser-safe ./schemas export, when the Website imports it.

Tests

Your evidence should include:

  • golden tests for the calculator output
  • graph validation for every required and provided fact
  • schema decode tests for calculator input and report schemas
  • type tests for SDK descriptor inference
  • API compatibility tests for POST /api/v2/calculators/:calculatorId/calculate
  • SDK compatibility tests for calculate, calculateSafe and any jurisdiction helper such as annualIncomeTax

Pull request evidence

Attach source citations, test output, compatibility notes and a Changeset or no-Changeset rationale in PR evidence checklist.