<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: hongtao fang</title>
    <description>The latest articles on DEV Community by hongtao fang (@steuerklar).</description>
    <link>https://dev.to/steuerklar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4159081%2F7420bdb0-f552-4b94-a388-e64768e149f8.png</url>
      <title>DEV Community: hongtao fang</title>
      <link>https://dev.to/steuerklar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/steuerklar"/>
    <language>en</language>
    <item>
      <title>How I built German tax calculators where every number shows its law paragraph (Astro + TypeScript + 68 tests)</title>
      <dc:creator>hongtao fang</dc:creator>
      <pubDate>Sat, 03 Oct 2026 06:16:38 +0000</pubDate>
      <link>https://dev.to/steuerklar/how-i-built-german-tax-calculators-where-every-number-shows-its-law-paragraph-astro-typescript--3f9o</link>
      <guid>https://dev.to/steuerklar/how-i-built-german-tax-calculators-where-every-number-shows-its-law-paragraph-astro-typescript--3f9o</guid>
      <description>&lt;p&gt;When my wife and I planned for a baby, I tried to figure out her &lt;strong&gt;Elterngeld&lt;/strong&gt; (German parental allowance). Every calculator I found was a black box: enter numbers, get one result, trust us. None of them showed &lt;em&gt;how&lt;/em&gt; the number was computed, and several still showed an income limit that was replaced in April 2025.&lt;/p&gt;

&lt;p&gt;So I built the opposite — a suite of calculators where every step displays its formula, percentage, and the legal paragraph. This post is about the engineering behind it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The core idea: tax law as pure functions
&lt;/h2&gt;

&lt;p&gt;German tax law is surprisingly deterministic. § 2c BEEG tells you exactly which deductions to apply, § 32a EStG is literally a piecewise-linear income tax formula. So the whole calculation became a pure TypeScript module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;berechneElterngeld&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Eingabe&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;Ergebnis&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;bemessen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;monatsSteuer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;monatsSV&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;bemessungseinkommen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;prozent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;prozentSatz&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bemessen&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// 67% → 65% above €1,200&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;basis&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bemessen&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;prozent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;EG&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hoechstbetrag&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;basis&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prozent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;schritte&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;rechenweg&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;schritte&lt;/code&gt; (steps) array is the product: every intermediate value with its formula and law reference gets rendered on the page. If a number appears in the UI, it exists in the calculation trace.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tests as a trust contract
&lt;/h2&gt;

&lt;p&gt;Because the target audience will make real financial decisions, every rule got a test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;applies 67% up to €1,200 and tapers to 65%&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;berechneElterngeld&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;BASIS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;bruttoMonat&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;_000&lt;/span&gt; &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nx"&gt;prozent&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toBeCloseTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.67&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;berechneElterngeld&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;BASIS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;bruttoMonat&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="nx"&gt;_500&lt;/span&gt; &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nx"&gt;prozent&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toBeCloseTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.65&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;68 tests now encode the rules: minimum benefit (€300), the cap (€1,800), the April-2025 income limit (€175,000 zvE — one most sites still get wrong), sibling/twin/premature-birth bonuses, and the severance Fünftelregelung (§ 34 EStG). For the Minijob employer-cost model I validated against the official Minijob-Zentrale calculator — to the cent.&lt;/p&gt;

&lt;h2&gt;
  
  
  The stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Astro&lt;/strong&gt; static output — the whole site ships &amp;lt;200 KB, zero third-party requests&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TypeScript calc modules&lt;/strong&gt; shared between the page JS and the test suite&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloudflare Pages&lt;/strong&gt; — free hosting, Frankfurt edge for the German audience&lt;/li&gt;
&lt;li&gt;No cookies, no tracking, no signup — calculations run entirely client-side (which also means the privacy policy fits in one paragraph)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I'd do differently
&lt;/h2&gt;

&lt;p&gt;Translating § 2c BEEG deduction logic into code took three attempts — the interaction between Lohnsteuer, Soli, and Kirchensteuer per &lt;em&gt;month&lt;/em&gt; is subtly different from the annual calculation. Testing against the official Prognoserechnung examples caught the drift.&lt;/p&gt;




&lt;p&gt;The result is live at &lt;a href="https://rechner.hunterfang.com/en/" rel="noopener noreferrer"&gt;rechner.hunterfang.com/en&lt;/a&gt; (German/English/Chinese). It launches on Product Hunt next Tuesday — feedback from anyone who knows German tax law would be incredibly welcome, stress-testing the math is exactly what the test suite can't do alone.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>typescript</category>
      <category>astro</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
