<?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: Sylar Long (SylarLong)</title>
    <description>The latest articles on DEV Community by Sylar Long (SylarLong) (@sylar_longsylarlong_8e).</description>
    <link>https://dev.to/sylar_longsylarlong_8e</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%2F4262010%2F7600890e-d521-48e0-9416-320be85672f9.jpg</url>
      <title>DEV Community: Sylar Long (SylarLong)</title>
      <link>https://dev.to/sylar_longsylarlong_8e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sylar_longsylarlong_8e"/>
    <language>en</language>
    <item>
      <title>Building iztro: Modeling Traditional Chinese Astrology (Zi Wei Dou Shu) in Strongly-Typed TypeScript</title>
      <dc:creator>Sylar Long (SylarLong)</dc:creator>
      <pubDate>Tue, 24 Nov 2026 07:13:56 +0000</pubDate>
      <link>https://dev.to/sylar_longsylarlong_8e/building-iztro-modeling-traditional-chinese-astrology-zi-wei-dou-shu-in-strongly-typed-typescript-4bif</link>
      <guid>https://dev.to/sylar_longsylarlong_8e/building-iztro-modeling-traditional-chinese-astrology-zi-wei-dou-shu-in-strongly-typed-typescript-4bif</guid>
      <description>&lt;p&gt;When most developers think of rule-heavy domain engines, they think of tax calculators, game state machines, or scheduling algorithms. Few realize that traditional East Asian astrology systems are essentially deterministic, multi-layered rule engines running on top of intricate lunisolar calendar math.&lt;/p&gt;

&lt;p&gt;Over the past couple of years, I’ve been building and maintaining &lt;strong&gt;&lt;a href="https://github.com/SylarLong/iztro" rel="noopener noreferrer"&gt;iztro&lt;/a&gt;&lt;/strong&gt;, an open-source, lightweight TypeScript/JavaScript library for calculating and generating &lt;strong&gt;Zi Wei Dou Shu&lt;/strong&gt; (Purple Star Astrology) astrolabes and horoscopes.&lt;/p&gt;

&lt;p&gt;Here is a look at why I built it, the technical challenges behind modeling ancient calendar rules in modern TypeScript, and how the library is structured.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Problem: Legacy Code &amp;amp; Tight Coupling
&lt;/h2&gt;

&lt;p&gt;Zi Wei Dou Shu involves converting Gregorian (solar) dates into traditional lunisolar dates, handling leap months, calculating heavenly stems and earthly branches (&lt;em&gt;Ganzhi&lt;/em&gt;), and placing over a hundred stars across 12 palaces based on interdependent rules—followed by dynamic temporal overlays (decadal, yearly, monthly, and daily horoscopes).&lt;/p&gt;

&lt;p&gt;When I started looking for existing implementations in the JS/TS ecosystem, I ran into a few recurring issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unmaintained &amp;amp; Untyped:&lt;/strong&gt; Most open-source snippets were written years ago in plain JavaScript without type definitions, making complex nested chart objects error-prone to consume.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UI-Coupled:&lt;/strong&gt; Calculation logic was often hardcoded directly into specific frontend components or legacy PHP/Java templates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rigid Rule Sets:&lt;/strong&gt; Different regional schools apply slight variations to leap-month handling or star mutagens (&lt;em&gt;Si Hua&lt;/em&gt;), yet existing libraries hardcoded a single interpretation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I wanted to extract the core calculation engine into a clean, framework-agnostic, and strictly typed library that developers could drop into any Node.js backend or modern frontend app.&lt;/p&gt;




&lt;h2&gt;
  
  
  Key Design Decisions in &lt;code&gt;iztro&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Strongly-Typed Domain Models
&lt;/h3&gt;

&lt;p&gt;An astrolabe contains deeply nested relationships—each of the 12 palaces holds major stars, minor stars, adjective stars, brightness levels, and dynamic mutagens. Using TypeScript, I modeled the entire chart structure so developers get full IDE autocomplete and compile-time safety when traversing palaces or querying horoscopes.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Quick Usage Example
&lt;/h3&gt;

&lt;p&gt;Installing and generating a complete chart takes just a few lines of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install iztro
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;astro&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'iztro'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Generate an astrolabe by solar date, time index (0–12), and gender&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;astrolabe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;astro&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bySolar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2000-8-16'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'female'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'en-US'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Inspect the 12 palaces and their stars&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;astrolabe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;palaces&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Query dynamic decadal, yearly, monthly, and daily horoscopes for a target date&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;horoscope&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;astrolabe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;horoscope&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2026-11-24'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;horoscope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;decadal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;horoscope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;yearly&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;h3&gt;
  
  
  3. Configurability &amp;amp; Plugin Extensibility
&lt;/h3&gt;

&lt;p&gt;Because regional schools disagree on certain edge cases (such as how leap months split between the current and next month, or specific year-boundary cutoffs), &lt;code&gt;iztro&lt;/code&gt; exposes global configuration APIs (&lt;code&gt;astro.config()&lt;/code&gt;) alongside a plugin mechanism. This lets developers customize mutagen tables or inject custom rule extensions without forking the core repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Built-in Internationalization (i18n)
&lt;/h3&gt;

&lt;p&gt;Traditional astrology terminology doesn't translate trivially. &lt;code&gt;iztro&lt;/code&gt; ships with built-in localization supporting English (en-US), Simplified Chinese (zh-CN), Traditional Chinese (zh-TW), Japanese (ja-JP), Korean (ko-KR), and Vietnamese (vi-VN), making it easier to build multi-region applications out of the box.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ecosystem &amp;amp; Cross-Platform Support
&lt;/h3&gt;

&lt;p&gt;Beyond the core &lt;code&gt;iztro&lt;/code&gt; package (which runs seamlessly in both browsers and Node.js), the ecosystem has grown to support different stacks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;React Integration: Companion packages like iztro-hook and react-iztro for declarative UI rendering.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Community Ports: Cross-language implementations inspired by the core architecture, such as dart_iztro for Flutter/Dart developers.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Try It Out &amp;amp; Feedback
&lt;/h3&gt;

&lt;p&gt;If you're interested in rule engines, calendar algorithms, or building cultural/entertainment apps with TypeScript, feel free to explore the repository or test the interactive playground:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GitHub Repository: &lt;a href="https://github.com/SylarLong/iztro" rel="noopener noreferrer"&gt;https://github.com/SylarLong/iztro&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Documentation &amp;amp; Live Demo: &lt;a href="https://iztro.com" rel="noopener noreferrer"&gt;https://iztro.com&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I’d love to hear your thoughts on the API design, TypeScript type ergonomics, or how you structure plugin architectures for domain-heavy libraries. Issues, discussions, and PRs are always welcome!&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>opensource</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
