The Destiny Grid Gets Its East Wing: I Rebuilt Saju (四柱八字) in TypeScript
The Destiny Grid now has two tabs: Western Astrology and Eastern 四柱八字 Saju. Here's what Saju actually is, how the algorithm works, and why implementing a 2,000-year-old cosmological system in TypeScript broke my brain in the best possible way.
Series: VIBE.LOG
- 1. The Layout Vocabulary Cheat Sheet: What to Call That Thing on Your Screen
- 2. I Spent 3 Hours Trying to Proxy a Blog Subdomain. Here's My Descent Into Madness.
- 3. The Complete SEO Guide: How to Make Google Actually Notice Your Website
- 4. Why Your Next.js Favicon Isn't Showing (And the Three Ways to Actually Fix It)
- 5. GitHub Keeps Telling Me My Branch Is Fine. And Also Not Fine. At the Same Time.
- 6. Mobile-First Playground: Making an Astrology Grid Actually Work on a Phone (And Go Viral While Doing It)
- 7. Playground Is Live: The Destiny Grid, Real Astrology, and Why I'm Shipping a Toy Every Month
- 8. The Interactive Component Cheat Sheet: What to Call That Clickable Thing
- 9. Google Rejected My Site for 'Low-Value Content.' Here's What I Actually Fixed.
- 10. I Actually Fixed Everything. Here's What That Looked Like.
- 11. I Hired 131 AI Employees Today. Here's How.
- 12. I Let My AI Run 72 Backtests While I Watched. It Picked the Winner.
- 13. I Taught My AI to Stop Asking Questions. It Took Five Rewrites.
- 14. Obsidian Turned My Scattered Notes Into a Second Brain. Here's How to Set It Up.
- 15. The Destiny Grid Gets Its East Wing: I Rebuilt Saju (四柱八字) in TypeScript ← you are here
- 16. Molecule Me: Your Personality, Encoded in Chemistry
When I launched the Destiny Grid last month, it was a Western astrology toy. Jupiter cycles. Saturn returns. Chiron wounds. I was proud of it.
But there was something missing.
Half of my users — and, if I'm being honest, the half I care most about — grew up in a world where the real fortune-telling isn't done in zodiac signs. It's done in Year Pillar (年柱), Month Pillar (月柱), Day Pillar (日柱), Hour Pillar (時柱). Four pillars, eight characters, five elements. Two thousand years of empirical pattern-matching dressed up as cosmology.
四柱八字 — Saju.
I originally wanted to just mash both systems onto the same grid — Western colors on the left, Eastern on the right, a grand unified theory of your life. Then I thought about what that would actually look like and decided it would look like a disaster. So: tabs. The grid now has a ☽ Western tab and a ☯ Saju tab, and you can flip between them.
This post is about what's actually running under the Saju tab. Because it turns out that Saju — despite being used for horoscope content in every Korean kakao chat group — is genuinely, surprisingly deep.
🏗️ First, the Architecture Decision Nobody Asked About
My original plan was to add a second column to the existing grid component. Western on the left, Eastern on the right. One DestinyGridClient.tsx to rule them all.
My AI pointed out that this was a terrible idea. The Western grid is already ~400 lines. Adding Eastern logic inline would push it past 1,200 lines, make debugging a nightmare, and mix two completely unrelated conceptual systems in one file.
So we separated it. SajuGridClient.tsx is its own file — 1,616 lines of pure Saju engine and UI, lazy-loaded as a dynamic import when you click the East tab. The main DestinyGridClient.tsx just handles the tab bar and conditionally renders whichever system you've selected.
The East tab also has two extra inputs that don't exist in the West tab: birth hour (時辰) in the traditional 12-period system, and gender, which affects which direction your 大運 (major fortune cycles) flow. More on that in a moment.
URL sharing works too: ?tab=east&hour=4&gender=F snapshots your East view and opens directly to it.
🧭 What Even Is 四柱八字?
Let me explain this from scratch, because I had to.
四柱八字 literally translates to "Four Pillars, Eight Characters." The four pillars are:
| 柱 | Pillar | Determined by |
|---|---|---|
| 年柱 | Year Pillar | Birth year |
| 月柱 | Month Pillar | Birth month |
| 日柱 | Day Pillar | Birth day |
| 時柱 | Hour Pillar | Birth hour (one of 12 時辰) |
Each pillar has two characters: one Heavenly Stem (天干) and one Earthly Branch (地支). Four pillars × two characters = eight characters total — 八字. That's the full name explained.
The 10 Heavenly Stems (天干)
甲 乙 丙 丁 戊 己 庚 辛 壬 癸
These cycle through ten positions. Each stem belongs to a Five Element (五行) and a polarity (陽 or 陰):
| Stem | Element | Polarity |
|---|---|---|
| 甲 | 木 Wood | 陽(+) |
| 乙 | 木 Wood | 陰(-) |
| 丙 | 火 Fire | 陽(+) |
| 丁 | 火 Fire | 陰(-) |
| 戊 | 土 Earth | 陽(+) |
| 己 | 土 Earth | 陰(-) |
| 庚 | 金 Metal | 陽(+) |
| 辛 | 金 Metal | 陰(-) |
| 壬 | 水 Water | 陽(+) |
| 癸 | 水 Water | 陰(-) |
The 12 Earthly Branches (地支)
子 丑 寅 卯 辰 巳 午 未 申 酉 戌 亥
You know these. They're the twelve zodiac animals — rat, ox, tiger, rabbit, dragon, snake, horse, goat, monkey, rooster, dog, pig. Each one also maps to an element and a polarity.
The 60-Year Cycle (六十甲子)
The 10 stems and 12 branches interlock. Their LCM is 60. So every 60 years, the same stem-branch pair recurs. This is the 六十甲子 — the 60-year cycle underlying all of East Asian calendrical tradition. 2024 was 甲辰: Yang Wood Dragon. 1964 was also 甲辰. Your grandparents' "same year" was 60 years ago, not 100.
The Saju engine uses this: every year gets its stem-branch pair from the perpetual cycle. Every day does too — that's how the 日柱 is calculated.
⚙️ The Algorithm: The Hard Parts
Here's where it gets interesting.
Calculating the Day Pillar (日柱)
The year and month pillars are easy — they follow clean cycles off the birth year and month. But the day pillar needs to know exactly which day you were born, not just which month. And the cycle of days doesn't reset per year. It runs continuously since... effectively the beginning of time.
I needed an anchor. The approach:
- Convert the birth date to a Julian Day Number (JDN) — a continuous count of days since January 1, 4713 BC. Yes, that's actually a real astronomical standard.
- Pick a known anchor: January 7, 2000 = 甲子日 (Day 0 in the 60-cycle). This is well-documented and cross-verified.
- Compute
(JDN - anchorJDN) mod 60→ stem index and branch index.
The code looks almost disappointingly simple once you have the anchor:
const dayIndex = ((julianDayNumber - ANCHOR_JDN) % 60 + 60) % 60;
const stem = HEAVENLY_STEMS[dayIndex % 10];
const branch = EARTHLY_BRANCHES[dayIndex % 12];But getting the Julian Day Number right — especially handling the Gregorian/Julian calendar switchover for old dates — took longer than I want to admit.
Calculating the Month Pillar (月柱)
The month pillar isn't just "month 1 = 寅, month 2 = 卯." The branch part is fixed — lunar months map directly to branches starting from 寅月 in the first lunar month.
But the stem part depends on the year stem. The classical formula is called 五虎遁年起月法 — "the five tigers pursuing the year, finding the month start." It determines which stem the first month of any given year begins with:
| Year Stem | Month 1 (寅) starts at stem |
|---|---|
| 甲 己 | 丙 |
| 乙 庚 | 戊 |
| 丙 辛 | 庚 |
| 丁 壬 | 壬 |
| 戊 癸 | 甲 |
So if you're born in a 甲 or 己 year, the first month's stem is 丙, and each subsequent month increments by one. This keeps the monthly cycle phase-locked to the yearly cycle.
I actually had to look up the original Chinese classical source for this. My AI pulled it correctly. I still cross-checked it.
The 大運 Direction (This Is the Wild Part)
大運 are the major fortune periods — ten-year chunks that define the arc of your life. Every person gets about 8 of them across a typical lifespan.
But which direction you flow through the cycle — forward or backward — depends on your birth gender and the polarity of your year stem.
The rule:
- 陽 year stem + Male → forward through the cycle (順行)
- 陽 year stem + Female → backward (逆行)
- 陰 year stem + Male → backward (逆行)
- 陰 year stem + Female → forward through the cycle (順行)
Why? The classical explanation involves 陽 energy moving forward through time and 陰 energy moving in reverse — and males being yang-aspected, females yin-aspected. So they flow in opposite directions.
The practical effect: two people born on the exact same day, same year, same month — one male, one female — have entirely different 大運 sequences. Their grids look completely different from their late twenties onward.
I find this philosophically interesting regardless of whether you believe any of it. The system is deeply personal: your fortune arc is not universal, it's specific to the combination of when you arrived and who you are.
歲運 Scoring (The Annual Layers)
Each year in the grid gets a score from several overlapping layers:
1. 五行 Generation & Destruction (相生相剋)
The five elements cycle in two wheels:
- 相生 (Generation): Wood → Fire → Earth → Metal → Water → Wood
- 相剋 (Destruction): Wood → Earth → Water → Fire → Metal → Wood
The current year's element vs. your day stem's element determines a base fortune modifier. Is the year element feeding yours (相生)? Score boost. Is it destroying yours (相剋)? Score penalty. Is it the same? Neutral but stable.
2. 合沖刑 (Combinations, Clashes, Punishments)
Branch relationships are not all equal. Some pairs 合 — they harmonize and amplify. Some pairs 沖 — they clash and destabilize. Some create more exotic 刑 punishment patterns.
The most important ones:
- 六合 (Six Harmonies): 子丑, 寅亥, 卯戌, 辰酉, 巳申, 午未 — strong positive resonance
- 三合 (Three Harmonies): Branch triads forming elemental triangles — 寅午戌 = Fire trinity, 亥卯未 = Wood trinity, etc.
- 沖 (Direct Clash): Branches six positions apart — 子午, 卯酉, etc. A clash year is turbulent regardless of your other indicators.
3. 十二運星 (Twelve Phase Cycle)
This is the aging/energy metaphor inside the system. Every stem-branch pair maps onto one of twelve life phases: birth (長生), growth (沐浴), crown (冠帶), career entry (臨官), peak (帝旺)... and then decline, illness, death, entombment, void.
The year's phase for your day stem tells you whether that year's energy is in ascent or descent. 長生, 冠帶, 帝旺 years score high. 死, 墓, 絶 years score low.
Combine all three layers — 五行, 合沖刑, 十二運星 — and the year's score emerges.
🎨 The Design System
I didn't want the Eastern tab to look like the Western tab with different labels.
The Western tab is astronomical and cool — planet symbols, gradient fills, planetary cycle charts. It feels like a planetarium poster.
The Saju tab needed to feel like a 命理學 (fate + reason) manuscript — ancient, serious, dense with meaning. I went with:
- Color palette: Crimson → Purple → Gold → Jade → Teal (凶 → 平 → 吉 → 大吉) — the progression of ink colors you'd find in a traditional fortune-telling scroll
- Typography: Chinese characters throughout, every stem paired with its romanized pronunciation
- Visual elements: Ink-bleed texture simulation via box-shadows, ink-wash background tones
- Layout: Three sections — 四柱 chart (your four pillars), 大運 timeline (the ten-year arcs), 歲運 grid (100-year annual grid)
The 四柱 chart card at the top shows your four pillars in columns, with the element, animal, and polarity for each. The element color codes follow the traditional 五方色 (five directional colors): Wood = green, Fire = red, Earth = yellow, Metal = white/silver, Water = deep blue.
The 大運 timeline shows each 10-year period as a horizontal bar with its stem-branch pair, element indicator, and fortune intensity. It's the section I spent the most time on — the visual hierarchy needed to clearly communicate "here's the major theme of your thirties, here's your forties."
🤔 The Part I'm Still Thinking About
四柱八字 has been used continuously for roughly 2,000 years. Multiple dynasties. Multiple countries. The system survived because practitioners kept refining it based on observed outcomes — millions of readings, generations of cross-checking.
That's not nothing. It's not science. But it's also not random superstition.
What it actually is — I think — is a very sophisticated personality and timing framework built on natural cycles. The 60-year stem-branch system is a real mathematical structure. 十二運星 is genuinely a metaphor for life phases with real pattern-matching potential. The 合沖刑 relationships encode real observations about how certain energies interact.
Whether you believe the mechanism (cosmological force fields), the metaphor (psychological resonance), or neither (pure entertainment) — the pattern language is internally consistent and surprisingly expressive.
I'm a pharmacist who builds AI tools for fun. And it turns out the 五行 framework isn't foreign to my field at all — traditional Korean medicine (韓醫學) uses the exact same Wood/Fire/Earth/Metal/Water classification system for organs, flavors, seasons, and drug properties. The 四柱八字 practitioner and the Korean medicine doctor are reading from the same underlying manual. I came into this project believing none of it. I'm leaving it still believing none of it, but with a much greater respect for the system's internal coherence.
That seems like the right place to land.
🎯 Try It
The Saju tab is live in the Destiny Grid at vibed-lab.com/playground/destiny-grid.
Click ☯ 四柱八字 Saju, enter your birth year/month/day. For more accurate 大運 direction, add your birth hour (時辰) and gender.
If your day pillar is 甲子 — Yang Wood Rat — I'm told that's a particularly powerful combination and you should be very confident about yourself.
I don't know if that's true. But I'm not going to tell you it isn't.
2026.03.14
Written by
Jay
Licensed Pharmacist · Senior Researcher
Building production-grade AI tools across medicine, finance, and productivity — without a CS degree. Domain expertise first, code second.
About the author →Related posts