# hjsh200219/fortuneteller architecture

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

- Interactive diagram: https://gitdiagram.com/hjsh200219/fortuneteller
- Repository: https://github.com/hjsh200219/fortuneteller

## Overview

This repository is a Korean Saju fortune-analysis MCP server. Its principal workflow accepts a client tool request, routes it to a tool handler, calculates a birth chart, and returns a requested analysis; separate tools handle calendar conversion, compatibility, and fortune periods. The graph preserves documented analysis capabilities and the central calendar, interpretation, and data subsystems. Some feature implementations were not sampled, so their internal call paths are omitted rather than inferred.

Main entry points: [`src/lib/saju.ts`](https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/saju.ts) (Pillar calculation), [`src/tools/analyze_saju.ts`](https://github.com/hjsh200219/fortuneteller/blob/main/src/tools/analyze_saju.ts) (Saju analysis tool), [`src/tools`](https://github.com/hjsh200219/fortuneteller/tree/main/src/tools) (Tool handlers), [`src/lib/fortune.ts`](https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/fortune.ts) (Fortune analysis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["MCP interface"]
  node_server["MCP server<br/>[server.ts]"]
  node_router["Tool router<br/>[tool-handler.ts]"]
  node_toolset["Tool handlers"]
  node_analyze["Saju analysis tool<br/>[analyze_saju.ts]"]
  node_compatibility_tool["Compatibility tool"]
  node_calendar_tool["Calendar tool"]
  node_period_tool["Period fortune tool"]
end

subgraph group_calendar["Calendar foundations"]
  node_calendar_logic["Calendar conversion<br/>[calendar.ts]"]
  node_lunar_data[("Lunar tables")]
  node_solar_data[("Solar-term tables")]
  node_solar_terms["Solar-term queries<br/>[solar_terms.ts]"]
  node_date_utils["Birth time adjustment<br/>[date.ts]"]
  node_longitude[("Longitude data<br/>[longitude_table.ts]")]
end

subgraph group_analysis["Saju analysis"]
  node_saju["Pillar calculation<br/>[saju.ts]"]
  node_fortune["Fortune analysis<br/>[fortune.ts]"]
  node_compatibility["Compatibility analysis<br/>[compatibility.ts]"]
  node_period_logic["Period analysis<br/>[se_un.ts]"]
  node_ten_gods["Ten-gods analysis<br/>[ten_gods.ts]"]
  node_sin_sal["Spirit-star analysis<br/>[sin_sal.ts]"]
  node_wuxing["Five elements<br/>[wuxing.ts]"]
  node_cache["Saju cache"]
end

subgraph group_interpretation["Interpretation"]
  node_interpretation["School interpretation"]
  node_school_compare["School comparison"]
  node_settings["Interpretation settings"]
  node_yongsin["Yong-sin selection<br/>[selector.ts]"]
  node_yongsin_base["Yong-sin algorithms<br/>[base.ts]"]
end

node_client(("MCP client"))

node_client -->|"requests tools"| node_server
node_server -->|"routes calls"| node_router
node_router -->|"dispatches to"| node_toolset
node_toolset -->|"exports handler"| node_analyze
node_toolset -->|"exports handler"| node_compatibility_tool
node_toolset -->|"exports handler"| node_calendar_tool
node_toolset -->|"exports handler"| node_period_tool
node_analyze -->|"calculates chart"| node_saju
node_analyze -->|"analyzes fortune"| node_fortune
node_analyze -->|"selects method"| node_yongsin
node_analyze -->|"compares schools"| node_school_compare
node_analyze -->|"reads settings"| node_settings
node_compatibility_tool -->|"analyzes pair"| node_compatibility
node_compatibility_tool -->|"calculates charts"| node_saju
node_calendar_tool -->|"converts dates"| node_calendar_logic
node_period_tool -->|"calculates chart"| node_saju
node_period_tool -->|"queries periods"| node_period_logic
node_saju -->|"queries terms"| node_solar_terms
node_saju -->|"adjusts birth time"| node_date_utils
node_saju -->|"calculates distribution"| node_ten_gods
node_saju -->|"finds stars"| node_sin_sal
node_saju -->|"uses cache key"| node_cache
node_date_utils -->|"reads longitude"| node_longitude
node_solar_terms -->|"queries year data"| node_solar_data
node_calendar_logic -->|"uses lunar table"| node_lunar_data
node_calendar_logic -->|"uses term data"| node_solar_terms
node_fortune -->|"uses analysis"| node_ten_gods
node_fortune -->|"uses analysis"| node_sin_sal
node_fortune -->|"uses elements"| node_wuxing
node_school_compare -.->|"compares readings"| node_interpretation
node_yongsin -->|"uses algorithms"| node_yongsin_base

click node_server "https://github.com/hjsh200219/fortuneteller/blob/main/src/core/server.ts"
click node_router "https://github.com/hjsh200219/fortuneteller/blob/main/src/core/tool-handler.ts"
click node_toolset "https://github.com/hjsh200219/fortuneteller/tree/main/src/tools"
click node_analyze "https://github.com/hjsh200219/fortuneteller/blob/main/src/tools/analyze_saju.ts"
click node_compatibility_tool "https://github.com/hjsh200219/fortuneteller/blob/main/src/tools/check_compatibility.ts"
click node_calendar_tool "https://github.com/hjsh200219/fortuneteller/blob/main/src/tools/convert_calendar.ts"
click node_period_tool "https://github.com/hjsh200219/fortuneteller/blob/main/src/tools/get_fortune_by_period.ts"
click node_calendar_logic "https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/calendar.ts"
click node_lunar_data "https://github.com/hjsh200219/fortuneteller/blob/main/src/data/lunar_table_1900_2200.ts"
click node_solar_data "https://github.com/hjsh200219/fortuneteller/blob/main/src/data/solar_terms_1900_2200.ts"
click node_solar_terms "https://github.com/hjsh200219/fortuneteller/blob/main/src/data/solar_terms.ts"
click node_date_utils "https://github.com/hjsh200219/fortuneteller/blob/main/src/utils/date.ts"
click node_longitude "https://github.com/hjsh200219/fortuneteller/blob/main/src/data/longitude_table.ts"
click node_saju "https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/saju.ts"
click node_fortune "https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/fortune.ts"
click node_compatibility "https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/compatibility.ts"
click node_period_logic "https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/se_un.ts"
click node_ten_gods "https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/ten_gods.ts"
click node_sin_sal "https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/sin_sal.ts"
click node_wuxing "https://github.com/hjsh200219/fortuneteller/blob/main/src/data/wuxing.ts"
click node_interpretation "https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/school_interpreter.ts"
click node_school_compare "https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/school_comparator.ts"
click node_settings "https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/interpretation_settings.ts"
click node_yongsin "https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/yongsin/selector.ts"
click node_yongsin_base "https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/yongsin/base.ts"
click node_cache "https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/performance_cache.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_server,node_router,node_toolset,node_analyze,node_compatibility_tool,node_calendar_tool,node_period_tool,node_client toneBlue
class node_calendar_logic,node_lunar_data,node_solar_data,node_solar_terms,node_date_utils,node_longitude toneAmber
class node_saju,node_fortune,node_compatibility,node_period_logic,node_ten_gods,node_sin_sal,node_wuxing,node_cache toneMint
class node_interpretation,node_school_compare,node_settings,node_yongsin,node_yongsin_base toneRose
```

## Components

### MCP interface

- [MCP server](https://github.com/hjsh200219/fortuneteller/blob/main/src/core/server.ts): `src/core/server.ts`
- [Tool router](https://github.com/hjsh200219/fortuneteller/blob/main/src/core/tool-handler.ts): `src/core/tool-handler.ts`
- [Tool handlers](https://github.com/hjsh200219/fortuneteller/tree/main/src/tools): `src/tools`
- [Saju analysis tool](https://github.com/hjsh200219/fortuneteller/blob/main/src/tools/analyze_saju.ts): `src/tools/analyze_saju.ts`
- [Compatibility tool](https://github.com/hjsh200219/fortuneteller/blob/main/src/tools/check_compatibility.ts): `src/tools/check_compatibility.ts`
- [Calendar tool](https://github.com/hjsh200219/fortuneteller/blob/main/src/tools/convert_calendar.ts): `src/tools/convert_calendar.ts`
- [Period fortune tool](https://github.com/hjsh200219/fortuneteller/blob/main/src/tools/get_fortune_by_period.ts): `src/tools/get_fortune_by_period.ts`

### Calendar foundations

- [Calendar conversion](https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/calendar.ts): `src/lib/calendar.ts`
- [Lunar tables](https://github.com/hjsh200219/fortuneteller/blob/main/src/data/lunar_table_1900_2200.ts): `src/data/lunar_table_1900_2200.ts`
- [Solar-term tables](https://github.com/hjsh200219/fortuneteller/blob/main/src/data/solar_terms_1900_2200.ts): `src/data/solar_terms_1900_2200.ts`
- [Solar-term queries](https://github.com/hjsh200219/fortuneteller/blob/main/src/data/solar_terms.ts): `src/data/solar_terms.ts`
- [Birth time adjustment](https://github.com/hjsh200219/fortuneteller/blob/main/src/utils/date.ts): `src/utils/date.ts`
- [Longitude data](https://github.com/hjsh200219/fortuneteller/blob/main/src/data/longitude_table.ts): `src/data/longitude_table.ts`

### Saju analysis

- [Pillar calculation](https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/saju.ts): `src/lib/saju.ts`
- [Fortune analysis](https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/fortune.ts): `src/lib/fortune.ts`
- [Compatibility analysis](https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/compatibility.ts): `src/lib/compatibility.ts`
- [Period analysis](https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/se_un.ts): `src/lib/se_un.ts`
- [Ten-gods analysis](https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/ten_gods.ts): `src/lib/ten_gods.ts`
- [Spirit-star analysis](https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/sin_sal.ts): `src/lib/sin_sal.ts`
- [Five elements](https://github.com/hjsh200219/fortuneteller/blob/main/src/data/wuxing.ts): `src/data/wuxing.ts`
- [Saju cache](https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/performance_cache.ts): `src/lib/performance_cache.ts`

### Interpretation

- [School interpretation](https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/school_interpreter.ts): `src/lib/school_interpreter.ts`
- [School comparison](https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/school_comparator.ts): `src/lib/school_comparator.ts`
- [Interpretation settings](https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/interpretation_settings.ts): `src/lib/interpretation_settings.ts`
- [Yong-sin selection](https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/yongsin/selector.ts): `src/lib/yongsin/selector.ts`
- [Yong-sin algorithms](https://github.com/hjsh200219/fortuneteller/blob/main/src/lib/yongsin/base.ts): `src/lib/yongsin/base.ts`

### Other components

- **MCP client**

## Connections

- MCP client → MCP server: requests tools (evidence: `README.md`)
- MCP server → Tool router: routes calls (evidence: `src/core/server.ts`)
- Tool router → Tool handlers: dispatches to (evidence: `src/core/tool-handler.ts`)
- Tool handlers → Saju analysis tool: exports handler (evidence: `src/tools/index.ts`)
- Tool handlers → Compatibility tool: exports handler (evidence: `src/tools/index.ts`)
- Tool handlers → Calendar tool: exports handler (evidence: `src/tools/index.ts`)
- Tool handlers → Period fortune tool: exports handler (evidence: `src/tools/index.ts`)
- Saju analysis tool → Pillar calculation: calculates chart (evidence: `src/tools/analyze_saju.ts`)
- Saju analysis tool → Fortune analysis: analyzes fortune (evidence: `src/tools/analyze_saju.ts`)
- Saju analysis tool → Yong-sin selection: selects method (evidence: `src/tools/analyze_saju.ts`)
- Saju analysis tool → School comparison: compares schools (evidence: `src/tools/analyze_saju.ts`)
- Saju analysis tool → Interpretation settings: reads settings (evidence: `src/tools/analyze_saju.ts`)
- Compatibility tool → Compatibility analysis: analyzes pair (evidence: `src/tools/check_compatibility.ts`)
- Compatibility tool → Pillar calculation: calculates charts (evidence: `src/tools/check_compatibility.ts`)
- Calendar tool → Calendar conversion: converts dates (evidence: `src/tools/convert_calendar.ts`)
- Period fortune tool → Pillar calculation: calculates chart (evidence: `src/tools/get_fortune_by_period.ts`)
- Period fortune tool → Period analysis: queries periods (evidence: `src/tools/get_fortune_by_period.ts`)
- Pillar calculation → Solar-term queries: queries terms (evidence: `src/lib/saju.ts`)
- Pillar calculation → Birth time adjustment: adjusts birth time (evidence: `src/lib/saju.ts`)
- Pillar calculation → Ten-gods analysis: calculates distribution (evidence: `src/lib/saju.ts`)
- Pillar calculation → Spirit-star analysis: finds stars (evidence: `src/lib/saju.ts`)
- Pillar calculation → Saju cache: uses cache key (evidence: `src/lib/saju.ts`)
- Birth time adjustment → Longitude data: reads longitude (evidence: `src/utils/date.ts`)
- Solar-term queries → Solar-term tables: queries year data (evidence: `src/data/solar_terms.ts`)
- Calendar conversion → Lunar tables: uses lunar table
- Calendar conversion → Solar-term queries: uses term data
- Fortune analysis → Ten-gods analysis: uses analysis (evidence: `src/lib/fortune.ts`)
- Fortune analysis → Spirit-star analysis: uses analysis (evidence: `src/lib/fortune.ts`)
- Fortune analysis → Five elements: uses elements (evidence: `src/lib/fortune.ts`)
- School comparison → School interpretation: compares readings
- Yong-sin selection → Yong-sin algorithms: uses algorithms (evidence: `src/lib/yongsin/selector.ts`)
