How perfhelf/bigfishmarquis-qimen works
Purpose and Entry Points
This is a pure TypeScript Qimen Dun Jia chart-generation library. It produces yearly, monthly, daily, and hourly charts, with interpretation of resulting patterns. The primary unified entry point is src/engine.ts; callers may also invoke method- or layer-specific generators directly, especially src/engines/shijia.ts.
Domain Contract and Static Model
src/types.ts defines the chart/domain contracts shared across generators and interpretation. src/constants.ts centralizes calendrical, palace, stem/branch, and Qimen ordering rules. These form the boundary between caller-supplied calendrical inputs—GanZhi, solar terms, dates/four pillars—and deterministic chart output.
Unified Dispatch and Layer Selection
src/engine.ts routes a requested chart layer and applicable method to the proper engine. The system separates:
• annual charting: src/engines/nianjia.ts
• monthly charting: src/engines/yuejia.ts
• daily charting: src/engines/rijia.ts
• hourly charting: src/engines/shijia.ts
Year/month/day logic shares common placement behavior through src/engines/shared.ts; hourly generation has its own fuller construction path.
Hourly Ju Determination
Hourly charting first determines Yin/Yang Dun, Ju number, and Yuan from a solar term plus GanZhi context. Three alternative strategies are isolated behind:
• ChaiBu: src/engines/chaibuquju.ts
• MaoShan: src/engines/maoshan.ts
• ZhiRun: src/engines/zhirun.ts
Their output feeds src/engines/shijia.ts, which builds the final hourly palace layout and associated elements. This separation lets consumers select calendrical tradition without replacing chart construction.
Chart Construction
The chart engines calculate and arrange core Qimen layers: nine-palace earth/heaven plates, stars, doors, gods, hidden stems, duty relationships, lodging behavior, voids, post-horse, and tomb/punishment/pressure markers. src/engines/shijia.ts is the central high-detail assembly stage, while src/engines/shared.ts supplies reusable layer-placement mechanics for non-hourly charts.
Interpretation Pipeline
src/interpretation.ts consumes generated chart state and identifies classical patterns and correspondences. It combines structural chart relationships with reference content for 81 patterns, ten-stem interactions, duty-star correspondences, deity selection, and strategic guidance. Interpretation is downstream of chart generation, so chart creation can be used independently of textual analysis.
Data, Runtime, and External Boundaries
Reference knowledge is packaged as repository JSON, including palace/star/door/god definitions and interpretation texts: src/data/gong_wei.json, src/data/ge_ju_duan_yu.json, and src/data/shi_gan_ke_ying.json. The runtime has no required external engine or service. Upstream callers must provide or derive solar-term and GanZhi/four-pillar inputs; lunar-javascript or lunar-typescript is optional for that calendrical acquisition boundary.
Main entry points: engine.ts Unified engine · shijia.ts Hourly generator · interpretation.ts Pattern interpretation · shared.ts Shared placement
Components 19
Public API
- Caller calendrical input · Solar terms, GanZhi, dates, and four pillars.
- Optional calendar library · May derive calendrical inputs before chart generation.
- Domain contracts · Shared chart and input contracts.
src/types.ts - Qimen rules · Calendrical orderings and palace, stem, and branch rules.
src/constants.ts
Chart Generation
- Unified engine · Selects chart layer and applicable method.
src/engine.ts - Annual generator
src/engines/nianjia.ts - Monthly generator
src/engines/yuejia.ts - Daily generator
src/engines/rijia.ts - Shared placement · Reusable placement behavior for annual, monthly, and daily charts.
src/engines/shared.ts - Hourly generator · Builds the detailed hourly palace layout and related markers.
src/engines/shijia.ts - ChaiBu Ju strategy
src/engines/chaibuquju.ts - MaoShan Ju strategy
src/engines/maoshan.ts - ZhiRun Ju strategy
src/engines/zhirun.ts - Generated chart · Palace layers, duty relations, voids, post-horse, and markers.
Interpretation Knowledge
- Pattern interpretation · Derives classical patterns, correspondences, and guidance from chart state.
src/interpretation.ts - Pattern reference texts · 81-pattern and ten-stem interaction texts.
src/data/ge_ju_duan_yu.json - Stem interaction data
src/data/shi_gan_ke_ying.json - Palace reference data · Palace, star, door, and god definitions.
src/data/gong_wei.json - Interpretation result · Detected patterns and strategic guidance.
Connections 21
- Optional calendar library → Caller calendrical input: derives inputs
- Caller calendrical input → Unified engine: chart request
- Domain contracts → Unified engine: contracts
- Qimen rules → Unified engine: rules
- Unified engine → Annual generator: annual
- Unified engine → Monthly generator: monthly
- Unified engine → Daily generator: daily
- Unified engine → Hourly generator: hourly
- Annual generator → Shared placement: placement
- Monthly generator → Shared placement: placement
- Daily generator → Shared placement: placement
- ChaiBu Ju strategy → Hourly generator: Yin/Yang Dun, Ju, Yuan
- MaoShan Ju strategy → Hourly generator: Yin/Yang Dun, Ju, Yuan
- ZhiRun Ju strategy → Hourly generator: Yin/Yang Dun, Ju, Yuan
- Shared placement → Generated chart: non-hourly layers
- Hourly generator → Generated chart: hourly layout
- Generated chart → Pattern interpretation: chart state
- Pattern reference texts → Pattern interpretation: pattern texts
- Stem interaction data → Pattern interpretation: stem interactions
- Palace reference data → Pattern interpretation: definitions
- Pattern interpretation → Interpretation result: findings