# sylarlong/iztro architecture

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

- Interactive diagram: https://gitdiagram.com/sylarlong/iztro
- Repository: https://github.com/sylarlong/iztro

## Overview

1. This repository is primarily a TypeScript library for Zi Wei Dou Shu astrolabe generation and querying. The core runtime code lives under `src/`, and the rest of the repo is documentation, tests, build output, and usage examples.

2. The public entry point is `src/index.ts`, which re-exports the main modules. The most important API surface is the `astro` namespace in `src/astro/`, plus star- and palace-oriented helpers in `src/star/`. The README examples show the intended usage pattern: create an astrolabe from solar or lunar birth data, then query it through a chainable API.

3. The central computation pipeline is in `src/astro/astro.ts` and related files. This layer turns birth inputs into an astrolabe model, including natal chart construction and derived time layers such as major luck, minor luck, annual, monthly, daily, and hourly contexts. `src/astro/analyzer.ts` appears to handle rule-based analysis over the computed chart.

4. The astrolabe domain model is split into functional wrappers:
   - `FunctionalAstrolabe.ts`
   - `FunctionalHoroscope.ts`
   - `FunctionalPalace.ts`
   - `FunctionalSurpalaces.ts`
   These are the chainable objects that power queries like “does this palace contain a star?” or “what are the surrounding palaces for this star?”. They form the main boundary between raw chart data and higher-level query behavior.

5. The star subsystem is isolated in `src/star/`. It distinguishes different star categories and behaviors through files such as `majorStar.ts`, `minorStar.ts`, `adjectiveStar.ts`, `decorativeStar.ts`, and `horoscopeStar.ts`. `location.ts` and `FunctionalStar.ts` provide location-based navigation, such as “which palace contains this star?” or “what is the opposite palace?”.

6. Core static domain data is centralized in `src/data/`. This includes constants, heavenly stems, earthly branches, and star definitions. The `src/data/types/` folder defines the structured types used throughout the library for astrolabes, palaces, stars, and general domain objects. This separation keeps rule data distinct from computation logic.

7. Internationalization is a first-class subsystem. `src/i18n/` contains locale-specific translation data for `zh-CN`, `zh-TW`, `en-US`, `ja-JP`, `ko-KR`, and `vi-VN`. The library supports mixed-language input and localized output, so the i18n layer is not just UI text—it is part of the domain model for names of stars, palaces, stems, branches, genders, and mutagens.

8. The repository’s architecture is strongly data-driven and rule-based rather than service-oriented. The main data flow is: user input for birth date/time/gender/language → astro computation → astrolabe model → functional wrappers for palace/star queries → localized results. Most query methods operate on the same underlying chart object rather than creating separate service layers.

9. There is a clear boundary between pure library code and examples that integrate external services. `examples/chat-api/` demonstrates HTTP-based AI usage in JavaScript and Python, while `examples/fullstack-demo/` contains a frontend, a Node backend, and a Python backend. These examples are not part of the core astrolabe engine; they show how to wrap the library in a conversational or web application.

10. The `examples/fullstack-demo/frontend` folder is a Vite + React/TypeScript app, and `examples/fullstack-demo/backend` is a Node.js service. The Python backend in `examples/fullstack-demo/python-backend` offers the same kind of integration path in Python. These example apps sit at the edge of the architecture and consume the library or AI API rather than implementing the chart logic themselves.

11. Testing is concentrated under `src/__tests__/` and covers astro, star, palace, analyzer, and utility behavior. This indicates the repository treats rule correctness and query semantics as the most important stability boundary. `jestconfig.json` confirms Jest-based test execution.

12. Build and distribution tooling reflects a library-first package: `tsconfig.json`, `webpack.config.js`, `.babelrc`, ESLint/Prettier configs, and a `package.json` entry point for npm publication. The repository also ships prebuilt documentation assets under `docs/`, suggesting the docs site is statically generated and published alongside the package.

