# renhuai123/ziwei-doushu architecture

> Architecture diagram of the GitHub repository renhuai123/ziwei-doushu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/renhuai123/ziwei-doushu
- Repository: https://github.com/renhuai123/ziwei-doushu

## Overview

This repository is an open-source Ziwei astrology charting engine with a small demo website and reference libraries. The main user workflow is entering birth details, generating a chart, then viewing its palaces, time-period navigation, and interpretation. Separate routes provide a two-person chart demo, star/topic knowledge pages, and searchable classical texts. The README documents supporting time and school-configuration capabilities, but their runtime wiring is not fully sampled; those links are marked unverified where appropriate.

Main entry points: [`lib/ziwei/algorithm.ts`](https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/algorithm.ts) (Chart generation), [`app/chart/page.tsx`](https://github.com/renhuai123/ziwei-doushu/blob/main/app/chart/page.tsx) (Chart demo), [`app/heming/page.tsx`](https://github.com/renhuai123/ziwei-doushu/blob/main/app/heming/page.tsx) (Pair chart demo), [`components/BirthForm.tsx`](https://github.com/renhuai123/ziwei-doushu/blob/main/components/BirthForm.tsx) (Birth form)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_chart["Chart experience"]
  node_chartpage["Chart demo<br/>[page.tsx]"]
  node_birthform["Birth form<br/>[BirthForm.tsx]"]
  node_chartboard["Chart board<br/>[ChartBoard.tsx]"]
  node_insight["Insight panel<br/>[InsightPanel.tsx]"]
  node_timenav["Time navigation<br/>[TimeNav.tsx]"]
  node_heming["Pair chart demo<br/>[page.tsx]"]
end

subgraph group_engine["Chart engine"]
  node_chartengine["Chart generation<br/>[algorithm.ts]"]
  node_charttypes["Chart data model<br/>[types.ts]"]
  node_schooldata["School brightness data<br/>[school-data.ts]"]
  node_schoolconfig["School configuration<br/>[school-config.ts]"]
  node_timeadjust["Time adjustment<br/>[true-solar-time.ts]"]
  node_lunar["Lunar conversion<br/>[lunar-solar.ts]"]
  node_dst["China DST rules<br/>[dst-cn.ts]"]
  node_clock["Clock adjustment<br/>[clock-adjust.ts]"]
end

subgraph group_reference["Knowledge and texts"]
  node_knowledgepage["Star knowledge pages<br/>[page.tsx]"]
  node_knowledge["Knowledge content<br/>[knowledge.ts]"]
  node_stardb["Star analysis data<br/>[db-analysis.ts]"]
  node_classicsroutes["Classical text pages<br/>[page.tsx]"]
  node_classicsearch["Classical text search<br/>[page.tsx]"]
  node_classics["Classics catalog and API<br/>[index.ts]"]
  node_classicdata["Classical texts<br/>[quanshu.ts]"]
  node_nihai["Ni Haixia materials<br/>[index.ts]"]
end

subgraph group_site["Site experience"]
  node_home["Home page<br/>[page.tsx]"]
  node_theme["Theme provider<br/>[ThemeProvider.tsx]"]
  node_siteconfig["Site configuration<br/>[site.ts]"]
end

node_visitor(("Visitor"))

node_visitor -->|"opens chart"| node_chartpage
node_chartpage -->|"renders form"| node_birthform
node_birthform -->|"submits details"| node_chartpage
node_chartpage -->|"generates chart"| node_chartengine
node_chartengine -->|"returns chart"| node_chartpage
node_chartpage -->|"renders chart"| node_chartboard
node_chartpage -->|"renders insight"| node_insight
node_chartpage -->|"renders navigation"| node_timenav
node_visitor -->|"opens pair demo"| node_heming
node_heming -->|"renders forms"| node_birthform
node_heming -->|"generates pair"| node_chartengine
node_chartengine -->|"reads brightness"| node_schooldata
node_chartengine -->|"uses configuration"| node_schoolconfig
node_chartengine -.->|"supports correction"| node_timeadjust
node_chartengine -.->|"supports conversion"| node_lunar
node_chartengine -.->|"uses DST rules"| node_dst
node_chartengine -.->|"supports adjustment"| node_clock
node_visitor -->|"opens knowledge"| node_knowledgepage
node_knowledgepage -->|"gets content"| node_knowledge
node_knowledge -->|"reads analysis"| node_stardb
node_visitor -->|"browses texts"| node_classicsroutes
node_visitor -->|"searches texts"| node_classicsearch
node_classicsroutes -->|"loads catalog"| node_classics
node_classicsearch -->|"searches catalog"| node_classics
node_classics -->|"loads text data"| node_classicdata
node_visitor -->|"opens site"| node_home
node_home -->|"reads theme"| node_theme
node_nihai -.->|"provides study data"| node_visitor

click node_chartpage "https://github.com/renhuai123/ziwei-doushu/blob/main/app/chart/page.tsx"
click node_birthform "https://github.com/renhuai123/ziwei-doushu/blob/main/components/BirthForm.tsx"
click node_chartboard "https://github.com/renhuai123/ziwei-doushu/blob/main/components/ChartBoard.tsx"
click node_insight "https://github.com/renhuai123/ziwei-doushu/blob/main/components/InsightPanel.tsx"
click node_timenav "https://github.com/renhuai123/ziwei-doushu/blob/main/components/TimeNav.tsx"
click node_heming "https://github.com/renhuai123/ziwei-doushu/blob/main/app/heming/page.tsx"
click node_chartengine "https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/algorithm.ts"
click node_charttypes "https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/types.ts"
click node_schooldata "https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/school-data.ts"
click node_schoolconfig "https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/school-config.ts"
click node_timeadjust "https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/true-solar-time.ts"
click node_lunar "https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/lunar-solar.ts"
click node_dst "https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/dst-cn.ts"
click node_clock "https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/clock-adjust.ts"
click node_knowledgepage "https://github.com/renhuai123/ziwei-doushu/blob/main/app/knowledge/%5Bstar%5D/%5Btopic%5D/page.tsx"
click node_knowledge "https://github.com/renhuai123/ziwei-doushu/blob/main/lib/seo/knowledge.ts"
click node_stardb "https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/db-analysis.ts"
click node_classicsroutes "https://github.com/renhuai123/ziwei-doushu/blob/main/app/library/page.tsx"
click node_classicsearch "https://github.com/renhuai123/ziwei-doushu/blob/main/app/library/search/page.tsx"
click node_classics "https://github.com/renhuai123/ziwei-doushu/blob/main/lib/classics/index.ts"
click node_classicdata "https://github.com/renhuai123/ziwei-doushu/blob/main/lib/classics/data/quanshu.ts"
click node_nihai "https://github.com/renhuai123/ziwei-doushu/blob/main/lib/nihai/index.ts"
click node_home "https://github.com/renhuai123/ziwei-doushu/blob/main/app/page.tsx"
click node_theme "https://github.com/renhuai123/ziwei-doushu/blob/main/components/ThemeProvider.tsx"
click node_siteconfig "https://github.com/renhuai123/ziwei-doushu/blob/main/lib/site.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_chartpage,node_birthform,node_chartboard,node_insight,node_timenav,node_heming toneBlue
class node_chartengine,node_charttypes,node_schooldata,node_schoolconfig,node_timeadjust,node_lunar,node_dst,node_clock toneAmber
class node_knowledgepage,node_knowledge,node_stardb,node_classicsroutes,node_classicsearch,node_classics,node_classicdata,node_nihai toneMint
class node_home,node_theme,node_siteconfig toneRose
class node_visitor toneIndigo
```

## Components

### Chart experience

- [Chart demo](https://github.com/renhuai123/ziwei-doushu/blob/main/app/chart/page.tsx): `app/chart/page.tsx`
- [Birth form](https://github.com/renhuai123/ziwei-doushu/blob/main/components/BirthForm.tsx): `components/BirthForm.tsx`
- [Chart board](https://github.com/renhuai123/ziwei-doushu/blob/main/components/ChartBoard.tsx): `components/ChartBoard.tsx`
- [Insight panel](https://github.com/renhuai123/ziwei-doushu/blob/main/components/InsightPanel.tsx): `components/InsightPanel.tsx`
- [Time navigation](https://github.com/renhuai123/ziwei-doushu/blob/main/components/TimeNav.tsx): `components/TimeNav.tsx`
- [Pair chart demo](https://github.com/renhuai123/ziwei-doushu/blob/main/app/heming/page.tsx): `app/heming/page.tsx`

### Chart engine

- [Chart generation](https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/algorithm.ts): `lib/ziwei/algorithm.ts`
- [Chart data model](https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/types.ts): `lib/ziwei/types.ts`
- [School brightness data](https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/school-data.ts): `lib/ziwei/school-data.ts`
- [School configuration](https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/school-config.ts): `lib/ziwei/school-config.ts`
- [Time adjustment](https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/true-solar-time.ts): `lib/ziwei/true-solar-time.ts`
- [Lunar conversion](https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/lunar-solar.ts): `lib/ziwei/lunar-solar.ts`
- [China DST rules](https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/dst-cn.ts): `lib/ziwei/dst-cn.ts`
- [Clock adjustment](https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/clock-adjust.ts): `lib/ziwei/clock-adjust.ts`

### Knowledge and texts

- [Star knowledge pages](https://github.com/renhuai123/ziwei-doushu/blob/main/app/knowledge/%5Bstar%5D/%5Btopic%5D/page.tsx): `app/knowledge/[star]/[topic]/page.tsx`
- [Knowledge content](https://github.com/renhuai123/ziwei-doushu/blob/main/lib/seo/knowledge.ts): `lib/seo/knowledge.ts`
- [Star analysis data](https://github.com/renhuai123/ziwei-doushu/blob/main/lib/ziwei/db-analysis.ts): `lib/ziwei/db-analysis.ts`
- [Classical text pages](https://github.com/renhuai123/ziwei-doushu/blob/main/app/library/page.tsx): `app/library/page.tsx`
- [Classical text search](https://github.com/renhuai123/ziwei-doushu/blob/main/app/library/search/page.tsx): `app/library/search/page.tsx`
- [Classics catalog and API](https://github.com/renhuai123/ziwei-doushu/blob/main/lib/classics/index.ts): `lib/classics/index.ts`
- [Classical texts](https://github.com/renhuai123/ziwei-doushu/blob/main/lib/classics/data/quanshu.ts): `lib/classics/data/quanshu.ts`
- [Ni Haixia materials](https://github.com/renhuai123/ziwei-doushu/blob/main/lib/nihai/index.ts): `lib/nihai/index.ts`

### Site experience

- [Home page](https://github.com/renhuai123/ziwei-doushu/blob/main/app/page.tsx): `app/page.tsx`
- [Theme provider](https://github.com/renhuai123/ziwei-doushu/blob/main/components/ThemeProvider.tsx): `components/ThemeProvider.tsx`
- [Site configuration](https://github.com/renhuai123/ziwei-doushu/blob/main/lib/site.ts): `lib/site.ts`

### Other components

- **Visitor**

## Connections

- Visitor → Chart demo: opens chart (evidence: `app/chart/page.tsx`)
- Chart demo → Birth form: renders form (evidence: `app/chart/page.tsx`)
- Birth form → Chart demo: submits details (evidence: `app/chart/page.tsx`)
- Chart demo → Chart generation: generates chart (evidence: `app/chart/page.tsx`)
- Chart generation → Chart demo: returns chart (evidence: `app/chart/page.tsx`)
- Chart demo → Chart board: renders chart (evidence: `app/chart/page.tsx`)
- Chart demo → Insight panel: renders insight (evidence: `app/chart/page.tsx`)
- Chart demo → Time navigation: renders navigation (evidence: `app/chart/page.tsx`)
- Visitor → Pair chart demo: opens pair demo (evidence: `app/heming/page.tsx`)
- Pair chart demo → Birth form: renders forms (evidence: `app/heming/page.tsx`)
- Pair chart demo → Chart generation: generates pair (evidence: `app/heming/page.tsx`)
- Chart generation → School brightness data: reads brightness (evidence: `lib/ziwei/algorithm.ts`)
- Chart generation → School configuration: uses configuration (evidence: `lib/ziwei/algorithm.ts`)
- Chart generation → Time adjustment: supports correction (evidence: `README.md`)
- Chart generation → Lunar conversion: supports conversion (evidence: `README.md`)
- Chart generation → China DST rules: uses DST rules (evidence: `README.md`)
- Chart generation → Clock adjustment: supports adjustment (evidence: `README.md`)
- Visitor → Star knowledge pages: opens knowledge (evidence: `app/knowledge/[star]/[topic]/page.tsx`)
- Star knowledge pages → Knowledge content: gets content (evidence: `app/knowledge/[star]/[topic]/page.tsx`)
- Knowledge content → Star analysis data: reads analysis (evidence: `lib/seo/knowledge.ts`)
- Visitor → Classical text pages: browses texts (evidence: `app/library/page.tsx`)
- Visitor → Classical text search: searches texts (evidence: `app/library/search/page.tsx`)
- Classical text pages → Classics catalog and API: loads catalog (evidence: `app/library/page.tsx`)
- Classical text search → Classics catalog and API: searches catalog (evidence: `app/library/search/page.tsx`)
- Classics catalog and API → Classical texts: loads text data (evidence: `lib/classics/index.ts`)
- Visitor → Home page: opens site (evidence: `app/page.tsx`)
- Home page → Theme provider: reads theme (evidence: `app/page.tsx`)
- Ni Haixia materials → Visitor: provides study data
