How tommitoan/bazica works
Project type and purpose
• This is a Go library (bazica) for computing Chinese astrology Ba-Zi (Four Pillars) charts, not a standalone service or full-stack app.
• Its public entry point is the GetBaziChart function, which, given a time.Time, location and gender, returns a structured Ba-Zi chart.
File structure
Top level
• get_bazi_chart.go — public API entry point
• data/ — JSON fixtures (solar terms, lunar new year)
• model/ — exported data structures (chart, pillar, life cycle, solar terms)
• internal/
– fourpillars/ — core “Four Pillars” calculation logic (year, month, day, hour)
– luckpillars/ — “Luck Pillars” / ten-year luck cycle logic
– ultis/ — utility algorithms (Ganzhi, solar-term conversion, life cycles)
Other files
• go.mod, go.sum — module config
• tests (*_test.go) — unit tests for each package
README for architectural insights
• Describes the public API usage (bazica.GetBaziChart)
• Emphasizes manual JSON data copying for the data folder
• Mentions supported date range and external domain knowledge sources
Main components
A. Client / Consumer
• Any Go program that imports github.com/tommitoan/bazica and calls GetBaziChart
B. Public API Layer
• get_bazi_chart.go → exposes GetBaziChart(now time.Time, loc *time.Location, gender int) (Chart, error)
C. Domain Logic Layer (internal packages)
1. internal/fourpillars
• get_four_pillars.go
• get_pillar_{year,month,day,hour}.go
2. internal/luckpillars
• get_luck_pillars.go
3. internal/ultis
• Ganzhi conversion, solar-term lookup, life-cycle boundaries
D. Data Layer
• JSON files in /data (lunar-new-year.json, solar-term.json)
• Read by util functions to map calendar dates to stems/branches
E. Model Layer
• model/model_*.go defines strongly typed structs for Chart, Pillar, LifeCycle, SolarTerm
Relationships and data flow
1. Client calls → Public API (GetBaziChart)
2. API orchestrates:
a. Load raw JSON data via util functions
b. Compute Four Pillars (year, month, day, hour)
c. Compute Luck Pillars (ten-year cycles)
d. Assemble results into Model structs
3. Return populated Chart struct to client
Architectural patterns and principles
• Layered architecture: clear separation between Public API → Domain logic → Data → Models
• Package encapsulation: all core logic in internal/, preventing external misuse
• Single responsibility: each package has one focus (e.g., four-pillar, luck-pillar, utils)
• Test coverage: each package has corresponding _test.go for unit tests