13. The `docs/` directory is a deployed static documentation site, not source code. It includes localized HTML pages, versioned JS/CSS assets, sitemap/robots metadata, and route-specific pages like quick-start, type-definition, and learning posts. This site is a separate presentation layer for the library’s API and concepts.

14. CI/CD and release automation live in `.github/workflows/` and `.gitlab-ci.yml`. The workflows cover code coverage, documentation publishing, and releases, which implies the repo’s delivery pipeline is centered on packaging the library and updating its docs rather than deploying a long-running server.

15. In architecture-diagram terms, the main subsystems are: domain data, core astrolabe engine, star/palace query wrappers, i18n translations, tests, docs site, and external integration examples. The critical boundary is between the pure deterministic computation engine in `src/` and the consuming applications or AI/API examples in `examples/` and `docs/`.

Main entry points: [`src/astro/index.ts`](https://github.com/sylarlong/iztro/blob/main/src/astro/index.ts) (Astro API), [`src/index.ts`](https://github.com/sylarlong/iztro/blob/main/src/index.ts) (Entry Point), [`src/astro/astro.ts`](https://github.com/sylarlong/iztro/blob/main/src/astro/astro.ts) (Astro Engine), [`src/astro/FunctionalAstrolabe.ts`](https://github.com/sylarlong/iztro/blob/main/src/astro/FunctionalAstrolabe.ts) (Astrolabe)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core Library"]
  node_src_index["Entry Point<br/>re-export<br/>[index.ts]"]
  node_astro_index["Astro API<br/>module barrel<br/>[index.ts]"]
  node_astro_core["Astro Engine<br/>calculator<br/>[astro.ts]"]
  node_astro_analyzer["Analyzer<br/>rule engine<br/>[analyzer.ts]"]
  node_func_astrolabe["Astrolabe<br/>functional wrapper"]
  node_func_horoscope["Horoscope<br/>functional wrapper"]
  node_func_palace["Palace<br/>functional wrapper"]
  node_func_surpalaces["Surpalaces<br/>functional wrapper"]
  node_palace_module["Palace Logic<br/>domain helper<br/>[palace.ts]"]
  node_star_index["Star API<br/>module barrel<br/>[index.ts]"]
  node_func_star["Star<br/>functional wrapper<br/>[FunctionalStar.ts]"]
  node_star_location["Location<br/>navigation<br/>[location.ts]"]
end

subgraph group_domain["Domain Data"]
  node_data_index["Data API<br/>data barrel<br/>[index.ts]"]
  node_data_types["Data Types<br/>type models<br/>[index.ts]"]
  node_data_constants["Domain Constants<br/>static tables<br/>[constants.ts]"]
end

subgraph group_locale["Localization"]
  node_i18n_index["I18n API<br/>locale barrel<br/>[index.ts]"]
  node_i18n_types["Locale Types<br/>translation types<br/>[index.ts]"]
  node_i18n_locales["Locale Packs<br/>translations<br/>[index.ts]"]
end

subgraph group_quality["Validation"]
  node_tests_astro["Astro Tests<br/>jest suite<br/>[astro.test.ts]"]
  node_tests_star["Star Tests<br/>jest suite<br/>[star.test.ts]"]
end

subgraph group_publish["Docs & Examples"]
  node_docs_site["Docs Site<br/>static site<br/>[index.html]"]
  node_example_chat["Chat API<br/>integration example<br/>[README.md]"]
  node_example_fullstack["Fullstack Demo<br/>integration demo<br/>[README.md]"]
end

node_src_index -->|"exports"| node_astro_index
node_src_index -->|"exports"| node_star_index
node_src_index -->|"exports"| node_data_index
node_src_index -->|"exports"| node_i18n_index
node_astro_index -->|"exposes"| node_astro_core
node_astro_index -->|"exposes"| node_astro_analyzer
node_astro_index -->|"exposes"| node_func_astrolabe
node_astro_index -->|"exposes"| node_func_horoscope
node_astro_index -->|"exposes"| node_func_palace
node_astro_index -->|"exposes"| node_func_surpalaces
node_astro_core -->|"reads"| node_data_index
node_astro_core -->|"builds"| node_palace_module
node_astro_core -->|"produces"| node_func_astrolabe
node_astro_core -->|"feeds"| node_astro_analyzer
node_func_astrolabe -->|"chains to"| node_func_horoscope
node_func_astrolabe -->|"chains to"| node_func_palace
node_func_horoscope -->|"navigates"| node_func_surpalaces
node_func_palace -->|"uses"| node_palace_module
node_star_index -->|"exposes"| node_func_star
node_star_index -->|"exposes"| node_star_location
node_func_star -->|"uses"| node_star_location
node_star_location -->|"resolves"| node_palace_module
node_data_index -->|"typed by"| node_data_types
node_i18n_index -->|"typed by"| node_i18n_types
node_i18n_index -->|"loads"| node_i18n_locales
node_tests_astro -.->|"verifies"| node_astro_core
node_tests_star -.->|"verifies"| node_func_star
node_docs_site -.->|"documents"| node_src_index
node_example_chat -.->|"consumes"| node_src_index
node_example_fullstack -.->|"consumes"| node_src_index

click node_src_index "https://github.com/sylarlong/iztro/blob/main/src/index.ts"
click node_astro_index "https://github.com/sylarlong/iztro/blob/main/src/astro/index.ts"
click node_astro_core "https://github.com/sylarlong/iztro/blob/main/src/astro/astro.ts"
click node_astro_analyzer "https://github.com/sylarlong/iztro/blob/main/src/astro/analyzer.ts"
click node_func_astrolabe "https://github.com/sylarlong/iztro/blob/main/src/astro/FunctionalAstrolabe.ts"
click node_func_horoscope "https://github.com/sylarlong/iztro/blob/main/src/astro/FunctionalHoroscope.ts"
click node_func_palace "https://github.com/sylarlong/iztro/blob/main/src/astro/FunctionalPalace.ts"
click node_func_surpalaces "https://github.com/sylarlong/iztro/blob/main/src/astro/FunctionalSurpalaces.ts"
click node_palace_module "https://github.com/sylarlong/iztro/blob/main/src/astro/palace.ts"
click node_star_index "https://github.com/sylarlong/iztro/blob/main/src/star/index.ts"
click node_func_star "https://github.com/sylarlong/iztro/blob/main/src/star/FunctionalStar.ts"
click node_star_location "https://github.com/sylarlong/iztro/blob/main/src/star/location.ts"
click node_data_index "https://github.com/sylarlong/iztro/blob/main/src/data/index.ts"
click node_data_types "https://github.com/sylarlong/iztro/blob/main/src/data/types/index.ts"
click node_data_constants "https://github.com/sylarlong/iztro/blob/main/src/data/constants.ts"
click node_i18n_index "https://github.com/sylarlong/iztro/blob/main/src/i18n/index.ts"
click node_i18n_types "https://github.com/sylarlong/iztro/blob/main/src/i18n/types/index.ts"
click node_i18n_locales "https://github.com/sylarlong/iztro/blob/main/src/i18n/locales/zh-CN/index.ts"
click node_tests_astro "https://github.com/sylarlong/iztro/blob/main/src/__tests__/astro/astro.test.ts"
click node_tests_star "https://github.com/sylarlong/iztro/blob/main/src/__tests__/star/star.test.ts"
click node_docs_site "https://github.com/sylarlong/iztro/blob/main/docs/index.html"
click node_example_chat "https://github.com/sylarlong/iztro/blob/main/examples/chat-api/README.md"
click node_example_fullstack "https://github.com/sylarlong/iztro/blob/main/examples/fullstack-demo/README.md"

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_src_index,node_astro_index,node_astro_core,node_astro_analyzer,node_func_astrolabe,node_func_horoscope,node_func_palace,node_func_surpalaces,node_palace_module,node_star_index,node_func_star,node_star_location toneBlue
class node_data_index,node_data_types,node_data_constants toneAmber
class node_i18n_index,node_i18n_types,node_i18n_locales toneMint
class node_tests_astro,node_tests_star toneRose
class node_docs_site,node_example_chat,node_example_fullstack toneIndigo
```

## Components

### Core Library

Public TypeScript entry points, computation pipeline, and query wrappers.

- [Entry Point](https://github.com/sylarlong/iztro/blob/main/src/index.ts): re-export · Public package surface that re-exports the main modules. · `src/index.ts`
- [Astro API](https://github.com/sylarlong/iztro/blob/main/src/astro/index.ts): module barrel · Exports the astrolabe computation and functional wrappers. · `src/astro/index.ts`
- [Astro Engine](https://github.com/sylarlong/iztro/blob/main/src/astro/astro.ts): calculator · Builds astrolabes from birth input and derives time-layer contexts. · `src/astro/astro.ts`
- [Analyzer](https://github.com/sylarlong/iztro/blob/main/src/astro/analyzer.ts): rule engine · Applies rule-based analysis over computed chart data. · `src/astro/analyzer.ts`
- [Astrolabe](https://github.com/sylarlong/iztro/blob/main/src/astro/FunctionalAstrolabe.ts): functional wrapper · Chainable facade around the raw astrolabe model. · `src/astro/FunctionalAstrolabe.ts`
- [Horoscope](https://github.com/sylarlong/iztro/blob/main/src/astro/FunctionalHoroscope.ts): functional wrapper · Higher-level query surface for horoscope-oriented operations. · `src/astro/FunctionalHoroscope.ts`
- [Palace](https://github.com/sylarlong/iztro/blob/main/src/astro/FunctionalPalace.ts): functional wrapper · Chainable palace query object for containment and relation checks. · `src/astro/FunctionalPalace.ts`
- [Surpalaces](https://github.com/sylarlong/iztro/blob/main/src/astro/FunctionalSurpalaces.ts): functional wrapper · Surrounding-palace navigation and neighborhood queries. · `src/astro/FunctionalSurpalaces.ts`
- [Palace Logic](https://github.com/sylarlong/iztro/blob/main/src/astro/palace.ts): domain helper · Core palace positioning and derivation logic. · `src/astro/palace.ts`
- [Star API](https://github.com/sylarlong/iztro/blob/main/src/star/index.ts): module barrel · Exports star categories, location helpers, and star wrapper APIs. · `src/star/index.ts`
- [Star](https://github.com/sylarlong/iztro/blob/main/src/star/FunctionalStar.ts): functional wrapper · Location-aware star facade for navigation and containment queries. · `src/star/FunctionalStar.ts`
- [Location](https://github.com/sylarlong/iztro/blob/main/src/star/location.ts): navigation · Star-to-palace navigation helpers such as opposite and containing palace. · `src/star/location.ts`

### Domain Data

Static astrolabe constants, stars, stems/branches, and shared types.

- [Data API](https://github.com/sylarlong/iztro/blob/main/src/data/index.ts): data barrel · Central export for static domain constants and definitions. · `src/data/index.ts`
- [Data Types](https://github.com/sylarlong/iztro/blob/main/src/data/types/index.ts): type models · Structured astrolabe, palace, star, and general domain types. · `src/data/types/index.ts`
- [Domain Constants](https://github.com/sylarlong/iztro/blob/main/src/data/constants.ts): static tables · Core constants, stems, branches, and star definition tables. · `src/data/constants.ts`

### Localization

Language packs and translation types used across the domain model.

- [I18n API](https://github.com/sylarlong/iztro/blob/main/src/i18n/index.ts): locale barrel · Locale loader and translation entry point. · `src/i18n/index.ts`
- [Locale Types](https://github.com/sylarlong/iztro/blob/main/src/i18n/types/index.ts): translation types · Shared translation schema for stars, palaces, stems, branches, and mutagens. · `src/i18n/types/index.ts`
- [Locale Packs](https://github.com/sylarlong/iztro/blob/main/src/i18n/locales/zh-CN/index.ts): translations · Language-specific dictionaries for localized domain names and labels. · `src/i18n/locales/zh-CN/index.ts`

### Validation

Automated tests and build/release tooling that protect the library contract.

- [Astro Tests](https://github.com/sylarlong/iztro/blob/main/src/__tests__/astro/astro.test.ts): jest suite · Covers astrolabe generation, analysis, palace behavior, and plugin semantics. · `src/__tests__/astro/astro.test.ts`
- [Star Tests](https://github.com/sylarlong/iztro/blob/main/src/__tests__/star/star.test.ts): jest suite · Covers star categories and location helpers. · `src/__tests__/star/star.test.ts`

### Docs & Examples

Static documentation site and integration examples that consume the library.

- [Docs Site](https://github.com/sylarlong/iztro/blob/main/docs/index.html): static site · Published documentation and localized learning pages. · `docs/index.html`
- [Chat API](https://github.com/sylarlong/iztro/blob/main/examples/chat-api/README.md): integration example · HTTP/AI usage examples in JavaScript and Python. · `examples/chat-api/README.md`
- [Fullstack Demo](https://github.com/sylarlong/iztro/blob/main/examples/fullstack-demo/README.md): integration demo · Frontend, Node backend, and Python backend showing library integration paths. · `examples/fullstack-demo/README.md`

## Connections

- Entry Point → Astro API: exports · Package entry re-exports the astro API.
- Entry Point → Star API: exports · Package entry re-exports star helpers.
- Entry Point → Data API: exports · Package entry exposes domain data.
- Entry Point → I18n API: exports · Package entry exposes localization helpers.
- Astro API → Astro Engine: exposes · Astro barrel surfaces chart construction.
- Astro API → Analyzer: exposes · Astro barrel surfaces analysis logic.
- Astro API → Astrolabe: exposes · Astro barrel surfaces the main chart wrapper.
- Astro API → Horoscope: exposes · Astro barrel surfaces horoscope queries.
- Astro API → Palace: exposes · Astro barrel surfaces palace queries.
- Astro API → Surpalaces: exposes · Astro barrel surfaces neighborhood queries.
- Astro Engine → Data API: reads · Computation uses the static domain tables.
- Astro Engine → Palace Logic: builds · Astro engine relies on palace derivation logic.
- Astro Engine → Astrolabe: produces · Engine output is wrapped as an astrolabe object.
- Astro Engine → Analyzer: feeds · Computed charts are analyzed by rule logic.
- Astrolabe → Horoscope: chains to · Astrolabe wrapper exposes horoscope-level queries.
- Astrolabe → Palace: chains to · Astrolabe wrapper exposes palace-level queries.
- Horoscope → Surpalaces: navigates · Horoscope queries can reach surrounding palaces.
- Palace → Palace Logic: uses · Palace wrapper delegates core palace logic.
- Star API → Star: exposes · Star barrel surfaces the chainable star wrapper.
- Star API → Location: exposes · Star barrel surfaces navigation helpers.
- Star → Location: uses · Star wrapper relies on navigation helpers.
- Location → Palace Logic: resolves · Star location logic maps stars to palace positions.
- Data API → Data Types: typed by · Static domain data is shaped by shared types.
- I18n API → Locale Types: typed by · Localization API follows shared translation types.
- I18n API → Locale Packs: loads · Localization API resolves locale packs.
- Astro Tests → Astro Engine: verifies · Astro tests validate deterministic chart generation.
- Star Tests → Star: verifies · Star tests validate star query behavior.
- Docs Site → Entry Point: documents · Docs explain the public library entry point and API.
- Chat API → Entry Point: consumes · Chat examples consume the library API.
- Fullstack Demo → Entry Point: consumes · Demo app integrates the library into frontend and backend services.
