1. The Core Bottleneck: What Engineering Dead Ends Does It Pierce?
Traditional mysticism applications have long been trapped in the dual quagmire of large language model hallucinations and closed-source black boxes. When developers prompt general-purpose LLMs to generate astrological outputs, models frequently tamper with stellar placements and fabricate rule variants, causing the same birth timestamp to yield contradictory results across different prompt runs. The ziwei-doushu project cuts through this with a purely deterministic engineering solution, translating the astrological systems from Master Hai-Xia Ni's "Tian Ji" and the "Full Book of Ziwei Doushu" into hard-coded TypeScript engines, paired with millions of pre-rendered interpretation texts to completely seal off non-deterministic output vulnerabilities.
💡 Architectural Core Insight: By transforming complex numerological deduction into spatial coordinate resolution and static text key-value retrieval, this architecture completely eliminates probabilistic drift during the inference stage, steering metaphysical computation back onto the rigorous track of modern computer engineering.
2. Core Architecture and Underlying Data Flow
Its core architecture is built entirely around deterministic computation streams. The input end is driven by Gregorian dates, gender, and geographic coordinates, calibrated by true solar time modules and daylight saving time judges, before feeding into the astrolabe engine to generate chart structures, and finally matching keys to retrieve the corresponding 13-dimensional static interpretation text.
[ Raw Input: YYYY-MM-DD + Gender + Geo ]
│
▼
[ True Solar Time & DST Parser ] ---> [ Lunar-Solar & Hour Indexer ]
│
▼
[ Deterministic Astrological Engine ] ---> [ Astrolabe & Sihua Matrix ]
│
▼
[ Zstd Compressed Interp Dataset (v4.0) ] ---> [ 13-Dim Markdown Output ]
The true solar time module true-solar-time.ts performs second-level corrections on birth timing using longitude differences and equation of time formulas. For overseas birth locations, the system supports passing the utcOffsetMinutes parameter to lock onto the local timezone's central meridian. The hour index converter strictly maps inputs to internal earthly branch indexes from 0 to 11, eliminating boundary overflow errors caused by traditional clock conversions. The entire data flow completes full astrolabe deductions entirely via local memory computation without any external network request dependencies.
3. Hardcore Technical Selection and Performance Benchmark
| Evaluation Dimension | This Solution (ziwei-doushu) | Traditional Commercial APIs | General LLM Prompt Approach | Legacy Static Web Apps |
|---|---|---|---|---|
| Computation Determinism | 100% deterministic hardcoding | Closed-source black box | High hallucination & context drift | Open algorithm but basic frontend scripts |
| Spatiotemporal Precision | True solar time, DST, county longitude | Coarse timezone offset only | Incapable of underlying calendar math | Fixed formulas, weak boundary handling |
| Offline Execution | Fully offline, autonomous single-node | Strongly dependent on cloud uptime | Consumes continuous API tokens & bandwidth | Offline-capable, extremely limited dimensions |
| Storage & Distribution | Zstd compressed split by year | Remote database, no export capability | No local storage, relies on model weights | Monolithic files, frontend memory bloat |
| Engineering Maintenance | Open test coverage, CI auto-regression | Dependent on third-party SLA commitments | High inference costs & prompt degradation | Stale codebase, lacking continuous iteration |
The architecture completely rids itself of dependence on external AI inference services, converting what would be exorbitant token bills into a one-time static storage overhead, delivering a dimensionality reduction strike in engineering throughput and calculation reproducibility.
4. Hands-on Geek Practice: Building a Minimal Loop from Zero
Developers can clone the repository, install dependencies, and run core astrolabe tests using the standard workflow below. This process is compatible with macOS, Linux, and WSL2 environments.
# Clone the repository locally
git clone https://github.com/Renhuai123/ziwei-doushu.git
# Enter project directory
cd ziwei-doushu
# Install project dependencies
npm install
# Run the astrolabe regression test suite
npm test
The following minimal production TypeScript demo invokes the calculation engine to generate basic chart data:
import { calculateAstrolabe } from './src/engine/algorithm';
// Construct input parameters: Jan 1, 1990, Wu hour (index 6), Male
const inputProfile = {
year: 1990,
month: 1,
day: 1,
hourIndex: 6, // 6 represents Wu hour
gender: 'male',
longitude: 116.46, // Birth longitude: Beijing
isLeapMonth: false
};
// Execute deterministic astrolabe calculation
const astrolabeResult = calculateAstrolabe(inputProfile);
// Output destiny palace major stars and 12-palace layout
console.log('Destiny Major Stars:', astrolabeResult.palaces[2].majorStars);
console.log('Five Elements Bureau:', astrolabeResult.fiveElementsBureau);
Executing npm test prompts GitHub Actions to automatically run regression tests, ensuring calendar conversions and stellar brightness configurations remain absolutely consistent across every code commit.
5. Production Gotchas and Deployment Warnings
When embedding this open-source engine into high-concurrency production environments, developers must pay close attention to underlying dataset decompression configurations and daylight saving time logic. The v4.0 dataset reaches 56.6 GB after decompression; direct full-scale loading will crash Node.js processes with out-of-memory errors.
⚠️ Deployment Warning [Zstd Long Window Decompression Failure]: The v4.0 dataset was compressed utilizing large dictionary and long window parameters. Omitting the explicit
--long=27flag during extraction throws immediate memory allocation faults or checksum mismatches. Production pipelines must mandatezstd -d --long=27 year-YYYY.jsonl.zstfor stream extraction.
Another common trap lies in China's daylight saving time handling mechanism. The engine strictly provides validation functions for DST active intervals and never performs automated forceful numeric deductions.
⚠️ Deployment Warning [DST Timestamp Shifting]: Internal utilities such as
chinaDSTSpanmerely determine whether a target date falls within an active DST window. Clock readings adjustments must be explicitly confirmed by users via frontend UI toggles. Never execute stateless silent time offsets in backend services, or cross-day birth records will experience systemic data corruption.
